From 19465760b4ce7a66cb7bfbd2790d7c87c34cbb28 Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Wed, 26 Nov 2014 14:35:38 +0100 Subject: [PATCH] Fix the menu entries which are sometimes not shown correctly --- autoload/vimwiki/base.vim | 52 +------------------------------------- autoload/vimwiki/diary.vim | 2 -- plugin/vimwiki.vim | 38 ++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 55 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index be5082f..3d68a2c 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -10,30 +10,6 @@ let g:loaded_vimwiki_auto = 1 " MISC helper functions {{{ -" s:normalize_path -function! s:normalize_path(path) "{{{ - let g:VimwikiLog.normalize_path += 1 "XXX - " resolve doesn't work quite right with symlinks ended with / or \ - let path = substitute(a:path, '[/\\]\+$', '', '') - if path !~# '^scp:' - return resolve(expand(path)).'/' - else - return path.'/' - endif -endfunction "}}} - -" s:path_html -function! s:path_html(idx) "{{{ - let path_html = VimwikiGet('path_html', a:idx) - if !empty(path_html) - return path_html - else - let g:VimwikiLog.path_html += 1 "XXX - let path = VimwikiGet('path', a:idx) - return substitute(path, '[/\\]\+$', '', '').'_html/' - endif -endfunction "}}} - function! vimwiki#base#get_known_extensions() " {{{ " Getting all extensions that different wikis could have let extensions = {} @@ -74,7 +50,7 @@ function! vimwiki#base#apply_wiki_options(options) " {{{ Update the current for kk in keys(a:options) let g:vimwiki_list[g:vimwiki_current_idx][kk] = a:options[kk] endfor - call vimwiki#base#validate_wiki_options(g:vimwiki_current_idx) + call Validate_wiki_options(g:vimwiki_current_idx) call vimwiki#base#setup_buffer_state(g:vimwiki_current_idx) endfunction " }}} @@ -160,27 +136,6 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki endif endfunction " }}} -" vimwiki#base#validate_wiki_options -function! vimwiki#base#validate_wiki_options(idx) " {{{ Validate wiki options - " Only call this function *before* opening a wiki page. - " - " XXX: It's too early to update global / buffer variables, because they are - " still needed in their existing state for s:setup_buffer_leave() - "" let g:vimwiki_current_idx = a:idx - - " update normalized path & path_html - call VimwikiSet('path', s:normalize_path(VimwikiGet('path', a:idx)), a:idx) - call VimwikiSet('path_html', s:normalize_path(s:path_html(a:idx)), a:idx) - call VimwikiSet('template_path', - \ s:normalize_path(VimwikiGet('template_path', a:idx)), a:idx) - call VimwikiSet('diary_rel_path', - \ s:normalize_path(VimwikiGet('diary_rel_path', a:idx)), a:idx) - - " XXX: It's too early to update global / buffer variables, because they are - " still needed in their existing state for s:setup_buffer_leave() - "" call vimwiki#base#cache_buffer_state() -endfunction " }}} - " vimwiki#base#setup_buffer_state function! vimwiki#base#setup_buffer_state(idx) " {{{ Init page-specific variables " Only call this function *after* opening a wiki page. @@ -366,10 +321,6 @@ function! vimwiki#base#resolve_scheme(lnk, as_html) " {{{ Resolve scheme if idx < 0 || idx >= len(g:vimwiki_list) echom 'Vimwiki Error: Numbered scheme refers to a non-existent wiki!' return [idx,'','','','','','', ''] - else - if idx != g:vimwiki_current_idx - call vimwiki#base#validate_wiki_options(idx) - endif endif if a:as_html @@ -1140,7 +1091,6 @@ function! vimwiki#base#goto_index(wnum, ...) "{{{ echom "--- Goto_index g:curr_idx=".g:vimwiki_current_idx." ww_idx=".idx."" endif - call vimwiki#base#validate_wiki_options(idx) call vimwiki#base#edit_file(cmd, \ VimwikiGet('path', idx).VimwikiGet('index', idx). \ VimwikiGet('ext', idx), diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim index 36d59de..0ad42ec 100644 --- a/autoload/vimwiki/diary.vim +++ b/autoload/vimwiki/diary.vim @@ -234,7 +234,6 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{ let idx = 0 endif - call vimwiki#base#validate_wiki_options(idx) call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)) if a:0 && a:1 == 1 @@ -265,7 +264,6 @@ function! vimwiki#diary#goto_diary_index(wnum) "{{{ let idx = 0 endif - call vimwiki#base#validate_wiki_options(idx) call vimwiki#base#edit_file('e', s:diary_index(idx), '') call vimwiki#base#setup_buffer_state(idx) endfunction "}}} diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index 738532a..5ed32ad 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -48,6 +48,36 @@ function! s:find_wiki(path) "{{{ " an orphan page has been detected endfunction "}}} +function! s:path_html(idx) "{{{ + let path_html = VimwikiGet('path_html', a:idx) + if !empty(path_html) + return path_html + else + let g:VimwikiLog.path_html += 1 "XXX + let path = VimwikiGet('path', a:idx) + return substitute(path, '[/\\]\+$', '', '').'_html/' + endif +endfunction "}}} + +function! s:normalize_path(path) "{{{ + let g:VimwikiLog.normalize_path += 1 "XXX + " resolve doesn't work quite right with symlinks ended with / or \ + let path = substitute(a:path, '[/\\]\+$', '', '') + if path !~# '^scp:' + return resolve(expand(path)).'/' + else + return path.'/' + endif +endfunction "}}} + +function! Validate_wiki_options(idx) " {{{ + call VimwikiSet('path', s:normalize_path(VimwikiGet('path', a:idx)), a:idx) + call VimwikiSet('path_html', s:normalize_path(s:path_html(a:idx)), a:idx) + call VimwikiSet('template_path', + \ s:normalize_path(VimwikiGet('template_path', a:idx)), a:idx) + call VimwikiSet('diary_rel_path', + \ s:normalize_path(VimwikiGet('diary_rel_path', a:idx)), a:idx) +endfunction " }}} function! s:vimwiki_idx() " {{{ if exists('b:vimwiki_idx') @@ -108,8 +138,8 @@ function! s:setup_filetype() "{{{ endif call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1}) let idx = len(g:vimwiki_list) - 1 + call Validate_wiki_options(idx) endif - call vimwiki#base#validate_wiki_options(idx) " initialize and cache global vars of current state call vimwiki#base#setup_buffer_state(idx) if g:vimwiki_debug ==3 @@ -161,8 +191,8 @@ function! s:setup_buffer_enter() "{{{ endif call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1}) let idx = len(g:vimwiki_list) - 1 + call Validate_wiki_options(idx) endif - call vimwiki#base#validate_wiki_options(idx) " initialize and cache global vars of current state call vimwiki#base#setup_buffer_state(idx) if g:vimwiki_debug ==3 @@ -441,6 +471,10 @@ call s:default('rxSchemeUrl', s:rxSchemes.':.*') call s:default('rxSchemeUrlMatchScheme', '\zs'.s:rxSchemes.'\ze:.*') call s:default('rxSchemeUrlMatchUrl', s:rxSchemes.':\zs.*\ze') " scheme regexes }}} + +for s:idx in range(len(g:vimwiki_list)) + call Validate_wiki_options(s:idx) +endfor "}}} " AUTOCOMMANDS for all known wiki extensions {{{