mirror of
https://github.com/freitass/todo.txt-vim.git
synced 2025-11-13 20:33:46 -05:00
Implemented sorting on visual selection.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user