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