won't allow to disable combo on specific filetypes for the time being
This commit is contained in:
parent
08201add5c
commit
a7fc88de04
1 changed files with 47 additions and 52 deletions
|
@ -12,57 +12,52 @@ else
|
||||||
let g:combo_file = $HOME . '/.vim/.combo/none.cmb'
|
let g:combo_file = $HOME . '/.vim/.combo/none.cmb'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If file should be ignored, just set text, else continue with script
|
" Find best score for current filetype. If none exists, start tracking
|
||||||
if g:disable_combo
|
if filereadable(g:combo_file)
|
||||||
let g:combo = "N/A"
|
let g:best_combo = readfile(g:combo_file)
|
||||||
|
let g:best_combo = g:best_combo[0]
|
||||||
else
|
else
|
||||||
" Find best score for current filetype. If none exists, start tracking
|
silent exec '!echo 0 > ' . g:combo_file
|
||||||
if filereadable(g:combo_file)
|
let g:best_combo = 0
|
||||||
let g:best_combo = readfile(g:combo_file)
|
|
||||||
let g:best_combo = g:best_combo[0]
|
|
||||||
else
|
|
||||||
silent exec '!echo 0 > ' . g:combo_file
|
|
||||||
let g:best_combo = 0
|
|
||||||
endif
|
|
||||||
let g:best_last_combo = g:best_combo " Used to revert
|
|
||||||
|
|
||||||
" Configure variables
|
|
||||||
let g:combo_counter = 0 " The actual combo variable
|
|
||||||
let g:timeout = 1
|
|
||||||
let g:combo = printf("[%d] 0", g:best_combo)
|
|
||||||
let g:last_combo = reltime() " Set current time as last combo time
|
|
||||||
" Main check function, executed every time the file is changed
|
|
||||||
function! UpdateCombo()
|
|
||||||
if reltimefloat(reltime(g:last_combo)) > g:timeout
|
|
||||||
call SaveCombo()
|
|
||||||
let g:combo_counter = 1
|
|
||||||
else
|
|
||||||
let g:combo_counter +=1
|
|
||||||
endif
|
|
||||||
let g:combo = printf("[%d] %d", g:best_combo, g:combo_counter)
|
|
||||||
let g:last_combo = reltime()
|
|
||||||
endfunction
|
|
||||||
" Checks if a new combo has been achieved and saves it to file
|
|
||||||
function! SaveCombo() " Should check inside because it can be called on InsertLeave
|
|
||||||
if g:combo_counter > g:best_combo
|
|
||||||
call writefile([g:combo_counter], g:combo_file)
|
|
||||||
let g:best_last_combo = g:best_combo
|
|
||||||
let g:best_combo = g:combo_counter
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
autocmd TextChangedI * call UpdateCombo() " Every time text is changed, call combo function
|
|
||||||
autocmd InsertLeave * call SaveCombo()
|
|
||||||
" In case you want to revert your last combo
|
|
||||||
function! Cheated()
|
|
||||||
let g:best_combo = g:best_last_combo
|
|
||||||
let g:combo_counter = g:best_last_combo
|
|
||||||
call writefile([g:combo_counter], g:combo_file)
|
|
||||||
endfunction
|
|
||||||
" This is only needed to avoid backspace cheating.
|
|
||||||
function! Decrease()
|
|
||||||
let g:combo_counter -= 1
|
|
||||||
return "\<BS>"
|
|
||||||
endfunction
|
|
||||||
inoremap <expr> <BS> Decrease()
|
|
||||||
endif
|
endif
|
||||||
|
let g:best_last_combo = g:best_combo " Used to revert
|
||||||
|
|
||||||
|
" Configure variables
|
||||||
|
let g:combo_counter = 0 " The actual combo variable
|
||||||
|
let g:timeout = 1
|
||||||
|
let g:combo = printf("[%d] 0", g:best_combo)
|
||||||
|
let g:last_combo = reltime() " Set current time as last combo time
|
||||||
|
" Main check function, executed every time the file is changed
|
||||||
|
function! UpdateCombo()
|
||||||
|
if reltimefloat(reltime(g:last_combo)) > g:timeout
|
||||||
|
call SaveCombo()
|
||||||
|
let g:combo_counter = 1
|
||||||
|
else
|
||||||
|
let g:combo_counter +=1
|
||||||
|
endif
|
||||||
|
let g:combo = printf("[%d] %d", g:best_combo, g:combo_counter)
|
||||||
|
let g:last_combo = reltime()
|
||||||
|
endfunction
|
||||||
|
" Checks if a new combo has been achieved and saves it to file
|
||||||
|
function! SaveCombo() " Should check inside because it can be called on InsertLeave
|
||||||
|
if g:combo_counter > g:best_combo
|
||||||
|
call writefile([g:combo_counter], g:combo_file)
|
||||||
|
let g:best_last_combo = g:best_combo
|
||||||
|
let g:best_combo = g:combo_counter
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
autocmd TextChangedI * call UpdateCombo() " Every time text is changed, call combo function
|
||||||
|
autocmd InsertLeave * call SaveCombo()
|
||||||
|
" In case you want to revert your last combo
|
||||||
|
function! Cheated()
|
||||||
|
let g:best_combo = g:best_last_combo
|
||||||
|
let g:combo_counter = g:best_last_combo
|
||||||
|
call writefile([g:combo_counter], g:combo_file)
|
||||||
|
endfunction
|
||||||
|
" This is only needed to avoid backspace cheating.
|
||||||
|
function! Decrease()
|
||||||
|
let g:combo_counter -= 1
|
||||||
|
return "\<BS>"
|
||||||
|
endfunction
|
||||||
|
inoremap <expr> <BS> Decrease()
|
||||||
|
|
Loading…
Reference in a new issue