From 507439112e34aa4eae32d7c3eedbf4ac5487ba62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= Date: Sun, 1 Feb 2015 15:34:59 +0100 Subject: [PATCH] When sorting on priority, sort also on projects and contexts After pressing 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. --- ftplugin/todo.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index 132f9c9..957060b 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -64,10 +64,18 @@ function! TodoTxtRemoveCompleted() 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("s",'n') - nnoremap