Skip to content

Commit da3f33d

Browse files
committed
Adds cancel/push features to simple todo list
,x -> toggle task marked as canceled ,> -> toggle task marked as pushed Also added option for marking a task as done without a timestamp (because sometimes I mark it done way after I actually did it, but I don't care about the timestamp, but I also don't want an incorrect timestamp) ,d -> toggle task marked done, sans timestamp Also improved speed of marking task done w/ timestamp by using built-in strftime() instead of making system call to the system's date command. Minor change to the date format. The year portion is unecessary, and prefer a lowercase am/pm.
1 parent 43cfbf7 commit da3f33d

File tree

3 files changed

+69
-44
lines changed

3 files changed

+69
-44
lines changed

vim/unpublished/simple-todo-list/ftplugin/simple-todo-list.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ command! -buffer -complete=custom,STL_ListPagesComp -nargs=1 OpenPage call STL_O
1212

1313
command! -buffer FindPage call fzf#run(fzf#wrap({ 'sink': function('STL_OpenPageByName'), 'source':'note page list' }))
1414

15-
nnoremap <buffer> <silent> <Leader>m :call STL_ToggleTodoDone()<CR>
16-
nnoremap <buffer> <silent> <Leader>l :call STL_ToggleTodoLogged()<CR>
17-
nnoremap <buffer> <silent> <Leader>d :call STL_ToggleTodoDoneAndLogged()<CR>
18-
15+
nnoremap <buffer> <silent> <Leader>d :call STL_ToggleTodoDone(0)<CR>
16+
nnoremap <buffer> <silent> <Leader>m :call STL_ToggleTodoDone(1)<CR>
1917
nnoremap <buffer> <silent> <Leader>T :call STL_ToggleSectionTitle()<CR>
18+
nnoremap <buffer> <silent> <Leader>x :call STL_ToggleTodoCanceled()<CR>
19+
nnoremap <buffer> <silent> <Leader>> :call STL_ToggleTodoPushed()<CR>
2020
2121
nnoremap <buffer> <C-n> /^----<CR><CR>
2222
nnoremap <buffer> <C-p> ?^----<CR>n<CR>

vim/unpublished/simple-todo-list/plugin/simple-todo-list.vim

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
command Todo :e ~/.todo
22

3-
function STL_ToggleTodoLogged()
4-
let done_icon = ""
5-
let notdone_icon = ""
3+
let s:done_icon = ""
4+
let s:notdone_icon = ""
5+
let s:canceled_icon = ""
6+
let s:pushed_icon = ""
7+
8+
function s:now_timestamp()
9+
let timestamp = strftime("%b %e, %l:%M%p")
10+
let timestamp = substitute(timestamp, " ", " ", "g")
11+
let timestamp = substitute(timestamp, "AM", "am", "")
12+
let timestamp = substitute(timestamp, "PM", "pm", "")
13+
return timestamp
14+
endfunction
15+
16+
function STL_ToggleTodoDone(include_timestamp)
617
let save_cursor = getpos(".")
718

819
" FML this didn't work for multibyte char
@@ -11,28 +22,33 @@ function STL_ToggleTodoLogged()
1122
normal! "lyl
1223
let first_char = @l
1324

14-
if first_char == done_icon
15-
" Move to log
16-
normal! dd
17-
call search("DONE LOG")
18-
normal! jp
25+
if first_char == s:done_icon
26+
" Mark as not done
27+
s/ \[.*\]//e
28+
execute "normal! xi".s:notdone_icon
29+
30+
elseif first_char == s:notdone_icon
31+
" Mark as done
32+
if a:include_timestamp
33+
execute "normal! xi".s:done_icon." [".s:now_timestamp()."]"
34+
else
35+
execute "normal! xi".s:done_icon
36+
endif
37+
38+
elseif first_char == s:canceled_icon
39+
execute "normal! xi".s:notdone_icon
1940

20-
elseif first_char == notdone_icon
21-
" Move to todo list
22-
normal! dd
23-
call search("TODO LIST", "b")
24-
normal! jp
41+
elseif first_char == s:pushed_icon
42+
execute "normal! xi".s:notdone_icon
2543

2644
else
27-
" do nothing
45+
execute "normal! i".s:notdone_icon." "
2846
end
2947

3048
call setpos('.', save_cursor)
3149
endfunction
3250

33-
function STL_ToggleTodoDone()
34-
let done_icon = ""
35-
let notdone_icon = ""
51+
function STL_ToggleTodoCanceled()
3652
let save_cursor = getpos(".")
3753

3854
" FML this didn't work for multibyte char
@@ -41,27 +57,33 @@ function STL_ToggleTodoDone()
4157
normal! "lyl
4258
let first_char = @l
4359

44-
if first_char == done_icon
45-
" Mark as not done
46-
s/ \[.*\]//
47-
execute "normal! xi".notdone_icon
48-
49-
elseif first_char == notdone_icon
50-
" Mark as done
51-
let date_command = "date ".shellescape("+%h %d, %Y %l:%M%p")
52-
let timestamp = substitute(system(date_command), "\n", "", "")
53-
execute "normal! xi".done_icon." [".timestamp."]"
54-
60+
if first_char != s:canceled_icon
61+
" Mark canceled
62+
execute "normal! xi".s:canceled_icon
5563
else
56-
execute "normal! i".notdone_icon." "
64+
execute "normal! xi".s:notdone_icon
5765
end
5866

5967
call setpos('.', save_cursor)
6068
endfunction
6169

62-
function STL_ToggleTodoDoneAndLogged()
63-
call STL_ToggleTodoDone()
64-
call STL_ToggleTodoLogged()
70+
function STL_ToggleTodoPushed()
71+
let save_cursor = getpos(".")
72+
73+
" FML this didn't work for multibyte char
74+
" let first_char = getline('.')[col('.')-1]
75+
normal! ^
76+
normal! "lyl
77+
let first_char = @l
78+
79+
if first_char != s:pushed_icon
80+
" Mark canceled
81+
execute "normal! xi".s:pushed_icon
82+
else
83+
execute "normal! xi".s:notdone_icon
84+
end
85+
86+
call setpos('.', save_cursor)
6587
endfunction
6688

6789
function STL_ToggleSectionTitle()

vim/unpublished/simple-todo-list/syntax/simple-todo-list.vim

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ endif
1010
syntax sync fromstart
1111
set foldmethod=syntax
1212

13-
1413
syn region simpleTodoSection start=/^[^-].\+\n----\+$/ end=/\n[^-].\+\n----\+$/me=s-1 keepend contains=simpleTodoTitle,simpleTodoBody
15-
syn region simpleTodoBody start=/./ end=/__nothing_matches__/ contained fold contains=simpleTodoTaskOpen,simpleTodoTaskDone
16-
syn match simpleTodoTaskOpen /^ *❒ .\+$/ contained
17-
syn match simpleTodoTaskDone /^ *✔ .\+$/ contained
14+
syn region simpleTodoBody start=/./ end=/__nothing_matches__/ contained fold contains=simpleTodoTaskOpen,simpleTodoTaskDone,simpleTodoTaskCanceled,simpleTodoTaskPushed
15+
syn match simpleTodoTaskOpen /^ *❒ .\+$/ contained
16+
syn match simpleTodoTaskDone /^ *✔ .\+$/ contained
17+
syn match simpleTodoTaskCanceled /^ *✘ .\+$/ contained
18+
syn match simpleTodoTaskPushed /^ *⍄ .\+$/ contained
1819
syn region simpleTodoTitle start=/^[^-].\+\n\z\(----\+$\)/ end=/^\z1/ contained
1920

20-
hi def link simpleTodoBody Normal
21-
hi def link simpleTodoTitle PreProc
22-
hi def link simpleTodoTaskOpen Function
23-
hi def link simpleTodoTaskDone Type
21+
hi def link simpleTodoBody Normal
22+
hi def link simpleTodoTitle PreProc
23+
hi def link simpleTodoTaskOpen Function
24+
hi def link simpleTodoTaskDone Type
25+
hi def link simpleTodoTaskCanceled Comment
26+
hi def link simpleTodoTaskPushed Comment
2427

2528
let b:current_syntax = "simple-todo"

0 commit comments

Comments
 (0)