Add: Completion for todo.txt

Intelligent complete for context and projects, try it ;)
This commit is contained in:
David Beniamine
2015-03-12 21:02:55 -03:00
parent 8c378b5646
commit d3d06926a6
3 changed files with 88 additions and 6 deletions

View File

@@ -3,8 +3,8 @@
## 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 (see section
1.4).
a nice two level sorting function designed for todo.txt files and a complete
function for context and projects (see section 1.4).
## Install
@@ -69,6 +69,28 @@ see :help sort
Also `<LocalLeader>-x` is a toggle which allow you to unmark a task as done.
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 user complete
au filetype todo setlocal completefunc=TodoComplete
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-U>
" Auto complete contexts
au filetype todo imap @ @<C-X><C-U>
The TodoComplete function is designed to complete projects (starting by '+')
and context (starting by '@'). If you use it on a regulard word, it will do a
normal buffer completion.
If you try to complete a project, it will propose all projects in the file and
for each of them, it will show their context 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.
## Todo
Complete documentation

View File

@@ -31,7 +31,7 @@ COMMANDS *todo-commands*
`date<tab>` : (Insert mode) Insert the current date
`<LocalLeader>-x` : Toggle mark task as done (inserts or remove current date as
`<LocalLeader>-x` : Toggle mark task as done (inserts or remove current date as
completion date)
`<LocalLeader>-X` : Mark all tasks as completed
@@ -56,3 +56,28 @@ 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 user complete
au filetype todo setlocal completefunc=TodoComplete
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-U>
" Auto complete contexts
au filetype todo imap @ @<C-X><C-U>
===============================================================================
COMPLETION *todo-complete*
The TodoComplete function is designed to complete projects (starting by '+')
and context (starting by '@'). If you use it on a regulard word, it will do a
normal buffer completion.
If you try to complete a project, it will propose all projects in the file and
for each of them, it will show their context 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.

View File

@@ -16,6 +16,7 @@ set cpo&vim
setlocal textwidth=0
setlocal wrapmargin=0
" Functions {{{1
function! s:TodoTxtRemovePriority()
:s/^(\w)\s\+//ge
@@ -38,9 +39,9 @@ function! TodoTxtUnMarkAsDone()
:s/\s*x\s*\d\{4}-\d\{1,2}-\d\{1,2}\s*//g
endfunction
function! TodoTxtMarkAsDone()
" call s:TodoTxtRemovePriority()
call TodoTxtPrependDate()
function! TodoTxtMarkAsDone()
" call s:TodoTxtRemovePriority()
call TodoTxtPrependDate()
normal! Ix
endfunction
@@ -218,6 +219,40 @@ function! TodoFoldText()
\ . (v:foldend - v:foldstart + 1)
\ . ' 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
let res = []
let file = readfile(expand("%:p"))
for line in file
if line =~ " ".a:base
let item={}
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
if a:base =~ '+'
let item.info="Context: ".substitute(line,'.*\s\(@\S\S*\).*','\1',"")
elseif a:base =~ '@'
let l:pr=[]
for line2 in file
if line2 =~ l:item.word
call add(l:pr,substitute(line2,'.*\s\(+\S\S*\).*','\1',""))
endif
endfor
let item.info="Projects: ".join(uniq(l:pr), " ")
endif
call add(res,item)
endif
endfor
return res
endif
endfun
" Restore context {{{1
let &cpo = s:save_cpo