2 " Description: Todo.txt filetype detection
3 " Author: Leandro Freitas <freitass@gmail.com>
5 " Website: http://github.com/freitass/todo.txt-vim
8 " Export Context Dictionary for unit testing {{{1
10 return matchstr(expand('<sfile>'), '<SNR>\d\+_')
12 let s:SID = s:get_SID()
15 function! todo#txt#__context__()
16 return { 'sid': s:SID, 'scope': s: }
20 function! s:remove_priority()
24 function! s:get_current_date()
25 return strftime('%Y-%m-%d')
28 function! todo#txt#prepend_date()
29 execute 'normal! I' . s:get_current_date() . ' '
32 function! todo#txt#replace_date()
33 let current_line = getline('.')
34 if (current_line =~ '^\(([a-zA-Z]) \)\?\d\{2,4\}-\d\{2\}-\d\{2\} ') &&
35 \ exists('g:todo_existing_date') && g:todo_existing_date == 'n'
38 execute 's/^\(([a-zA-Z]) \)\?\(\d\{2,4\}-\d\{2\}-\d\{2\} \)\?/\1' . s:get_current_date() . ' /'
41 function! todo#txt#mark_as_done()
42 call s:remove_priority()
43 call todo#txt#prepend_date()
47 function! todo#txt#mark_all_as_done()
48 :g!/^x /:call todo#txt#mark_as_done()
51 function! s:append_to_file(file, lines)
54 " Place existing tasks in done.txt at the beggining of the list.
55 if filereadable(a:file)
56 call extend(l:lines, readfile(a:file))
59 " Append new completed tasks to the list.
60 call extend(l:lines, a:lines)
63 call writefile(l:lines, a:file)
66 function! todo#txt#remove_completed()
67 " Check if we can write to done.txt before proceeding.
69 let l:target_dir = expand('%:p:h')
70 let l:todo_file = expand('%:p')
71 let l:done_file = substitute(substitute(l:todo_file, 'todo.txt$', 'done.txt', ''), 'Todo.txt$', 'Done.txt', '')
72 if !filewritable(l:done_file) && !filewritable(l:target_dir)
73 echoerr "Can't write to file 'done.txt'"
78 :g/^x /call add(l:completed, getline(line(".")))|d
79 call s:append_to_file(l:done_file, l:completed)
82 function! todo#txt#sort_by_context() range
83 execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs@[^[:blank:]]\\+/ r"
86 function! todo#txt#sort_by_project() range
87 execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
90 function! todo#txt#sort_by_date() range
91 let l:date_regex = "\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}"
92 execute a:firstline . "," . a:lastline . "sort /" . l:date_regex . "/ r"
93 execute a:firstline . "," . a:lastline . "g!/" . l:date_regex . "/m" . a:lastline
96 function! todo#txt#sort_by_due_date() range
97 let l:date_regex = "due:\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}"
98 execute a:firstline . "," . a:lastline . "sort /" . l:date_regex . "/ r"
99 execute a:firstline . "," . a:lastline . "g!/" . l:date_regex . "/m" . a:lastline
102 " Increment and Decrement The Priority
103 :set nf=octal,hex,alpha
105 function! todo#txt#prioritize_increase()
109 function! todo#txt#prioritize_decrease()
113 function! todo#txt#prioritize_add(priority)
114 " Need to figure out how to only do this if the first visible letter in a line is not (
115 :call todo#txt#prioritize_add_action(a:priority)
118 function! todo#txt#prioritize_add_action(priority)
119 execute 's/^\(([a-zA-Z]) \)\?/(' . a:priority . ') /'
123 " vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1