forked from tagtime/TagTime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.vim.template
151 lines (124 loc) · 3.74 KB
/
tasks.vim.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"These macros call the external script tskproc.pl
set nocompatible
"Append a marker, prepend a '!', filter thru tskproc, remove marker.
fun! ToggleTask()
let col = col(".")
if getline(".") =~ "^X "
let col = col - 2
endif
normal A TIMEPIFVR
normal 0i!
silent execute ":%!./tskproc.pl"
call search("TIMEPIFVR", "")
execute ":.s/\\s*TIMEPIFVR\\s*/ /"
if getline(".") =~ "^X "
let col = col + 2
endif
call cursor(line("."), col)
execute ":w"
"echo "[SPC/RET toggles task, F5 sorts active tasks, +/- inserts new task]"
endfun
"Same as ToggleTask() but doesn't prepend '!' so doesn't toggle current task.
fun! SortActive()
let col = col(".")
normal A TIMEPIFVS
silent execute ":%!./tskproc.pl -sort"
call search("TIMEPIFVS", "")
execute ":.s/\\s*TIMEPIFVS\\s*/ /"
call cursor(line("."), col)
"echo "[active tasks sorted (u to undo)]"
endfun
"Make <enter> toggle task without changing how <enter> normally works.
fun! PressEnter()
if strlen(getline(".")) == col(".")
call ToggleTask()
normal o
else
normal lDo
normal p0
endif
endfun
"Pause task
fun! PauseTask()
if getline(".") =~ "PAUSE("
call ToggleTask()
return
endif
let col = col(".")
normal A TIMEPIFVR
normal 0f=iPAUSE()
call ToggleTask()
"execute ":%!./tskproc.pl"
call search("TIMEPIFVR", "")
execute ":.s/\\s*TIMEPIFVR\\s*/ /"
call cursor(line("."), col)
endfun
"Use enter or space to toggle tasks in normal mode.
map <silent> <cr> :call ToggleTask()<cr>
map <space> <cr>
"This makes <enter> toggle the task iff at eol in insert mode.
imap <silent> <cr> <esc>:call PressEnter()<cr>i
"F5 sorts the active tasks.
map <silent> <f5> :call SortActive()<cr>
imap <f5> <esc><f5>
"F6 pauses a task (TODO: just inserting the PAUSE() string for now)
map <silent> <f6> :call PauseTask()<cr>
imap <f6> <esc><f6>
map \ <f6>
"Go into insert mode at the top or bottom of the active tasks.
map + ggO
map - gg/----<cr>O
"---------------------------------------------------------------
"could put the following in a file and do, eg, source syntax.vim
" Vim syntax file for TagTime task editor
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
if version < 508
command! -nargs=+ HiLink hi link <args>
else
command! -nargs=+ HiLink hi def link <args>
endif
hi def tpGray ctermfg=Gray guifg=Gray ctermbg=Black guibg=Black
hi def tpWhite ctermfg=White guifg=White ctermbg=Black guibg=Black
syn case ignore
syn match tpEst "\~\S*"
syn match tpNum "^\d*"
syn match tpDiv "^\-\-\-\-.*"
syn match tpTag "\s\:\S*"
syn match tpTS "\d\d\d\d\d\d\d\d\d\d"hs=s+6
syn match tpTS1 "\s\zs\d\d\d\d\d\d"
syn match tpTS2 "\-\zs\d\d*"he=e-4
syn match tpElap "\s=\S*"
syn match tpDone "^X\s\d*"
syn match tpPaus "PAUSE("he=e-1
syn sync fromstart
"highlighting (Keyword, String, Type, Tag, Comment)
HiLink tpEst Type
HiLink tpDone String
HiLink tpNum Type
HiLink tpDiv Type
HiLink tpTag Tag
HiLink tpTS1 Comment
HiLink tpTS2 Comment
HiLink tpPaus Comment
HiLink tpElap String
let b:current_syntax = "tagtime"
delcommand HiLink
"---------------------------------------------------------------
"SCRATCH:
"this is nice, since who uses the tab key in normal text:
"imap <tab> <esc>
"this does what ToggleTask() does but all as a single macro:
":w<cr>:let g:tpcol = col(".")<cr>A TIMEPIFVR<ESC>I!<ESC>:%!./tskproc.pl<CR>/TIMEPIFVR<CR>:.s/\s*TIMEPIFVR\s*/ /<cr>:call cursor(line("."), g:tpcol)<cr>:echo "[SPC/RET toggles task, F5 sorts active tasks, +/- inserts new task]"<cr>
" WideMsg() prints [long] message up to (&columns-1) length
" guaranteed without "Press Enter" prompt.
function! WideMsg(msg)
let x=&ruler | let y=&showcmd
set noruler noshowcmd
redraw
echo a:msg
let &ruler=x | let &showcmd=y
endfun