From cf10a3b0b80a3be78a124bafad942ee554c3af7e Mon Sep 17 00:00:00 2001 From: David Beniamine Date: Sun, 5 Jul 2015 13:17:50 +0200 Subject: [PATCH] better due date sorting and due compeltion --- README.markdown | 4 +++- ftplugin/todo.vim | 31 ++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.markdown b/README.markdown index 53948af..e07bac1 100644 --- a/README.markdown +++ b/README.markdown @@ -32,7 +32,7 @@ This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files. `s@` : Sort the file on @Contexts -`-sd` : Sort @_sched entries by due-date +`-sd` : Sort the file by due-date `j` : Lower the priority of the current line @@ -48,6 +48,8 @@ This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files. `date` : (Insert mode) Insert the current date +`due:` : (Insert mode) Insert 'due:' followed by the current date + `x` : Toggle mark task as done (inserts current date as completion date) `X` : Mark all tasks as completed diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index e5b2108..3cc51d8 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -79,15 +79,28 @@ endfunction function! TodoTxtSort() " vim :sort is usually stable " we sort first on contexts, then on projects and then on priority - :sort /@[a-zA-Z]*/ r - :sort /+[a-zA-Z]*/ r - :sort /\v\([A-Z]\)/ r + sort /@[a-zA-Z]*/ r + ssort /+[a-zA-Z]*/ r + sort /\v\([A-Z]\)/ r endfunction function! TodoTxtSortDue() - :silent! %s/\(due:\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g - :sort! n /due:/ - :silent! %s/\(due:\d\{4}\)\(\d\{2}\)/\1-\2-/g + silent! %s/\(due:\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g + " Sort adding entries with due dates add the beginning + sort n /due:/ + " Count the number of lines + silent normal gg + execute "/due:" + let l:first=getpos(".")[1] + silent normal N + let l:last=getpos(".")[1] + let l:diff=l:last-l:first+1 + " Put the sorted lines at the beginning of the file + execute ':'.l:first + execute ':d'.l:diff + silent normal gg + silent normal P + silent! %s/\(due:\s*\d\{4}\)\(\d\{2}\)/\1-\2-/g " TODO: add time sorting (YYYY-MM-DD HH:MM) endfunction @@ -188,6 +201,10 @@ if !hasmapto("date",'i') inoremap