diff options
Diffstat (limited to 'autoload/hints.vim')
-rw-r--r-- | autoload/hints.vim | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/autoload/hints.vim b/autoload/hints.vim index 7ab8797..ac0a3e5 100644 --- a/autoload/hints.vim +++ b/autoload/hints.vim @@ -1,7 +1,7 @@ " Display qutebrowser-like hints. " Max number of tags is 105, which is LCM(21, 5) -let s:cons = "bcdfghjklmnpqrstvwxyz" " 21 +let s:cons = "tnshrdlcumwfgypkbvjxqz" " 21 let s:vowel = "aeiou" " 5 let s:signs_to_unplace = [] @@ -15,27 +15,24 @@ endif " Generate hints on the current file. This may use specific plugins for each " filetype. function! s:generate_hints() abort + let marklist = getmarklist(bufnr()) + let plugin = hints#plugins#getPluginForFiletype(&ft) call plugin.Before(expand("%")) - let ci = 0 - let vi = 0 - let line = line('w0') let endline = line('w$') let hints = {} + for i in marklist + let hints[i.mark] = i.pos[1] + endfor while line <= endline if plugin.TagLine(line, getline(line)) let tag=printf("%s%s", - \ s:cons[ci % len(s:cons)], s:vowel[vi % len(s:vowel)]) + \ s:cons[line % len(s:cons)], s:vowel[line % len(s:vowel)]) let hints[tag] = line - - " Advance _both_ the consonants and vowels. We want the tags to generally - " have as little in common as possible. - let ci += 1 - let vi += 1 endif let line += 1 @@ -78,6 +75,18 @@ function! s:cleanup_hints() abort endfor endfunction +function! s:get(hint_dict, str) abort + if has_key(a:hint_dict, a:str) + return a:hint_dict[a:str] + endif + + if len(a:str) == 1 || a:str[0] == a:str[1] + return s:get(a:hint_dict, "'" . a:str[0]) + endif + + return -1 +endfunction + function! hints#runHints(visual) abort let hints = s:generate_hints() call s:display_hints(hints) @@ -90,11 +99,15 @@ function! hints#runHints(visual) abort return endif - let c2 = getchar() + if stridx(s:cons, nr2char(c1)) >= 0 || nr2char(c1) == "'" + let c2 = getchar() + else + let c2 = "" + endif call s:cleanup_hints() - let line = get(hints, nr2char(c1) . nr2char(c2), -1) + let line = s:get(hints, nr2char(c1) . nr2char(c2)) if line >= 0 if a:visual == 'o' |