Added per file tracking
This commit is contained in:
parent
b6a5636325
commit
1107b8460e
3 changed files with 46 additions and 29 deletions
1
.combo/none.cmb
Normal file
1
.combo/none.cmb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0
|
|
@ -13,7 +13,9 @@ Each keystroke in insert mode increases your combo,
|
||||||
but not typing for 1 second resets it.
|
but not typing for 1 second resets it.
|
||||||
The script is triggered whenever a text edit is detected in insert mode.
|
The script is triggered whenever a text edit is detected in insert mode.
|
||||||
|
|
||||||
Best score is displayed next to the current combo in square brackets.
|
Progress is tracked per filetype (and stored in ~/.vim/.combo/).
|
||||||
|
Best score is displayed next to the current combo, and in square brackets
|
||||||
|
the best score across all filetypes is shown.
|
||||||
When a new high score is achieved, it is saved inside .vim as .combo.
|
When a new high score is achieved, it is saved inside .vim as .combo.
|
||||||
If you get errors at launch, check that .combo exists and has just a
|
If you get errors at launch, check that .combo exists and has just a
|
||||||
number inside (should be 0, or last best combo).
|
number inside (should be 0, or last best combo).
|
||||||
|
@ -22,8 +24,6 @@ By default, combo is not tracked in .txt, .tex, .vim files and in files with
|
||||||
no extension. This can be removed by deleting (or commenting) the first lines
|
no extension. This can be removed by deleting (or commenting) the first lines
|
||||||
in the script.
|
in the script.
|
||||||
|
|
||||||
The plugin is not in its final version. Right now, you will need to edit
|
|
||||||
the path to the .combo file and choose where to display the combo information.
|
|
||||||
By default, the section B of airline-vim is overwritten to display current
|
By default, the section B of airline-vim is overwritten to display current
|
||||||
combo. A random Runic character has been chosen to indicate the combo field.
|
combo. A random Runic character has been chosen to indicate the combo field.
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,48 @@
|
||||||
" COMBO Counter
|
" COMBO Counter
|
||||||
let g:disable_combo = 0
|
" Choose combo file depending on extension
|
||||||
" Combo counting is disabled in plain text, LaTeX, vim config and files
|
if strlen(expand("%:e")) > 0
|
||||||
" without extension (usually configuration files)
|
let g:combo_file = $HOME . '/.vim/.combo/' . expand("%:e") . ".cmb"
|
||||||
if expand("%:e") == "txt" || expand("%:e") == "tex" || expand("%:e") == "vim" || expand("%:e") == ""
|
else
|
||||||
let g:disable_combo = 1
|
let g:combo_file = $HOME . '/.vim/.combo/none.cmb'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if g:disable_combo == 1
|
" Find best score across all filetypes
|
||||||
let g:best_combo = readfile('$HOME/.vim/.combo')
|
let scores = []
|
||||||
|
for f in split(globpath($HOME . '/.vim/.combo/', '*'), '\n')
|
||||||
|
let buf = readfile(f)
|
||||||
|
call insert(scores, buf[0])
|
||||||
|
endfor
|
||||||
|
let g:best_combo_all = max(scores)
|
||||||
|
|
||||||
|
" Find best score for current filetype
|
||||||
|
if filereadable(g:combo_file)
|
||||||
|
let g:best_combo = readfile(g:combo_file)
|
||||||
let g:best_combo = g:best_combo[0]
|
let g:best_combo = g:best_combo[0]
|
||||||
let g:airline_section_b = 'ᛥ [%{g:best_combo}]'
|
|
||||||
else
|
else
|
||||||
let g:combo_counter = 0 " The actual combo variable
|
silent !echo 0 > $HOME/.vim/.combo/%:e.cmb
|
||||||
let g:best_combo = readfile('$HOME/.vim/.combo') " ~ is not expanded ???
|
let g:best_combo = 0
|
||||||
let g:best_combo = g:best_combo[0] " Reading from file returns a list, but an int is needed
|
endif
|
||||||
let g:last_combo = reltime() " Set current time as last combo time
|
|
||||||
let g:airline_section_b = 'ᛥ %{g:combo_counter} [%{g:best_combo}]' " I use airline vim and inserted the combo meter in it
|
" Configure variables
|
||||||
function! UpdateCombo()
|
let g:combo_counter = 0 " The actual combo variable
|
||||||
if reltimefloat(reltime(g:last_combo)) > 1 " Timeout is 1 second
|
let g:timeout = 1
|
||||||
if g:combo_counter > g:best_combo " Before resetting combo counter, check if new high score
|
let g:last_combo = reltime() " Set current time as last combo time
|
||||||
call writefile([g:combo_counter], "$HOME/.vim/.combo")
|
let g:airline_section_b = 'ᛥ %{g:combo_counter}|%{g:best_combo} [%{g:best_combo_all}]' " I use airline vim and inserted the combo meter in it
|
||||||
let g:best_combo = g:combo_counter
|
function! UpdateCombo()
|
||||||
endif
|
if reltimefloat(reltime(g:last_combo)) > g:timeout " Timeout is 1 second
|
||||||
|
call SaveCombo()
|
||||||
let g:combo_counter = 1
|
let g:combo_counter = 1
|
||||||
else
|
else
|
||||||
let g:combo_counter +=1
|
let g:combo_counter +=1
|
||||||
endif
|
endif
|
||||||
let g:last_combo = reltime()
|
let g:last_combo = reltime()
|
||||||
endfunction
|
endfunction
|
||||||
autocmd TextChangedI * call UpdateCombo() " Every time text in the file changes, call combo function
|
function! SaveCombo()
|
||||||
endif
|
if g:combo_counter > g:best_combo
|
||||||
|
call writefile([g:combo_counter], g:combo_file)
|
||||||
|
let g:best_combo = g:combo_counter
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
autocmd TextChangedI * call UpdateCombo() " Every time the cursor moves, call combo function
|
||||||
|
autocmd InsertLeave * call SaveCombo()
|
||||||
|
|
Loading…
Reference in a new issue