Fix the menu entries which are sometimes not shown correctly

This commit is contained in:
EinfachToll 2014-11-26 14:35:38 +01:00
parent a3e06e4e8d
commit 19465760b4
3 changed files with 37 additions and 55 deletions

View File

@ -10,30 +10,6 @@ let g:loaded_vimwiki_auto = 1
" MISC helper functions {{{ " 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() " {{{ function! vimwiki#base#get_known_extensions() " {{{
" Getting all extensions that different wikis could have " Getting all extensions that different wikis could have
let extensions = {} let extensions = {}
@ -74,7 +50,7 @@ function! vimwiki#base#apply_wiki_options(options) " {{{ Update the current
for kk in keys(a:options) for kk in keys(a:options)
let g:vimwiki_list[g:vimwiki_current_idx][kk] = a:options[kk] let g:vimwiki_list[g:vimwiki_current_idx][kk] = a:options[kk]
endfor 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) call vimwiki#base#setup_buffer_state(g:vimwiki_current_idx)
endfunction " }}} endfunction " }}}
@ -160,27 +136,6 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
endif endif
endfunction " }}} 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 " vimwiki#base#setup_buffer_state
function! vimwiki#base#setup_buffer_state(idx) " {{{ Init page-specific variables function! vimwiki#base#setup_buffer_state(idx) " {{{ Init page-specific variables
" Only call this function *after* opening a wiki page. " 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) if idx < 0 || idx >= len(g:vimwiki_list)
echom 'Vimwiki Error: Numbered scheme refers to a non-existent wiki!' echom 'Vimwiki Error: Numbered scheme refers to a non-existent wiki!'
return [idx,'','','','','','', ''] return [idx,'','','','','','', '']
else
if idx != g:vimwiki_current_idx
call vimwiki#base#validate_wiki_options(idx)
endif
endif endif
if a:as_html 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."" echom "--- Goto_index g:curr_idx=".g:vimwiki_current_idx." ww_idx=".idx.""
endif endif
call vimwiki#base#validate_wiki_options(idx)
call vimwiki#base#edit_file(cmd, call vimwiki#base#edit_file(cmd,
\ VimwikiGet('path', idx).VimwikiGet('index', idx). \ VimwikiGet('path', idx).VimwikiGet('index', idx).
\ VimwikiGet('ext', idx), \ VimwikiGet('ext', idx),

View File

@ -234,7 +234,6 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
let idx = 0 let idx = 0
endif endif
call vimwiki#base#validate_wiki_options(idx)
call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)) call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx))
if a:0 && a:1 == 1 if a:0 && a:1 == 1
@ -265,7 +264,6 @@ function! vimwiki#diary#goto_diary_index(wnum) "{{{
let idx = 0 let idx = 0
endif endif
call vimwiki#base#validate_wiki_options(idx)
call vimwiki#base#edit_file('e', s:diary_index(idx), '') call vimwiki#base#edit_file('e', s:diary_index(idx), '')
call vimwiki#base#setup_buffer_state(idx) call vimwiki#base#setup_buffer_state(idx)
endfunction "}}} endfunction "}}}

View File

@ -48,6 +48,36 @@ function! s:find_wiki(path) "{{{
" an orphan page has been detected " an orphan page has been detected
endfunction "}}} 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() " {{{ function! s:vimwiki_idx() " {{{
if exists('b:vimwiki_idx') if exists('b:vimwiki_idx')
@ -108,8 +138,8 @@ function! s:setup_filetype() "{{{
endif endif
call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1}) call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1})
let idx = len(g:vimwiki_list) - 1 let idx = len(g:vimwiki_list) - 1
call Validate_wiki_options(idx)
endif endif
call vimwiki#base#validate_wiki_options(idx)
" initialize and cache global vars of current state " initialize and cache global vars of current state
call vimwiki#base#setup_buffer_state(idx) call vimwiki#base#setup_buffer_state(idx)
if g:vimwiki_debug ==3 if g:vimwiki_debug ==3
@ -161,8 +191,8 @@ function! s:setup_buffer_enter() "{{{
endif endif
call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1}) call add(g:vimwiki_list, {'path': path, 'ext': ext, 'syntax': syn, 'temp': 1})
let idx = len(g:vimwiki_list) - 1 let idx = len(g:vimwiki_list) - 1
call Validate_wiki_options(idx)
endif endif
call vimwiki#base#validate_wiki_options(idx)
" initialize and cache global vars of current state " initialize and cache global vars of current state
call vimwiki#base#setup_buffer_state(idx) call vimwiki#base#setup_buffer_state(idx)
if g:vimwiki_debug ==3 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('rxSchemeUrlMatchScheme', '\zs'.s:rxSchemes.'\ze:.*')
call s:default('rxSchemeUrlMatchUrl', s:rxSchemes.':\zs.*\ze') call s:default('rxSchemeUrlMatchUrl', s:rxSchemes.':\zs.*\ze')
" scheme regexes }}} " scheme regexes }}}
for s:idx in range(len(g:vimwiki_list))
call Validate_wiki_options(s:idx)
endfor
"}}} "}}}
" AUTOCOMMANDS for all known wiki extensions {{{ " AUTOCOMMANDS for all known wiki extensions {{{