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:
Mateusz Jończyk
2015-02-01 15:34:59 +01:00
parent f07b2b2202
commit 507439112e

View File

@@ -64,10 +64,18 @@ function! TodoTxtRemoveCompleted()
:g/^x /call add(l:completed, getline(line(".")))|d
call s:AppendToFile(l:done_file, l:completed)
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
" Sort tasks {{{2
if !hasmapto("<leader>s",'n')
if !hasmapto("<leader>s",'n')
nnoremap <script> <silent> <buffer> <leader>s :call TodoTxtSort()<CR>
endif