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
|
: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! 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
|
" Mappings {{{1
|
||||||
" Sort tasks {{{2
|
" 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>
|
vnoremap <script> <silent> <buffer> <leader>s :sort<CR>
|
||||||
endif
|
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>
|
vnoremap <script> <silent> <buffer> <leader>s@ :call TodoTxtSortByContext()<CR>
|
||||||
endif
|
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>
|
vnoremap <script> <silent> <buffer> <leader>s+ :call TodoTxtSortByProject()<CR>
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# lorem_ipsum
|
||||||
(B) Linear regression Rnet=Qh@Qle. @cons_emp_model
|
(B) Linear regression Rnet=Qh@Qle. @cons_emp_model
|
||||||
(B) Review key questions. @benchmarking
|
(B) Review key questions. @benchmarking
|
||||||
(A) simple model first @cons_emp_model
|
(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()
|
function! s:tc.test_sort_by_context()
|
||||||
execute 'normal ' . s:LEADER . 's@'
|
call self.data.visual_execute('call TodoTxtSortByContext()', 'lorem_ipsum')
|
||||||
execute 'normal ggO# lorem_ipsum'
|
|
||||||
execute 'normal Go# end_lorem_ipsum'
|
|
||||||
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# lorem_ipsum
|
||||||
(B) Linear regression Rnet=Qh+Qle. +cons_emp_model
|
(B) Linear regression Rnet=Qh+Qle. +cons_emp_model
|
||||||
(B) Review key questions. +benchmarking
|
(B) Review key questions. +benchmarking
|
||||||
(A) simple model first +cons_emp_model
|
(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()
|
function! s:tc.test_sort_by_project()
|
||||||
execute 'normal ' . s:LEADER . 's+'
|
call self.data.visual_execute('call TodoTxtSortByProject()', 'lorem_ipsum')
|
||||||
execute 'normal ggO# lorem_ipsum'
|
|
||||||
execute 'normal Go# end_lorem_ipsum'
|
|
||||||
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user