From 9b580acf14d5f3cdcaac94b3bb0ef656f694b7dc Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 08:55:46 -0600 Subject: [PATCH 1/9] support PAGER pipe for help output --- todo.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/todo.sh b/todo.sh index 2c38de4..879e12a 100755 --- a/todo.sh +++ b/todo.sh @@ -787,7 +787,13 @@ case $action in cleanup ;; "help" ) - help + if [ -t 1 ] ; then # STDOUT is a TTY + if (exec which ${PAGER:-less} 2>/dev/null >/dev/null); then + # we have a working PAGER (or less as a default) + help | exec ${PAGER:-less} + fi + fi + help # just in case something failed above, we go ahead and just spew to STDOUT ;; "list" | "ls" ) From 9a56bdd4ede0cc1ea9aad31f2a369ff48bb7da1d Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 12:09:51 -0600 Subject: [PATCH 2/9] vim support! (first cut, anyway) --- vim/plugin/todo.vim | 126 +++++++++++++++++++++++++++++++++++++++ vim/syntax/todo-list.vim | 19 ++++++ 2 files changed, 145 insertions(+) create mode 100644 vim/plugin/todo.vim create mode 100644 vim/syntax/todo-list.vim diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim new file mode 100644 index 0000000..7854011 --- /dev/null +++ b/vim/plugin/todo.vim @@ -0,0 +1,126 @@ +command! -nargs=* Todo call Todo() +command! -nargs=+ TodoAdd call TodoAdd() +command! -nargs=* -complete=customlist,CompleteTodoList TodoList call TodoList() +command! -nargs=0 TodoListProjects call TodoListProj() +command! -nargs=0 TodoListContexts call TodoListCon() +nnoremap tl :TodoList + +function! TodoList(args) + call Todo('list ' . a:args) + nnoremap q :q + execute 'nnoremap r :silent TodoList ' . a:args . '' + execute 'nnoremap d :silent call TodoDoneCurrent():silent TodoList ' . a:args . '' + execute 'nnoremap p :call TodoPriorityCurrent():silent TodoList ' . a:args . '' + execute 'nnoremap P :call TodoAppendProjectCurrent():silent TodoList ' . a:args . '' + execute 'nnoremap C :call TodoAppendContextCurrent():silent TodoList ' . a:args . '' +endfunction + +function! TodoCurrentLineId() + let row = split(getline('.')) + return row[0] +endfunction + +function! TodoDoneCurrent() + let id = TodoCurrentLineId() + call TodoAction('do ' . id) +endfunction + +function! TodoPriorityCurrent() + let id = TodoCurrentLineId() + call inputsave() + let priority = input("Priority?", "A") + call inputrestore() + call TodoAction('pri ' . id . ' ' . priority) +endfunction + +function! TodoAppendContextCurrent() + let id = TodoCurrentLineId() + call inputsave() + let context = input("Context: ", "@", "customlist,CompleteTodoProjects") + call inputrestore() + call TodoAction('append ' . id . ' ' . context) +endfunction + +function! TodoAppendProjectCurrent() + let id = TodoCurrentLineId() + call inputsave() + let project = input("Project: ", "+", "customlist,CompleteTodoProjects") + call inputrestore() + call TodoAction('append ' . id . ' ' . project) +endfunction + +function! TodoListProj() + call TodoAction('listproj') +endfunction + +function! TodoListCon() + call TodoAction('listcon') +endfunction + +function! TodoAdd(args) + call TodoAction('add "' . a:args . '"') +endfunction + +function! CompleteTodo(type, arg_lead, cmd_line, cursor_pos) + let opts = split(SystemTodo('list' . a:type)) + return filter(opts, 'match(v:val, ''\V'' . a:arg_lead) == 0') +endfunction + +function! CompleteTodoContexts(arg_lead, cmd_line, cursor_pos) + return CompleteTodo('con', a:arg_lead, a:cmd_line, a:cursor_pos) +endfunction + +function! CompleteTodoProjects(arg_lead, cmd_line, cursor_pos) + return CompleteTodo('proj', a:arg_lead, a:cmd_line, a:cursor_pos) +endfunction + +function! CompleteTodoList(arg_lead, cmd_line, cursor_pos) + let opts = [ ] + if !strlen(a:arg_lead) || a:arg_lead =~ '^+' + let opts += CompleteTodoProjects(a:arg_lead, a:cmd_line, a:cursor_pos) + endif + if !strlen(a:arg_lead) || a:arg_lead =~ '^@' + let opts += CompleteTodoContexts(a:arg_lead, a:cmd_line, a:cursor_pos) + endif + return opts +endfunction + +function! TodoAction(args) + echo SystemTodo(a:args) +endfunction + +function! Todo(args) + let todo_output = SystemTodo(a:args) + if !strlen(todo_output) + echo "No output from todo command" + return + endif + call OpenTodoBuffer(todo_output) + setlocal filetype=todo-list +endfunction + +function! s:SystemTodo(args) + let default_args = DefaultTodoArgs() + return system('todo.sh ' . default_args . ' ' . a:args . ' < /dev/null') +endfunction + +function! s:DefaultTodoArgs() + let args = "" + if exists('g:todotxt_cfg_file') && strlen(g:todotxt_cfg_file) + args += '-d ' . g:todotxt_cfg_file + endif + return args +endfunction + +function! s:OpenTodoBuffer(content) + if exists('b:is_todo_output_buffer') && b:is_todo_output_buffer + enew! + else + new + endif + setlocal buftype=nofile readonly modifiable + silent put=a:content + keepjumps 0d + setlocal nomodifiable + let b:is_todo_output_buffer = 1 +endfunction diff --git a/vim/syntax/todo-list.vim b/vim/syntax/todo-list.vim new file mode 100644 index 0000000..fae01b8 --- /dev/null +++ b/vim/syntax/todo-list.vim @@ -0,0 +1,19 @@ +if exists("b:current_syntax") + finish +endif + +syntax match todoItemID /^\d\+/ contained +syntax match todoItemProject /+[^ ]\+/ contained +syntax match todoItemContext /@[^ ]\+/ contained +syntax match todoItemText /^\d\+ .*$/ contains=todoItemID,todoItemProject,todoItemContext +syntax match todoItemSeparator +--+ +syntax match todoItemSummary /^TODO:.*/ + +hi link todoItemID Statement +hi link todoItemProject SpecialKey +hi link todoItemContext Title +hi link todoItemText Comment +hi link todoItemSeparator Ignore +hi link todoItemSummary Ignore + +let b:current_syntax = "todo-list" From b8ced51a22a5eb0e3a00eabb1bc7d9edcacb9782 Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 14:37:36 -0600 Subject: [PATCH 3/9] added some additional mappings, plus a project context --- vim/plugin/todo.vim | 61 +++++++++++++++++++++++++++++++++------- vim/syntax/todo-list.vim | 16 +++++++++-- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim index 7854011..3a91bd5 100644 --- a/vim/plugin/todo.vim +++ b/vim/plugin/todo.vim @@ -1,20 +1,56 @@ +if !exists('g:todo_project_context') + let g:todo_project_context = '' +endif + command! -nargs=* Todo call Todo() command! -nargs=+ TodoAdd call TodoAdd() command! -nargs=* -complete=customlist,CompleteTodoList TodoList call TodoList() command! -nargs=0 TodoListProjects call TodoListProj() command! -nargs=0 TodoListContexts call TodoListCon() nnoremap tl :TodoList +nnoremap ta :TodoAdd function! TodoList(args) - call Todo('list ' . a:args) + let list_args = a:args . ' ' . g:todo_project_context + call Todo('list ' . list_args) nnoremap q :q - execute 'nnoremap r :silent TodoList ' . a:args . '' - execute 'nnoremap d :silent call TodoDoneCurrent():silent TodoList ' . a:args . '' - execute 'nnoremap p :call TodoPriorityCurrent():silent TodoList ' . a:args . '' - execute 'nnoremap P :call TodoAppendProjectCurrent():silent TodoList ' . a:args . '' - execute 'nnoremap C :call TodoAppendContextCurrent():silent TodoList ' . a:args . '' + execute 'nnoremap o :call TodoAddInput():silent TodoList ' . list_args . '' + execute 'nnoremap r :silent TodoList ' . list_args . '' + execute 'nnoremap d :silent call TodoDoneCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap D :silent call TodoDeleteCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap p :call TodoPriorityCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap P :call TodoAppendProjectCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap C :call TodoAppendContextCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap + :silent call TodoPriorityAdjust(1):silent TodoList ' . list_args . '' + execute 'nnoremap - :silent call TodoPriorityAdjust(-1):silent TodoList ' . list_args . '' endfunction +function! TodoPriorityAdjust(amount) + let id = TodoCurrentLineId() + let item = getline('.') + let priorities = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] + let index = 0 + while index < len(priorities) + let p = priorities[index] + if match(item, "(" . p . ")") > -1 + if index + a:amount >= len(priorities) + call TodoAction('pri ' . id . ' ' . priorities[0]) + else + call TodoAction('pri ' . id . ' ' . priorities[index + a:amount]) + endif + break + endif + let index += 1 + endwhile + +endfunction + +function! TodoAddInput() + call inputsave() + let task = input("Task: ") + call inputrestore() + call TodoAction('add "' . task . '"') +endfunction function! TodoCurrentLineId() let row = split(getline('.')) return row[0] @@ -25,10 +61,15 @@ function! TodoDoneCurrent() call TodoAction('do ' . id) endfunction +function! TodoDeleteCurrent() + let id = TodoCurrentLineId() + call TodoAction('rm ' . id) +endfunction + function! TodoPriorityCurrent() let id = TodoCurrentLineId() call inputsave() - let priority = input("Priority?", "A") + let priority = input("Priority (A-Z): ", "A") call inputrestore() call TodoAction('pri ' . id . ' ' . priority) endfunction @@ -58,7 +99,7 @@ function! TodoListCon() endfunction function! TodoAdd(args) - call TodoAction('add "' . a:args . '"') + call TodoAction('add "' . a:args . ' ' . g:todo_project_context . '"') endfunction function! CompleteTodo(type, arg_lead, cmd_line, cursor_pos) @@ -105,9 +146,9 @@ function! s:SystemTodo(args) endfunction function! s:DefaultTodoArgs() - let args = "" + let args = '-p' if exists('g:todotxt_cfg_file') && strlen(g:todotxt_cfg_file) - args += '-d ' . g:todotxt_cfg_file + args += ' -d ' . g:todotxt_cfg_file endif return args endfunction diff --git a/vim/syntax/todo-list.vim b/vim/syntax/todo-list.vim index fae01b8..b8974c0 100644 --- a/vim/syntax/todo-list.vim +++ b/vim/syntax/todo-list.vim @@ -3,16 +3,26 @@ if exists("b:current_syntax") endif syntax match todoItemID /^\d\+/ contained +syntax match todoItemPriorityA /(A)/ contained +syntax match todoItemPriorityB /(B)/ contained +syntax match todoItemPriorityC /(C)/ contained +syntax match todoItemPriority /([D-Z])/ contained syntax match todoItemProject /+[^ ]\+/ contained syntax match todoItemContext /@[^ ]\+/ contained -syntax match todoItemText /^\d\+ .*$/ contains=todoItemID,todoItemProject,todoItemContext +syntax match todoItemText /^\d\+ .*$/ contains=todoItemID,todoItemProject,todoItemContext,todoItemPriority,todoItemPriorityA,todoItemPriorityB,todoItemPriorityC syntax match todoItemSeparator +--+ syntax match todoItemSummary /^TODO:.*/ hi link todoItemID Statement -hi link todoItemProject SpecialKey -hi link todoItemContext Title +hi link todoItemProject Identifier +hi link todoItemContext Type hi link todoItemText Comment + +hi link todoItemPriority Constant +hi link todoItemPriorityA Todo +hi link todoItemPriorityB Visual +hi link todoItemPriorityC DiffAdd + hi link todoItemSeparator Ignore hi link todoItemSummary Ignore From ceed8bf8418ce4825424b38b7f8ded62500c2c52 Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 15:17:12 -0600 Subject: [PATCH 4/9] more tweaks --- vim/plugin/todo.vim | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim index 3a91bd5..5944efe 100644 --- a/vim/plugin/todo.vim +++ b/vim/plugin/todo.vim @@ -11,18 +11,21 @@ nnoremap tl :TodoList nnoremap ta :TodoAdd function! TodoList(args) - let list_args = a:args . ' ' . g:todo_project_context + let list_args = a:args + if match(list_args, g:todo_project_context) == -1 + let list_args .= " " . g:todo_project_context + endif call Todo('list ' . list_args) nnoremap q :q - execute 'nnoremap o :call TodoAddInput():silent TodoList ' . list_args . '' - execute 'nnoremap r :silent TodoList ' . list_args . '' - execute 'nnoremap d :silent call TodoDoneCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap D :silent call TodoDeleteCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap p :call TodoPriorityCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap P :call TodoAppendProjectCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap C :call TodoAppendContextCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap + :silent call TodoPriorityAdjust(1):silent TodoList ' . list_args . '' - execute 'nnoremap - :silent call TodoPriorityAdjust(-1):silent TodoList ' . list_args . '' + execute 'nnoremap o :call TodoAddInput():TodoList ' . list_args . '' + execute 'nnoremap r :TodoList ' . list_args . '' + execute 'nnoremap d :silent call TodoDoneCurrent():TodoList ' . list_args . '' + execute 'nnoremap D :silent call TodoDeleteCurrent():TodoList ' . list_args . '' + execute 'nnoremap p :call TodoPriorityCurrent():TodoList ' . list_args . '' + execute 'nnoremap P :call TodoAppendProjectCurrent():TodoList ' . list_args . '' + execute 'nnoremap C :call TodoAppendContextCurrent():TodoList ' . list_args . '' + execute 'nnoremap + :silent call TodoPriorityAdjust(-1):TodoList ' . list_args . '' + execute 'nnoremap - :silent call TodoPriorityAdjust(1):TodoList ' . list_args . '' endfunction function! TodoPriorityAdjust(amount) @@ -42,12 +45,18 @@ function! TodoPriorityAdjust(amount) endif let index += 1 endwhile + if index == len(priorities) + call TodoAction('pri ' . id . ' ' . priorities[0]) + endif endfunction function! TodoAddInput() call inputsave() let task = input("Task: ") + if len(g:todo_project_context) > 0 + let task .= " " . g:todo_project_context + endif call inputrestore() call TodoAction('add "' . task . '"') endfunction From 9c56d2137a1cc59d035f2ec8edb9a2c99ce48bbb Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 15:26:32 -0600 Subject: [PATCH 5/9] added 'silent' to a bunch of calls --- vim/plugin/todo.vim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim index 5944efe..e798a0f 100644 --- a/vim/plugin/todo.vim +++ b/vim/plugin/todo.vim @@ -17,15 +17,15 @@ function! TodoList(args) endif call Todo('list ' . list_args) nnoremap q :q - execute 'nnoremap o :call TodoAddInput():TodoList ' . list_args . '' + execute 'nnoremap o :call TodoAddInput():silent TodoList ' . list_args . '' execute 'nnoremap r :TodoList ' . list_args . '' - execute 'nnoremap d :silent call TodoDoneCurrent():TodoList ' . list_args . '' - execute 'nnoremap D :silent call TodoDeleteCurrent():TodoList ' . list_args . '' - execute 'nnoremap p :call TodoPriorityCurrent():TodoList ' . list_args . '' - execute 'nnoremap P :call TodoAppendProjectCurrent():TodoList ' . list_args . '' - execute 'nnoremap C :call TodoAppendContextCurrent():TodoList ' . list_args . '' - execute 'nnoremap + :silent call TodoPriorityAdjust(-1):TodoList ' . list_args . '' - execute 'nnoremap - :silent call TodoPriorityAdjust(1):TodoList ' . list_args . '' + execute 'nnoremap d :silent call TodoDoneCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap D :silent call TodoDeleteCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap p :call TodoPriorityCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap P :call TodoAppendProjectCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap C :call TodoAppendContextCurrent():silent TodoList ' . list_args . '' + execute 'nnoremap + :silent call TodoPriorityAdjust(-1):silent TodoList ' . list_args . '' + execute 'nnoremap - :silent call TodoPriorityAdjust(1):silent TodoList ' . list_args . '' endfunction function! TodoPriorityAdjust(amount) @@ -58,7 +58,7 @@ function! TodoAddInput() let task .= " " . g:todo_project_context endif call inputrestore() - call TodoAction('add "' . task . '"') + silent call TodoAction('add "' . task . '"') endfunction function! TodoCurrentLineId() let row = split(getline('.')) From 20e04d5a4de9308b2335009995bd8ee1578e5167 Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 15:38:46 -0600 Subject: [PATCH 6/9] more 'silent' additions --- vim/plugin/todo.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim index e798a0f..ea67212 100644 --- a/vim/plugin/todo.vim +++ b/vim/plugin/todo.vim @@ -80,7 +80,7 @@ function! TodoPriorityCurrent() call inputsave() let priority = input("Priority (A-Z): ", "A") call inputrestore() - call TodoAction('pri ' . id . ' ' . priority) + silent call TodoAction('pri ' . id . ' ' . priority) endfunction function! TodoAppendContextCurrent() @@ -88,7 +88,7 @@ function! TodoAppendContextCurrent() call inputsave() let context = input("Context: ", "@", "customlist,CompleteTodoProjects") call inputrestore() - call TodoAction('append ' . id . ' ' . context) + silent call TodoAction('append ' . id . ' ' . context) endfunction function! TodoAppendProjectCurrent() @@ -96,7 +96,7 @@ function! TodoAppendProjectCurrent() call inputsave() let project = input("Project: ", "+", "customlist,CompleteTodoProjects") call inputrestore() - call TodoAction('append ' . id . ' ' . project) + silent call TodoAction('append ' . id . ' ' . project) endfunction function! TodoListProj() From f6cf3fe76fcf3a535591dc006c6c69c625ef6361 Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 15:55:59 -0600 Subject: [PATCH 7/9] fixed auto-complete function name for contexts --- vim/plugin/todo.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim index ea67212..5a6db8e 100644 --- a/vim/plugin/todo.vim +++ b/vim/plugin/todo.vim @@ -86,7 +86,7 @@ endfunction function! TodoAppendContextCurrent() let id = TodoCurrentLineId() call inputsave() - let context = input("Context: ", "@", "customlist,CompleteTodoProjects") + let context = input("Context: ", "@", "customlist,CompleteTodoContexts") call inputrestore() silent call TodoAction('append ' . id . ' ' . context) endfunction From 0e326067e3865a1a3fc9676c82cf55b85bf672c0 Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Thu, 3 Dec 2009 13:14:13 -0600 Subject: [PATCH 8/9] fixed tabs/spaces, also set height on new window --- vim/plugin/todo.vim | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim index 5a6db8e..b9876df 100644 --- a/vim/plugin/todo.vim +++ b/vim/plugin/todo.vim @@ -1,9 +1,9 @@ if !exists('g:todo_project_context') - let g:todo_project_context = '' + let g:todo_project_context = '' endif -command! -nargs=* Todo call Todo() -command! -nargs=+ TodoAdd call TodoAdd() +command! -nargs=* Todo call Todo() +command! -nargs=+ TodoAdd call TodoAdd() command! -nargs=* -complete=customlist,CompleteTodoList TodoList call TodoList() command! -nargs=0 TodoListProjects call TodoListProj() command! -nargs=0 TodoListContexts call TodoListCon() @@ -166,11 +166,12 @@ function! s:OpenTodoBuffer(content) if exists('b:is_todo_output_buffer') && b:is_todo_output_buffer enew! else - new + 10new endif - setlocal buftype=nofile readonly modifiable - silent put=a:content - keepjumps 0d - setlocal nomodifiable - let b:is_todo_output_buffer = 1 + setlocal buftype=nofile readonly modifiable + silent put=a:content + keepjumps 0d + setlocal nomodifiable + setlocal winfixheight + let b:is_todo_output_buffer = 1 endfunction From bf537934d7b2db5f9fe38a082932e19c51e7b28b Mon Sep 17 00:00:00 2001 From: Gina Trapani Date: Tue, 5 Jan 2010 20:54:14 -0800 Subject: [PATCH 9/9] Removed vim plugin; should be in separate repo for addons --- vim/plugin/todo.vim | 177 --------------------------------------- vim/syntax/todo-list.vim | 29 ------- 2 files changed, 206 deletions(-) delete mode 100644 vim/plugin/todo.vim delete mode 100644 vim/syntax/todo-list.vim diff --git a/vim/plugin/todo.vim b/vim/plugin/todo.vim deleted file mode 100644 index b9876df..0000000 --- a/vim/plugin/todo.vim +++ /dev/null @@ -1,177 +0,0 @@ -if !exists('g:todo_project_context') - let g:todo_project_context = '' -endif - -command! -nargs=* Todo call Todo() -command! -nargs=+ TodoAdd call TodoAdd() -command! -nargs=* -complete=customlist,CompleteTodoList TodoList call TodoList() -command! -nargs=0 TodoListProjects call TodoListProj() -command! -nargs=0 TodoListContexts call TodoListCon() -nnoremap tl :TodoList -nnoremap ta :TodoAdd - -function! TodoList(args) - let list_args = a:args - if match(list_args, g:todo_project_context) == -1 - let list_args .= " " . g:todo_project_context - endif - call Todo('list ' . list_args) - nnoremap q :q - execute 'nnoremap o :call TodoAddInput():silent TodoList ' . list_args . '' - execute 'nnoremap r :TodoList ' . list_args . '' - execute 'nnoremap d :silent call TodoDoneCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap D :silent call TodoDeleteCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap p :call TodoPriorityCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap P :call TodoAppendProjectCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap C :call TodoAppendContextCurrent():silent TodoList ' . list_args . '' - execute 'nnoremap + :silent call TodoPriorityAdjust(-1):silent TodoList ' . list_args . '' - execute 'nnoremap - :silent call TodoPriorityAdjust(1):silent TodoList ' . list_args . '' -endfunction - -function! TodoPriorityAdjust(amount) - let id = TodoCurrentLineId() - let item = getline('.') - let priorities = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] - let index = 0 - while index < len(priorities) - let p = priorities[index] - if match(item, "(" . p . ")") > -1 - if index + a:amount >= len(priorities) - call TodoAction('pri ' . id . ' ' . priorities[0]) - else - call TodoAction('pri ' . id . ' ' . priorities[index + a:amount]) - endif - break - endif - let index += 1 - endwhile - if index == len(priorities) - call TodoAction('pri ' . id . ' ' . priorities[0]) - endif - -endfunction - -function! TodoAddInput() - call inputsave() - let task = input("Task: ") - if len(g:todo_project_context) > 0 - let task .= " " . g:todo_project_context - endif - call inputrestore() - silent call TodoAction('add "' . task . '"') -endfunction -function! TodoCurrentLineId() - let row = split(getline('.')) - return row[0] -endfunction - -function! TodoDoneCurrent() - let id = TodoCurrentLineId() - call TodoAction('do ' . id) -endfunction - -function! TodoDeleteCurrent() - let id = TodoCurrentLineId() - call TodoAction('rm ' . id) -endfunction - -function! TodoPriorityCurrent() - let id = TodoCurrentLineId() - call inputsave() - let priority = input("Priority (A-Z): ", "A") - call inputrestore() - silent call TodoAction('pri ' . id . ' ' . priority) -endfunction - -function! TodoAppendContextCurrent() - let id = TodoCurrentLineId() - call inputsave() - let context = input("Context: ", "@", "customlist,CompleteTodoContexts") - call inputrestore() - silent call TodoAction('append ' . id . ' ' . context) -endfunction - -function! TodoAppendProjectCurrent() - let id = TodoCurrentLineId() - call inputsave() - let project = input("Project: ", "+", "customlist,CompleteTodoProjects") - call inputrestore() - silent call TodoAction('append ' . id . ' ' . project) -endfunction - -function! TodoListProj() - call TodoAction('listproj') -endfunction - -function! TodoListCon() - call TodoAction('listcon') -endfunction - -function! TodoAdd(args) - call TodoAction('add "' . a:args . ' ' . g:todo_project_context . '"') -endfunction - -function! CompleteTodo(type, arg_lead, cmd_line, cursor_pos) - let opts = split(SystemTodo('list' . a:type)) - return filter(opts, 'match(v:val, ''\V'' . a:arg_lead) == 0') -endfunction - -function! CompleteTodoContexts(arg_lead, cmd_line, cursor_pos) - return CompleteTodo('con', a:arg_lead, a:cmd_line, a:cursor_pos) -endfunction - -function! CompleteTodoProjects(arg_lead, cmd_line, cursor_pos) - return CompleteTodo('proj', a:arg_lead, a:cmd_line, a:cursor_pos) -endfunction - -function! CompleteTodoList(arg_lead, cmd_line, cursor_pos) - let opts = [ ] - if !strlen(a:arg_lead) || a:arg_lead =~ '^+' - let opts += CompleteTodoProjects(a:arg_lead, a:cmd_line, a:cursor_pos) - endif - if !strlen(a:arg_lead) || a:arg_lead =~ '^@' - let opts += CompleteTodoContexts(a:arg_lead, a:cmd_line, a:cursor_pos) - endif - return opts -endfunction - -function! TodoAction(args) - echo SystemTodo(a:args) -endfunction - -function! Todo(args) - let todo_output = SystemTodo(a:args) - if !strlen(todo_output) - echo "No output from todo command" - return - endif - call OpenTodoBuffer(todo_output) - setlocal filetype=todo-list -endfunction - -function! s:SystemTodo(args) - let default_args = DefaultTodoArgs() - return system('todo.sh ' . default_args . ' ' . a:args . ' < /dev/null') -endfunction - -function! s:DefaultTodoArgs() - let args = '-p' - if exists('g:todotxt_cfg_file') && strlen(g:todotxt_cfg_file) - args += ' -d ' . g:todotxt_cfg_file - endif - return args -endfunction - -function! s:OpenTodoBuffer(content) - if exists('b:is_todo_output_buffer') && b:is_todo_output_buffer - enew! - else - 10new - endif - setlocal buftype=nofile readonly modifiable - silent put=a:content - keepjumps 0d - setlocal nomodifiable - setlocal winfixheight - let b:is_todo_output_buffer = 1 -endfunction diff --git a/vim/syntax/todo-list.vim b/vim/syntax/todo-list.vim deleted file mode 100644 index b8974c0..0000000 --- a/vim/syntax/todo-list.vim +++ /dev/null @@ -1,29 +0,0 @@ -if exists("b:current_syntax") - finish -endif - -syntax match todoItemID /^\d\+/ contained -syntax match todoItemPriorityA /(A)/ contained -syntax match todoItemPriorityB /(B)/ contained -syntax match todoItemPriorityC /(C)/ contained -syntax match todoItemPriority /([D-Z])/ contained -syntax match todoItemProject /+[^ ]\+/ contained -syntax match todoItemContext /@[^ ]\+/ contained -syntax match todoItemText /^\d\+ .*$/ contains=todoItemID,todoItemProject,todoItemContext,todoItemPriority,todoItemPriorityA,todoItemPriorityB,todoItemPriorityC -syntax match todoItemSeparator +--+ -syntax match todoItemSummary /^TODO:.*/ - -hi link todoItemID Statement -hi link todoItemProject Identifier -hi link todoItemContext Type -hi link todoItemText Comment - -hi link todoItemPriority Constant -hi link todoItemPriorityA Todo -hi link todoItemPriorityB Visual -hi link todoItemPriorityC DiffAdd - -hi link todoItemSeparator Ignore -hi link todoItemSummary Ignore - -let b:current_syntax = "todo-list"