having fun with vim, an event tracker
The idea of this script came by realizing that the main reason I (almost) never fill my timesheet, is because I just forget it. How easier could it be if my editor (namely vim) could fill it for me ? Or at least, help me fill it. This script is meant to help this process. It will hook to every configured event (in the code below, BufRead and BufNewFile) and add a log line to the log file. Easy heh ? Of course, the script it self won't be of much use, I'll have to add some more events to track as well as writting some kind of frontend for it, with reporting & all.
if exists('trackloaded')
finish
endif
" list of autocmd events:
" http://www.vim.org/htmldoc/autocmd.html#autocmd-events
let trackevents = ['BufRead', 'BufNewFile', 'BufEnter', 'BufWrite', 'BufLeave']
let trackfile = '/tmp/timetrack.dat'
let trackloaded = 1
for event in trackevents
execute 'autocmd '.event.' * call Track("'.event.'")'
endfor
unlet event
function Track(event)
let l:filename = @%
if l:filename != g:trackfile
if match(l:filename, '/') != 0
let l:filename = getcwd().'/'.l:filename
endif
silent execute '!echo `date +\%s` '.a:event.' '.l:filename.' >> '.g:trackfile
endif
endfunction
You might note from this snippet that I'm not very comfortable with vimscripting :-) If you have a better way of doing this (I'm thinking mostly about the file writting here), don't hesitate to tell me.
Comments
Very sexy!
And when you combine it with backup.vim, you can see what code you actually wrote :)
Nice tip, thx.
I'm not sure to fully understand, but it appears it logs only physics interactions. While we can interpolate the time spend between first and last action, maybe that we can take more advantage from the FocusGained and FocusLost events : http://www.vim.org/htmldoc/autocmd.... .
This way, you don't have to register a huge amount of events, and your time tracking stay relevant if you have your editor already open since morning in a desktop and get to it just for thinking, without actually typing.
The problem is that it only works in gvim...
Yep I though about using the Focus* events too, I'm going to do a little testing to see what fits well and what doesn't (I mean, your vim can still have focus while you're gone to grab a cup of coffee) :-)
I'm looking forward to hook on events like "entering insert mode" too, but couldn't find an autocmd event for this, maybe I'll have to play with :map, but it seems a bit too much for this job :s
Found it, with InsertEnter and InsertLeave : http://gist.github.com/76390