Implemented sorting on visual selection.

This commit is contained in:
Leandro Freitas
2015-04-16 20:25:58 -03:00
parent b8a5bd64ca
commit 639fcd85a2
5 changed files with 29 additions and 9 deletions

View File

@@ -81,18 +81,38 @@ function! TodoTxtRemoveCompleted()
:g/^x /call add(l:completed, getline(line(".")))|d
call s:AppendToFile(l:done_file, l:completed)
endfunction
function! TodoTxtSortByContext() range
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs@[^[:blank:]]\\+/ r"
endfunction
function! TodoTxtSortByProject() range
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
endfunction
" Mappings {{{1
" Sort tasks {{{2
if !hasmapto("<leader>s",'n')
if !hasmapto("<leader>s",'n')
nnoremap <script> <silent> <buffer> <leader>s :%sort<CR>
endif
if !hasmapto("<leader>s",'v')
vnoremap <script> <silent> <buffer> <leader>s :sort<CR>
endif
if !hasmapto("<leader>s@",'n')
if !hasmapto("<leader>s@",'n')
nnoremap <script> <silent> <buffer> <leader>s@ :%call TodoTxtSortByContext()<CR>
endif
if !hasmapto("<leader>s@",'v')
vnoremap <script> <silent> <buffer> <leader>s@ :call TodoTxtSortByContext()<CR>
endif
if !hasmapto("<leader>s+",'n')
if !hasmapto("<leader>s+",'n')
nnoremap <script> <silent> <buffer> <leader>s+ :%call TodoTxtSortByProject()<CR>
endif
if !hasmapto("<leader>s+",'v')
vnoremap <script> <silent> <buffer> <leader>s+ :call TodoTxtSortByProject()<CR>
endif

View File

@@ -1,3 +1,5 @@
# lorem_ipsum
(B) Linear regression Rnet=Qh@Qle. @cons_emp_model
(B) Review key questions. @benchmarking
(A) simple model first @cons_emp_model
# end_lorem_ipsum

View File

@@ -11,9 +11,7 @@ let s:SORTED_TASKS = [
\ ]
function! s:tc.test_sort_by_context()
execute 'normal ' . s:LEADER . 's@'
execute 'normal ggO# lorem_ipsum'
execute 'normal Go# end_lorem_ipsum'
call self.data.visual_execute('call TodoTxtSortByContext()', 'lorem_ipsum')
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
endfunction

View File

@@ -1,3 +1,5 @@
# lorem_ipsum
(B) Linear regression Rnet=Qh+Qle. +cons_emp_model
(B) Review key questions. +benchmarking
(A) simple model first +cons_emp_model
# end_lorem_ipsum

View File

@@ -11,9 +11,7 @@ let s:SORTED_TASKS = [
\ ]
function! s:tc.test_sort_by_project()
execute 'normal ' . s:LEADER . 's+'
execute 'normal ggO# lorem_ipsum'
execute 'normal Go# end_lorem_ipsum'
call self.data.visual_execute('call TodoTxtSortByProject()', 'lorem_ipsum')
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
endfunction