More flexible file naming (Request #2)

CHG: More flexible file naming files matching one of the following are todo
files:
    YYYY-MM-[Tt]odo.txt
    YYYY-MM-DD[Tt]odo.txt
    [Tt]odo-YYYY-MM.txt
    [Tt]odo-YYYY-MM-DD.txt
    [Tt]odo.txt
    [Tt]oday.txt
    YYYY-MM-[Dd]one.txt
    YYYY-MM-DD[Dd]one.txt
    [Dd]one-YYYY-MM.txt
    [Dd]one-YYYY-MM-DD.txt
    [Dd]one.txt
    [Dd]one-[Tt]oday.txt
 Moreover, remove complete tasks (<LocalLeader>D) moves the task to the
 done.txt file corresponding to the current todo.txt, aka if you are editing
 2015-07-07-todo.txt, the done file while be 2015-07-07-done.txt.
 This behaviour can be cancelled by fixing the done filename using
 g:TodoTxtForceDoneName
FIX: Bug while completing empty file
This commit is contained in:
David Beniamine
2015-07-08 09:27:59 +02:00
parent 53ad73ebda
commit 9f87eec204
4 changed files with 144 additions and 58 deletions

View File

@@ -3,9 +3,11 @@
## What is this plugin ? ## What is this plugin ?
This plugin is a fork of [freitass This plugin is a fork of [freitass
todo.txt](https://github.com/freitass/todo.txt-vim). It add severals functionalities including a [hierarchical sort](#sort), a todo.txt](https://github.com/freitass/todo.txt-vim). It add severals
[complete](#completion) function, some stuff to handle [due dates](#due-dates) functionalities including a [hierarchical sort](#sort), a
and others stuff see [new features](#new-features). [complete](#completion) function, some stuff to handle [due
dates](#due-dates), a more [flexible file naming](#flexible-file-naming), and
others stuff see [new features](#new-features).
Freitass announced on october 30th 2014 that he is not going to merge his version. Freitass announced on october 30th 2014 that he is not going to merge his version.
@@ -120,6 +122,34 @@ sorted by at the beginning of the file, the rest of the file is not modified.
`DUE:` : (Insert mode) Insert `DUE:` followed by the current date `DUE:` : (Insert mode) Insert `DUE:` followed by the current date
### Flexible File naming
This plugin provides a Flexible file naming for todo.txt, all the following
names are recognized as todo:
YYYY-MM-[Tt]odo.txt
YYYY-MM-DD[Tt]odo.txt
[Tt]odo-YYYY-MM.txt
[Tt]odo-YYYY-MM-DD.txt
[Tt]odo.txt
[Tt]oday.txt
And obviously the same are recognize as done:
YYYY-MM-[Dd]one.txt
YYYY-MM-DD[Dd]one.txt
[Dd]one-YYYY-MM.txt
[Dd]one-YYYY-MM-DD.txt
[Dd]one.txt
[Dd]one-[Tt]oday.txt
Moreover, remove complete tasks `<LocalLeader>D` moves the task to the
done.txt file corresponding to the current todo.txt, aka if you are editing
2015-07-07-todo.txt, the done file while be 2015-07-07-done.txt. If you don't
like this behavior, you can set the default done.txt name:
let g:TodoTxtForceDoneName='done.txt'
### Others ### Others
`<LocalLeader>x` is a toggle which allow you to unmark a task as done. `<LocalLeader>x` is a toggle which allow you to unmark a task as done.

View File

@@ -45,9 +45,9 @@ sorted by at the beginning of the file, the rest of the file is not modified.
`<LocalLeader>X` : Mark all tasks as completed `<LocalLeader>X` : Mark all tasks as completed
`<LocalLeader>D` : Move completed tasks to done.txt `<LocalLeader>D` : Move completed tasks to done file, see |todo-flexibleFileNaming|
<LocalLeader> is \ by default, so <leader>-s means you type \s `<LocalLeader>` is \ by default, so ̀`<LocaLeader>-s` means you type \s
=============================================================================== ===============================================================================
CONFIGURATION *todo-configuration* CONFIGURATION *todo-configuration*
@@ -60,26 +60,35 @@ g:Todo_txt_second_level_sort_mode
Defaults values are: Defaults values are:
>
g:Todo_txt_first_level_sort_mode="i" g:Todo_txt_first_level_sort_mode="i"
g:Todo_txt_second_level_sort_mode="i" g:Todo_txt_second_level_sort_mode="i"
<
For more information on the available flags see help :sort For more information on the available flags see help :sort
We also provide a nice complete function for project and context, to use it We also provide a nice complete function for project and context, to use it
add the following lines to your vimrc: add the following lines to your vimrc:
>
" Use TodoComplete as the omni complete for todo files " Use TodoComplete as the omni complete for todo files
au filetype todo setlocal omnifunc=TodoComplete au filetype todo setlocal omnifunc=TodoComplete
<
You can also start automatically the completion when entering '+' or '@' by You can also start automatically the completion when entering '+' or '@' by
adding the next lines to your vimrc: adding the next lines to your vimrc:
>
" Auto complete projects " Auto complete projects
au filetype todo imap <buffer> + +<C-X><C-O> au filetype todo imap <buffer> + +<C-X><C-O>
" Auto complete contexts " Auto complete contexts
au filetype todo imap <buffer> @ @<C-X><C-O> au filetype todo imap <buffer> @ @<C-X><C-O>
<
To force completed task to be moved to a file independently from the current
file name, add the following to your vimrc:
>
let g:TodoTxtForceDoneName='done.txt'
<
For more explanations, see |todo-flexibleFileNaming|
=============================================================================== ===============================================================================
COMPLETION *todo-complete* COMPLETION *todo-complete*
@@ -92,3 +101,33 @@ buffers and for each of them, it will show their context and the name of the
buffers in which they appears in the preview window. buffers in which they appears in the preview window.
TodoCompelte does the same thing for context except that it gives in the TodoCompelte does the same thing for context except that it gives in the
preview the list of projects existing in each existing contexts. preview the list of projects existing in each existing contexts.
===============================================================================
FLEXIBLE FILE NAMING *todo-flexibleFileNaming*
This plugin provides a Flexible file naming for todo.txt, all the following
names are recognized as todo:
>
YYYY-MM-[Tt]odo.txt
YYYY-MM-DD[Tt]odo.txt
[Tt]odo-YYYY-MM.txt
[Tt]odo-YYYY-MM-DD.txt
[Tt]odo.txt
[Tt]oday.txt
<
And obviously the same are recognize as done:
>
YYYY-MM-[Dd]one.txt
YYYY-MM-DD[Dd]one.txt
[Dd]one-YYYY-MM.txt
[Dd]one-YYYY-MM-DD.txt
[Dd]one.txt
[Dd]one-[Tt]oday.txt
<
Moreover, remove complete tasks `<LocalLeader>D` moves the task to the
done.txt file corresponding to the current todo.txt, aka if you are editing
2015-07-07-todo.txt, the done file while be 2015-07-07-done.txt. If you don't
like this behavior, you can set the default done.txt name:
>
let g:TodoTxtForceDoneName='done.txt'
<

View File

@@ -6,5 +6,14 @@
" Version: 0.7 " Version: 0.7
autocmd BufNewFile,BufRead [Tt]odo.txt set filetype=todo autocmd BufNewFile,BufRead [Tt]odo.txt set filetype=todo
autocmd BufNewFile,BufRead [Tt]odo-\d\\\{4\}-\d\\\{2\}-\d\\\{2\}.txt set filetype=todo
autocmd BufNewFile,BufRead [Tt]odo-\d\\\{4\}-\d\\\{2\}.txt set filetype=todo
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-\d\\\{2\}-[Tt]odo.txt set filetype=todo
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-[Tt]odo.txt set filetype=todo
autocmd BufNewFile,BufRead [Tt]oday.txt set filetype=todo
autocmd BufNewFile,BufRead [Dd]one.txt set filetype=todo autocmd BufNewFile,BufRead [Dd]one.txt set filetype=todo
autocmd BufNewFile,BufRead [Dd]one-\d\\\{4\}-\d\\\{2\}-\d\\\{2\}.txt set filetype=todo
autocmd BufNewFile,BufRead [Dd]one-\d\\\{4\}-\d\\\{2\}.txt set filetype=todo
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-\d\\\{2\}-[Dd]one.txt set filetype=todo
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-[Dd]one.txt set filetype=todo
autocmd BufNewFile,BufRead [Dd]one-[Tt]oday.txt set filetype=todo

View File

@@ -65,7 +65,13 @@ endfunction
function! TodoTxtRemoveCompleted() function! TodoTxtRemoveCompleted()
" Check if we can write to done.txt before proceeding. " Check if we can write to done.txt before proceeding.
let l:target_dir = expand('%:p:h') let l:target_dir = expand('%:p:h')
if exists("g:TodoTxtForceDoneName")
let l:done=g:TodoTxtForceDoneName
else
let l:done=substitute(substitute(expand('%:t'),'todo','done',''),'Todo','Done','')
fi
let l:done_file = l:target_dir.'/'.l:done
echo "Writing to ".l:done_file echo "Writing to ".l:done_file
if !filewritable(l:done_file) && !filewritable(l:target_dir) if !filewritable(l:done_file) && !filewritable(l:target_dir)
echoerr "Can't write to file 'done.txt'" echoerr "Can't write to file 'done.txt'"
@@ -79,7 +85,7 @@ endfunction
function! TodoTxtSort() function! TodoTxtSort()
" vim :sort is usually stable " vim :sort is usually stable
" we sort first on contexts, then on projects and then on priority " we sort first on contexts, then on projects and then on priority
if expand('%')=~'done.*.txt' if expand('%')=~'done.*.txt'
silent! %s/\(x\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g silent! %s/\(x\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
sort n /^x\s*/ sort n /^x\s*/
@@ -326,6 +332,7 @@ fun! TodoComplete(findstart, base)
endfor endfor
call sort(res) call sort(res)
" Here all results are sorted in res, but we need to merge them " Here all results are sorted in res, but we need to merge them
let ret=[]
if res != [] if res != []
let curitem={} let curitem={}
let curitem.word=res[0].word let curitem.word=res[0].word
@@ -353,6 +360,7 @@ fun! TodoComplete(findstart, base)
let curitem.related=[it.related] let curitem.related=[it.related]
let curitem.buffers=[it.buffers] let curitem.buffers=[it.buffers]
endif endif
endfor
endif endif
return ret return ret
endif endif