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

Ref #256
This commit is contained in:
EinfachToll 2016-12-23 20:05:53 +01:00
parent 2329d602a7
commit 250fd3c47b
8 changed files with 40 additions and 33 deletions

View File

@ -13,10 +13,9 @@ function! s:vimwiki_get_known_syntaxes() " {{{
" Getting all syntaxes that different wikis could have " Getting all syntaxes that different wikis could have
let syntaxes = {} let syntaxes = {}
let syntaxes['default'] = 1 let syntaxes['default'] = 1
for wiki in g:vimwiki_list for wiki_nr in range(vimwiki#vars#number_of_wikis())
if has_key(wiki, 'syntax') let wiki_syntax = vimwiki#vars#get_wikilocal('syntax', wiki_nr)
let syntaxes[wiki.syntax] = 1 let syntaxes[wiki_syntax] = 1
endif
endfor endfor
" also consider the syntaxes from g:vimwiki_ext2syntax " also consider the syntaxes from g:vimwiki_ext2syntax
for syn in values(vimwiki#vars#get_global('ext2syntax')) for syn in values(vimwiki#vars#get_global('ext2syntax'))
@ -490,7 +489,7 @@ function! vimwiki#base#backlinks() "{{{
let current_filename = expand("%:p") let current_filename = expand("%:p")
let locations = [] let locations = []
for idx in range(len(g:vimwiki_list)) for idx in range(len(g:vimwiki_list))
let syntax = VimwikiGet('syntax', idx) let syntax = vimwiki#vars#get_wikilocal('syntax', idx)
let wikifiles = vimwiki#base#find_files(idx, 0) let wikifiles = vimwiki#base#find_files(idx, 0)
for source_file in wikifiles for source_file in wikifiles
let links = s:get_links(source_file, idx) let links = s:get_links(source_file, idx)
@ -675,14 +674,17 @@ function! s:jump_to_anchor(anchor) "{{{
let anchor = vimwiki#u#escape(a:anchor) let anchor = vimwiki#u#escape(a:anchor)
let segments = split(anchor, '#', 0) let segments = split(anchor, '#', 0)
let current_syntax = vimwiki#vars#get_wikilocal('syntax')
for segment in segments for segment in segments
let anchor_header = substitute( let anchor_header = substitute(
\ g:vimwiki_{VimwikiGet('syntax')}_header_match, \ g:vimwiki_{current_syntax}_header_match,
\ '__Header__', "\\='".segment."'", '') \ '__Header__', "\\='".segment."'", '')
let anchor_bold = substitute(g:vimwiki_{VimwikiGet('syntax')}_bold_match, let anchor_bold = substitute(g:vimwiki_{current_syntax}_bold_match,
\ '__Text__', "\\='".segment."'", '') \ '__Text__', "\\='".segment."'", '')
let anchor_tag = substitute(g:vimwiki_{VimwikiGet('syntax')}_tag_match, let anchor_tag = substitute(g:vimwiki_{current_syntax}_tag_match,
\ '__Tag__', "\\='".segment."'", '') \ '__Tag__', "\\='".segment."'", '')
if !search(anchor_tag, 'Wc') if !search(anchor_tag, 'Wc')
@ -704,7 +706,7 @@ function! s:get_links(wikifile, idx) "{{{
return [] return []
endif endif
let syntax = VimwikiGet('syntax', a:idx) let syntax = vimwiki#vars#get_wikilocal('syntax', a:idx)
let rx_link = g:vimwiki_{syntax}_wikilink let rx_link = g:vimwiki_{syntax}_wikilink
let links = [] let links = []
let lnum = 0 let lnum = 0
@ -736,7 +738,7 @@ function! vimwiki#base#check_links() "{{{
let links_of_files = {} let links_of_files = {}
let errors = [] let errors = []
for idx in range(len(g:vimwiki_list)) for idx in range(len(g:vimwiki_list))
let syntax = VimwikiGet('syntax', idx) let syntax = vimwiki#vars#get_wikilocal('syntax', idx)
let wikifiles = vimwiki#base#find_files(idx, 0) let wikifiles = vimwiki#base#find_files(idx, 0)
for wikifile in wikifiles for wikifile in wikifiles
let links_of_files[wikifile] = s:get_links(wikifile, idx) let links_of_files[wikifile] = s:get_links(wikifile, idx)
@ -1222,15 +1224,15 @@ endfunction " }}}
" vimwiki#base#follow_link " vimwiki#base#follow_link
function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pass function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pass
" to VimwikiLinkHandler, or failing that, the default open_link handler " to VimwikiLinkHandler, or failing that, the default open_link handler
if exists('*vimwiki#'.VimwikiGet('syntax').'_base#follow_link') if exists('*vimwiki#'.vimwiki#vars#get_wikilocal('syntax').'_base#follow_link')
" Syntax-specific links " Syntax-specific links
" XXX: @Stuart: do we still need it? " XXX: @Stuart: do we still need it?
" XXX: @Maxim: most likely! I am still working on a seemless way to " XXX: @Maxim: most likely! I am still working on a seemless way to
" integrate regexp's without complicating syntax/vimwiki.vim " integrate regexp's without complicating syntax/vimwiki.vim
if a:0 if a:0
call vimwiki#{VimwikiGet('syntax')}_base#follow_link(a:split, a:1) call vimwiki#{vimwiki#vars#get_wikilocal('syntax')}_base#follow_link(a:split, a:1)
else else
call vimwiki#{VimwikiGet('syntax')}_base#follow_link(a:split) call vimwiki#{vimwiki#vars#get_wikilocal('syntax')}_base#follow_link(a:split)
endif endif
else else
if a:split ==# "split" if a:split ==# "split"
@ -1987,9 +1989,9 @@ endfunction " }}}
" vimwiki#base#normalize_link " vimwiki#base#normalize_link
function! vimwiki#base#normalize_link(is_visual_mode) "{{{ function! vimwiki#base#normalize_link(is_visual_mode) "{{{
if exists('*vimwiki#'.VimwikiGet('syntax').'_base#normalize_link') if exists('*vimwiki#'.vimwiki#vars#get_wikilocal('syntax').'_base#normalize_link')
" Syntax-specific links " Syntax-specific links
call vimwiki#{VimwikiGet('syntax')}_base#normalize_link(a:is_visual_mode) call vimwiki#{vimwiki#vars#get_wikilocal('syntax')}_base#normalize_link(a:is_visual_mode)
else else
if !a:is_visual_mode if !a:is_visual_mode
call s:normalize_link_syntax_n() call s:normalize_link_syntax_n()

View File

@ -26,7 +26,7 @@ function! s:root_path(subdir) "{{{
endfunction "}}} endfunction "}}}
function! s:syntax_supported() " {{{ function! s:syntax_supported() " {{{
return VimwikiGet('syntax') ==? "default" return vimwiki#vars#get_wikilocal('syntax') ==? "default"
endfunction " }}} endfunction " }}}
function! s:remove_blank_lines(lines) " {{{ function! s:remove_blank_lines(lines) " {{{
@ -1356,7 +1356,7 @@ function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) "{{{
call vimwiki#path#mkdir(a:path) call vimwiki#path#mkdir(a:path)
echomsg system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '. echomsg system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '.
\ a:force. ' '. \ a:force. ' '.
\ VimwikiGet('syntax'). ' '. \ vimwiki#vars#get_wikilocal('syntax'). ' '.
\ strpart(vimwiki#vars#get_wikilocal('ext'), 1). ' '. \ strpart(vimwiki#vars#get_wikilocal('ext'), 1). ' '.
\ shellescape(a:path). ' '. \ shellescape(a:path). ' '.
\ shellescape(a:wikifile). ' '. \ shellescape(a:wikifile). ' '.

View File

@ -188,7 +188,7 @@ function! s:get_level(lnum) "{{{
if getline(a:lnum) =~# '^\s*$' if getline(a:lnum) =~# '^\s*$'
return 0 return 0
endif endif
if VimwikiGet('syntax') !=? 'media' if vimwiki#vars#get_wikilocal('syntax') !=? 'media'
let level = indent(a:lnum) let level = indent(a:lnum)
else else
let level = s:string_length(matchstr(getline(a:lnum), s:rx_bullet_chars))-1 let level = s:string_length(matchstr(getline(a:lnum), s:rx_bullet_chars))-1
@ -922,7 +922,7 @@ endfunction "}}}
function! s:decrease_level(item) "{{{ function! s:decrease_level(item) "{{{
let removed_indent = 0 let removed_indent = 0
if VimwikiGet('syntax') ==? 'media' && a:item.type == 1 && if vimwiki#vars#get_wikilocal('syntax') ==? 'media' && a:item.type == 1 &&
\ index(s:multiple_bullet_chars, s:first_char(a:item.mrkr)) > -1 \ index(s:multiple_bullet_chars, s:first_char(a:item.mrkr)) > -1
if s:string_length(a:item.mrkr) >= 2 if s:string_length(a:item.mrkr) >= 2
call s:substitute_string_in_line(a:item.lnum, call s:substitute_string_in_line(a:item.lnum,
@ -944,7 +944,7 @@ endfunction "}}}
function! s:increase_level(item) "{{{ function! s:increase_level(item) "{{{
let additional_indent = 0 let additional_indent = 0
if VimwikiGet('syntax') ==? 'media' && a:item.type == 1 && if vimwiki#vars#get_wikilocal('syntax') ==? 'media' && a:item.type == 1 &&
\ index(s:multiple_bullet_chars, s:first_char(a:item.mrkr)) > -1 \ index(s:multiple_bullet_chars, s:first_char(a:item.mrkr)) > -1
call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:item.mrkr . call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:item.mrkr .
\ s:first_char(a:item.mrkr)) \ s:first_char(a:item.mrkr))
@ -966,7 +966,7 @@ endfunction "}}}
"a:indent_by can be negative "a:indent_by can be negative
function! s:indent_line_by(lnum, indent_by) "{{{ function! s:indent_line_by(lnum, indent_by) "{{{
let item = s:get_item(a:lnum) let item = s:get_item(a:lnum)
if VimwikiGet('syntax') ==? 'media' && item.type == 1 && if vimwiki#vars#get_wikilocal('syntax') ==? 'media' && item.type == 1 &&
\ index(s:multiple_bullet_chars, s:first_char(item.mrkr)) > -1 \ index(s:multiple_bullet_chars, s:first_char(item.mrkr)) > -1
if a:indent_by > 0 if a:indent_by > 0
call s:substitute_string_in_line(a:lnum, item.mrkr, call s:substitute_string_in_line(a:lnum, item.mrkr,
@ -1112,7 +1112,7 @@ endfunction "}}}
function! s:set_new_mrkr(item, new_mrkr) "{{{ function! s:set_new_mrkr(item, new_mrkr) "{{{
if a:item.type == 0 if a:item.type == 0
call s:substitute_rx_in_line(a:item.lnum, '^\s*\zs\ze', a:new_mrkr.' ') call s:substitute_rx_in_line(a:item.lnum, '^\s*\zs\ze', a:new_mrkr.' ')
if indent(a:item.lnum) == 0 && VimwikiGet('syntax') !=? 'media' if indent(a:item.lnum) == 0 && vimwiki#vars#get_wikilocal('syntax') !=? 'media'
call s:set_indent(a:item.lnum, vimwiki#lst#get_list_margin()) call s:set_indent(a:item.lnum, vimwiki#lst#get_list_margin())
endif endif
else else
@ -1193,7 +1193,7 @@ endfunction "}}}
"sets kind of the item depending on neighbor items and the parent item "sets kind of the item depending on neighbor items and the parent item
function! s:adjust_mrkr(item) "{{{ function! s:adjust_mrkr(item) "{{{
if a:item.type == 0 || VimwikiGet('syntax') ==? 'media' if a:item.type == 0 || vimwiki#vars#get_wikilocal('syntax') ==? 'media'
return return
endif endif
@ -1223,7 +1223,7 @@ function! s:clone_marker_from_to(from, to) "{{{
if item_from.type == 0 | return | endif if item_from.type == 0 | return | endif
let new_mrkr = item_from.mrkr . ' ' let new_mrkr = item_from.mrkr . ' '
call s:substitute_rx_in_line(a:to, '^\s*', new_mrkr) call s:substitute_rx_in_line(a:to, '^\s*', new_mrkr)
let new_indent = ( VimwikiGet('syntax') !=? 'media' ? indent(a:from) : 0 ) let new_indent = ( vimwiki#vars#get_wikilocal('syntax') !=? 'media' ? indent(a:from) : 0 )
call s:set_indent(a:to, new_indent) call s:set_indent(a:to, new_indent)
if item_from.cb != '' if item_from.cb != ''
call s:create_cb(s:get_item(a:to)) call s:create_cb(s:get_item(a:to))

View File

@ -68,8 +68,9 @@ function! s:scan_tags(lines, page_name) "{{{
" Code wireframe to scan for headers -- borrowed from " Code wireframe to scan for headers -- borrowed from
" vimwiki#base#get_anchors(), with minor modifications. " vimwiki#base#get_anchors(), with minor modifications.
let rxheader = g:vimwiki_{VimwikiGet('syntax')}_header_search let syntax = vimwiki#vars#get_wikilocal('syntax')
let rxtag = g:vimwiki_{VimwikiGet('syntax')}_tag_search let rxheader = g:vimwiki_{syntax}_header_search
let rxtag = g:vimwiki_{syntax}_tag_search
let anchor_level = ['', '', '', '', '', '', ''] let anchor_level = ['', '', '', '', '', '', '']
let current_complete_anchor = '' let current_complete_anchor = ''

View File

@ -43,7 +43,7 @@ endfunction "}}}
" Load concrete Wiki syntax: sets regexes and templates for headers and links " Load concrete Wiki syntax: sets regexes and templates for headers and links
function vimwiki#u#reload_regexes() "{{{ function vimwiki#u#reload_regexes() "{{{
execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'.vim' execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'.vim'
endfunction "}}} endfunction "}}}
" Load omnipresent Wiki syntax " Load omnipresent Wiki syntax
@ -53,7 +53,7 @@ endfunction "}}}
" Load syntax-specific functionality " Load syntax-specific functionality
function vimwiki#u#reload_regexes_custom() "{{{ function vimwiki#u#reload_regexes_custom() "{{{
execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'_custom.vim' execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'_custom.vim'
endfunction "}}} endfunction "}}}
" Backward compatible version of the built-in function shiftwidth() " Backward compatible version of the built-in function shiftwidth()

View File

@ -228,6 +228,11 @@ function! vimwiki#vars#get_wikilocal(key, ...)
endfunction endfunction
function! vimwiki#vars#get_wikilocal_default(key)
return g:vimwiki_wikilocal_vars[-1][a:key]
endfunction
function! vimwiki#vars#set_wikilocal(key, value, wiki_nr) 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)

View File

@ -45,7 +45,7 @@ function! Complete_wikifiles(findstart, base)
let s:line_context = '[' let s:line_context = '['
return startoflink return startoflink
endif endif
if VimwikiGet('syntax') ==? 'markdown' if vimwiki#vars#get_wikilocal('syntax') ==? 'markdown'
let startofinlinelink = match(line, '\[.*\](\zs[^)]*$') let startofinlinelink = match(line, '\[.*\](\zs[^)]*$')
if startofinlinelink != -1 if startofinlinelink != -1
let s:line_context = '[' let s:line_context = '['
@ -109,7 +109,7 @@ function! Complete_wikifiles(findstart, base)
let given_wikifile = segments[0] == '' ? expand('%:t:r') : segments[0] let given_wikifile = segments[0] == '' ? expand('%:t:r') : segments[0]
let link_infos = vimwiki#base#resolve_link(given_wikifile.'#') let link_infos = vimwiki#base#resolve_link(given_wikifile.'#')
let wikifile = link_infos.filename let wikifile = link_infos.filename
let syntax = VimwikiGet('syntax', link_infos.index) let syntax = vimwiki#vars#get_wikilocal('syntax', link_infos.index)
let anchors = vimwiki#base#get_anchors(wikifile, syntax) let anchors = vimwiki#base#get_anchors(wikifile, syntax)
let filtered_anchors = [] let filtered_anchors = []

View File

@ -86,7 +86,7 @@ function! s:setup_filetype() "{{{
if idx == -1 if idx == -1
let ext = '.'.expand('%:e') let ext = '.'.expand('%:e')
" lookup syntax using g:vimwiki_ext2syntax " lookup syntax using g:vimwiki_ext2syntax
let syn = get(vimwiki#vars#get_global('ext2syntax'), ext, s:vimwiki_defaults.syntax) let syn = get(vimwiki#vars#get_global('ext2syntax'), ext, vimwiki#vars#get_wikilocal_default('syntax'))
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) call Validate_wiki_options(idx)
@ -119,7 +119,7 @@ function! s:setup_buffer_enter() "{{{
if idx == -1 if idx == -1
let ext = '.'.expand('%:e') let ext = '.'.expand('%:e')
" lookup syntax using g:vimwiki_ext2syntax " lookup syntax using g:vimwiki_ext2syntax
let syn = get(vimwiki#vars#get_global('ext2syntax'), ext, s:vimwiki_defaults.syntax) let syn = get(vimwiki#vars#get_global('ext2syntax'), ext, vimwiki#vars#get_wikilocal_default('syntax'))
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) call Validate_wiki_options(idx)
@ -317,7 +317,6 @@ endif "}}}
" DEFAULT wiki {{{ " DEFAULT wiki {{{
let s:vimwiki_defaults = {} let s:vimwiki_defaults = {}
let s:vimwiki_defaults.syntax = 'default'
" 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.