mirror of
https://github.com/freitass/todo.txt-vim.git
synced 2025-11-16 22:03:38 -05:00
Sorting tasks by date.
This commit is contained in:
@@ -89,6 +89,10 @@ function! TodoTxtSortByProject() range
|
|||||||
function! TodoTxtSortByProject() range
|
function! TodoTxtSortByProject() range
|
||||||
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
|
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! TodoTxtSortByDate() range
|
||||||
|
execute a:firstline . "," . a:lastline . "sort! /\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}/ r"
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Mappings {{{1
|
" Mappings {{{1
|
||||||
" Sort tasks {{{2
|
" Sort tasks {{{2
|
||||||
@@ -115,6 +119,14 @@ if !hasmapto("<leader>s+",'v')
|
|||||||
if !hasmapto("<leader>s+",'v')
|
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
|
||||||
|
|
||||||
|
if !hasmapto("<leader>sd",'n')
|
||||||
|
nnoremap <script> <silent> <buffer> <leader>sd :%call TodoTxtSortByDate()<CR>
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !hasmapto("<leader>sd",'v')
|
||||||
|
vnoremap <script> <silent> <buffer> <leader>sd :call TodoTxtSortByDate()<CR>
|
||||||
|
endif
|
||||||
|
|
||||||
" Increment and Decrement The Priority
|
" Increment and Decrement The Priority
|
||||||
:set nf=octal,hex,alpha
|
:set nf=octal,hex,alpha
|
||||||
|
|||||||
5
test/tc_sort_date.todo.txt
Normal file
5
test/tc_sort_date.todo.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# lorem_ipsum
|
||||||
|
(B) 2013-03-15 2015-03-17
|
||||||
|
(A) 2012-04-16 2015-04-16
|
||||||
|
(B) 2013-03-16 2013-03-10
|
||||||
|
# end_lorem_ipsum
|
||||||
18
test/tc_sort_date.vim
Normal file
18
test/tc_sort_date.vim
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
let s:here = expand('<sfile>:p:h')
|
||||||
|
let s:tc = unittest#testcase#new('Sort Date',
|
||||||
|
\ { 'data': s:here . '/tc_sort_date.todo.txt' })
|
||||||
|
|
||||||
|
let s:LEADER = mapleader
|
||||||
|
|
||||||
|
let s:SORTED_TASKS = [
|
||||||
|
\ '(B) 2013-03-16 2013-03-10',
|
||||||
|
\ '(B) 2013-03-15 2015-03-17',
|
||||||
|
\ '(A) 2012-04-16 2015-04-16',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
function! s:tc.test_sort_by_context()
|
||||||
|
call self.data.visual_execute('call TodoTxtSortByDate()', 'lorem_ipsum')
|
||||||
|
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
unlet s:tc
|
||||||
Reference in New Issue
Block a user