17 Commits
v0.6 ... v0.7.3

Author SHA1 Message Date
David Beniamine
f9715af4a4 move hierarchical sort to auto start
Note: because of this, TodoComplete is now known as todo#Complete, you might
need to update your vimrc.
2015-08-22 18:39:59 +02:00
David Beniamine
ab4ecf5220 FIX: sort done.txt 2015-07-08 11:04:55 +02:00
David Beniamine
dc4bb8e856 Fix: vimscript is not bash 2015-07-08 11:00:54 +02:00
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
David Beniamine
73ba0effca Small improvements on due dates + key:value
ADD: syntax highlight for couples key:value
ADD: Handle DUE:date
CHG: No space between due: and date
CHG: Doc updated
2015-07-05 15:00:07 +02:00
David Beniamine
cf10a3b0b8 better due date sorting and due compeltion 2015-07-05 13:17:50 +02:00
David Beniamine
e49cc7d595 Incorporated due date workaround from durcheinandr 2015-07-05 12:29:02 +02:00
David Beniamine
7bca6726ea Recommand buffer mapping for completion 2015-06-12 15:24:23 +02:00
durcheinandr
eb5ece482d shorten short due date function 2015-05-27 16:24:48 +02:00
durcheinandr
eb6d973887 last fix for sorting due dates 2015-05-27 05:56:52 +02:00
durcheinandr
84c815bb21 fixed sorting by due-date 2015-05-26 19:50:37 +02:00
durcheinandr
1b49ec094c here we go 2015-05-25 23:57:26 +02:00
7 changed files with 575 additions and 372 deletions

View File

@@ -1,10 +1,18 @@
# Readme
**Note:** Since v0.7.3, `TodoComplete` is `todo#Complete`, you might need to
update your vimrc.
## What is this plugin ?
This plugin is a fork of freitass todo.txt (see section 1.3) vim plugin adding
a nice two level sorting function designed for todo.txt files and a complete
function for context and projects (see section 1.4).
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
[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.
## Install
@@ -14,10 +22,17 @@ function for context and projects (see section 1.4).
cd todo.txt-vim
cp -r ./* ~/.vim
If you want the help installed, run `:helptags ~/.vim/doc` inside vim after
having copied the files. Then you will be able to get the commands help with:
`:h todo.txt`
### Pathogen install
git clone https://github.com/dbeniamine/todo.txt-vim.git ~/.vim/bundle/todo.txt-vim
Then from vim: `:Helptags` to update the doc
## Features included in Freitass version
This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files. It also defines a few mappings, to help with editing these files:
@@ -48,11 +63,10 @@ This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files.
`<leader>-D` : Move completed tasks to done.txt
If you want the help installed, run ":helptags ~/.vim/doc" inside vim after having copied the files.
Then you will be able to get the commands help with: :h todo.txt
## New features
### Sort
This fork provides a hierarchical sorting function designed to do by project
and/or by context sorts and a priority sort.
@@ -67,28 +81,83 @@ see :help sort
let g:Todo_txt_first_level_sort_mode="! i"
let g:Todo_txt_second_level_sort_mode="i"
Also `<LocalLeader>x` is a toggle which allow you to unmark a task as done.
### Completion
We also provide a nice complete function for project and context, to use it
add the following lines to your vimrc:
" Use TodoComplete as the omni complete function for todo files
au filetype todo setlocal omnifunc=TodoComplete
" Use todo#complete as the omni complete function for todo files
au filetype todo setlocal omnifunc=todo#complete
You can also start automatically the completion when entering '+' or '@' by
adding the next lines to your vimrc:
" Auto complete projects
au filetype todo imap + +<C-X><C-O>
au filetype todo imap <buffer> + +<C-X><C-O>
" Auto complete contexts
au filetype todo imap @ @<C-X><C-O>
au filetype todo imap <buffer> @ @<C-X><C-O>
The TodoComplete function is designed to complete projects (starting by '+')
The `todo#complete` function is designed to complete projects (starting by '+')
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
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.
TodoCompelte does the same thing for context except that it gives in the
preview the list of projects existing in each existing contexts.
### Due dates
I've integrated the [work from
durcheinandr](https://github.com/durcheinandr/todo.txt-vim/) concerning due
dates + some little improvements:
Accorrding to the todo.txt rules, one can define due dates using `due:date` or
`DUE:date` or any other `key:value` combination. This plugins handle dates at
the format `YYYY-MM-DD` and the key `due` can be spell using any combination
of lower and upper case letters. The following mappings are provided:
`<leader>-sd` : Sort the file by due-date. Entries with a due date appears
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
`<LocalLeader>x` is a toggle which allow you to unmark a task as done.
Syntax highlighting for couples key:value
If the current buffer is a done.txt file, the basic sort sorts on completion
date.

331
autoload/todo.vim Normal file
View File

@@ -0,0 +1,331 @@
" File: autoload/todo.vim
" Description: Todo.txt sorting plugin
" Author: David Beniamine <david@beniamine.net>
" Licence: Vim licence
" Website: http://github.com/dbeniamine/todo.txt.vim
" Version: 0.7.3
" vim: ts=4 sw=4 :help tw=78 cc=80
" These two variables are parameters for the successive calls the vim sort
" '' means no flags
" '! i' means reverse and ignore case
" for more information on flags, see :help sort
if (! exists("g:Todo_txt_first_level_sort_mode"))
let g:Todo_txt_first_level_sort_mode='i'
endif
if (! exists("g:Todo_txt_second_level_sort_mode"))
let g:Todo_txt_second_level_sort_mode='i'
endif
if (! exists("g:Todo_txt_third_level_sort_mode"))
let g:Todo_txt_third_level_sort_mode='i'
endif
" Functions {{{1
" Increment and Decrement The Priority
:set nf=octal,hex,alpha
function! todo#PrioritizeIncrease()
normal! 0f)h
endfunction
function! todo#PrioritizeDecrease()
normal! 0f)h
endfunction
function! todo#PrioritizeAdd (priority)
let oldpos=getcurpos()
let line=getline('.')
if line !~ '^([A-F])'
:call todo#PrioritizeAddAction(a:priority)
let oldpos[2]+=4
else
exec ':s/^([A-F])/('.a:priority.')/'
endif
call setpos('.',oldpos)
endfunction
function! todo#PrioritizeAddAction (priority)
execute "normal! mq0i(".a:priority.") \<esc>`q"
endfunction
function! todo#RemovePriority()
:s/^(\w)\s\+//ge
endfunction
function! todo#PrependDate()
normal! 0"=strftime("%Y-%m-%d ")
P
endfunction
function! todo#ToggleMarkAsDone()
if (getline(".") =~ 'x\s*\d\{4\}')
:call todo#UnMarkAsDone()
else
:call todo#MarkAsDone()
endif
endfunction
function! todo#UnMarkAsDone()
:s/\s*x\s*\d\{4}-\d\{1,2}-\d\{1,2}\s*//g
endfunction
function! todo#MarkAsDone()
call todo#PrependDate()
normal! Ix
endfunction
function! todo#MarkAllAsDone()
:g!/^x /:call todo#MarkAsDone()
endfunction
function! s:AppendToFile(file, lines)
let l:lines = []
" Place existing tasks in done.txt at the beggining of the list.
if filereadable(a:file)
call extend(l:lines, readfile(a:file))
endif
" Append new completed tasks to the list.
call extend(l:lines, a:lines)
" Write to file.
call writefile(l:lines, a:file)
endfunction
function! todo#RemoveCompleted()
" Check if we can write to done.txt before proceeding.
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','')
endif
let l:done_file = l:target_dir.'/'.l:done
echo "Writing to ".l:done_file
if !filewritable(l:done_file) && !filewritable(l:target_dir)
echoerr "Can't write to file '".l:done_file."'"
return
endif
let l:completed = []
:g/^x /call add(l:completed, getline(line(".")))|d
call s:AppendToFile(l:done_file, l:completed)
endfunction
function! todo#Sort()
" vim :sort is usually stable
" we sort first on contexts, then on projects and then on priority
if expand('%')=~'[Dd]one.*.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
sort /@[a-zA-Z]*/ r
sort /+[a-zA-Z]*/ r
sort /\v\([A-Z]\)/ r
endif
endfunction
function! todo#SortDue()
silent! %s/\([dD][uU][eE]:\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
" Sort adding entries with due dates add the beginning
sort n /[dD][uU][eE]:/
" Count the number of lines
silent normal gg
execute "/[dD][uU][eE]:"
let l:first=getpos(".")[1]
silent normal N
let l:last=getpos(".")[1]
let l:diff=l:last-l:first+1
" Put the sorted lines at the beginning of the file
execute ':'.l:first
execute ':d'.l:diff
silent normal gg
silent normal P
silent! %s/\([dD][uU][eE]:\d\{4}\)\(\d\{2}\)/\1-\2-/g
" TODO: add time sorting (YYYY-MM-DD HH:MM)
endfunction
" This is a Hierarchical sort designed for todo.txt todo lists, however it
" might be used for other files types
" At the first level, lines are sorted by the word right after the first
" occurence of a:symbol, there must be no space between the symbol and the
" word. At the second level, the same kind of sort is done based on
" a:symbolsub, is a:symbol==' ', the second sort doesn't occurs
" Therefore, according to todo.txt syntaxt, if
" a:symbol is a '+' it sort by the first project
" a:symbol is an '@' it sort by the first context
" The last level of sort is done directly on the line, so according to
" todo.txt syntax, it means by priority. This sort is done if and only if the
" las argument is not 0
function! todo#HierarchicalSort(symbol, symbolsub, dolastsort)
if v:statusmsg =~ '--No lines in buffer--'
"Empty buffer do nothing
return
endif
"if the sort modes doesn't start by '!' it must start with a space
let l:sortmode=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_first_level_sort_mode)
let l:sortmodesub=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_second_level_sort_mode)
let l:sortmodefinal=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_third_level_sort_mode)
" Count the number of lines
let l:position= getpos(".")
execute "silent normal g\<c-g>"
let l:linecount=str2nr(split(v:statusmsg)[7])
" Get all the groups names
let l:groups=GetGroups(a:symbol,1,l:linecount)
" Sort by groups
execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/'
for l:g in l:groups
let l:pat=a:symbol.l:g.'.*$'
normal gg
" Find the beginning of the group
let l:groupBegin=search(l:pat,'c')
" Find the end of the group
let l:groupEnd=search(l:pat,'b')
" I'm too lazy to sort groups of one line
if(l:groupEnd==l:groupBegin)
continue
endif
if a:dolastsort
if( a:symbolsub!='')
" Sort by subgroups
let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd)
" Go before the first line of the group
" Sort the group using the second symbol
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
let l:subgroupBegin=search(l:pat,'c')
" Find the end of the subgroup
let l:subgroupEnd=search(l:pat,'b')
" Sort by priority
execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal
endfor
else
" Sort by priority
execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal
endif
endif
endfor
" Restore the cursor position
call setpos('.', position)
endfunction
" Returns the list of groups starting by a:symbol between lines a:begin and
" a:end
function! GetGroups(symbol,begin, end)
let l:curline=a:begin
let l:groups=[]
while l:curline <= a:end
let l:curproj=strpart(matchstr(getline(l:curline),a:symbol.'\a*'),1)
if l:curproj != "" && index(l:groups,l:curproj) == -1
let l:groups=add(l:groups , l:curproj)
endif
let l:curline += 1
endwhile
return l:groups
endfunction
" Insert a space if needed (the first char isn't '!' or ' ') in front of
" sort parameters
function! Todo_txt_InsertSpaceIfNeeded(str)
let l:c=strpart(a:str,1,1)
if( l:c != '!' && l:c !=' ')
return " ".a:str
endif
retur a:str
endfunction
" Completion {{{1
" Simple keyword completion on all buffers {{{2
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 {{{2
fun! todo#Complete(findstart, base)
if a:findstart
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start - 1] !~ '\s'
let start -= 1
endwhile
return start
else
if a:base !~ '^+' && a:base !~ '^@'
return TodoKeywordComplete(a:base)
endif
" Opposite sign
let opp=a:base=~'+'?'@':'+'
" Search for matchs
let res = []
for bufnr in range(1,bufnr('$'))
let lines=getbufline(bufnr,1,"$")
for line in lines
if line =~ "[x\s0-9\-]*([a-Z]).* ".a:base
" init temporary item
let item={}
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
let item.buffers=bufname(bufnr)
let item.related=substitute(line,'.*\s\('.opp.'\S\S*\).*','\1',"")
call add(res,item)
endif
endfor
endfor
call sort(res)
" Here all results are sorted in res, but we need to merge them
let ret=[]
if res != []
let curitem={}
let curitem.word=res[0].word
let curitem.related=[]
let curitem.buffers=[]
for it in res
if curitem.word==it.word
" Merge results
if index(curitem.related,it.related) <0
call add(curitem.related,it.related)
endif
if index(curitem.buffers,it.buffers) <0
call add(curitem.buffers,it.buffers)
endif
else
" Create the definitive item
let resitem={}
let resitem.word=curitem.word
let resitem.info=opp=='+'?"Projects":"Contexts"
let resitem.info.=": ".join(curitem.related, ", ")
\."\nBuffers: ".join(curitem.buffers, ", ")
call add(ret,resitem)
" Init new item from it
let curitem.word=it.word
let curitem.related=[it.related]
let curitem.buffers=[it.buffers]
endif
endfor
endif
return ret
endif
endfun

View File

@@ -1,5 +1,8 @@
*todo.txt*
Note: Since v0.7.3, `TodoComplete` is `todo#Complete`, you might need to
update your vimrc.
==============================================================================
COMMANDS *todo-commands*
@@ -9,6 +12,8 @@ COMMANDS *todo-commands*
`<LocalLeader>s@` : Sort the file on @Contexts
`<LocalLeader>s@` : Sort the file on due dates
`<LocalLeader>sc` : Sort the file by context then by priority
`<LocalLeader>scp` : Sort the file by context, project then by priority
@@ -17,6 +22,9 @@ COMMANDS *todo-commands*
`<LocalLeader>spc` : Sort the file by project, context then by priority
`<leader>-sd` : Sort the file by due-date. Entries with a due date appears
sorted by at the beginning of the file, the rest of the file is not modified.
`<LocalLeader>j` : Lower the priority of the current line
`<LocalLeader>k` : Increase the priority of the current line
@@ -31,14 +39,18 @@ COMMANDS *todo-commands*
`date<tab>` : (Insert mode) Insert the current date
`due:` : (Insert mode) Insert `due:` followed by the current date
`DUE:` : (Insert mode) Insert `DUE:` followed by the current date
`<LocalLeader>x` : Toggle mark task as done (inserts or remove current date as
completion date)
`<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*
@@ -51,34 +63,74 @@ g:Todo_txt_second_level_sort_mode
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
We also provide a nice complete function for project and context, to use it
add the following lines to your vimrc:
" Use TodoComplete as the omni complete for todo files
au filetype todo setlocal omnifunc=TodoComplete
>
" Use todo#Completete as the omni complete for todo files
au filetype todo setlocal omnifunc=todo#Complete
<
You can also start automatically the completion when entering '+' or '@' by
adding the next lines to your vimrc:
>
" Auto complete projects
au filetype todo imap <buffer> + +<C-X><C-O>
" Auto complete projects
au filetype todo imap + +<C-X><C-O>
" Auto complete contexts
au filetype todo imap @ @<C-X><C-O>
" Auto complete contexts
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*
The TodoComplete function is designed to complete projects (starting by '+')
The `todo#Complete`te function is designed to complete projects (starting by '+')
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
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.
TodoCompelte does the same thing for context except that it gives in the
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

@@ -1,10 +1,19 @@
" File: todo.txt.vim
" Description: Todo.txt filetype detection
" Author: Leandro Freitas <freitass@gmail.com>
" Author: David Beniamine <david@beniamine.net>, Leandro Freitas <freitass@gmail.com>
" License: Vim license
" Website: http://github.com/dbeniamine/todo.txt-vim
" Version: 0.6
" Version: 0.7.2
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-\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

@@ -1,9 +1,10 @@
" File: todo.txt.vim
" Description: Todo.txt filetype detection
" Author: Leandro Freitas <freitass@gmail.com>, David Beniamine <David@Beniamine.net>
" Author: David Beniamine <David@Beniamine.net>, Leandro Freitas <freitass@gmail.com>
" License: Vim license
" Website: http://github.com/dbeniamine/todo.txt-vim
" Version: 0.6
" Version: 0.7.2
" vim: ts=4 sw=4 :help tw=78 cc=80
" Save context {{{1
let s:save_cpo = &cpo
@@ -16,79 +17,27 @@ set cpo&vim
setlocal textwidth=0
setlocal wrapmargin=0
" Functions {{{1
function! s:TodoTxtRemovePriority()
:s/^(\w)\s\+//ge
endfunction
function! TodoTxtPrependDate()
normal! 0"=strftime("%Y-%m-%d ")
P
endfunction
function! TodoTxtToggleMarkAsDone()
if (getline(".") =~ 'x\s*\d\{4\}')
:call TodoTxtUnMarkAsDone()
else
:call TodoTxtMarkAsDone()
endif
endfunction
function! TodoTxtUnMarkAsDone()
:s/\s*x\s*\d\{4}-\d\{1,2}-\d\{1,2}\s*//g
endfunction
function! TodoTxtMarkAsDone()
" call s:TodoTxtRemovePriority()
call TodoTxtPrependDate()
normal! Ix
endfunction
function! TodoTxtMarkAllAsDone()
:g!/^x /:call TodoTxtMarkAsDone()
endfunction
function! s:AppendToFile(file, lines)
let l:lines = []
" Place existing tasks in done.txt at the beggining of the list.
if filereadable(a:file)
call extend(l:lines, readfile(a:file))
endif
" Append new completed tasks to the list.
call extend(l:lines, a:lines)
" Write to file.
call writefile(l:lines, a:file)
endfunction
function! TodoTxtRemoveCompleted()
" Check if we can write to done.txt before proceeding.
let l:target_dir = expand('%:p:h')
let l:done_file = l:target_dir.'/done.txt'
if !filewritable(l:done_file) && !filewritable(l:target_dir)
echoerr "Can't write to file 'done.txt'"
return
endif
let l:completed = []
:g/^x /call add(l:completed, getline(line(".")))|d
call s:AppendToFile(l:done_file, l:completed)
endfunction
function! TodoTxtSort()
" vim :sort is usually stable
" we sort first on contexts, then on projects and then on priority
:sort /@[a-zA-Z]*/ r
:sort /+[a-zA-Z]*/ r
:sort /\v\([A-Z]\)/ r
endfunction
" Mappings {{{1
" Sort todo by (first) context
if !hasmapto("<localleader>sc",'n')
noremap <silent><localleader>sc :call todo#HierarchicalSort('@', '', 1)<CR>
endif
if !hasmapto("<localleader>scp",'n')
noremap <silent><localleader>scp :call todo#HierarchicalSort('@', '+', 1)<CR>
endif
" Sort todo by (first) project
if !hasmapto("<localleader>sp",'n')
noremap <silent><localleader>sp :call todo#HierarchicalSort('+', '',1)<CR>
endif
if !hasmapto("<localleader>spc",'n')
noremap <silent><localleader>spc :call todo#HierarchicalSort('+', '@',1)<CR>
endif
" Sort tasks {{{2
if !hasmapto("<localleader>s",'n')
if !hasmapto("<localleader>s",'n')
nnoremap <script> <silent> <buffer> <LocalLeader>s :call todo#Sort()<CR>
endif
if !hasmapto("<LocalLeader>s@",'n')
@@ -99,82 +48,55 @@ if !hasmapto("<LocalLeader>s+",'n')
nnoremap <script> <silent> <buffer> <LocalLeader>s+ :sort /.\{-}\ze+/ <CR>
endif
" Increment and Decrement The Priority
:set nf=octal,hex,alpha
function! TodoTxtPrioritizeIncrease()
normal! 0f)h
endfunction
function! TodoTxtPrioritizeDecrease()
normal! 0f)h
endfunction
function! TodoTxtPrioritizeAdd (priority)
let oldpos=getcurpos()
let line=getline('.')
if line !~ '^([A-F])'
:call TodoTxtPrioritizeAddAction(a:priority)
let oldpos[2]+=4
else
exec ':s/^([A-F])/('.a:priority.')/'
endif
call setpos('.',oldpos)
endfunction
function! TodoTxtPrioritizeAddAction (priority)
execute "normal! mq0i(".a:priority.") \<esc>`q"
endfunction
if !hasmapto("<LocalLeader>j",'n')
if !hasmapto("<LocalLeader>j",'n')
nnoremap <script> <silent> <buffer> <LocalLeader>j :call todo#PrioritizeIncrease()<CR>
endif
if !hasmapto("<LocalLeader>j",'v')
if !hasmapto("<LocalLeader>j",'v')
vnoremap <script> <silent> <buffer> <LocalLeader>j :call todo#PrioritizeIncrease()<CR>
endif
if !hasmapto("<LocalLeader>k",'n')
if !hasmapto("<LocalLeader>k",'n')
nnoremap <script> <silent> <buffer> <LocalLeader>k :call todo#PrioritizeDecrease()<CR>
endif
if !hasmapto("<LocalLeader>k",'v')
if !hasmapto("<LocalLeader>k",'v')
vnoremap <script> <silent> <buffer> <LocalLeader>k :call todo#PrioritizeDecrease()<CR>
endif
if !hasmapto("<LocalLeader>a",'n')
if !hasmapto("<LocalLeader>a",'n')
nnoremap <script> <silent> <buffer> <LocalLeader>a :call todo#PrioritizeAdd('A')<CR>
endif
if !hasmapto("<LocalLeader>a",'i')
if !hasmapto("<LocalLeader>a",'i')
inoremap <script> <silent> <buffer> <LocalLeader>a <ESC>:call todo#PrioritizeAdd('A')<CR>i
endif
if !hasmapto("<LocalLeader>a",'v')
if !hasmapto("<LocalLeader>a",'v')
vnoremap <script> <silent> <buffer> <LocalLeader>a :call todo#PrioritizeAdd('A')<CR>
endif
if !hasmapto("<LocalLeader>b",'n')
if !hasmapto("<LocalLeader>b",'n')
nnoremap <script> <silent> <buffer> <LocalLeader>b :call todo#PrioritizeAdd('B')<CR>
endif
if !hasmapto("<LocalLeader>b",'i')
if !hasmapto("<LocalLeader>b",'i')
inoremap <script> <silent> <buffer> <LocalLeader>b <ESC>:call todo#PrioritizeAdd('B')<CR>i
endif
if !hasmapto("<LocalLeader>b",'v')
if !hasmapto("<LocalLeader>b",'v')
vnoremap <script> <silent> <buffer> <LocalLeader>b :call todo#PrioritizeAdd('B')<CR>
endif
if !hasmapto("<LocalLeader>c",'n')
if !hasmapto("<LocalLeader>c",'n')
nnoremap <script> <silent> <buffer> <LocalLeader>c :call todo#PrioritizeAdd('C')<CR>
endif
if !hasmapto("<LocalLeader>c",'i')
if !hasmapto("<LocalLeader>c",'i')
inoremap <script> <silent> <buffer> <LocalLeader>c <ESC>:call todo#PrioritizeAdd('C')<CR>i
endif
if !hasmapto("<LocalLeader>c",'v')
if !hasmapto("<LocalLeader>c",'v')
vnoremap <script> <silent> <buffer> <LocalLeader>c :call todo#PrioritizeAdd('C')<CR>
endif
" Insert date {{{2
@@ -182,31 +104,44 @@ if !hasmapto("date<Tab>",'i')
inoremap <script> <silent> <buffer> date<Tab> <C-R>=strftime("%Y-%m-%d")<CR>
endif
if !hasmapto("due:",'i')
inoremap <script> <silent> <buffer> due: due:<C-R>=strftime("%Y-%m-%d")<CR>
endif
if !hasmapto("DUE:",'i')
inoremap <script> <silent> <buffer> DUE: DUE:<C-R>=strftime("%Y-%m-%d")<CR>
endif
if !hasmapto("<localleader>d",'n')
if !hasmapto("<localleader>d",'n')
nnoremap <script> <silent> <buffer> <localleader>d :call todo#PrependDate()<CR>
endif
if !hasmapto("<localleader>d",'v')
if !hasmapto("<localleader>d",'v')
vnoremap <script> <silent> <buffer> <localleader>d :call todo#PrependDate()<CR>
endif
" Mark done {{{2
if !hasmapto("<localleader>x",'n')
if !hasmapto("<localleader>x",'n')
nnoremap <script> <silent> <buffer> <localleader>x :call todo#ToggleMarkAsDone()<CR>
endif
if !hasmapto("<localleader>x",'v')
if !hasmapto("<localleader>x",'v')
vnoremap <script> <silent> <buffer> <localleader>x :call todo#ToggleMarkAsDone()<CR>
endif
" Mark all done {{{2
if !hasmapto("<localleader>X",'n')
if !hasmapto("<localleader>X",'n')
nnoremap <script> <silent> <buffer> <localleader>X :call todo#MarkAllAsDone()<CR>
endif
" Remove completed {{{2
if !hasmapto("<localleader>D",'n')
if !hasmapto("<localleader>D",'n')
nnoremap <script> <silent> <buffer> <localleader>D :call todo#RemoveCompleted()<CR>
endif
" Sort by due: date {{{2
if !hasmapto("<localleader>sd".'n')
nnoremap <script> <silent> <buffer> <localleader>sd :call todo#SortDue()<CR>
endif
" Folding {{{1
@@ -237,68 +172,6 @@ function! TodoFoldText()
\ . ' Completed tasks '
endfunction
" Intelligent completion for projects and Contexts
fun! TodoComplete(findstart, base)
if a:findstart
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start - 1] !~ '\s'
let start -= 1
endwhile
return start
else
" Opposite sign
let opp=a:base=~'+'?'@':'+'
" Search for matchs
let res = []
for bufnr in range(1,bufnr('$'))
let lines=getbufline(bufnr,1,"$")
for line in lines
if line =~ "[x\s0-9\-]*([a-Z]).* ".a:base
" init temporary item
let item={}
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
let item.buffers=bufname(bufnr)
let item.related=substitute(line,'.*\s\('.opp.'\S\S*\).*','\1',"")
call add(res,item)
endif
endfor
endfor
call sort(res)
" Here all results are sorted in res, but we need to merge them
let ret=[]
let curitem={}
let curitem.word=res[0].word
let curitem.related=[]
let curitem.buffers=[]
for it in res
if curitem.word==it.word
" Merge results
if index(curitem.related,it.related) <0
call add(curitem.related,it.related)
endif
if index(curitem.buffers,it.buffers) <0
call add(curitem.buffers,it.buffers)
endif
else
" Create the definitive item
let resitem={}
let resitem.word=curitem.word
let resitem.info=opp=='+'?"Projects":"Contexts"
let resitem.info.=": ".join(curitem.related, ", ")
\."\nBuffers: ".join(curitem.buffers, ", ")
call add(ret,resitem)
" Init new item from it
let curitem.word=it.word
let curitem.related=[it.related]
let curitem.buffers=[it.buffers]
endif
endfor
return ret
endif
endfun
" Restore context {{{1
let &cpo = s:save_cpo
" Modeline {{{1
" Modeline {{{1

View File

@@ -1,133 +0,0 @@
" File: todo.txt.vim
" Description: Todo.txt sorting plugin
" Author: David Beniamine <david@beniamine.net>
" Licence: Vim licence
" Website: http://github.com/dbeniamine/todo.txt.vim
" Version: 0.6
" vim: ts=4 sw=4 :help tw=78 cc=80
" These two variables are parameters for the successive calls the vim sort
" '' means no flags
" '! i' means reverse and ignore case
" for more information on flags, see :help sort
if (! exists("g:Todo_txt_first_level_sort_mode"))
let g:Todo_txt_first_level_sort_mode='i'
endif
if (! exists("g:Todo_txt_second_level_sort_mode"))
let g:Todo_txt_second_level_sort_mode='i'
endif
if (! exists("g:Todo_txt_third_level_sort_mode"))
let g:Todo_txt_third_level_sort_mode='i'
endif
" Sort todo by (first) context
if !hasmapto("<localleader>sc",'n')
noremap <localleader>sc :call Todo_txt_HierarchicalSort('@', '', 1)<CR>
endif
if !hasmapto("<localleader>scp",'n')
noremap <localleader>scp :call Todo_txt_HierarchicalSort('@', '+', 1)<CR>
endif
" Sort todo by (first) project
if !hasmapto("<localleader>sp",'n')
noremap <localleader>sp :call Todo_txt_HierarchicalSort('+', '',1)<CR>
endif
if !hasmapto("<localleader>spc",'n')
noremap <localleader>spc :call Todo_txt_HierarchicalSort('+', '@',0)<CR>
endif
" This is a Hierarchical sort designed for todo.txt todo lists, however it
" might be used for other files types
" At the first level, lines are sorted by the word right after the first
" occurence of a:symbol, there must be no space between the symbol and the
" word. At the second level, the same kind of sort is done based on
" a:symbolsub, is a:symbol==' ', the second sort doesn't occurs
" Therefore, according to todo.txt syntaxt, if
" a:symbol is a '+' it sort by the first project
" a:symbol is an '@' it sort by the first context
" The last level of sort is done directly on the line, so according to
" todo.txt syntax, it means by priority. This sort is done if and only if the
" las argument is not 0
function! Todo_txt_HierarchicalSort(symbol, symbolsub, dolastsort)
if v:statusmsg =~ '--No lines in buffer--'
"Empty buffer do nothing
return
endif
"if the sort modes doesn't start by '!' it must start with a space
let l:sortmode=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_first_level_sort_mode)
let l:sortmodesub=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_second_level_sort_mode)
let l:sortmodefinal=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_third_level_sort_mode)
" Count the number of lines
let l:position= getpos(".")
execute "silent normal g\<c-g>"
let l:linecount=str2nr(split(v:statusmsg)[7])
" Get all the groups names
let l:groups=GetGroups(a:symbol,0,l:linecount)
" Sort by groups
execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/'
for l:g in l:groups
" Find the beginning of the group
execute '/'.a:symbol.l:g.'.*$'
let l:groupBegin=getpos(".")[1]
" Find the end of the group
silent normal N
let l:groupEnd=getpos(".")[1]
" I'm too lazy to sort one groups of one line
if(l:groupEnd==l:groupBegin)
continue
endif
if( a:symbolsub!='')
" Sort by subgroups
let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd)
" Go before the first line of the group
" Sort the group using the second symbol
for l:sg in l:subgroups
" 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=getpos(".")[1]
" Find the end of the subgroup
silent normal N
let l:subgroupEnd=getpos(".")[1]
" Sort by priority
if a:dolastsort
execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal
endif
endfor
else
" Sort by priority
if a:dolastsort
execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal
endif
endif
endfor
" Restore the cursor position
call setpos('.', position)
endfunction
" Returns the list of groups starting by a:symbol between lines a:begin and
" a:end
function! GetGroups(symbol,begin, end)
let l:curline=a:begin
let l:groups=[]
while l:curline <= a:end
let l:curproj=strpart(matchstr(getline(l:curline),a:symbol.'\a*'),1)
if l:curproj != "" && index(l:groups,l:curproj) == -1
let l:groups=add(l:groups , l:curproj)
endif
let l:curline += 1
endwhile
return l:groups
endfunction
" Insert a space if needed (the first char isn't '!' or ' ') in front of
" sort parameters
function! Todo_txt_InsertSpaceIfNeeded(str)
let l:c=strpart(a:str,1,1)
if( l:c != '!' && l:c !=' ')
return " ".a:str
endif
retur a:str
endfunction

View File

@@ -1,46 +1,48 @@
" File: todo.txt.vim
" Description: Todo.txt syntax settings
" Author: Leandro Freitas <freitass@gmail.com>, David Beniamine <David@Beniamine.net>
" Author: David Beniamine <David@Beniamine.net>,Leandro Freitas <freitass@gmail.com>
" License: Vim license
" Website: http://github.com/dbeniamine/todo.txt-vim
" Version: 0.6
" Version: 0.7.2
if exists("b:current_syntax")
finish
endif
syntax match TodoDone '^[xX]\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityA '^([aA])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityB '^([bB])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityC '^([cC])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityD '^([dD])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityE '^([eE])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityF '^([fF])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityG '^([gG])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityH '^([hH])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityI '^([iI])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityJ '^([jJ])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityK '^([kK])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityL '^([lL])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityM '^([mM])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityN '^([nN])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityO '^([oO])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityP '^([pP])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityQ '^([qQ])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityR '^([rR])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityS '^([sS])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityT '^([tT])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityU '^([uU])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityV '^([vV])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityW '^([wW])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityX '^([xX])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityY '^([yY])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoPriorityZ '^([zZ])\s.\+$' contains=TodoDate,TodoProject,TodoContext
syntax match TodoDone '^[xX]\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityA '^([aA])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityB '^([bB])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityC '^([cC])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityD '^([dD])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityE '^([eE])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityF '^([fF])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityG '^([gG])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityH '^([hH])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityI '^([iI])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityJ '^([jJ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityK '^([kK])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityL '^([lL])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityM '^([mM])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityN '^([nN])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityO '^([oO])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityP '^([pP])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityQ '^([qQ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityR '^([rR])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityS '^([sS])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityT '^([tT])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityU '^([uU])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityV '^([vV])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityW '^([wW])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
syntax match TodoPriorityX '^([xX])\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 TodoDate '\d\{2,4\}-\d\{2\}-\d\{2\}' contains=NONE
syntax match TodoKey '\S*\S:\S\S*' contains=TodoDate
syntax match TodoProject '\(^\|\W\)+[^[:blank:]]\+' contains=NONE
syntax match TodoContext '\(^\|\W\)@[^[:blank:]]\+' contains=NONE
" Other priority colours might be defined by the user
highlight default link TodoKey Special
highlight default link TodoDone Comment
highlight default link TodoPriorityA Identifier
highlight default link TodoPriorityB statement