When sorting on priority, sort also on projects and contexts
After pressing <leader>s, todo.vim used to sort all lines alphabetically. This caused tasks related to different projects to be placed apart from each other - the whole list was then difficult to follow. This patch fixes this by taking into account the fact that :sort in vim is usually stable (see http://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so that when we sort first on contexts, then on projects and then on priority, everything is placed in the order we want.
This commit is contained in:
@@ -64,10 +64,18 @@ function! TodoTxtRemoveCompleted()
|
|||||||
:g/^x /call add(l:completed, getline(line(".")))|d
|
:g/^x /call add(l:completed, getline(line(".")))|d
|
||||||
call s:AppendToFile(l:done_file, l:completed)
|
call s:AppendToFile(l:done_file, l:completed)
|
||||||
endfunction
|
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
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Mappings {{{1
|
" Mappings {{{1
|
||||||
" Sort tasks {{{2
|
" Sort tasks {{{2
|
||||||
if !hasmapto("<leader>s",'n')
|
if !hasmapto("<leader>s",'n')
|
||||||
nnoremap <script> <silent> <buffer> <leader>s :call TodoTxtSort()<CR>
|
nnoremap <script> <silent> <buffer> <leader>s :call TodoTxtSort()<CR>
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user