Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Time spent on tasks support (Closes #2)

Store total time spent on tasks in an INFO drawer
  • Loading branch information...
commit c8a602e8b12109b1120005db6fa464b724d597c6 1 parent e980d02
@mivok authored
Showing with 99 additions and 0 deletions.
  1. +20 −0 doc/todo.txt
  2. +33 −0 ftplugin/todo.vim
  3. +46 −0 test/test007.vim
View
20 doc/todo.txt
@@ -246,6 +246,26 @@ basic commands used to open/close folds are |zo| and |zc| (both normal mode
commands).
==============================================================================
+TIME SPENT ON TASKS *vimtodo-timespent*
+
+Vimtodo has limited support for logging the time spent on tasks. For each
+subtask in a todo entry, you can add the time spent tag that looks something
+like: [1.5h] (for 1.5 hours spent on the task).
+
+Vimtodo can then total up the time spent on each subtask and display the total
+in the top level task. The command to update the totals is <LocalLeader>ce,
+which will create or update a TIMETOTAL property inside the INFO drawer on the
+top level task.
+
+In addition to the normal mode command, the ex command :UpdateTimeTotal is
+provided, which will allow you to automate the updating as desired. One option
+is to update the totals just before saving the file with an autocommand. The
+following example is something you could add in ~/.vim/after/ftplugin/todo.vim
+which would automatically update the times whenever a todo file is written: >
+
+ au BufWrite <buffer> :UpdateTimeTotal
+
+==============================================================================
CONFIGURATION *vimtodo-config* *vimtodo-configuration*
Much of vimtodo's behavior can be changed if desired. There are two options
View
33 ftplugin/todo.vim
@@ -318,6 +318,7 @@ call s:Map("cs", "NextTaskState")
call s:Map("ct", "LoadTaskLink")
call s:Map("cl", "LoadLink")
call s:Map("ca", "ArchiveDone")
+call s:Map("ce", "UpdateTimeTotal")
"1}}}
" Todo entry macros
@@ -669,6 +670,38 @@ function! s:ArchiveTask(startline, endline)
endfunction
" 1}}}
+" Automatically filled in fields
+" s:UpdateTimeTotal {{{1
+" Updates any total time values for the current task
+function! s:UpdateTimeTotal()
+ let time_re = '\[\([0-9.]\+\)h\]'
+ let totaltimes = {}
+ let linenum = 1
+ let oldfilelen = line("$")
+ while linenum <= line("$")
+ let m = matchlist(getline(linenum), time_re)
+ if m != []
+ let currtask = s:GetCurrentTask(linenum)
+ let drawerline = s:FindOrMakeDrawer("INFO", currtask[0])
+ let currtotal = get(totaltimes, drawerline, 0)
+ let totaltimes[drawerline] = currtotal + str2float(m[1])
+ endif
+ let linenum += 1
+ " Skip ahead if the file grew in length because we added a drawer
+ let linenum += (line("$") - oldfilelen)
+ let oldfilelen = line("$")
+ endwhile
+ " Update the drawers here (in reverse order as updating will likely change
+ " line numbers)
+ for drawer in reverse(sort(keys(totaltimes)))
+ call s:SetProperty(drawer, "TOTALTIME",
+ \printf("%.2f", totaltimes[drawer]))
+ endfor
+endfunction
+" Command definition
+command -buffer UpdateTimeTotal :call s:UpdateTimeTotal()
+" 1}}}
+
" Restore the old compatible mode setting {{{1
let &cpo = s:save_cpo
"1}}}
View
46 test/test007.vim
@@ -0,0 +1,46 @@
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+" Test task time totals
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+source setup_tests.inc
+call vimtap#Plan(7)
+
+" Basic test
+normal icn TODO test entry
+normal o Some Subtask [0.5h]
+normal o Some other subtask [1.5h]
+
+normal \ce
+call vimtap#Is(getline(2), " :INFO:",
+ \ "INFO drawer created")
+call vimtap#Is(getline(3), " +TOTALTIME: 2.00",
+ \ "TOTALTIME property added")
+
+normal ggdG
+
+" Try with two entries instead of 1
+normal icn TODO test entry [2.5h]
+normal o Some subtask [1.5h]
+normal o Some subtask [13.25h]
+normal ocn TODO another entry
+normal o Subtask 1 [1.00h]
+normal o Subtask 2 [4.75h]
+
+normal \ce
+call vimtap#Is(getline(2), " :INFO:",
+ \ "First INFO drawer created (2 entries)")
+call vimtap#Is(getline(3), " +TOTALTIME: 17.25",
+ \ "First total time correct (2 entries)")
+call vimtap#Is(getline(7), " :INFO:",
+ \ "Second INFO drawer created (2 entries)")
+call vimtap#Is(getline(8), " +TOTALTIME: 5.75",
+ \ "Second total time correct (2 entries)")
+
+" Change one time entry
+" Open all folds first
+normal zR
+normal 4Gc$Some subtask [1.75h]
+normal \ce
+call vimtap#Is(getline(3), " +TOTALTIME: 17.50",
+ \ "Total time changed correctly")
+
+call vimtest#Quit()
Please sign in to comment.
Something went wrong with that request. Please try again.