Use new access functions for buffer-local variables

Ref #256
This commit is contained in:
EinfachToll 2017-01-13 16:33:41 +01:00
parent ce5c822072
commit fea76ace23
3 changed files with 39 additions and 32 deletions

View File

@ -722,7 +722,7 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{
" a:1 -- previous vimwiki link to save
" a:2 -- should we update previous link
if a:0 && a:2 && len(a:1) > 0
let b:vimwiki_prev_link = a:1
call vimwiki#vars#set_bufferlocal('prev_link', a:1)
endif
endfunction " }}}
@ -880,8 +880,10 @@ function! s:get_wiki_buffers() "{{{
while bcount<=bufnr("$")
if bufexists(bcount)
let bname = fnamemodify(bufname(bcount), ":p")
" this may find buffers that are not part of the current wiki, but that
" doesn't hurt
if bname =~# vimwiki#vars#get_wikilocal('ext')."$"
let bitem = [bname, getbufvar(bname, "vimwiki_prev_link")]
let bitem = [bname, vimwiki#vars#get_bufferlocal('prev_link', bcount)]
call add(blist, bitem)
endif
endif
@ -894,7 +896,7 @@ endfunction " }}}
function! s:open_wiki_buffer(item) "{{{
call vimwiki#base#edit_file(':e', a:item[0], '')
if !empty(a:item[1])
call setbufvar(a:item[0], "vimwiki_prev_link", a:item[1])
call vimwiki#vars#set_bufferlocal('prev_link', a:item[1], a:item[0])
endif
endfunction " }}}
@ -1125,11 +1127,11 @@ endfunction " }}}
" vimwiki#base#go_back_link
function! vimwiki#base#go_back_link() "{{{
if exists("b:vimwiki_prev_link")
let prev_link = vimwiki#vars#get_bufferlocal('prev_link')
if prev_link !=# ''
" go back to saved wiki link
let prev_word = b:vimwiki_prev_link
execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g')
call setpos('.', prev_word[1])
execute ":e ".substitute(prev_link[0], '\s', '\\\0', 'g')
call setpos('.', prev_link[1])
else
" maybe we came here by jumping to a tag -> pop from the tag stack
silent! pop!
@ -1251,7 +1253,7 @@ function! vimwiki#base#rename_link() "{{{
let &buftype="nofile"
let cur_buffer = [expand('%:p'),
\getbufvar(expand('%:p'), "vimwiki_prev_link")]
\ vimwiki#vars#get_bufferlocal('prev_link')]
let blist = s:get_wiki_buffers()

View File

@ -540,35 +540,40 @@ function! vimwiki#vars#get_syntaxlocal(key, ...)
endfunction
" Get a variable for the buffer we are currently in.
" Get a variable for the buffer we are currently in or for the given buffer (number or name).
" Populate the variable, if it doesn't exist.
function! vimwiki#vars#get_bufferlocal(key)
if exists('b:vimwiki_'.a:key)
return b:vimwiki_{a:key}
function! vimwiki#vars#get_bufferlocal(key, ...)
let buffer = a:0 ? a:1 : '%'
let value = getbufvar(buffer, 'vimwiki_'.a:key, '/\/\')
if type(value) != 1 || value !=# '/\/\'
return value
elseif a:key ==# 'wiki_nr'
let b:vimwiki_wiki_nr = vimwiki#base#find_wiki(expand('%:p'))
return b:vimwiki_wiki_nr
call setbufvar(buffer, 'vimwiki_wiki_nr', vimwiki#base#find_wiki(expand('%:p')))
elseif a:key ==# 'subdir'
let b:vimwiki_subdir = vimwiki#base#current_subdir()
return b:vimwiki_subdir
call setbufvar(buffer, 'vimwiki_subdir', vimwiki#base#current_subdir())
elseif a:key ==# 'invsubdir'
let subdir = vimwiki#vars#get_bufferlocal('subdir')
let b:vimwiki_invsubdir = vimwiki#base#invsubdir(subdir)
return b:vimwiki_invsubdir
call setbufvar(buffer, 'vimwiki_invsubdir', vimwiki#base#invsubdir(subdir))
elseif a:key ==# 'existing_wikifiles'
let b:vimwiki_existing_wikifiles =
\ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 1)
return b:vimwiki_existing_wikifiles
call setbufvar(buffer, 'vimwiki_existing_wikifiles',
\ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 1))
elseif a:key ==# 'existing_wikidirs'
let b:vimwiki_existing_wikidirs =
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr'))
return b:vimwiki_existing_wikidirs
call setbufvar(buffer, 'vimwiki_existing_wikidirs',
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr')))
elseif a:key ==# 'prev_link'
call setbufvar(buffer, 'vimwiki_prev_link', '')
elseif a:key ==# 'fs_rescan'
call setbufvar(buffer, 'vimwiki_fs_rescan', 0)
endif
return getbufvar(buffer, 'vimwiki_'.a:key)
endfunction
function! vimwiki#vars#set_bufferlocal(key, value)
let b:vimwiki_{a:key} = a:value
function! vimwiki#vars#set_bufferlocal(key, value, ...)
let buffer = a:0 ? a:1 : '%'
call setbufvar(buffer, 'vimwiki_' . a:key, a:value)
endfunction

View File

@ -66,11 +66,11 @@ function! s:setup_new_wiki_buffer() "{{{
" to force a rescan of the filesystem which may have changed
" and update VimwikiLinks syntax group that depends on it;
" b:vimwiki_fs_rescan indicates that setup_filetype() has not been run
if exists('b:vimwiki_fs_rescan') && vimwiki#vars#get_wikilocal('maxhi')
" 'fs_rescan' indicates that setup_filetype() has not been run
if vimwiki#vars#get_bufferlocal('fs_rescan') == 1 && vimwiki#vars#get_wikilocal('maxhi')
set syntax=vimwiki
endif
let b:vimwiki_fs_rescan = 1
call vimwiki#vars#set_bufferlocal('fs_rescan', 1)
endfunction "}}}
@ -90,11 +90,11 @@ function! s:setup_buffer_enter() "{{{
elseif &syntax ==? 'vimwiki'
" to force a rescan of the filesystem which may have changed
" and update VimwikiLinks syntax group that depends on it;
" b:vimwiki_fs_rescan indicates that setup_filetype() has not been run
if exists("b:vimwiki_fs_rescan") && vimwiki#vars#get_wikilocal('maxhi')
" 'fs_rescan' indicates that setup_filetype() has not been run
if vimwiki#vars#get_bufferlocal('fs_rescan') == 1 && vimwiki#vars#get_wikilocal('maxhi')
set syntax=vimwiki
endif
let b:vimwiki_fs_rescan = 1
call vimwiki#vars#set_bufferlocal('fs_rescan', 1)
endif
" The settings foldmethod, foldexpr and foldtext are local to window. Thus in