fixed bug triggered when opening fresh vim

This commit is contained in:
Alan Hamlett 2013-07-07 22:18:47 -07:00
parent 0b07cb21bd
commit a58ffed60c
1 changed files with 12 additions and 10 deletions

View File

@ -38,6 +38,7 @@
" Globals " Globals
let s:plugin_directory = expand("<sfile>:p:h") . '/' let s:plugin_directory = expand("<sfile>:p:h") . '/'
let s:last_action = 0 let s:last_action = 0
let s:fresh = 1
" Import things python needs " Import things python needs
python import time python import time
@ -57,7 +58,7 @@
return current_time return current_time
endfunction endfunction
function! s:api(targetFile, time, endtime, is_write, last) function! s:Api(targetFile, time, endtime, is_write, last)
let targetFile = a:targetFile let targetFile = a:targetFile
if targetFile == '' if targetFile == ''
let targetFile = a:last[1] let targetFile = a:last[1]
@ -91,10 +92,11 @@
endfunction endfunction
function! s:SetLastAction(time, targetFile) function! s:SetLastAction(time, targetFile)
let s:fresh = 0
call writefile([a:time, a:targetFile], expand("$HOME/.wakatime.data")) call writefile([a:time, a:targetFile], expand("$HOME/.wakatime.data"))
endfunction endfunction
function! s:getchar() function! s:GetChar()
let c = getchar() let c = getchar()
if c =~ '^\d\+$' if c =~ '^\d\+$'
let c = nr2char(c) let c = nr2char(c)
@ -102,15 +104,15 @@
return c return c
endfunction endfunction
function! s:enoughTimePassed(now, prev) function! s:EnoughTimePassed(now, prev)
if a:now - a:prev >= 299 if a:now - a:prev >= 299
return 1 return 1
endif endif
return 0 return 0
endfunction endfunction
function! s:away(now, last) function! s:Away(now, last)
if a:last[0] < 1 if s:fresh || a:last[0] < 1
return 0 return 0
endif endif
@ -146,17 +148,17 @@
let targetFile = s:GetCurrentFile() let targetFile = s:GetCurrentFile()
let now = s:GetCurrentTime() let now = s:GetCurrentTime()
let last = s:GetLastAction() let last = s:GetLastAction()
if s:enoughTimePassed(now, last[0]) || targetFile != last[1] if s:EnoughTimePassed(now, last[0]) || targetFile != last[1]
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, 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, 1, s:GetLastAction())
endfunction endfunction
" }}} " }}}