Don't highlight absolute links when 'maxhi' is on

Ref #105
This commit is contained in:
EinfachToll 2015-03-17 10:33:43 +01:00
parent 6922836a0c
commit 4511bf09e6
3 changed files with 29 additions and 9 deletions

View File

@ -605,7 +605,7 @@ endfunction " }}}
" vimwiki#base#generate_links " vimwiki#base#generate_links
function! vimwiki#base#generate_links() "{{{ function! vimwiki#base#generate_links() "{{{
let links = vimwiki#base#get_wikilinks(g:vimwiki_current_idx) let links = vimwiki#base#get_wikilinks(g:vimwiki_current_idx, 0)
call append(line('$'), substitute(g:vimwiki_rxH1_Template, '__Header__', 'Generated Links', '')) call append(line('$'), substitute(g:vimwiki_rxH1_Template, '__Header__', 'Generated Links', ''))
@ -686,9 +686,11 @@ function! s:find_files(wiki_nr, directories_only)
return split(globpath(root_directory, pattern), '\n') return split(globpath(root_directory, pattern), '\n')
endfunction endfunction
" Returns: a list containing the links to all wiki files for the given wiki " Returns: a list containing the links to get from the current file to all wiki
" If the given wiki number is negative, the diary of the current wiki is used " files in the given wiki.
function! vimwiki#base#get_wikilinks(wiki_nr) " If the given wiki number is negative, the diary of the current wiki is used.
" If also_absolute_links is nonzero, also return links of the form /file
function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
let files = s:find_files(a:wiki_nr, 0) let files = s:find_files(a:wiki_nr, 0)
if a:wiki_nr == g:vimwiki_current_idx if a:wiki_nr == g:vimwiki_current_idx
let cwd = vimwiki#path#wikify_path(expand('%:p:h')) let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
@ -703,21 +705,38 @@ function! vimwiki#base#get_wikilinks(wiki_nr)
let wikifile = vimwiki#path#relpath(cwd, wikifile) let wikifile = vimwiki#path#relpath(cwd, wikifile)
call add(result, wikifile) call add(result, wikifile)
endfor endfor
if a:also_absolute_links
for wikifile in files
if a:wiki_nr == g:vimwiki_current_idx
let cwd = VimwikiGet('path')
elseif a:wiki_nr < 0
let cwd = VimwikiGet('path').VimwikiGet('diary_rel_path')
endif
let wikifile = fnamemodify(wikifile, ':r') " strip extension
let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile)
call add(result, wikifile)
endfor
endif
return result return result
endfunction endfunction
" Returns: a list containing " Returns: a list containing the links to all directories from the current file
function! vimwiki#base#get_wiki_directories(wiki_nr) function! vimwiki#base#get_wiki_directories(wiki_nr)
let dirs = s:find_files(a:wiki_nr, 1) let dirs = s:find_files(a:wiki_nr, 1)
if a:wiki_nr == g:vimwiki_current_idx if a:wiki_nr == g:vimwiki_current_idx
let cwd = vimwiki#path#wikify_path(expand('%:p:h')) let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
let root_dir = VimwikiGet('path')
else else
let cwd = VimwikiGet('path', a:wiki_nr) let cwd = VimwikiGet('path', a:wiki_nr)
endif endif
let result = ['./'] let result = ['./']
for wikidir in dirs for wikidir in dirs
let wikidir = vimwiki#path#relpath(cwd, wikidir).'/' let wikidir_relative = vimwiki#path#relpath(cwd, wikidir).'/'
call add(result, wikidir) call add(result, wikidir_relative)
if a:wiki_nr == g:vimwiki_current_idx
let wikidir_absolute = '/'.vimwiki#path#relpath(root_dir, wikidir).'/'
call add(result, wikidir_absolute)
endif
endfor endfor
return result return result
endfunction endfunction

View File

@ -70,7 +70,7 @@ function! Complete_wikifiles(findstart, base)
let scheme = '' let scheme = ''
endif endif
let links = vimwiki#base#get_wikilinks(wikinumber) let links = vimwiki#base#get_wikilinks(wikinumber, 0)
let result = [] let result = []
for wikifile in links for wikifile in links
if wikifile =~ '^'.vimwiki#u#escape(prefix) if wikifile =~ '^'.vimwiki#u#escape(prefix)

View File

@ -12,7 +12,8 @@ endif
"TODO do nothing if ...? (?) "TODO do nothing if ...? (?)
let g:starttime = reltime() " start the clock let g:starttime = reltime() " start the clock
if VimwikiGet('maxhi') if VimwikiGet('maxhi')
let b:existing_wikifiles = vimwiki#base#get_wikilinks(g:vimwiki_current_idx) let b:existing_wikifiles =
\ vimwiki#base#get_wikilinks(g:vimwiki_current_idx, 1)
let b:existing_wikidirs = let b:existing_wikidirs =
\ vimwiki#base#get_wiki_directories(g:vimwiki_current_idx) \ vimwiki#base#get_wiki_directories(g:vimwiki_current_idx)
endif endif