Skip to content

Instantly share code, notes, and snippets.

@tyru
Created March 19, 2018 14:02
Show Gist options
  • Save tyru/045a4636388810f330d45730cc27b326 to your computer and use it in GitHub Desktop.
Save tyru/045a4636388810f330d45730cc27b326 to your computer and use it in GitHub Desktop.
(picked from my old repository)
function! s:run() abort
mark Z
let winnum = winnr('$')
let noexist = []
let keywords = uniq(sort(s:get_all_matches(join(getline(1, '$'), "\n"), '|\zs[^|]\{-1,}\ze|')))
let allnum = len(keywords)
let i = 1
echon "\rChecking..."
for keyword in keywords
try
keepmarks keepjumps keepalt keeppatterns silent
\ execute 'help' keyword
catch
let noexist += [keyword]
finally
if winnr('$') !=# winnum
close
endif
keepmarks keepjumps keepalt keeppatterns silent
\ normal! 'Z
" redraw
echon "\r" . printf('Checking... %d%% (%d/%d)', (100 * i) / allnum, i, allnum)
let i += 1
endtry
endfor
if !empty(noexist)
new
setlocal buftype=nofile
call setline(1, ['Wrong references:', ''] + noexist)
else
redraw
echo 'All references are correct! Good work! :)'
endif
endfunction
" XXX: taglist() doesn't pick up some candidates... why?
" function! s:run() abort
" let keywords = uniq(sort(s:get_all_matches(join(getline(1, '$'), "\n"), '|\zs[^|]\{-1,}\ze|')))
" let noexist = filter(keywords, '!empty(taglist("^\\V" . v:val . "\\v$"))')
" echom 'noexist:' string(noexist)
" if !empty(noexist)
" new
" setlocal buftype=nofile
" call setline(1, ['Wrong references:', ''] + noexist)
" else
" echo 'All references are correct! Good work! :)'
" endif
" endfunction
function! s:get_all_matches(str, pat) abort
let list = []
let idx = 0
while 1
let i = match(a:str, a:pat, idx)
if i ==# -1
break
endif
let end = matchend(a:str, a:pat, idx)
let list += [a:str[i : end-1]]
" +1 for "|"
let idx = end + 1
endwhile
return list
endfunction
call s:run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment