aboutsummaryrefslogtreecommitdiff
path: root/autoload/hints.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/hints.vim')
-rw-r--r--autoload/hints.vim45
1 files changed, 31 insertions, 14 deletions
diff --git a/autoload/hints.vim b/autoload/hints.vim
index ac0a3e5..757fc5f 100644
--- a/autoload/hints.vim
+++ b/autoload/hints.vim
@@ -1,6 +1,6 @@
" Display qutebrowser-like hints.
-" Max number of tags is 105, which is LCM(21, 5)
+" Max number of tags is 105, which is LCM(21, 5) because 21 and 5 are coprime
let s:cons = "tnshrdlcumwfgypkbvjxqz" " 21
let s:vowel = "aeiou" " 5
@@ -20,25 +20,34 @@ function! s:generate_hints() abort
let plugin = hints#plugins#getPluginForFiletype(&ft)
call plugin.Before(expand("%"))
- let line = line('w0')
- let endline = line('w$')
+ let cur_line = line('.')
+ let line = 1
let hints = {}
+ let tag_hints = {}
for i in marklist
- let hints[i.mark] = i.pos[1]
+ let tag_hints[i.mark] = i.pos[1]
endfor
- while line <= endline
+ let hints_left = len(s:vowel) * len(s:cons)
+ let last_line = line('$')
+
+ let cnt = 0
+ while line <= last_line
if plugin.TagLine(line, getline(line))
let tag=printf("%s%s",
- \ s:cons[line % len(s:cons)], s:vowel[line % len(s:vowel)])
- let hints[tag] = line
+ \ s:cons[cnt % len(s:cons)], s:vowel[cnt % len(s:vowel)])
+ let cnt += 1
+ " We want to keep the hints closest to the cursor line.
+ if !has_key(hints, tag) || abs(cur_line - hints[tag]) > abs(cur_line - line)
+ let hints[tag] = line
+ endif
endif
let line += 1
endwhile
- return hints
+ return extend(tag_hints, hints, 'force')
endfunction
function! s:display_hints(hints) abort
@@ -76,15 +85,21 @@ function! s:cleanup_hints() abort
endfunction
function! s:get(hint_dict, str) abort
+ if a:str =~ '^[A-Z]\+$'
+ let [a, _] = s:get(a:hint_dict, tolower(a:str))
+ return [a, "^"]
+ endif
+
if has_key(a:hint_dict, a:str)
- return a:hint_dict[a:str]
+ return [a:hint_dict[a:str], col('.') . '|']
endif
if len(a:str) == 1 || a:str[0] == a:str[1]
- return s:get(a:hint_dict, "'" . a:str[0])
+ let [a, _] = s:get(a:hint_dict, "'" . a:str[0])
+ return [a, "`" . a:str[0]]
endif
- return -1
+ return [-1, '']
endfunction
function! hints#runHints(visual) abort
@@ -99,7 +114,7 @@ function! hints#runHints(visual) abort
return
endif
- if stridx(s:cons, nr2char(c1)) >= 0 || nr2char(c1) == "'"
+ if stridx(s:cons, tolower(nr2char(c1))) >= 0 || nr2char(c1) == "'"
let c2 = getchar()
else
let c2 = ""
@@ -107,7 +122,7 @@ function! hints#runHints(visual) abort
call s:cleanup_hints()
- let line = s:get(hints, nr2char(c1) . nr2char(c2))
+ let [line, act] = s:get(hints, nr2char(c1) . nr2char(c2))
if line >= 0
if a:visual == 'o'
@@ -115,6 +130,8 @@ function! hints#runHints(visual) abort
endif
norm m'
call cursor(line, 1)
- norm ^
+ if len(act) > 0
+ exec "norm! " . act
+ endif
endif
endfunction