diff --git a/autoload/todo/txt.vim b/autoload/todo/txt.vim index feaad6e..e41dbc4 100644 --- a/autoload/todo/txt.vim +++ b/autoload/todo/txt.vim @@ -26,7 +26,10 @@ function! s:get_current_date() endfunction function! todo#txt#prepend_date() - execute 's/^\(([a-zA-Z]) \)\?/\1' . s:get_current_date() . ' /' + if exists('g:todo_existing_date') && g:todo_existing_date == 'n' + return + endif + execute 's/^\(([a-zA-Z]) \)\?\(\d\{2,4\}-\d\{2\}-\d\{2\} \)\?/\1' . s:get_current_date() . ' /' endfunction function! todo#txt#mark_as_done() diff --git a/doc/todo.txt b/doc/todo.txt index 078c0f7..b948a82 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,5 +1,11 @@ *todo.txt* +============================================================================== +CONTENTS *todo-contents* + + 1. Commands ........................... |todo-commands| + 2. Options ............................ |todo-options| + ============================================================================== COMMANDS *todo-commands* @@ -32,3 +38,17 @@ COMMANDS *todo-commands* `-D` : Move completed tasks to done.txt See :h for more information about the commands' prefix. + +============================================================================== +OPTIONS *todo-options* + + *'g:todo_existing_date'* +Specify the behavior of date insertion functions when the task already has a +date of creation: > + let g:todo_existing_date = 'n' +< + r - replace existing date (default) + n - do nothing + +=============================================================================== +vim:ft=help:et:ts=2:sw=2:sts=2:norl diff --git a/test/tc_date.todo.txt b/test/tc_date.todo.txt index 72966e4..a6d6eac 100644 --- a/test/tc_date.todo.txt +++ b/test/tc_date.todo.txt @@ -10,3 +10,15 @@ example task (A) Call Mom (B) Call Dad # end_date_after_priority_visual + +# existing_date_no_priority +2014-05-06 example task +# end_existing_date_no_priority + +# existing_date_after_priority +(A) 2014-05-06 Call Mom +# end_existing_date_after_priority + +# existing_date_do_nothing +2014-05-06 example task +# end_existing_date_do_nothing diff --git a/test/tc_date.vim b/test/tc_date.vim index 161ef59..fed665d 100644 --- a/test/tc_date.vim +++ b/test/tc_date.vim @@ -22,6 +22,10 @@ let s:DATE_INSERTED_AFTER_PRIORITY_VISUAL = [ \ '(B) ' . s:TODAY . ' Call Dad', \ ] +let s:DATE_INSERTED_DO_NOTHING = [ + \ '2014-05-06 example task', + \ ] + function! s:tc.test_insert_date_normal_mode() call self.data.goto('lorem_ipsum') call todo#txt#prepend_date() @@ -49,4 +53,21 @@ function! s:tc.test_insert_date_after_priority_visual_mode() call self.assert_equal(s:DATE_INSERTED_AFTER_PRIORITY_VISUAL, self.data.get('date_after_priority_visual')) endfunction +function! s:tc.test_insert_with_existing_date() + call self.data.execute('call todo#txt#prepend_date()', 'existing_date_no_priority') + call self.assert_equal(s:DATE_INSERTED, self.data.get('existing_date_no_priority')) +endfunction + +function! s:tc.test_insert_with_existing_date_and_priority() + call self.data.execute('call todo#txt#prepend_date()', 'existing_date_after_priority') + call self.assert_equal(s:DATE_INSERTED_AFTER_PRIORITY, self.data.get('existing_date_after_priority')) +endfunction + +function! s:tc.test_insert_with_existing_date_and_priority() + let g:todo_existing_date = 'n' + call self.data.execute('call todo#txt#prepend_date()', 'existing_date_do_nothing') + call self.assert_equal(s:DATE_INSERTED_DO_NOTHING, self.data.get('existing_date_do_nothing')) + unlet g:todo_existing_date +endfunction + unlet s:tc