diff options
-rw-r--r-- | autoload/hints.vim | 37 | ||||
-rw-r--r-- | autoload/hints/plugins.vim | 20 |
2 files changed, 35 insertions, 22 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' diff --git a/autoload/hints/plugins.vim b/autoload/hints/plugins.vim index db08535..645b07e 100644 --- a/autoload/hints/plugins.vim +++ b/autoload/hints/plugins.vim @@ -17,16 +17,16 @@ endfunction let s:WHITESPACE_OR_COMMENT='\(^\s*$\)\|\(^\s*//\)\|\(^\s*\*/\)' function! s:java_plugin.TagLine(linenr, line) dict return v:true - # if self.last_line =~ s:WHITESPACE_OR_COMMENT - # \ && !(a:line =~ s:WHITESPACE_OR_COMMENT) - # let self.last_line = a:line - # return v:true - # endif - # let self.last_line = a:line + " if self.last_line =~ s:WHITESPACE_OR_COMMENT + " \ && !(a:line =~ s:WHITESPACE_OR_COMMENT) + " let self.last_line = a:line + " return v:true + " endif + " let self.last_line = a:line - # return - # \ a:line =~ '^\s*}$' || - # \ a:line =~ '\<\(public\|private\|protected\|class\|static\|try\|while\|for\|if\|else\|catch\)\>' + " return + " \ a:line =~ '^\s*}$' || + " \ a:line =~ '\<\(public\|private\|protected\|class\|static\|try\|while\|for\|if\|else\|catch\)\>' endfunction function! hints#plugins#registerFt(filetype, plugin) abort @@ -46,7 +46,7 @@ function! s:default_plugin.Before(file) endfunction let s:ISSPACE = '^\s*$' -let s:ISCOMMENT = '^\s*#' +let s:ISCOMMENT = '^\s*[-/#;"(]' function! s:default_plugin.TagLine(linenr, line) if a:line =~ s:ISSPACE let kind = 1 |