Use new access functions for wiki-local variables -- part 1

Ref #256
This commit is contained in:
EinfachToll 2016-12-22 18:16:05 +01:00
parent 23ee20887a
commit 6221861957
7 changed files with 43 additions and 55 deletions

View File

@ -335,7 +335,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
let link_infos.filename = let link_infos.filename =
\ VimwikiGet('path', link_infos.index) . \ VimwikiGet('path', link_infos.index) .
\ VimwikiGet('diary_rel_path', link_infos.index) . \ vimwiki#vars#get_wikilocal('diary_rel_path', link_infos.index) .
\ link_text . \ link_text .
\ VimwikiGet('ext', link_infos.index) \ VimwikiGet('ext', link_infos.index)
elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local') elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local')
@ -520,7 +520,7 @@ function! vimwiki#base#find_files(wiki_nr, directories_only)
if wiki_nr >= 0 if wiki_nr >= 0
let root_directory = VimwikiGet('path', wiki_nr) let root_directory = VimwikiGet('path', wiki_nr)
else else
let root_directory = VimwikiGet('path').VimwikiGet('diary_rel_path') let root_directory = VimwikiGet('path').vimwiki#vars#get_wikilocal('diary_rel_path')
let wiki_nr = g:vimwiki_current_idx let wiki_nr = g:vimwiki_current_idx
endif endif
if a:directories_only if a:directories_only
@ -548,7 +548,7 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
if a:wiki_nr == g:vimwiki_current_idx if a:wiki_nr == g:vimwiki_current_idx
let cwd = vimwiki#path#wikify_path(expand('%:p:h')) let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
elseif a:wiki_nr < 0 elseif a:wiki_nr < 0
let cwd = VimwikiGet('path').VimwikiGet('diary_rel_path') let cwd = VimwikiGet('path').vimwiki#vars#get_wikilocal('diary_rel_path')
else else
let cwd = VimwikiGet('path', a:wiki_nr) let cwd = VimwikiGet('path', a:wiki_nr)
endif endif
@ -563,7 +563,7 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
if a:wiki_nr == g:vimwiki_current_idx if a:wiki_nr == g:vimwiki_current_idx
let cwd = VimwikiGet('path') let cwd = VimwikiGet('path')
elseif a:wiki_nr < 0 elseif a:wiki_nr < 0
let cwd = VimwikiGet('path').VimwikiGet('diary_rel_path') let cwd = VimwikiGet('path').vimwiki#vars#get_wikilocal('diary_rel_path')
endif endif
let wikifile = fnamemodify(wikifile, ':r') " strip extension let wikifile = fnamemodify(wikifile, ':r') " strip extension
let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile) let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile)
@ -1856,7 +1856,7 @@ endfunction " }}}
" s:is_diary_file " s:is_diary_file
function! s:is_diary_file(filename) " {{{ function! s:is_diary_file(filename) " {{{
let file_path = vimwiki#path#path_norm(a:filename) let file_path = vimwiki#path#path_norm(a:filename)
let rel_path = VimwikiGet('diary_rel_path') let rel_path = vimwiki#vars#get_wikilocal('diary_rel_path')
let diary_path = vimwiki#path#path_norm(VimwikiGet('path') . rel_path) let diary_path = vimwiki#path#path_norm(VimwikiGet('path') . rel_path)
return rel_path != '' return rel_path != ''
\ && file_path =~# '^'.vimwiki#u#escape(diary_path) \ && file_path =~# '^'.vimwiki#u#escape(diary_path)
@ -1889,7 +1889,7 @@ function! s:normalize_link_in_diary(lnk) " {{{
let link = a:lnk . VimwikiGet('ext') let link = a:lnk . VimwikiGet('ext')
let link_wiki = VimwikiGet('path') . '/' . link let link_wiki = VimwikiGet('path') . '/' . link
let link_diary = VimwikiGet('path') . '/' let link_diary = VimwikiGet('path') . '/'
\ . VimwikiGet('diary_rel_path') . '/' . link \ . vimwiki#vars#get_wikilocal('diary_rel_path') . '/' . link
let link_exists_in_diary = filereadable(link_diary) let link_exists_in_diary = filereadable(link_diary)
let link_exists_in_wiki = filereadable(link_wiki) let link_exists_in_wiki = filereadable(link_wiki)
let link_is_date = a:lnk =~# '\d\d\d\d-\d\d-\d\d' let link_is_date = a:lnk =~# '\d\d\d\d-\d\d-\d\d'
@ -1900,7 +1900,7 @@ function! s:normalize_link_in_diary(lnk) " {{{
let rxDesc = '' let rxDesc = ''
let template = g:vimwiki_WikiLinkTemplate1 let template = g:vimwiki_WikiLinkTemplate1
else else
let depth = len(split(VimwikiGet('diary_rel_path'), '/')) let depth = len(split(vimwiki#vars#get_wikilocal('diary_rel_path'), '/'))
let str = repeat('../', depth) . a:lnk . '|' . a:lnk let str = repeat('../', depth) . a:lnk . '|' . a:lnk
let rxUrl = '^.*\ze|' let rxUrl = '^.*\ze|'
let rxDesc = '|\zs.*$' let rxDesc = '|\zs.*$'

View File

@ -20,23 +20,22 @@ function! s:prefix_zero(num) "{{{
return a:num return a:num
endfunction "}}} endfunction "}}}
function! s:get_date_link(fmt) "{{{
return strftime(a:fmt)
endfunction "}}}
function! s:diary_path(...) "{{{ function! s:diary_path(...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1 let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
return VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx) return VimwikiGet('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx)
endfunction "}}} endfunction "}}}
function! s:diary_index(...) "{{{ function! s:diary_index(...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1 let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
return s:diary_path(idx).VimwikiGet('diary_index', idx).VimwikiGet('ext', idx) return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).VimwikiGet('ext', idx)
endfunction "}}} endfunction "}}}
function! s:diary_date_link(...) "{{{ function! vimwiki#diary#diary_date_link(...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1 if a:0
return s:get_date_link(VimwikiGet('diary_link_fmt', idx)) return strftime('%Y-%m-%d', a:1)
else
return strftime('%Y-%m-%d')
endif
endfunction "}}} endfunction "}}}
function! s:get_position_links(link) "{{{ function! s:get_position_links(link) "{{{
@ -45,8 +44,8 @@ function! s:get_position_links(link) "{{{
if a:link =~# '^\d\{4}-\d\d-\d\d' if a:link =~# '^\d\{4}-\d\d-\d\d'
let links = keys(s:get_diary_links()) let links = keys(s:get_diary_links())
" include 'today' into links " include 'today' into links
if index(links, s:diary_date_link()) == -1 if index(links, vimwiki#diary#diary_date_link()) == -1
call add(links, s:diary_date_link()) call add(links, vimwiki#diary#diary_date_link())
endif endif
call sort(links) call sort(links)
let idx = index(links, a:link) let idx = index(links, a:link)
@ -85,7 +84,7 @@ endfun "}}}
fun! s:get_diary_links() "{{{ fun! s:get_diary_links() "{{{
let rx = '^\d\{4}-\d\d-\d\d' let rx = '^\d\{4}-\d\d-\d\d'
let s_files = glob(VimwikiGet('path').VimwikiGet('diary_rel_path').'*'.VimwikiGet('ext')) let s_files = glob(VimwikiGet('path').vimwiki#vars#get_wikilocal('diary_rel_path').'*'.VimwikiGet('ext'))
let files = split(s_files, '\n') let files = split(s_files, '\n')
call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"') call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"')
@ -119,7 +118,7 @@ fun! s:group_links(links) "{{{
endfun "}}} endfun "}}}
function! s:sort(lst) "{{{ function! s:sort(lst) "{{{
if VimwikiGet("diary_sort") ==? 'desc' if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
return reverse(sort(a:lst)) return reverse(sort(a:lst))
else else
return sort(a:lst) return sort(a:lst)
@ -172,7 +171,7 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
let idx = 0 let idx = 0
endif endif
call vimwiki#path#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)) call vimwiki#path#mkdir(VimwikiGet('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx))
if a:0 && a:1 == 1 if a:0 && a:1 == 1
let cmd = 'tabedit' let cmd = 'tabedit'
@ -182,7 +181,7 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
if a:0>1 if a:0>1
let link = 'diary:'.a:2 let link = 'diary:'.a:2
else else
let link = 'diary:'.s:diary_date_link(idx) let link = 'diary:'.vimwiki#diary#diary_date_link()
endif endif
call vimwiki#base#open_link(cmd, link, s:diary_index(idx)) call vimwiki#base#open_link(cmd, link, s:diary_index(idx))
@ -218,7 +217,7 @@ function! vimwiki#diary#goto_next_day() "{{{
let link = 'diary:'.links[idx+1] let link = 'diary:'.links[idx+1]
else else
" goto today " goto today
let link = 'diary:'.s:diary_date_link() let link = 'diary:'.vimwiki#diary#diary_date_link()
endif endif
if len(link) if len(link)
@ -238,7 +237,7 @@ function! vimwiki#diary#goto_prev_day() "{{{
let link = 'diary:'.links[idx-1] let link = 'diary:'.links[idx-1]
else else
" goto today " goto today
let link = 'diary:'.s:diary_date_link() let link = 'diary:'.vimwiki#diary#diary_date_link()
endif endif
if len(link) if len(link)
@ -252,7 +251,7 @@ function! vimwiki#diary#generate_diary_section() "{{{
if vimwiki#path#is_equal(current_file, diary_file) if vimwiki#path#is_equal(current_file, diary_file)
let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.g:vimwiki_rxHeader.'\)' let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.g:vimwiki_rxHeader.'\)'
call vimwiki#base#update_listing_in_buffer(s:format_diary(), call vimwiki#base#update_listing_in_buffer(s:format_diary(),
\ VimwikiGet('diary_header'), content_rx, line('$')+1, 1) \ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1)
else else
echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!' echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!'
endif endif
@ -286,7 +285,7 @@ endfunction "}}}
function vimwiki#diary#calendar_sign(day, month, year) "{{{ function vimwiki#diary#calendar_sign(day, month, year) "{{{
let day = s:prefix_zero(a:day) let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month) let month = s:prefix_zero(a:month)
let sfile = VimwikiGet('path').VimwikiGet('diary_rel_path'). let sfile = VimwikiGet('path').vimwiki#vars#get_wikilocal('diary_rel_path').
\ a:year.'-'.month.'-'.day.VimwikiGet('ext') \ a:year.'-'.month.'-'.day.VimwikiGet('ext')
return filereadable(expand(sfile)) return filereadable(expand(sfile))
endfunction "}}} endfunction "}}}

View File

@ -1348,13 +1348,13 @@ function! s:parse_line(line, state) " {{{
endfunction " }}} endfunction " }}}
function! s:use_custom_wiki2html() "{{{ function! s:use_custom_wiki2html() "{{{
let custom_wiki2html = VimwikiGet('custom_wiki2html') let custom_wiki2html = vimwiki#vars#get_wikilocal('custom_wiki2html')
return !empty(custom_wiki2html) && (s:file_exists(custom_wiki2html) || s:binary_exists(custom_wiki2html)) return !empty(custom_wiki2html) && (s:file_exists(custom_wiki2html) || s:binary_exists(custom_wiki2html))
endfunction " }}} endfunction " }}}
function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) "{{{ function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) "{{{
call vimwiki#path#mkdir(a:path) call vimwiki#path#mkdir(a:path)
echomsg system(VimwikiGet('custom_wiki2html'). ' '. echomsg system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '.
\ a:force. ' '. \ a:force. ' '.
\ VimwikiGet('syntax'). ' '. \ VimwikiGet('syntax'). ' '.
\ strpart(VimwikiGet('ext'), 1). ' '. \ strpart(VimwikiGet('ext'), 1). ' '.

View File

@ -113,10 +113,11 @@ function! vimwiki#lst#default_symbol() "{{{
endfunction "}}} endfunction "}}}
function! vimwiki#lst#get_list_margin() "{{{ function! vimwiki#lst#get_list_margin() "{{{
if VimwikiGet('list_margin') < 0 let list_margin = vimwiki#vars#get_wikilocal('list_margin')
if list_margin < 0
return &sw return &sw
else else
return VimwikiGet('list_margin') return list_margin
endif endif
endfunction "}}} endfunction "}}}

View File

@ -105,7 +105,6 @@ function! s:populate_wikilocal_options()
\ 'custom_wiki2html': '', \ 'custom_wiki2html': '',
\ 'diary_header': 'Diary', \ 'diary_header': 'Diary',
\ 'diary_index': 'diary', \ 'diary_index': 'diary',
\ 'diary_link_fmt': '%Y-%m-%d',
\ 'diary_rel_path': 'diary/', \ 'diary_rel_path': 'diary/',
\ 'diary_sort': 'desc', \ 'diary_sort': 'desc',
\ 'ext': '.wiki', \ 'ext': '.wiki',
@ -217,12 +216,18 @@ function! vimwiki#vars#get_global(key)
endfunction endfunction
function! vimwiki#vars#get_wikilocal(wiki_nr, key) " the second argument can be a wiki number. When absent, the wiki of the currently active buffer is
return g:vimwiki_wikilocal_vars[a:wiki_nr][a:key] " used
function! vimwiki#vars#get_wikilocal(key, ...)
if a:0
return g:vimwiki_wikilocal_vars[a:1][a:key]
else
return g:vimwiki_wikilocal_vars[vimwiki#vars#get_bufferlocal('wiki_nr')][a:key]
endif
endfunction endfunction
function! vimwiki#vars#set_wikilocal(wiki_nr, key, value) function! vimwiki#vars#set_wikilocal(key, value, wiki_nr)
if a:wiki_nr == len(g:vimwiki_wikilocal_vars) - 1 if a:wiki_nr == len(g:vimwiki_wikilocal_vars) - 1
call insert(g:vimwiki_wikilocal_vars, {}, -1) call insert(g:vimwiki_wikilocal_vars, {}, -1)
endif endif

View File

@ -655,7 +655,7 @@ if VimwikiGet('auto_toc')
augroup END augroup END
endif endif
if VimwikiGet('auto_tags') if vimwiki#vars#get_wikilocal('auto_tags')
" Automatically update tags metadata on page write. " Automatically update tags metadata on page write.
augroup vimwiki augroup vimwiki
au BufWritePost <buffer> call vimwiki#tags#update_tags(0, '') au BufWritePost <buffer> call vimwiki#tags#update_tags(0, '')

View File

@ -44,8 +44,8 @@ function! Validate_wiki_options(idx) " {{{
call VimwikiSet('path_html', s:normalize_path(s:path_html(a:idx)), a:idx) call VimwikiSet('path_html', s:normalize_path(s:path_html(a:idx)), a:idx)
call VimwikiSet('template_path', call VimwikiSet('template_path',
\ s:normalize_path(VimwikiGet('template_path', a:idx)), a:idx) \ s:normalize_path(VimwikiGet('template_path', a:idx)), a:idx)
call VimwikiSet('diary_rel_path', call vimwiki#vars#set_wikilocal('diary_rel_path',
\ s:normalize_path(VimwikiGet('diary_rel_path', a:idx)), a:idx) \ s:normalize_path(vimwiki#vars#get_wikilocal('diary_rel_path', a:idx)), a:idx)
endfunction " }}} endfunction " }}}
function! s:vimwiki_idx() " {{{ function! s:vimwiki_idx() " {{{
@ -339,23 +339,6 @@ let s:vimwiki_defaults.auto_toc = 0
" is wiki temporary -- was added to g:vimwiki_list by opening arbitrary wiki " is wiki temporary -- was added to g:vimwiki_list by opening arbitrary wiki
" file. " file.
let s:vimwiki_defaults.temp = 0 let s:vimwiki_defaults.temp = 0
" diary
let s:vimwiki_defaults.diary_rel_path = 'diary/'
let s:vimwiki_defaults.diary_index = 'diary'
let s:vimwiki_defaults.diary_header = 'Diary'
let s:vimwiki_defaults.diary_sort = 'desc'
" Do not change this! Will wait till vim become more datetime awareable.
let s:vimwiki_defaults.diary_link_fmt = '%Y-%m-%d'
" NEW! in v2.0
" custom_wiki2html
let s:vimwiki_defaults.custom_wiki2html = ''
"
let s:vimwiki_defaults.list_margin = -1
let s:vimwiki_defaults.auto_tags = 0
"}}} "}}}
" DEFAULT options {{{ " DEFAULT options {{{
@ -409,7 +392,7 @@ command! -count=1 VimwikiMakeDiaryNote
command! -count=1 VimwikiTabMakeDiaryNote command! -count=1 VimwikiTabMakeDiaryNote
\ call vimwiki#diary#make_note(v:count1, 1) \ call vimwiki#diary#make_note(v:count1, 1)
command! -count=1 VimwikiMakeYesterdayDiaryNote command! -count=1 VimwikiMakeYesterdayDiaryNote
\ call vimwiki#diary#make_note(v:count1, 0, strftime(VimwikiGet('diary_link_fmt', v:count1 - 1), localtime() - 60*60*24)) \ call vimwiki#diary#make_note(v:count1, 0, vimwiki#diary#diary_date_link(localtime() - 60*60*24))
command! VimwikiDiaryGenerateLinks command! VimwikiDiaryGenerateLinks
\ call vimwiki#diary#generate_diary_section() \ call vimwiki#diary#generate_diary_section()