From b5dcd1ebebd39e0314aa7c741d76aa1b6a5ea73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Fri, 27 Apr 2018 14:48:21 +0200 Subject: [PATCH] Allow wikis in subfolders of other wikis --- autoload/vimwiki/base.vim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 19f6094..4013dda 100644 --- 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