Skip to content

Commit 43cfbf7

Browse files
committed
Updates unpublished todo/note plugin
1 parent 8ef853c commit 43cfbf7

File tree

2 files changed

+98
-74
lines changed

2 files changed

+98
-74
lines changed

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

Lines changed: 11 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,86 +6,23 @@ if (exists("b:loaded_simpletodolugin"))
66
finish
77
endif
88

9-
function! ToggleTodoLogged()
10-
let done_icon = ""
11-
let notdone_icon = ""
12-
let save_cursor = getpos(".")
9+
command! -buffer -nargs=1 CreatePage call STL_CreateAndOpenPage(<f-args>)
1310

14-
" FML this didn't work for multibyte char
15-
" let first_char = getline('.')[col('.')-1]
16-
normal! ^
17-
normal! "lyl
18-
let first_char = @l
11+
command! -buffer -complete=custom,STL_ListPagesComp -nargs=1 OpenPage call STL_OpenPageByName(<f-args>)
1912

20-
if first_char == done_icon
21-
" Move to log
22-
normal! dd
23-
call search("DONE LOG")
24-
normal! jp
13+
command! -buffer FindPage call fzf#run(fzf#wrap({ 'sink': function('STL_OpenPageByName'), 'source':'note page list' }))
2514

26-
elseif first_char == notdone_icon
27-
" Move to todo list
28-
normal! dd
29-
call search("TODO LIST", "b")
30-
normal! jp
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>
3118
32-
else
33-
" do nothing
34-
end
35-
36-
call setpos('.', save_cursor)
37-
endfunction
38-
39-
function! ToggleTodoDone()
40-
let done_icon = ""
41-
let notdone_icon = ""
42-
let save_cursor = getpos(".")
43-
44-
" FML this didn't work for multibyte char
45-
" let first_char = getline('.')[col('.')-1]
46-
normal! ^
47-
normal! "lyl
48-
let first_char = @l
49-
50-
if first_char == done_icon
51-
" Mark as not done
52-
s/ \[.*\]//
53-
execute "normal! xi".notdone_icon
54-
55-
elseif first_char == notdone_icon
56-
" Mark as done
57-
let date_command = "date ".shellescape("+%h %d, %Y %l:%M%p")
58-
let timestamp = substitute(system(date_command), "\n", "", "")
59-
execute "normal! xi".done_icon." [".timestamp."]"
60-
61-
else
62-
execute "normal! i".notdone_icon." "
63-
end
64-
65-
call setpos('.', save_cursor)
66-
endfunction
67-
68-
function! ToggleTodoDoneAndLogged()
69-
call ToggleTodoDone()
70-
call ToggleTodoLogged()
71-
endfunction
72-
73-
function! ToggleSectionTitle()
74-
let regionName = synIDattr(synID(line("."), col("."), 0), "name")
75-
if regionName == "simpleTodoTitle"
76-
normal! jddk
77-
else
78-
normal! yypVr-k
79-
endif
80-
endfunction
81-
82-
nnoremap <buffer> <silent> <Leader>m :call ToggleTodoDone()<CR>
83-
nnoremap <buffer> <silent> <Leader>l :call ToggleTodoLogged()<CR>
84-
nnoremap <buffer> <silent> <Leader>d :call ToggleTodoDoneAndLogged()<CR>
85-
86-
nnoremap <buffer> <silent> <Leader>T :call ToggleSectionTitle()<CR>
19+
nnoremap <buffer> <silent> <Leader>T :call STL_ToggleSectionTitle()<CR>
8720
8821
nnoremap <buffer> <C-n> /^----<CR><CR>
8922
nnoremap <buffer> <C-p> ?^----<CR>n<CR>
9023
24+
nnoremap <buffer> <silent> <Leader>o :FindPage<CR>
25+
26+
set formatoptions+=t
27+
9128
let b:loaded_simpletodolugin = 1
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,88 @@
11
command Todo :e ~/.todo
2+
3+
function STL_ToggleTodoLogged()
4+
let done_icon = ""
5+
let notdone_icon = ""
6+
let save_cursor = getpos(".")
7+
8+
" FML this didn't work for multibyte char
9+
" let first_char = getline('.')[col('.')-1]
10+
normal! ^
11+
normal! "lyl
12+
let first_char = @l
13+
14+
if first_char == done_icon
15+
" Move to log
16+
normal! dd
17+
call search("DONE LOG")
18+
normal! jp
19+
20+
elseif first_char == notdone_icon
21+
" Move to todo list
22+
normal! dd
23+
call search("TODO LIST", "b")
24+
normal! jp
25+
26+
else
27+
" do nothing
28+
end
29+
30+
call setpos('.', save_cursor)
31+
endfunction
32+
33+
function STL_ToggleTodoDone()
34+
let done_icon = ""
35+
let notdone_icon = ""
36+
let save_cursor = getpos(".")
37+
38+
" FML this didn't work for multibyte char
39+
" let first_char = getline('.')[col('.')-1]
40+
normal! ^
41+
normal! "lyl
42+
let first_char = @l
43+
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+
55+
else
56+
execute "normal! i".notdone_icon." "
57+
end
58+
59+
call setpos('.', save_cursor)
60+
endfunction
61+
62+
function STL_ToggleTodoDoneAndLogged()
63+
call STL_ToggleTodoDone()
64+
call STL_ToggleTodoLogged()
65+
endfunction
66+
67+
function STL_ToggleSectionTitle()
68+
let regionName = synIDattr(synID(line("."), col("."), 0), "name")
69+
if regionName == "simpleTodoTitle"
70+
normal! jddk
71+
else
72+
normal! yypVr-k
73+
endif
74+
endfunction
75+
76+
function STL_ListPagesComp(ArgLead, CmdLine, CursorPos)
77+
return system("note page list")
78+
endfunction
79+
80+
function STL_CreateAndOpenPage(name)
81+
let filePath = system("note page create '" . a:name . "'")
82+
execute 'edit ' . filePath
83+
endfunction
84+
85+
function STL_OpenPageByName(name)
86+
execute 'edit ~/notebook/pages/' . a:name . '.todo.txt'
87+
endfunction
88+

0 commit comments

Comments
 (0)