When doing VimwikiCheckLinks, check if index files exist
Also, clean the code a bit
This commit is contained in:
parent
82c435c1e4
commit
ad4a12612c
@ -766,13 +766,13 @@ function! vimwiki#base#check_links() "{{{
|
|||||||
\'text': "there is no such anchor: ".target_anchor})
|
\'text': "there is no such anchor: ".target_anchor})
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if target_file =~ '/$' " maybe it's a link to a directory
|
if target_file =~ '\m/$' " maybe it's a link to a directory
|
||||||
if !isdirectory(target_file)
|
if !isdirectory(target_file)
|
||||||
call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
|
call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
|
||||||
\'text': "there is no such directory: ".target_file})
|
\'text': "there is no such directory: ".target_file})
|
||||||
endif
|
endif
|
||||||
else
|
else " maybe it's a non-wiki file
|
||||||
if filereadable(target_file) " maybe it's a non-wiki file
|
if filereadable(target_file)
|
||||||
let anchors_of_files[target_file] = []
|
let anchors_of_files[target_file] = []
|
||||||
else
|
else
|
||||||
call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
|
call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
|
||||||
@ -783,33 +783,50 @@ function! vimwiki#base#check_links() "{{{
|
|||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
|
||||||
|
" Check which wiki files are reachable from at least one of the index files.
|
||||||
|
" First, all index files are marked as reachable. Then, pick a reachable file
|
||||||
|
" and mark all files to which it links as reachable, too. Repeat until the
|
||||||
|
" links of all reachable files have been checked.
|
||||||
|
|
||||||
|
" Map every wiki file to a number. 0 means not reachable from any index file,
|
||||||
|
" 1 means reachable, but the outgoing links are not checked yet, 2 means
|
||||||
|
" reachable and done.
|
||||||
let reachable_wikifiles = {}
|
let reachable_wikifiles = {}
|
||||||
|
|
||||||
|
" first, all files are considered not reachable
|
||||||
for wikifile in keys(links_of_files)
|
for wikifile in keys(links_of_files)
|
||||||
let reachable_wikifiles[wikifile] = 0
|
let reachable_wikifiles[wikifile] = 0
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
" mark every index file as reachable
|
||||||
for idx in range(len(g:vimwiki_list))
|
for idx in range(len(g:vimwiki_list))
|
||||||
let index_file = VimwikiGet('path', idx) . VimwikiGet('index', idx) .
|
let index_file = VimwikiGet('path', idx) . VimwikiGet('index', idx) .
|
||||||
\ VimwikiGet('ext', idx)
|
\ VimwikiGet('ext', idx)
|
||||||
|
if filereadable(index_file)
|
||||||
let reachable_wikifiles[index_file] = 1
|
let reachable_wikifiles[index_file] = 1
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
while 1
|
while 1
|
||||||
let visit_wikifile = ''
|
let next_unvisited_wikifile = ''
|
||||||
for wf in keys(reachable_wikifiles)
|
for wf in keys(reachable_wikifiles)
|
||||||
if reachable_wikifiles[wf] == 1
|
if reachable_wikifiles[wf] == 1
|
||||||
let visit_wikifile = wf
|
let next_unvisited_wikifile = wf
|
||||||
let reachable_wikifiles[wf] = 2
|
let reachable_wikifiles[wf] = 2
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
if visit_wikifile == ''
|
if next_unvisited_wikifile == ''
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
for [target_file, target_anchor, lnum, col] in links_of_files[visit_wikifile]
|
for [target_file, target_anchor, lnum, col] in links_of_files[next_unvisited_wikifile]
|
||||||
if has_key(reachable_wikifiles, target_file) && reachable_wikifiles[target_file] == 0
|
if has_key(reachable_wikifiles, target_file) && reachable_wikifiles[target_file] == 0
|
||||||
let reachable_wikifiles[target_file] = 1
|
let reachable_wikifiles[target_file] = 1
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
for wf in keys(reachable_wikifiles)
|
for wf in keys(reachable_wikifiles)
|
||||||
if reachable_wikifiles[wf] == 0
|
if reachable_wikifiles[wf] == 0
|
||||||
call add(errors, {'text':wf." is not reachable from the index file"})
|
call add(errors, {'text':wf." is not reachable from the index file"})
|
||||||
@ -817,7 +834,7 @@ function! vimwiki#base#check_links() "{{{
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
if empty(errors)
|
if empty(errors)
|
||||||
echom 'vimwiki: all links are OK'
|
echom 'Vimwiki: all links are OK'
|
||||||
else
|
else
|
||||||
call setqflist(errors, 'r')
|
call setqflist(errors, 'r')
|
||||||
copen
|
copen
|
||||||
|
Loading…
Reference in New Issue
Block a user