]> git.sev.monster Git - dotfiles.git/blame_incremental - .vim/autoload/todo/txt.vim
initial commit
[dotfiles.git] / .vim / autoload / todo / txt.vim
... / ...
CommitLineData
1" File: todo.txt.vim
2" Description: Todo.txt filetype detection
3" Author: Leandro Freitas <freitass@gmail.com>
4" License: Vim license
5" Website: http://github.com/freitass/todo.txt-vim
6" Version: 0.4
7
8" Export Context Dictionary for unit testing {{{1
9function! s:get_SID()
10 return matchstr(expand('<sfile>'), '<SNR>\d\+_')
11endfunction
12let s:SID = s:get_SID()
13delfunction s:get_SID
14
15function! todo#txt#__context__()
16 return { 'sid': s:SID, 'scope': s: }
17endfunction
18
19" Functions {{{1
20function! s:remove_priority()
21 :s/^(\w)\s\+//ge
22endfunction
23
24function! s:get_current_date()
25 return strftime('%Y-%m-%d')
26endfunction
27
28function! todo#txt#prepend_date()
29 execute 'normal! I' . s:get_current_date() . ' '
30endfunction
31
32function! 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'
36 return
37 endif
38 execute 's/^\(([a-zA-Z]) \)\?\(\d\{2,4\}-\d\{2\}-\d\{2\} \)\?/\1' . s:get_current_date() . ' /'
39endfunction
40
41function! todo#txt#mark_as_done()
42 call s:remove_priority()
43 call todo#txt#prepend_date()
44 execute 'normal! Ix '
45endfunction
46
47function! todo#txt#mark_all_as_done()
48 :g!/^x /:call todo#txt#mark_as_done()
49endfunction
50
51function! s:append_to_file(file, lines)
52 let l:lines = []
53
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))
57 endif
58
59 " Append new completed tasks to the list.
60 call extend(l:lines, a:lines)
61
62 " Write to file.
63 call writefile(l:lines, a:file)
64endfunction
65
66function! todo#txt#remove_completed()
67 " Check if we can write to done.txt before proceeding.
68
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'"
74 return
75 endif
76
77 let l:completed = []
78 :g/^x /call add(l:completed, getline(line(".")))|d
79 call s:append_to_file(l:done_file, l:completed)
80endfunction
81
82function! todo#txt#sort_by_context() range
83 execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs@[^[:blank:]]\\+/ r"
84endfunction
85
86function! todo#txt#sort_by_project() range
87 execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
88endfunction
89
90function! 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
94endfunction
95
96function! 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
100endfunction
101
102" Increment and Decrement The Priority
103:set nf=octal,hex,alpha
104
105function! todo#txt#prioritize_increase()
106 normal! 0f)h\ 1
107endfunction
108
109function! todo#txt#prioritize_decrease()
110 normal! 0f)h\18
111endfunction
112
113function! 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)
116endfunction
117
118function! todo#txt#prioritize_add_action(priority)
119 execute 's/^\(([a-zA-Z]) \)\?/(' . a:priority . ') /'
120endfunction
121
122" Modeline {{{1
123" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1
This page took 0.027577 seconds and 4 git commands to generate.