Add: Completion for todo.txt
Intelligent complete for context and projects, try it ;)
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
## What is this plugin ?
|
## What is this plugin ?
|
||||||
|
|
||||||
This plugin is a fork of freitass todo.txt (see section 1.3) vim plugin adding
|
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
|
a nice two level sorting function designed for todo.txt files and a complete
|
||||||
1.4).
|
function for context and projects (see section 1.4).
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
@@ -69,6 +69,28 @@ see :help sort
|
|||||||
|
|
||||||
Also `<LocalLeader>-x` is a toggle which allow you to unmark a task as done.
|
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
|
## Todo
|
||||||
|
|
||||||
Complete documentation
|
Complete documentation
|
||||||
|
|||||||
27
doc/todo.txt
27
doc/todo.txt
@@ -31,7 +31,7 @@ COMMANDS *todo-commands*
|
|||||||
|
|
||||||
`date<tab>` : (Insert mode) Insert the current date
|
`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)
|
completion date)
|
||||||
|
|
||||||
`<LocalLeader>-X` : Mark all tasks as completed
|
`<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
|
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.
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ set cpo&vim
|
|||||||
setlocal textwidth=0
|
setlocal textwidth=0
|
||||||
setlocal wrapmargin=0
|
setlocal wrapmargin=0
|
||||||
|
|
||||||
|
|
||||||
" Functions {{{1
|
" Functions {{{1
|
||||||
function! s:TodoTxtRemovePriority()
|
function! s:TodoTxtRemovePriority()
|
||||||
:s/^(\w)\s\+//ge
|
:s/^(\w)\s\+//ge
|
||||||
@@ -38,9 +39,9 @@ function! TodoTxtUnMarkAsDone()
|
|||||||
:s/\s*x\s*\d\{4}-\d\{1,2}-\d\{1,2}\s*//g
|
:s/\s*x\s*\d\{4}-\d\{1,2}-\d\{1,2}\s*//g
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! TodoTxtMarkAsDone()
|
function! TodoTxtMarkAsDone()
|
||||||
" call s:TodoTxtRemovePriority()
|
" call s:TodoTxtRemovePriority()
|
||||||
call TodoTxtPrependDate()
|
call TodoTxtPrependDate()
|
||||||
normal! Ix
|
normal! Ix
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -218,6 +219,40 @@ function! TodoFoldText()
|
|||||||
\ . (v:foldend - v:foldstart + 1)
|
\ . (v:foldend - v:foldstart + 1)
|
||||||
\ . ' Completed tasks '
|
\ . ' Completed tasks '
|
||||||
endfunction
|
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
|
" Restore context {{{1
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
|
|||||||
Reference in New Issue
Block a user