forked from luna/vim-rana-local
fixed some bugs having to do with floats in Vim. added --plugin to command.
This commit is contained in:
parent
b2fa6cd875
commit
ebf6a26321
1 changed files with 17 additions and 13 deletions
|
@ -2,9 +2,10 @@
|
||||||
" File: wakatime.vim
|
" File: wakatime.vim
|
||||||
" Description: Automatic time tracking for Vim.
|
" Description: Automatic time tracking for Vim.
|
||||||
" Maintainer: Wakati.Me <support@wakatime.com>
|
" Maintainer: Wakati.Me <support@wakatime.com>
|
||||||
" Version: 0.2.1
|
|
||||||
" ============================================================================
|
" ============================================================================
|
||||||
|
|
||||||
|
let s:VERSION = '0.2.1'
|
||||||
|
|
||||||
|
|
||||||
" Init {{{
|
" Init {{{
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@
|
||||||
|
|
||||||
" Set default away minutes
|
" Set default away minutes
|
||||||
if !exists("g:wakatime_AwayMinutes")
|
if !exists("g:wakatime_AwayMinutes")
|
||||||
let g:wakatime_AwayMinutes = 10
|
let g:wakatime_AwayMinutes = 5
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Set default action frequency in seconds
|
" Set default action frequency in seconds
|
||||||
|
@ -74,17 +75,20 @@
|
||||||
let targetFile = a:last[1]
|
let targetFile = a:last[1]
|
||||||
endif
|
endif
|
||||||
if targetFile != ''
|
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
|
if a:is_write
|
||||||
let extras = extras + ['--write']
|
let cmd = cmd + ['--write']
|
||||||
endif
|
endif
|
||||||
if a:endtime
|
if a:endtime > 1
|
||||||
let extras = extras + ['--endtime', printf('%f', a:endtime)]
|
let cmd = cmd + ['--endtime', printf('%f', a:endtime)]
|
||||||
endif
|
endif
|
||||||
"let extras = extras + ['--verbose']
|
let cmd = cmd + ['--verbose']
|
||||||
exec "silent !python" s:plugin_directory . "packages/wakatime/wakatime.py --file" shellescape(targetFile) "--time" printf('%f', a:time) join(extras, ' ') "&"
|
exec 'silent !' . join(cmd, ' ') . ' &'
|
||||||
let time = a:time
|
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
|
let time = a:endtime
|
||||||
endif
|
endif
|
||||||
call s:SetLastAction(time, targetFile)
|
call s:SetLastAction(time, targetFile)
|
||||||
|
@ -93,11 +97,11 @@
|
||||||
|
|
||||||
function! s:GetLastAction()
|
function! s:GetLastAction()
|
||||||
if !filereadable(expand("$HOME/.wakatime.data"))
|
if !filereadable(expand("$HOME/.wakatime.data"))
|
||||||
return [0, '']
|
return [0.0, '']
|
||||||
endif
|
endif
|
||||||
let last = readfile(expand("$HOME/.wakatime.data"), '', 2)
|
let last = readfile(expand("$HOME/.wakatime.data"), '', 2)
|
||||||
if len(last) != 2
|
if len(last) != 2
|
||||||
return [0, '']
|
return [0.0, '']
|
||||||
endif
|
endif
|
||||||
return [str2float(last[0]), last[1]]
|
return [str2float(last[0]), last[1]]
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -164,13 +168,13 @@
|
||||||
if s:Away(now, last)
|
if s:Away(now, last)
|
||||||
call s:Api(targetFile, last[0], now, 0, last)
|
call s:Api(targetFile, last[0], now, 0, last)
|
||||||
else
|
else
|
||||||
call s:Api(targetFile, now, 0, 0, last)
|
call s:Api(targetFile, now, 0.0, 0, last)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:writeAction()
|
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
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
Loading…
Reference in a new issue