From ebf6a263214db16319f96e8d7d61f524df190ac7 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Tue, 9 Jul 2013 09:55:22 -0700 Subject: [PATCH] fixed some bugs having to do with floats in Vim. added --plugin to command. --- plugin/wakatime.vim | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/plugin/wakatime.vim b/plugin/wakatime.vim index 9b95a8e..24c96f4 100644 --- a/plugin/wakatime.vim +++ b/plugin/wakatime.vim @@ -2,9 +2,10 @@ " File: wakatime.vim " Description: Automatic time tracking for Vim. " Maintainer: Wakati.Me -" Version: 0.2.1 " ============================================================================ +let s:VERSION = '0.2.1' + " Init {{{ @@ -32,7 +33,7 @@ " Set default away minutes if !exists("g:wakatime_AwayMinutes") - let g:wakatime_AwayMinutes = 10 + let g:wakatime_AwayMinutes = 5 endif " Set default action frequency in seconds @@ -74,17 +75,20 @@ let targetFile = a:last[1] endif if targetFile != '' - let extras = [] + let cmd = ['python', s:plugin_directory . 'packages/wakatime/wakatime.py'] + let cmd = cmd + ['--file', shellescape(targetFile)] + let cmd = cmd + ['--time', printf('%f', a:time)] + let cmd = cmd + ['--plugin', printf('vim-wakatime/%s', s:VERSION)] if a:is_write - let extras = extras + ['--write'] + let cmd = cmd + ['--write'] endif - if a:endtime - let extras = extras + ['--endtime', printf('%f', a:endtime)] + if a:endtime > 1 + let cmd = cmd + ['--endtime', printf('%f', a:endtime)] endif - "let extras = extras + ['--verbose'] - exec "silent !python" s:plugin_directory . "packages/wakatime/wakatime.py --file" shellescape(targetFile) "--time" printf('%f', a:time) join(extras, ' ') "&" + let cmd = cmd + ['--verbose'] + exec 'silent !' . join(cmd, ' ') . ' &' let time = a:time - if a:endtime && time < a:endtime + if a:endtime > 1 && float2nr(round(time)) < float2nr(round(a:endtime)) let time = a:endtime endif call s:SetLastAction(time, targetFile) @@ -93,11 +97,11 @@ function! s:GetLastAction() if !filereadable(expand("$HOME/.wakatime.data")) - return [0, ''] + return [0.0, ''] endif let last = readfile(expand("$HOME/.wakatime.data"), '', 2) if len(last) != 2 - return [0, ''] + return [0.0, ''] endif return [str2float(last[0]), last[1]] endfunction @@ -164,13 +168,13 @@ if s:Away(now, last) call s:Api(targetFile, last[0], now, 0, last) else - call s:Api(targetFile, now, 0, 0, last) + call s:Api(targetFile, now, 0.0, 0, last) endif endif endfunction function! s:writeAction() - call s:Api(s:GetCurrentFile(), s:GetCurrentTime(), 0, 1, s:GetLastAction()) + call s:Api(s:GetCurrentFile(), s:GetCurrentTime(), 0.0, 1, s:GetLastAction()) endfunction " }}}