diff options
author | David Beniamine <david@beniamine.net> | 2019-01-23 11:00:28 +0100 |
---|---|---|
committer | David Beniamine <david@beniamine.net> | 2019-01-23 11:00:28 +0100 |
commit | a2090399fb2a7a7da37d3acc4ec9f4c8d36767af (patch) | |
tree | ea09e3a25d3e3d78e3d13692b956f247047fdc26 | |
parent | 93480dd2c7981f58f047593b1cdf30d08d79c783 (diff) | |
download | todo.txt-vim-a2090399fb2a7a7da37d3acc4ec9f4c8d36767af.zip |
Keep cursor pos on sorting see #33
-rw-r--r-- | autoload/todo.vim | 10 | ||||
-rw-r--r-- | ftplugin/todo.vim | 6 |
2 files changed, 9 insertions, 7 deletions
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 <script> <silent> <buffer> <localleader>spc :call todo#HierarchicalSort('+', '@',1)<CR> " Sort tasks {{{3 - nnoremap <script> <silent> <buffer> <localleader>s :call todo#Sort()<CR> - nnoremap <script> <silent> <buffer> <localleader>s@ :sort /.\{-}\ze@/ <CR> - nnoremap <script> <silent> <buffer> <localleader>s+ :sort /.\{-}\ze+/ <CR> + nnoremap <script> <silent> <buffer> <localleader>s :call todo#Sort("")<CR> + nnoremap <script> <silent> <buffer> <localleader>s@ :call todo#Sort("@")<CR> + nnoremap <script> <silent> <buffer> <localleader>s+ :call todo#Sort("+")<CR> " Priorities {{{3 " TODO: Make vim-repeat work on inc/dec priority |