Keep cursor pos on sorting see #33
This commit is contained in:
@@ -153,17 +153,19 @@ function! todo#RemoveCompleted()
|
|||||||
call s:AppendToFile(l:done_file, l:completed)
|
call s:AppendToFile(l:done_file, l:completed)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! todo#Sort()
|
function! todo#Sort(type)
|
||||||
" vim :sort is usually stable
|
" vim :sort is usually stable
|
||||||
" we sort first on contexts, then on projects and then on priority
|
" we sort first on contexts, then on projects and then on priority
|
||||||
let g:Todo_fold_char='x'
|
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.
|
" 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
|
silent! %s/\(x\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
|
||||||
sort n /^x\s*/
|
sort n /^x\s*/
|
||||||
silent! %s/\(x\s*\d\{4}\)\(\d\{2}\)/\1-\2-/g
|
silent! %s/\(x\s*\d\{4}\)\(\d\{2}\)/\1-\2-/g
|
||||||
else
|
else
|
||||||
let oldcursor=getpos(".")
|
|
||||||
silent normal gg
|
silent normal gg
|
||||||
let l:first=search('^\s*x')
|
let l:first=search('^\s*x')
|
||||||
if l:first != 0
|
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 /+[a-zA-Z]*/ r'
|
||||||
execute ':'.l:first.','.l:last.'sort /\v([A-Z])/ r'
|
execute ':'.l:first.','.l:last.'sort /\v([A-Z])/ r'
|
||||||
endif
|
endif
|
||||||
call cursor(oldcursor)
|
|
||||||
endif
|
endif
|
||||||
|
call setpos('.', oldcursor)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! todo#SortDue()
|
function! todo#SortDue()
|
||||||
|
|||||||
@@ -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>
|
noremap <script> <silent> <buffer> <localleader>spc :call todo#HierarchicalSort('+', '@',1)<CR>
|
||||||
|
|
||||||
" Sort tasks {{{3
|
" Sort tasks {{{3
|
||||||
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@ :sort /.\{-}\ze@/ <CR>
|
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+ :call todo#Sort("+")<CR>
|
||||||
|
|
||||||
" Priorities {{{3
|
" Priorities {{{3
|
||||||
" TODO: Make vim-repeat work on inc/dec priority
|
" TODO: Make vim-repeat work on inc/dec priority
|
||||||
|
|||||||
Reference in New Issue
Block a user