commit b5dcd1ebebd39e0314aa7c741d76aa1b6a5ea73b
parent c8b02e4bc59dbeca81cce2a2c94af7e795a8c167
Author: Michael F. Schönitzer <michael@schoenitzer.de>
Date: Fri, 27 Apr 2018 14:48:21 +0200
Allow wikis in subfolders of other wikis
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
@@ -82,18 +82,23 @@ endfunction
" to any registered wiki.
" The path can be the full path or just the directory of the file
function! vimwiki#base#find_wiki(path)
+ let bestmatch = -1
+ let bestlen = 0
let path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(a:path))
for idx in range(vimwiki#vars#number_of_wikis())
let idx_path = expand(vimwiki#vars#get_wikilocal('path', idx))
let idx_path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(idx_path))
- if vimwiki#path#is_equal(vimwiki#path#path_common_pfx(idx_path, path), idx_path)
- return idx
+ let common_pfx = vimwiki#path#path_common_pfx(idx_path, path)
+ if vimwiki#path#is_equal(common_pfx, idx_path)
+ if len(common_pfx) > bestlen
+ let bestlen = len(common_pfx)
+ let bestmatch = idx
+ endif
endif
let idx += 1
endfor
- " an orphan page has been detected
- return -1
+ return bestmatch
endfunction