6 Commits
v0.7 ... v0.7.2

Author SHA1 Message Date
David Beniamine
6a103f1429 v0.7.2 2015-07-08 09:53:02 +02:00
David Beniamine
9f87eec204 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
2015-07-08 09:48:12 +02:00
David Beniamine
53ad73ebda FIX hierarchical sort stability bug 2015-07-06 14:55:02 +02:00
David Beniamine
68a32427ab FIX: Todo Key detection
Fix bad detection of key: a couple key:value must not contain spaces foo: bar
was detected as a couple key:value while it shouldn't ...
2015-07-06 10:02:06 +02:00
David Beniamine
4da3c4ae12 Small bug fixes
FIX: Typo in sort function
FIX: Keyword completion
CHG: Sort done.txt by completion date
2015-07-05 16:41:58 +02:00
David Beniamine
e7dee69733 fix bad links in readme 2015-07-05 15:06:03 +02:00
6 changed files with 194 additions and 81 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](#complete) 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.
@@ -95,7 +97,7 @@ adding the next lines to your vimrc:
The TodoComplete function is designed to complete projects (starting by '+') The TodoComplete function is designed to complete projects (starting by '+')
and context (starting by '@'). If you use it on a regular word, it will do a and context (starting by '@'). If you use it on a regular word, it will do a
normal buffer completion. normal keyword completion (on all buffers).
If you try to complete a project, it will propose all projects in all open If you try to complete a project, it will propose all projects in all open
buffers and for each of them, it will show their context and the name of the 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.
@@ -120,8 +122,39 @@ 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.
Syntax highlighting for couples key:value Syntax highlighting for couples key:value
If the current buffer is a done.txt file, the basic sort sorts on completion
date.

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,35 +60,74 @@ g:Todo_txt_second_level_sort_mode
Defaults values are: Defaults values are:
g:Todo_txt_first_level_sort_mode="i" >
g:Todo_txt_second_level_sort_mode="i" g:Todo_txt_first_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
au filetype todo imap <buffer> + +<C-X><C-O>
" Auto complete projects " Auto complete contexts
au filetype todo imap <buffer> + +<C-X><C-O> au filetype todo imap <buffer> @ @<C-X><C-O>
<
" Auto complete contexts To force completed task to be moved to a file independently from the current
au filetype todo imap <buffer> @ @<C-X><C-O> 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*
The TodoComplete function is designed to complete projects (starting by '+') The TodoComplete function is designed to complete projects (starting by '+')
and context (starting by '@'). If you use it on a regular word, it will do a and context (starting by '@'). If you use it on a regular word, it will do a
normal buffer completion. normal keyword completion (on all buffers).
If you try to complete a project, it will propose all projects in all open If you try to complete a project, it will propose all projects in all open
buffers and for each of them, it will show their context and the name of the 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

@@ -3,8 +3,17 @@
" Author: David Beniamine <david@beniamine.net>, Leandro Freitas <freitass@gmail.com> " Author: David Beniamine <david@beniamine.net>, Leandro Freitas <freitass@gmail.com>
" License: Vim license " License: Vim license
" Website: http://github.com/dbeniamine/todo.txt-vim " Website: http://github.com/dbeniamine/todo.txt-vim
" Version: 0.7 " Version: 0.7.2
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

@@ -3,7 +3,7 @@
" Author: David Beniamine <David@Beniamine.net>, Leandro Freitas <freitass@gmail.com> " Author: David Beniamine <David@Beniamine.net>, Leandro Freitas <freitass@gmail.com>
" License: Vim license " License: Vim license
" Website: http://github.com/dbeniamine/todo.txt-vim " Website: http://github.com/dbeniamine/todo.txt-vim
" Version: 0.7 " Version: 0.7.2
" Save context {{{1 " Save context {{{1
let s:save_cpo = &cpo let s:save_cpo = &cpo
@@ -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,9 +85,15 @@ 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
if expand('%')=~'done.*.txt'
silent! %s/\(x\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
sort n /^x\s*/
silent! %s/\(x\s*\d\{4}\)\(\d\{2}\)/\1-\2-/g
else else
sort /@[a-zA-Z]*/ r sort /@[a-zA-Z]*/ r
sort /+[a-zA-Z]*/ r sort /+[a-zA-Z]*/ r
sort /\v\([A-Z]\)/ r
endif endif
endfunction endfunction
@@ -269,6 +281,24 @@ function! TodoFoldText()
\ . (v:foldend - v:foldstart + 1) \ . (v:foldend - v:foldstart + 1)
\ . ' Completed tasks ' \ . ' Completed tasks '
endfunction endfunction
" Simple keyword completion on all buffers
function! TodoKeywordComplete(base)
" Search for matchs
let res = []
for bufnr in range(1,bufnr('$'))
let lines=getbufline(bufnr,1,"$")
for line in lines
if line =~ a:base
" init temporary item
let item={}
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
call add(res,item)
endif
endfor
endfor
return res
endfunction
" Intelligent completion for projects and Contexts " Intelligent completion for projects and Contexts
fun! TodoComplete(findstart, base) fun! TodoComplete(findstart, base)
@@ -279,6 +309,9 @@ fun! TodoComplete(findstart, base)
let start -= 1 let start -= 1
endwhile endwhile
return start return start
else
if a:base !~ '^+' && a:base !~ '^@'
return TodoKeywordComplete(a:base)
endif endif
" Opposite sign " Opposite sign
let opp=a:base=~'+'?'@':'+' let opp=a:base=~'+'?'@':'+'
@@ -299,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
@@ -326,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

View File

@@ -3,7 +3,7 @@
" Author: David Beniamine <david@beniamine.net> " Author: David Beniamine <david@beniamine.net>
" Licence: Vim licence " Licence: Vim licence
" Website: http://github.com/dbeniamine/todo.txt.vim " Website: http://github.com/dbeniamine/todo.txt.vim
" Version: 0.7 " Version: 0.7.2
" vim: ts=4 sw=4 :help tw=78 cc=80 " vim: ts=4 sw=4 :help tw=78 cc=80
" These two variables are parameters for the successive calls the vim sort " These two variables are parameters for the successive calls the vim sort
@@ -32,7 +32,7 @@ if !hasmapto("<localleader>sp",'n')
noremap <localleader>sp :call Todo_txt_HierarchicalSort('+', '',1)<CR> noremap <localleader>sp :call Todo_txt_HierarchicalSort('+', '',1)<CR>
endif endif
if !hasmapto("<localleader>spc",'n') if !hasmapto("<localleader>spc",'n')
noremap <localleader>spc :call Todo_txt_HierarchicalSort('+', '@',0)<CR> noremap <localleader>spc :call Todo_txt_HierarchicalSort('+', '@',1)<CR>
endif endif
" This is a Hierarchical sort designed for todo.txt todo lists, however it " This is a Hierarchical sort designed for todo.txt todo lists, however it
@@ -63,42 +63,39 @@ function! Todo_txt_HierarchicalSort(symbol, symbolsub, dolastsort)
let l:linecount=str2nr(split(v:statusmsg)[7]) let l:linecount=str2nr(split(v:statusmsg)[7])
" Get all the groups names " Get all the groups names
let l:groups=GetGroups(a:symbol,0,l:linecount) let l:groups=GetGroups(a:symbol,1,l:linecount)
" Sort by groups " Sort by groups
execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/' execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/'
for l:g in l:groups for l:g in l:groups
let l:pat=a:symbol.l:g.'.*$'
normal gg
" Find the beginning of the group " Find the beginning of the group
execute '/'.a:symbol.l:g.'.*$' let l:groupBegin=search(l:pat,'c')
let l:groupBegin=getpos(".")[1]
" Find the end of the group " Find the end of the group
silent normal N let l:groupEnd=search(l:pat,'b')
let l:groupEnd=getpos(".")[1]
" I'm too lazy to sort one groups of one line " I'm too lazy to sort groups of one line
if(l:groupEnd==l:groupBegin) if(l:groupEnd==l:groupBegin)
continue continue
endif endif
if a:dolastsort
if( a:symbolsub!='') if( a:symbolsub!='')
" Sort by subgroups " Sort by subgroups
let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd) let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd)
" Go before the first line of the group " Go before the first line of the group
" Sort the group using the second symbol " Sort the group using the second symbol
for l:sg in l:subgroups for l:sg in l:subgroups
normal gg
let l:pat=a:symbol.l:g.'.*'.a:symbolsub.l:sg.'.*$\|'.a:symbolsub.l:sg.'.*'.a:symbol.l:g.'.*$'
" Find the beginning of the subgroup " Find the beginning of the subgroup
execute '/'.a:symbol.l:g.'.*'.a:symbolsub.l:sg.'.*$\|'.a:symbolsub.l:sg.'.*'.a:symbol.l:g.'.*$' let l:subgroupBegin=search(l:pat,'c')
let l:subgroupBegin=getpos(".")[1]
" Find the end of the subgroup " Find the end of the subgroup
silent normal N let l:subgroupEnd=search(l:pat,'b')
let l:subgroupEnd=getpos(".")[1]
" Sort by priority " Sort by priority
if a:dolastsort
execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal
endif
endfor endfor
else else
" Sort by priority " Sort by priority
if a:dolastsort
execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal
endif endif
endif endif

View File

@@ -3,7 +3,7 @@
" Author: David Beniamine <David@Beniamine.net>,Leandro Freitas <freitass@gmail.com> " Author: David Beniamine <David@Beniamine.net>,Leandro Freitas <freitass@gmail.com>
" License: Vim license " License: Vim license
" Website: http://github.com/dbeniamine/todo.txt-vim " Website: http://github.com/dbeniamine/todo.txt-vim
" Version: 0.7 " Version: 0.7.2
if exists("b:current_syntax") if exists("b:current_syntax")
finish finish
@@ -37,7 +37,7 @@ syntax match TodoPriorityX '^([xX])\s.\+$' contains=TodoKey,TodoD
syntax match TodoPriorityY '^([yY])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext syntax match TodoPriorityY '^([yY])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityZ '^([zZ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext syntax match TodoPriorityZ '^([zZ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoDate '\d\{2,4\}-\d\{2\}-\d\{2\}' contains=NONE syntax match TodoDate '\d\{2,4\}-\d\{2\}-\d\{2\}' contains=NONE
syntax match TodoKey '\S*:\S*' contains=TodoDate syntax match TodoKey '\S*\S:\S\S*' contains=TodoDate
syntax match TodoProject '\(^\|\W\)+[^[:blank:]]\+' contains=NONE syntax match TodoProject '\(^\|\W\)+[^[:blank:]]\+' contains=NONE
syntax match TodoContext '\(^\|\W\)@[^[:blank:]]\+' contains=NONE syntax match TodoContext '\(^\|\W\)@[^[:blank:]]\+' contains=NONE