diff --git a/README.markdown b/README.markdown index 7239a42..ecbdfc5 100644 --- a/README.markdown +++ b/README.markdown @@ -31,7 +31,7 @@ This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files. `-X` : Mark all tasks as completed -`-D` : Remove completed tasks +`-D` : Move completed tasks to done.txt If you want the help installed, run ":helptags ~/.vim/doc" inside vim after having copied the files. Then you will be able to get the commands help with: :h todo.txt diff --git a/doc/todo.txt b/doc/todo.txt index 1a04834..30b6c5f 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -27,6 +27,6 @@ COMMANDS *todo-commands* `-X` : Mark all tasks as completed -`-D` : Remove completed tasks +`-D` : Move completed tasks to done.txt is \ by default, so -s means you type \s diff --git a/Todo.txt b/done.txt similarity index 91% rename from Todo.txt rename to done.txt index 5d904a1..a3e8325 100644 --- a/Todo.txt +++ b/done.txt @@ -1,4 +1,3 @@ -2014-11-01 Find a way to import text into markdown and vim doc @doc x 2011-05-30 Create README.markdown to be published in github @doc x 2011-05-30 Implement colorized priorities @syntax x 2011-05-30 Implement filetype detection @ftdetect diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index dce3bb2..132f9c9 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -35,8 +35,33 @@ 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() - :g/^x /d + " 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 " Mappings {{{1 diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..73a3f3c --- /dev/null +++ b/todo.txt @@ -0,0 +1 @@ +2014-11-01 Find a way to import text into markdown and vim doc @doc