mirror of
https://github.com/freitass/todo.txt-vim.git
synced 2025-11-18 06:43:37 -05:00
Resolves #17
This commit is contained in:
@@ -35,8 +35,33 @@ function! TodoTxtMarkAllAsDone()
|
||||
function! TodoTxtMarkAllAsDone()
|
||||
:g!/^x /:call TodoTxtMarkAsDone()
|
||||
endfunction
|
||||
|
||||
function! s:AppendToFile(file, lines)
|
||||
let l:lines = []
|
||||
|
||||
" Place existing tasks in done.txt at the beggining of the list.
|
||||
if filereadable(a:file)
|
||||
call extend(l:lines, readfile(a:file))
|
||||
endif
|
||||
|
||||
" Append new completed tasks to the list.
|
||||
call extend(l:lines, a:lines)
|
||||
|
||||
" Write to file.
|
||||
call writefile(l:lines, a:file)
|
||||
endfunction
|
||||
|
||||
function! TodoTxtRemoveCompleted()
|
||||
function! TodoTxtRemoveCompleted()
|
||||
" Check if we can write to done.txt before proceeding.
|
||||
let l:target_dir = expand('%:p:h')
|
||||
let l:done_file = l:target_dir.'/done.txt'
|
||||
if !filewritable(l:done_file) && !filewritable(l:target_dir)
|
||||
echoerr "Can't write to file 'done.txt'"
|
||||
return
|
||||
endif
|
||||
|
||||
let l:completed = []
|
||||
:g/^x /call add(l:completed, getline(line(".")))|d
|
||||
call s:AppendToFile(l:done_file, l:completed)
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user