diff --git a/autoload/todo.vim b/autoload/todo.vim index 4e1ebe8..d3026d7 100644 --- a/autoload/todo.vim +++ b/autoload/todo.vim @@ -153,17 +153,19 @@ function! todo#RemoveCompleted() call s:AppendToFile(l:done_file, l:completed) endfunction -function! todo#Sort() +function! todo#Sort(type) " vim :sort is usually stable " we sort first on contexts, then on projects and then on priority let g:Todo_fold_char='x' - if expand('%')=~'[Dd]one.*.txt' + let oldcursor=todo#GetCurpos() + if(a:type != "") + exec ':sort /.\{-}\ze'.a:type.'/' + elseif expand('%')=~'[Dd]one.*.txt' " FIXME: Put some unit tests around this, and fix case sensitivity if ignorecase is set. silent! %s/\(x\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g sort n /^x\s*/ silent! %s/\(x\s*\d\{4}\)\(\d\{2}\)/\1-\2-/g else - let oldcursor=getpos(".") silent normal gg let l:first=search('^\s*x') if l:first != 0 @@ -193,8 +195,8 @@ function! todo#Sort() execute ':'.l:first.','.l:last.'sort /+[a-zA-Z]*/ r' execute ':'.l:first.','.l:last.'sort /\v([A-Z])/ r' endif - call cursor(oldcursor) endif + call setpos('.', oldcursor) endfunction function! todo#SortDue() diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index 5949e7b..2131475 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -49,9 +49,9 @@ if !exists("g:Todo_txt_do_not_map") || ! g:Todo_txt_do_not_map noremap