From 9a56bdd4ede0cc1ea9aad31f2a369ff48bb7da1d Mon Sep 17 00:00:00 2001 From: Brian Phillips Date: Wed, 2 Dec 2009 12:09:51 -0600 Subject: [PATCH] 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"