From d3d06926a671231a3801059434625bbcdea31cd7 Mon Sep 17 00:00:00 2001 From: David Beniamine Date: Thu, 12 Mar 2015 21:02:55 -0300 Subject: [PATCH] Add: Completion for todo.txt Intelligent complete for context and projects, try it ;) --- README.markdown | 26 ++++++++++++++++++++++++-- doc/todo.txt | 27 ++++++++++++++++++++++++++- ftplugin/todo.vim | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/README.markdown b/README.markdown index 2819f88..08cbe55 100644 --- a/README.markdown +++ b/README.markdown @@ -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 `-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 + + +" Auto complete contexts +au filetype todo imap @ @ + +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 diff --git a/doc/todo.txt b/doc/todo.txt index e9e07ac..024d238 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -31,7 +31,7 @@ COMMANDS *todo-commands* `date` : (Insert mode) Insert the current date -`-x` : Toggle mark task as done (inserts or remove current date as +`-x` : Toggle mark task as done (inserts or remove current date as completion date) `-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 + + +" Auto complete contexts +au filetype todo imap @ @ + +=============================================================================== +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. diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim index 4f65f21..81cd633 100644 --- a/ftplugin/todo.vim +++ b/ftplugin/todo.vim @@ -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() endfunction function! TodoTxtMarkAsDone() - " call s:TodoTxtRemovePriority() - call TodoTxtPrependDate() - normal! Ix + " call s:TodoTxtRemovePriority() + call TodoTxtPrependDate() + normal! Ix endfunction function! TodoTxtMarkAllAsDone() @@ -218,6 +219,40 @@ 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 + 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 " Modeline {{{1