Change: VimwikiCheckLinks work on current wiki or on given range

Problem: VimwikiCheckLinks can be slow
Solution: Work only on current wiki or accept a range
This commit is contained in:
Tinmarino 2020-08-08 04:01:31 -04:00
parent 659ca62b29
commit dede5a1eea
3 changed files with 16 additions and 4 deletions

View File

@ -955,11 +955,20 @@ endfunction
" Check if all wikilinks are reachable. Answer in quickfix " Check if all wikilinks are reachable. Answer in quickfix
function! vimwiki#base#check_links() abort function! vimwiki#base#check_links(range, line1, line2) abort
if a:range == 0
let wiki_list = [vimwiki#vars#get_bufferlocal('wiki_nr')]
elseif a:range == 1
let wiki_list = [a:line1]
else
let wiki_list = range(a:line1, a:line2)
endif
echom 'Vimwiki Checking links in wikis ' . string(wiki_list)
let anchors_of_files = {} let anchors_of_files = {}
let links_of_files = {} let links_of_files = {}
let errors = [] let errors = []
for idx in range(vimwiki#vars#number_of_wikis()) for idx in wiki_list
let syntax = vimwiki#vars#get_wikilocal('syntax', idx) let syntax = vimwiki#vars#get_wikilocal('syntax', idx)
let wikifiles = vimwiki#base#find_files(idx, 0) let wikifiles = vimwiki#base#find_files(idx, 0)
for wikifile in wikifiles for wikifile in wikifiles
@ -1013,7 +1022,7 @@ function! vimwiki#base#check_links() abort
endfor endfor
" Mark: every index file as reachable " Mark: every index file as reachable
for idx in range(vimwiki#vars#number_of_wikis()) for idx in wiki_list
let index_file = vimwiki#vars#get_wikilocal('path', idx) . let index_file = vimwiki#vars#get_wikilocal('path', idx) .
\ vimwiki#vars#get_wikilocal('index', idx) . vimwiki#vars#get_wikilocal('ext', idx) \ vimwiki#vars#get_wikilocal('index', idx) . vimwiki#vars#get_wikilocal('ext', idx)
if filereadable(index_file) if filereadable(index_file)

View File

@ -929,6 +929,8 @@ Vimwiki file.
and links to external files actually exist. Check also if all wiki files and links to external files actually exist. Check also if all wiki files
are reachable from the index file. The results are shown in the quickfix are reachable from the index file. The results are shown in the quickfix
window. window.
With range: the wiki number, by default current wiki
*:VimwikiRebuildTags* *:VimwikiRebuildTags*
Rebuilds the tags metadata file for all wiki files newer than the metadata Rebuilds the tags metadata file for all wiki files newer than the metadata
@ -3761,6 +3763,7 @@ New:~
* PR #934: RSS feed generation for diary with :VimwikiRss. * PR #934: RSS feed generation for diary with :VimwikiRss.
Changed:~ Changed:~
* VimwikiCheckLinks work on current wiki or on range
* |g:vimwiki_toc_link_format| == 0 (default) means old behavior: short links * |g:vimwiki_toc_link_format| == 0 (default) means old behavior: short links
Removed:~ Removed:~

View File

@ -295,7 +295,7 @@ command! -buffer -nargs=* VWS call vimwiki#base#search(<q-args>)
command! -buffer -nargs=* -complete=customlist,vimwiki#base#complete_links_escaped command! -buffer -nargs=* -complete=customlist,vimwiki#base#complete_links_escaped
\ VimwikiGoto call vimwiki#base#goto(<f-args>) \ VimwikiGoto call vimwiki#base#goto(<f-args>)
command! -buffer VimwikiCheckLinks call vimwiki#base#check_links() command! -buffer -range VimwikiCheckLinks call vimwiki#base#check_links(<range>, <line1>, <line2>)
" list commands " list commands
command! -buffer -nargs=+ VimwikiReturn call <SID>CR(<f-args>) command! -buffer -nargs=+ VimwikiReturn call <SID>CR(<f-args>)