Start refactoring the rest -- part 5

Ref #256
This commit is contained in:
EinfachToll 2017-01-07 21:51:15 +01:00
parent 4a96eb4d32
commit 1806d3edfa
12 changed files with 227 additions and 268 deletions

View File

@ -24,43 +24,6 @@ function! s:vimwiki_get_known_syntaxes() " {{{
return keys(syntaxes) return keys(syntaxes)
endfunction " }}} 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.
if a:idx < 0
return
endif
let g:vimwiki_current_idx = a:idx
" The following state depends on the current active wiki page
let subdir = vimwiki#base#current_subdir(a:idx)
call VimwikiSet('subdir', subdir, a:idx)
call VimwikiSet('invsubdir', vimwiki#base#invsubdir(subdir), a:idx)
if vimwiki#vars#get_global('auto_chdir') == 1
exe 'lcd' vimwiki#vars#get_wikilocal('path')
endif
" update cache
call vimwiki#base#cache_buffer_state()
endfunction " }}}
" vimwiki#base#cache_buffer_state
function! vimwiki#base#cache_buffer_state() "{{{
let b:vimwiki_idx = g:vimwiki_current_idx
endfunction "}}}
" vimwiki#base#recall_buffer_state
function! vimwiki#base#recall_buffer_state() "{{{
if !exists('b:vimwiki_idx')
return 0
else
let g:vimwiki_current_idx = b:vimwiki_idx
return 1
endif
endfunction " }}}
" vimwiki#base#file_pattern " vimwiki#base#file_pattern
function! vimwiki#base#file_pattern(files) "{{{ Get search regex from glob() function! vimwiki#base#file_pattern(files) "{{{ Get search regex from glob()
" string. Aim to support *all* special characters, forcing the user to choose " string. Aim to support *all* special characters, forcing the user to choose
@ -97,8 +60,8 @@ function! vimwiki#base#subdir(path, filename) "{{{
endfunction "}}} endfunction "}}}
" vimwiki#base#current_subdir " vimwiki#base#current_subdir
function! vimwiki#base#current_subdir(idx)"{{{ function! vimwiki#base#current_subdir()"{{{
return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path', a:idx), expand('%:p')) return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p'))
endfunction"}}} endfunction"}}}
" vimwiki#base#invsubdir " vimwiki#base#invsubdir
@ -1229,7 +1192,7 @@ endfunction "}}}
" vimwiki#base#rename_link " vimwiki#base#rename_link
" Rename current file, update all links to it " Rename current file, update all links to it
function! vimwiki#base#rename_link() "{{{ function! vimwiki#base#rename_link() "{{{
let subdir = VimwikiGet('subdir') let subdir = vimwiki#vars#get_bufferlocal('subdir')
let old_fname = subdir.expand('%:t') let old_fname = subdir.expand('%:t')
" there is no file (new one maybe) " there is no file (new one maybe)

View File

@ -21,12 +21,12 @@ function! s:prefix_zero(num) "{{{
endfunction "}}} 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 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
return vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx) return vimwiki#vars#get_wikilocal('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 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).vimwiki#vars#get_wikilocal('ext', idx) return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).vimwiki#vars#get_wikilocal('ext', idx)
endfunction "}}} endfunction "}}}
@ -62,14 +62,15 @@ endfun "}}}
" Diary index stuff {{{ " Diary index stuff {{{
fun! s:read_captions(files) "{{{ fun! s:read_captions(files) "{{{
let result = {} let result = {}
let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
for fl in a:files for fl in a:files
" remove paths and extensions " remove paths and extensions
let fl_key = fnamemodify(fl, ':t:r') let fl_key = fnamemodify(fl, ':t:r')
if filereadable(fl) if filereadable(fl)
for line in readfile(fl, '', s:vimwiki_max_scan_for_caption) for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
if line =~# g:vimwiki_rxHeader && !has_key(result, fl_key) if line =~# rx_header && !has_key(result, fl_key)
let result[fl_key] = vimwiki#u#trim(matchstr(line, g:vimwiki_rxHeader)) let result[fl_key] = vimwiki#u#trim(matchstr(line, rx_header))
endif endif
endfor endfor
endif endif
@ -132,19 +133,19 @@ function! s:format_diary() "{{{
for year in s:sort(keys(g_files)) for year in s:sort(keys(g_files))
call add(result, '') call add(result, '')
call add(result, substitute(g:vimwiki_rxH2_Template, '__Header__', year , '')) call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
for month in s:sort(keys(g_files[year])) for month in s:sort(keys(g_files[year]))
call add(result, '') call add(result, '')
call add(result, substitute(g:vimwiki_rxH3_Template, '__Header__', s:get_month_name(month), '')) call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'), '__Header__', s:get_month_name(month), ''))
for [fl, cap] in s:sort(items(g_files[year][month])) for [fl, cap] in s:sort(items(g_files[year][month]))
if empty(cap) if empty(cap)
let entry = substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', fl, '') let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', fl, '')
let entry = substitute(entry, '__LinkDescription__', cap, '') let entry = substitute(entry, '__LinkDescription__', cap, '')
call add(result, repeat(' ', &sw).'* '.entry) call add(result, repeat(' ', &sw).'* '.entry)
else else
let entry = substitute(g:vimwiki_WikiLinkTemplate2, '__LinkUrl__', fl, '') let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate2'), '__LinkUrl__', fl, '')
let entry = substitute(entry, '__LinkDescription__', cap, '') let entry = substitute(entry, '__LinkDescription__', cap, '')
call add(result, repeat(' ', &sw).'* '.entry) call add(result, repeat(' ', &sw).'* '.entry)
endif endif
@ -185,7 +186,6 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
endif endif
call vimwiki#base#open_link(cmd, link, s:diary_index(idx)) call vimwiki#base#open_link(cmd, link, s:diary_index(idx))
call vimwiki#base#setup_buffer_state(idx)
endfunction "}}} endfunction "}}}
function! vimwiki#diary#goto_diary_index(wnum) "{{{ function! vimwiki#diary#goto_diary_index(wnum) "{{{
@ -202,7 +202,6 @@ function! vimwiki#diary#goto_diary_index(wnum) "{{{
endif endif
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)
endfunction "}}} endfunction "}}}
function! vimwiki#diary#goto_next_day() "{{{ function! vimwiki#diary#goto_next_day() "{{{
@ -249,7 +248,7 @@ function! vimwiki#diary#generate_diary_section() "{{{
let current_file = vimwiki#path#path_norm(expand("%:p")) let current_file = vimwiki#path#path_norm(expand("%:p"))
let diary_file = vimwiki#path#path_norm(s:diary_index()) let diary_file = vimwiki#path#path_norm(s:diary_index())
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*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)'
call vimwiki#base#update_listing_in_buffer(s:format_diary(), call vimwiki#base#update_listing_in_buffer(s:format_diary(),
\ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1) \ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1)
else else
@ -278,7 +277,7 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
endif endif
" XXX: Well, +1 is for inconsistent index basing... " XXX: Well, +1 is for inconsistent index basing...
call vimwiki#diary#make_note(g:vimwiki_current_idx+1, 0, link) call vimwiki#diary#make_note(vimwiki#vars#get_bufferlocal('wiki_nr')+1, 0, link)
endfunction "}}} endfunction "}}}
" Sign function. " Sign function.

View File

@ -231,7 +231,7 @@ function! s:is_html_uptodate(wikifile) "{{{
endif endif
let wikifile = fnamemodify(a:wikifile, ":p") let wikifile = fnamemodify(a:wikifile, ":p")
let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') . VimwikiGet('subdir') . let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') . vimwiki#vars#get_bufferlocal('subdir') .
\fnamemodify(wikifile, ":t:r").".html") \fnamemodify(wikifile, ":t:r").".html")
if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile) if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile)
@ -345,12 +345,12 @@ endfunction "}}}
" match n-th ARG within {{URL[|ARG1|ARG2|...]}} " {{{ " match n-th ARG within {{URL[|ARG1|ARG2|...]}} " {{{
" *c,d,e),... " *c,d,e),...
function! vimwiki#html#incl_match_arg(nn_index) function! vimwiki#html#incl_match_arg(nn_index)
let rx = g:vimwiki_rxWikiInclPrefix. g:vimwiki_rxWikiInclUrl let rx = vimwiki#vars#get_global('rxWikiInclPrefix'). vimwiki#vars#get_global('rxWikiInclUrl')
let rx = rx. repeat(g:vimwiki_rxWikiInclSeparator. g:vimwiki_rxWikiInclArg, a:nn_index-1) let rx = rx. repeat(vimwiki#vars#get_global('rxWikiInclSeparator'). vimwiki#vars#get_global('rxWikiInclArg'), a:nn_index-1)
if a:nn_index > 0 if a:nn_index > 0
let rx = rx. g:vimwiki_rxWikiInclSeparator. '\zs'. g:vimwiki_rxWikiInclArg. '\ze' let rx = rx. vimwiki#vars#get_global('rxWikiInclSeparator'). '\zs'. vimwiki#vars#get_global('rxWikiInclArg'). '\ze'
endif endif
let rx = rx. g:vimwiki_rxWikiInclArgs. g:vimwiki_rxWikiInclSuffix let rx = rx. vimwiki#vars#get_global('rxWikiInclArgs'). vimwiki#vars#get_global('rxWikiInclSuffix')
return rx return rx
endfunction endfunction
"}}} "}}}
@ -359,7 +359,7 @@ function! vimwiki#html#linkify_link(src, descr) "{{{
let src_str = ' href="'.s:safe_html_anchor(a:src).'"' let src_str = ' href="'.s:safe_html_anchor(a:src).'"'
let descr = substitute(a:descr,'^\s*\(.*\)\s*$','\1','') let descr = substitute(a:descr,'^\s*\(.*\)\s*$','\1','')
let descr = (descr == "" ? a:src : descr) let descr = (descr == "" ? a:src : descr)
let descr_str = (descr =~# g:vimwiki_rxWikiIncl let descr_str = (descr =~# vimwiki#vars#get_global('rxWikiIncl')
\ ? s:tag_wikiincl(descr) \ ? s:tag_wikiincl(descr)
\ : descr) \ : descr)
return '<a'.src_str.'>'.descr_str.'</a>' return '<a'.src_str.'>'.descr_str.'</a>'
@ -375,8 +375,8 @@ endfunction "}}}
function! s:tag_weblink(value) "{{{ function! s:tag_weblink(value) "{{{
" Weblink Template -> <a href="url">descr</a> " Weblink Template -> <a href="url">descr</a>
let str = a:value let str = a:value
let url = matchstr(str, g:vimwiki_rxWeblinkMatchUrl) let url = matchstr(str, vimwiki#vars#get_global('rxWeblinkMatchUrl'))
let descr = matchstr(str, g:vimwiki_rxWeblinkMatchDescr) let descr = matchstr(str, vimwiki#vars#get_global('rxWeblinkMatchDescr'))
let line = vimwiki#html#linkify_link(url, descr) let line = vimwiki#html#linkify_link(url, descr)
return line return line
endfunction "}}} endfunction "}}}
@ -391,7 +391,7 @@ function! s:tag_wikiincl(value) "{{{
let line = VimwikiWikiIncludeHandler(str) let line = VimwikiWikiIncludeHandler(str)
" otherwise, assume image transclusion " otherwise, assume image transclusion
if line == '' if line == ''
let url_0 = matchstr(str, g:vimwiki_rxWikiInclMatchUrl) let url_0 = matchstr(str, vimwiki#vars#get_global('rxWikiInclMatchUrl'))
let descr = matchstr(str, vimwiki#html#incl_match_arg(1)) let descr = matchstr(str, vimwiki#html#incl_match_arg(1))
let verbatim_str = matchstr(str, vimwiki#html#incl_match_arg(2)) let verbatim_str = matchstr(str, vimwiki#html#incl_match_arg(2))
@ -424,8 +424,8 @@ function! s:tag_wikilink(value) "{{{
" [[url#a1#a2]] -> <a href="url.html#a1-a2">url#a1#a2</a> " [[url#a1#a2]] -> <a href="url.html#a1-a2">url#a1#a2</a>
" [[#a1#a2]] -> <a href="#a1-a2">#a1#a2</a> " [[#a1#a2]] -> <a href="#a1-a2">#a1#a2</a>
let str = a:value let str = a:value
let url = matchstr(str, g:vimwiki_rxWikiLinkMatchUrl) let url = matchstr(str, vimwiki#vars#get_global('rxWikiLinkMatchUrl'))
let descr = matchstr(str, g:vimwiki_rxWikiLinkMatchDescr) let descr = matchstr(str, vimwiki#vars#get_global('rxWikiLinkMatchDescr'))
let descr = (substitute(descr,'^\s*\(.*\)\s*$','\1','') != '' ? descr : url) let descr = (substitute(descr,'^\s*\(.*\)\s*$','\1','') != '' ? descr : url)
let line = VimwikiLinkConverter(url, s:current_wiki_file, let line = VimwikiLinkConverter(url, s:current_wiki_file,
@ -514,16 +514,16 @@ function! s:make_tag(line, regexp, func, ...) "{{{
" Exclude preformatted text and href links. " Exclude preformatted text and href links.
" FIXME " FIXME
let patt_splitter = '\(`[^`]\+`\)\|'. let patt_splitter = '\(`[^`]\+`\)\|'.
\ '\('.g:vimwiki_rxPreStart.'.\+'.g:vimwiki_rxPreEnd.'\)\|'. \ '\('.vimwiki#vars#get_syntaxlocal('rxPreStart').'.\+'.vimwiki#vars#get_syntaxlocal('rxPreEnd').'\)\|'.
\ '\(<a href.\{-}</a>\)\|'. \ '\(<a href.\{-}</a>\)\|'.
\ '\(<img src.\{-}/>\)\|'. \ '\(<img src.\{-}/>\)\|'.
\ '\(<pre.\{-}</pre>\)\|'. \ '\(<pre.\{-}</pre>\)\|'.
\ '\('.g:vimwiki_rxEqIn.'\)' \ '\('.vimwiki#vars#get_syntaxlocal('rxEqIn').'\)'
"FIXME FIXME !!! these can easily occur on the same line! "FIXME FIXME !!! these can easily occur on the same line!
"XXX {{{ }}} ??? obsolete "XXX {{{ }}} ??? obsolete
if '`[^`]\+`' ==# a:regexp || '{{{.\+}}}' ==# a:regexp || if '`[^`]\+`' ==# a:regexp || '{{{.\+}}}' ==# a:regexp ||
\ g:vimwiki_rxEqIn ==# a:regexp \ vimwiki#vars#get_syntaxlocal('rxEqIn') ==# a:regexp
let res_line = s:subst_func(a:line, a:regexp, a:func) let res_line = s:subst_func(a:line, a:regexp, a:func)
else else
let pos = 0 let pos = 0
@ -557,23 +557,23 @@ endfunction " }}}
function! s:process_tags_typefaces(line, header_ids) "{{{ function! s:process_tags_typefaces(line, header_ids) "{{{
let line = a:line let line = a:line
let line = s:make_tag(line, g:vimwiki_rxItalic, 's:tag_em') let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxItalic'), 's:tag_em')
let line = s:make_tag(line, g:vimwiki_rxBold, 's:tag_strong', a:header_ids) let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxBold'), 's:tag_strong', a:header_ids)
let line = s:make_tag(line, g:vimwiki_rxTodo, 's:tag_todo') let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxTodo'), 's:tag_todo')
let line = s:make_tag(line, g:vimwiki_rxDelText, 's:tag_strike') let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxDelText'), 's:tag_strike')
let line = s:make_tag(line, g:vimwiki_rxSuperScript, 's:tag_super') let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSuperScript'), 's:tag_super')
let line = s:make_tag(line, g:vimwiki_rxSubScript, 's:tag_sub') let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSubScript'), 's:tag_sub')
let line = s:make_tag(line, g:vimwiki_rxCode, 's:tag_code') let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxCode'), 's:tag_code')
let line = s:make_tag(line, g:vimwiki_rxEqIn, 's:tag_eqin') let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxEqIn'), 's:tag_eqin')
let line = s:make_tag(line, g:vimwiki_rxTags, 's:tag_tags', a:header_ids) let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxTags'), 's:tag_tags', a:header_ids)
return line return line
endfunction " }}} endfunction " }}}
function! s:process_tags_links(line) " {{{ function! s:process_tags_links(line) " {{{
let line = a:line let line = a:line
let line = s:make_tag(line, g:vimwiki_rxWikiLink, 's:tag_wikilink') let line = s:make_tag(line, vimwiki#vars#get_global('rxWikiLink'), 's:tag_wikilink')
let line = s:make_tag(line, g:vimwiki_rxWikiIncl, 's:tag_wikiincl') let line = s:make_tag(line, vimwiki#vars#get_global('rxWikiIncl'), 's:tag_wikiincl')
let line = s:make_tag(line, g:vimwiki_rxWeblink, 's:tag_weblink') let line = s:make_tag(line, vimwiki#vars#get_global('rxWeblink'), 's:tag_weblink')
return line return line
endfunction " }}} endfunction " }}}
@ -859,7 +859,7 @@ function! s:process_tag_list(line, lists) "{{{
let st_tag = '<li>' let st_tag = '<li>'
let chk = matchlist(a:line, a:rx_list) let chk = matchlist(a:line, a:rx_list)
if !empty(chk) && len(chk[1]) > 0 if !empty(chk) && len(chk[1]) > 0
let completion = index(g:vimwiki_listsyms_list, chk[1]) let completion = index(vimwiki#vars#get_syntaxlocal('listsyms_list'), chk[1])
if completion >= 0 && completion <=4 if completion >= 0 && completion <=4
let st_tag = '<li class="done'.completion.'">' let st_tag = '<li class="done'.completion.'">'
endif endif
@ -873,7 +873,7 @@ function! s:process_tag_list(line, lists) "{{{
" text. " text.
" XXX necessary? in *bold* text, no space must follow the first * " XXX necessary? in *bold* text, no space must follow the first *
if !in_list if !in_list
let pos = match(a:line, '^\s*'.g:vimwiki_rxBold) let pos = match(a:line, '^\s*'.vimwiki#vars#get_syntaxlocal('rxBold'))
if pos != -1 if pos != -1
return [0, []] return [0, []]
endif endif
@ -994,12 +994,12 @@ function! s:process_tag_h(line, id) "{{{
let h_text = '' let h_text = ''
let h_id = '' let h_id = ''
if a:line =~# g:vimwiki_rxHeader if a:line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
let h_level = vimwiki#u#count_first_sym(a:line) let h_level = vimwiki#u#count_first_sym(a:line)
endif endif
if h_level > 0 if h_level > 0
let h_text = vimwiki#u#trim(matchstr(line, g:vimwiki_rxHeader)) let h_text = vimwiki#u#trim(matchstr(line, vimwiki#vars#get_syntaxlocal('rxHeader')))
let h_number = '' let h_number = ''
let h_complete_id = '' let h_complete_id = ''
let h_id = s:safe_html_anchor(h_text) let h_id = s:safe_html_anchor(h_text)
@ -1175,7 +1175,7 @@ function! s:parse_line(line, state) " {{{
"}}} "}}}
if !processed if !processed
if line =~# g:vimwiki_rxComment if line =~# vimwiki#vars#get_syntaxlocal('rxComment')
let processed = 1 let processed = 1
endif endif
endif endif
@ -1364,7 +1364,7 @@ function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) "{{{
\ (len(vimwiki#vars#get_wikilocal('template_path')) > 1 ? shellescape(expand(vimwiki#vars#get_wikilocal('template_path'))) : '-'). ' '. \ (len(vimwiki#vars#get_wikilocal('template_path')) > 1 ? shellescape(expand(vimwiki#vars#get_wikilocal('template_path'))) : '-'). ' '.
\ (len(vimwiki#vars#get_wikilocal('template_default')) > 0 ? vimwiki#vars#get_wikilocal('template_default') : '-'). ' '. \ (len(vimwiki#vars#get_wikilocal('template_default')) > 0 ? vimwiki#vars#get_wikilocal('template_default') : '-'). ' '.
\ (len(vimwiki#vars#get_wikilocal('template_ext')) > 0 ? vimwiki#vars#get_wikilocal('template_ext') : '-'). ' '. \ (len(vimwiki#vars#get_wikilocal('template_ext')) > 0 ? vimwiki#vars#get_wikilocal('template_ext') : '-'). ' '.
\ (len(VimwikiGet('subdir')) > 0 ? shellescape(s:root_path(VimwikiGet('subdir'))) : '-')) \ (len(vimwiki#vars#get_bufferlocal('subdir')) > 0 ? shellescape(s:root_path(vimwiki#vars#get_bufferlocal('subdir'))) : '-'))
endfunction " }}} endfunction " }}}
function! s:convert_file(path_html, wikifile) "{{{ function! s:convert_file(path_html, wikifile) "{{{
@ -1372,7 +1372,7 @@ function! s:convert_file(path_html, wikifile) "{{{
let wikifile = fnamemodify(a:wikifile, ":p") let wikifile = fnamemodify(a:wikifile, ":p")
let path_html = expand(a:path_html).VimwikiGet('subdir') let path_html = expand(a:path_html).vimwiki#vars#get_bufferlocal('subdir')
let htmlfile = fnamemodify(wikifile, ":t:r").'.html' let htmlfile = fnamemodify(wikifile, ":t:r").'.html'
" the currently processed file name is needed when processing links " the currently processed file name is needed when processing links
@ -1481,7 +1481,7 @@ function! s:convert_file(path_html, wikifile) "{{{
" processing template variables (refactor to a function) " processing template variables (refactor to a function)
call map(html_lines, 'substitute(v:val, "%title%", "'. title .'", "g")') call map(html_lines, 'substitute(v:val, "%title%", "'. title .'", "g")')
call map(html_lines, 'substitute(v:val, "%root_path%", "'. call map(html_lines, 'substitute(v:val, "%root_path%", "'.
\ s:root_path(VimwikiGet('subdir')) .'", "g")') \ s:root_path(vimwiki#vars#get_bufferlocal('subdir')) .'", "g")')
let css_name = expand(vimwiki#vars#get_wikilocal('css_name')) let css_name = expand(vimwiki#vars#get_wikilocal('css_name'))
let css_name = substitute(css_name, '\', '/', 'g') let css_name = substitute(css_name, '\', '/', 'g')
@ -1541,8 +1541,8 @@ function! vimwiki#html#WikiAll2HTML(path_html) "{{{
setlocal nomore setlocal nomore
" temporarily adjust current_subdir global state variable " temporarily adjust current_subdir global state variable
let current_subdir = VimwikiGet('subdir') let current_subdir = vimwiki#vars#get_bufferlocal('subdir')
let current_invsubdir = VimwikiGet('invsubdir') let current_invsubdir = vimwiki#vars#get_bufferlocal('invsubdir')
let wikifiles = split(glob(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('ext')), '\n') let wikifiles = split(glob(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('ext')), '\n')
for wikifile in wikifiles for wikifile in wikifiles
@ -1550,8 +1550,8 @@ function! vimwiki#html#WikiAll2HTML(path_html) "{{{
" temporarily adjust 'subdir' and 'invsubdir' state variables " temporarily adjust 'subdir' and 'invsubdir' state variables
let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), wikifile) let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), wikifile)
call VimwikiSet('subdir', subdir) call vimwiki#vars#set_bufferlocal('subdir', subdir)
call VimwikiSet('invsubdir', vimwiki#base#invsubdir(subdir)) call vimwiki#vars#set_bufferlocal('invsubdir', vimwiki#base#invsubdir(subdir))
if !s:is_html_uptodate(wikifile) if !s:is_html_uptodate(wikifile)
echomsg 'Vimwiki: Processing '.wikifile echomsg 'Vimwiki: Processing '.wikifile
@ -1562,8 +1562,8 @@ function! vimwiki#html#WikiAll2HTML(path_html) "{{{
endif endif
endfor endfor
" reset 'subdir' state variable " reset 'subdir' state variable
call VimwikiSet('subdir', current_subdir) call vimwiki#vars#set_bufferlocal('subdir', current_subdir)
call VimwikiSet('invsubdir', current_invsubdir) call vimwiki#vars#set_bufferlocal('invsubdir', current_invsubdir)
let created = s:create_default_CSS(path_html) let created = s:create_default_CSS(path_html)
if created if created

View File

@ -109,7 +109,7 @@ else
endif "}}} endif "}}}
function! vimwiki#lst#default_symbol() "{{{ function! vimwiki#lst#default_symbol() "{{{
return g:vimwiki_list_markers[0] return vimwiki#vars#get_syntaxlocal('list_markers')[0]
endfunction "}}} endfunction "}}}
function! vimwiki#lst#get_list_margin() "{{{ function! vimwiki#lst#get_list_margin() "{{{
@ -124,16 +124,16 @@ endfunction "}}}
"Returns: the column where the text of a line starts (possible list item "Returns: the column where the text of a line starts (possible list item
"markers and checkboxes are skipped) "markers and checkboxes are skipped)
function! s:text_begin(lnum) "{{{ function! s:text_begin(lnum) "{{{
return s:string_length(matchstr(getline(a:lnum), g:vimwiki_rxListItem)) return s:string_length(matchstr(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem')))
endfunction "}}} endfunction "}}}
"Returns: 2 if there is a marker and text "Returns: 2 if there is a marker and text
" 1 for a marker and no text " 1 for a marker and no text
" 0 for no marker at all (empty line or only text) " 0 for no marker at all (empty line or only text)
function! s:line_has_marker(lnum) "{{{ function! s:line_has_marker(lnum) "{{{
if getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*$' if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxListItem').'\s*$'
return 1 return 1
elseif getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*\S' elseif getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxListItem').'\s*\S'
return 2 return 2
else else
return 0 return 0
@ -157,7 +157,7 @@ function! s:get_item(lnum) "{{{
return item return item
endif endif
let matches = matchlist(getline(a:lnum), g:vimwiki_rxListItem) let matches = matchlist(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem'))
if matches == [] || if matches == [] ||
\ (matches[1] == '' && matches[2] == '') || \ (matches[1] == '' && matches[2] == '') ||
\ (matches[1] != '' && matches[2] != '') \ (matches[1] != '' && matches[2] != '')
@ -377,10 +377,10 @@ endfunction "}}}
"If there is no second argument, 0 is returned at a header, otherwise the "If there is no second argument, 0 is returned at a header, otherwise the
"header is skipped "header is skipped
function! s:get_next_line(lnum, ...) "{{{ function! s:get_next_line(lnum, ...) "{{{
if getline(a:lnum) =~# g:vimwiki_rxPreStart if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
let cur_ln = a:lnum + 1 let cur_ln = a:lnum + 1
while cur_ln <= line('$') && while cur_ln <= line('$') &&
\ getline(cur_ln) !~# g:vimwiki_rxPreEnd \ getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
let cur_ln += 1 let cur_ln += 1
endwhile endwhile
let next_line = cur_ln let next_line = cur_ln
@ -388,12 +388,12 @@ function! s:get_next_line(lnum, ...) "{{{
let next_line = nextnonblank(a:lnum+1) let next_line = nextnonblank(a:lnum+1)
endif endif
if a:0 > 0 && getline(next_line) =~# g:vimwiki_rxHeader if a:0 > 0 && getline(next_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader')
let next_line = s:get_next_line(next_line, 1) let next_line = s:get_next_line(next_line, 1)
endif endif
if next_line < 0 || next_line > line('$') || if next_line < 0 || next_line > line('$') ||
\ (getline(next_line) =~# g:vimwiki_rxHeader && a:0 == 0) \ (getline(next_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') && a:0 == 0)
return 0 return 0
endif endif
@ -405,10 +405,10 @@ endfunction "}}}
function! s:get_prev_line(lnum) "{{{ function! s:get_prev_line(lnum) "{{{
let prev_line = prevnonblank(a:lnum-1) let prev_line = prevnonblank(a:lnum-1)
if getline(prev_line) =~# g:vimwiki_rxPreEnd if getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
let cur_ln = a:lnum - 1 let cur_ln = a:lnum - 1
while 1 while 1
if cur_ln == 0 || getline(cur_ln) =~# g:vimwiki_rxPreStart if cur_ln == 0 || getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
break break
endif endif
let cur_ln -= 1 let cur_ln -= 1
@ -417,7 +417,7 @@ function! s:get_prev_line(lnum) "{{{
endif endif
if prev_line < 0 || prev_line > line('$') || if prev_line < 0 || prev_line > line('$') ||
\ getline(prev_line) =~# g:vimwiki_rxHeader \ getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader')
return 0 return 0
endif endif
@ -694,7 +694,7 @@ function! s:get_rate(item) "{{{
return -1 return -1
endif endif
let state = a:item.cb let state = a:item.cb
return index(g:vimwiki_listsyms_list, state) * 25 return index(vimwiki#vars#get_syntaxlocal('listsyms_list'), state) * 25
endfunction "}}} endfunction "}}}
"Set state of the list item to [ ] or [o] or whatever "Set state of the list item to [ ] or [o] or whatever
@ -731,15 +731,15 @@ endfunction "}}}
function! s:rate_to_state(rate) "{{{ function! s:rate_to_state(rate) "{{{
let state = '' let state = ''
if a:rate == 100 if a:rate == 100
let state = g:vimwiki_listsyms_list[4] let state = vimwiki#vars#get_syntaxlocal('listsyms_list')[4]
elseif a:rate == 0 elseif a:rate == 0
let state = g:vimwiki_listsyms_list[0] let state = vimwiki#vars#get_syntaxlocal('listsyms_list')[0]
elseif a:rate >= 67 elseif a:rate >= 67
let state = g:vimwiki_listsyms_list[3] let state = vimwiki#vars#get_syntaxlocal('listsyms_list')[3]
elseif a:rate >= 34 elseif a:rate >= 34
let state = g:vimwiki_listsyms_list[2] let state = vimwiki#vars#get_syntaxlocal('listsyms_list')[2]
else else
let state = g:vimwiki_listsyms_list[1] let state = vimwiki#vars#get_syntaxlocal('listsyms_list')[1]
endif endif
return state return state
endfunction "}}} endfunction "}}}
@ -793,7 +793,7 @@ function! s:create_cb(item) "{{{
endif endif
let new_item = a:item let new_item = a:item
let new_item.cb = g:vimwiki_listsyms_list[0] let new_item.cb = vimwiki#vars#get_syntaxlocal('listsyms_list')[0]
call s:substitute_rx_in_line(new_item.lnum, call s:substitute_rx_in_line(new_item.lnum,
\ vimwiki#u#escape(new_item.mrkr) . '\zs\ze', ' [' . new_item.cb . ']') \ vimwiki#u#escape(new_item.mrkr) . '\zs\ze', ' [' . new_item.cb . ']')
@ -1081,31 +1081,33 @@ function! s:get_idx_list_markers(item) "{{{
else else
let m = s:guess_kind_of_numbered_item(a:item) . a:item.mrkr[-1:] let m = s:guess_kind_of_numbered_item(a:item) . a:item.mrkr[-1:]
endif endif
return index(g:vimwiki_list_markers, m) return index(vimwiki#vars#get_syntaxlocal('list_markers'), m)
endfunction "}}} endfunction "}}}
"changes the marker of the given item to the next in g:vimwiki_list_markers "changes the marker of the given item to the next in g:vimwiki_list_markers
function! s:get_next_mrkr(item) "{{{ function! s:get_next_mrkr(item) "{{{
let markers = vimwiki#vars#get_syntaxlocal('list_markers')
if a:item.type == 0 if a:item.type == 0
let new_mrkr = g:vimwiki_list_markers[0] let new_mrkr = markers[0]
else else
let idx = s:get_idx_list_markers(a:item) let idx = s:get_idx_list_markers(a:item)
let new_mrkr = g:vimwiki_list_markers[(idx+1) % len(g:vimwiki_list_markers)] let new_mrkr = markers[(idx+1) % len(markers)]
endif endif
return new_mrkr return new_mrkr
endfunction "}}} endfunction "}}}
"changes the marker of the given item to the previous in g:vimwiki_list_markers "changes the marker of the given item to the previous in g:vimwiki_list_markers
function! s:get_prev_mrkr(item) "{{{ function! s:get_prev_mrkr(item) "{{{
let markers = vimwiki#vars#get_syntaxlocal('list_markers')
if a:item.type == 0 if a:item.type == 0
return g:vimwiki_list_markers[-1] return markers[-1]
endif endif
let idx = s:get_idx_list_markers(a:item) let idx = s:get_idx_list_markers(a:item)
if idx == -1 if idx == -1
return g:vimwiki_list_markers[-1] return markers[-1]
else else
return g:vimwiki_list_markers[(idx - 1 + len(g:vimwiki_list_markers)) % return markers[(idx - 1 + len(markers)) %
\ len(g:vimwiki_list_markers)] \ len(markers)]
endif endif
endfunction "}}} endfunction "}}}
@ -1260,7 +1262,7 @@ function! s:create_marker(lnum) "{{{
call s:clone_marker_from_to(new_sibling.lnum, a:lnum) call s:clone_marker_from_to(new_sibling.lnum, a:lnum)
else else
let cur_item = s:get_item(a:lnum) let cur_item = s:get_item(a:lnum)
call s:set_new_mrkr(cur_item, g:vimwiki_list_markers[0]) call s:set_new_mrkr(cur_item, vimwiki#vars#get_syntaxlocal('list_markers')[0])
call s:adjust_numbered_list(cur_item, 0, 0) call s:adjust_numbered_list(cur_item, 0, 0)
endif endif
endfunction "}}} endfunction "}}}

View File

@ -17,20 +17,20 @@ function! vimwiki#markdown_base#scan_reflinks() " {{{
" construct list of references using vimgrep " construct list of references using vimgrep
try try
" Why noautocmd? Because https://github.com/vimwiki/vimwiki/issues/121 " Why noautocmd? Because https://github.com/vimwiki/vimwiki/issues/121
noautocmd execute 'vimgrep #'.g:vimwiki_rxMkdRef.'#j %' noautocmd execute 'vimgrep #'.vimwiki#vars#get_syntaxlocal('rxMkdRef').'#j %'
catch /^Vim\%((\a\+)\)\=:E480/ " No Match catch /^Vim\%((\a\+)\)\=:E480/ " No Match
"Ignore it, and move on to the next file "Ignore it, and move on to the next file
endtry endtry
" "
for d in getqflist() for d in getqflist()
let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ') let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ')
let descr = matchstr(matchline, g:vimwiki_rxMkdRefMatchDescr) let descr = matchstr(matchline, vimwiki#vars#get_syntaxlocal('rxMkdRefMatchDescr'))
let url = matchstr(matchline, g:vimwiki_rxMkdRefMatchUrl) let url = matchstr(matchline, vimwiki#vars#get_syntaxlocal('rxMkdRefMatchUrl'))
if descr != '' && url != '' if descr != '' && url != ''
let mkd_refs[descr] = url let mkd_refs[descr] = url
endif endif
endfor endfor
call VimwikiSet('markdown_refs', mkd_refs) call vimwiki#vars#set_bufferlocal('markdown_refs', mkd_refs)
return mkd_refs return mkd_refs
endfunction "}}} endfunction "}}}
@ -39,7 +39,7 @@ endfunction "}}}
function! vimwiki#markdown_base#get_reflinks() " {{{ function! vimwiki#markdown_base#get_reflinks() " {{{
let done = 1 let done = 1
try try
let mkd_refs = VimwikiGet('markdown_refs') let mkd_refs = vimwiki#vars#get_bufferlocal('markdown_refs')
catch catch
" work-around hack " work-around hack
let done = 0 let done = 0
@ -92,17 +92,17 @@ function! vimwiki#markdown_base#follow_link(split, ...) "{{{ Parse link at curso
endif endif
" try WikiLink " try WikiLink
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink), let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiLink')),
\ g:vimwiki_rxWikiLinkMatchUrl) \ vimwiki#vars#get_global('rxWikiLinkMatchUrl'))
" try WikiIncl " try WikiIncl
if lnk == "" if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl), let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')),
\ g:vimwiki_rxWikiInclMatchUrl) \ vimwiki#vars#get_global('rxWikiInclMatchUrl'))
endif endif
" try Weblink " try Weblink
if lnk == "" if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink), let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWeblink')),
\ g:vimwiki_rxWeblinkMatchUrl) \ vimwiki#vars#get_global('rxWeblinkMatchUrl'))
endif endif
if lnk != "" if lnk != ""
@ -132,50 +132,50 @@ function! s:normalize_link_syntax_n() " {{{
let lnum = line('.') let lnum = line('.')
" try WikiIncl " try WikiIncl
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl'))
if !empty(lnk) if !empty(lnk)
" NO-OP !! " NO-OP !!
return return
endif endif
" try WikiLink0: replace with WikiLink1 " try WikiLink0: replace with WikiLink1
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink0) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWikiLinkMatchUrl, g:vimwiki_rxWikiLinkMatchDescr, \ vimwiki#vars#get_global('rxWikiLinkMatchUrl'), vimwiki#vars#get_global('rxWikiLinkMatchDescr'),
\ g:vimwiki_WikiLink1Template2) \ vimwiki#vars#get_syntaxlocal('WikiLink1Template2'))
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWikiLink0, sub) call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'), sub)
return return
endif endif
" try WikiLink1: replace with WikiLink0 " try WikiLink1: replace with WikiLink0
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink1) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWikiLinkMatchUrl, g:vimwiki_rxWikiLinkMatchDescr, \ vimwiki#vars#get_global('rxWikiLinkMatchUrl'), vimwiki#vars#get_global('rxWikiLinkMatchDescr'),
\ g:vimwiki_WikiLinkTemplate2) \ vimwiki#vars#get_global('WikiLinkTemplate2'))
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWikiLink1, sub) call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), sub)
return return
endif endif
" try Weblink " try Weblink
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWeblink'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWeblinkMatchUrl, g:vimwiki_rxWeblinkMatchDescr, \ vimwiki#vars#get_global('rxWeblinkMatchUrl'), vimwiki#vars#get_global('rxWeblinkMatchDescr'),
\ g:vimwiki_Weblink1Template) \ vimwiki#vars#get_syntaxlocal('Weblink1Template'))
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWeblink, sub) call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_global('rxWeblink'), sub)
return return
endif endif
" try Word (any characters except separators) " try Word (any characters except separators)
" rxWord is less permissive than rxWikiLinkUrl which is used in " rxWord is less permissive than rxWikiLinkUrl which is used in
" normalize_link_syntax_v " normalize_link_syntax_v
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWord) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWord'))
if !empty(lnk) if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk, let sub = vimwiki#base#normalize_link_helper(lnk,
\ g:vimwiki_rxWord, '', \ vimwiki#vars#get_global('rxWord'), '',
\ g:vimwiki_Weblink1Template) \ vimwiki#vars#get_syntaxlocal('Weblink1Template'))
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub) call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
return return
endif endif
@ -194,7 +194,7 @@ function! s:normalize_link_syntax_v() " {{{
try try
norm! gvy norm! gvy
let visual_selection = @" let visual_selection = @"
let link = substitute(g:vimwiki_Weblink1Template, '__LinkUrl__', '\='."'".visual_selection."'", '') let link = substitute(vimwiki#vars#get_syntaxlocal('Weblink1Template'), '__LinkUrl__', '\='."'".visual_selection."'", '')
let link = substitute(link, '__LinkDescription__', '\='."'".visual_selection."'", '') let link = substitute(link, '__LinkDescription__', '\='."'".visual_selection."'", '')
call setreg('"', link, 'v') call setreg('"', link, 'v')

View File

@ -28,7 +28,7 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
let all_files = a:all_files != '' let all_files = a:all_files != ''
if !a:full_rebuild if !a:full_rebuild
" Updating for one page (current) " Updating for one page (current)
let page_name = VimwikiGet('subdir') . expand('%:t:r') let page_name = vimwiki#vars#get_bufferlocal('subdir') . expand('%:t:r')
" Collect tags in current file " Collect tags in current file
let tags = s:scan_tags(getline(1, '$'), page_name) let tags = s:scan_tags(getline(1, '$'), page_name)
" Load metadata file " Load metadata file
@ -40,8 +40,8 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
" Save " Save
call s:write_tags_metadata(metadata) call s:write_tags_metadata(metadata)
else " full rebuild else " full rebuild
let files = vimwiki#base#find_files(g:vimwiki_current_idx, 0) let files = vimwiki#base#find_files(vimwiki#vars#get_bufferlocal('wiki_nr'), 0)
let wiki_base_dir = vimwiki#vars#get_wikilocal('path', g:vimwiki_current_idx) let wiki_base_dir = vimwiki#vars#get_wikilocal('path')
let tags_file_last_modification = let tags_file_last_modification =
\ getftime(vimwiki#tags#metadata_file_path()) \ getftime(vimwiki#tags#metadata_file_path())
let metadata = s:load_tags_metadata() let metadata = s:load_tags_metadata()
@ -68,9 +68,8 @@ 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 syntax = vimwiki#vars#get_wikilocal('syntax') let rxheader = vimwiki#vars#get_syntaxlocal('header_search')
let rxheader = g:vimwiki_{syntax}_header_search let rxtag = vimwiki#vars#get_syntaxlocal('tag_search')
let rxtag = g:vimwiki_{syntax}_tag_search
let anchor_level = ['', '', '', '', '', '', ''] let anchor_level = ['', '', '', '', '', '', '']
let current_complete_anchor = '' let current_complete_anchor = ''
@ -316,18 +315,18 @@ function! vimwiki#tags#generate_tags(...) abort "{{{
if need_all_tags || index(specific_tags, tagname) != -1 if need_all_tags || index(specific_tags, tagname) != -1
call extend(lines, [ call extend(lines, [
\ '', \ '',
\ substitute(g:vimwiki_rxH2_Template, '__Header__', tagname, ''), \ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', tagname, ''),
\ '' ]) \ '' ])
for taglink in sort(tags_entries[tagname]) for taglink in sort(tags_entries[tagname])
call add(lines, bullet . call add(lines, bullet .
\ substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', taglink, '')) \ substitute(vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', taglink, ''))
endfor endfor
endif endif
endfor endfor
let links_rx = '\m\%(^\s*$\)\|\%('.g:vimwiki_rxH2.'\)\|\%(^\s*' let links_rx = '\m\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxH2').'\)\|\%(^\s*'
\ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' ' \ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
\ .g:vimwiki_rxWikiLink.'$\)' \ .vimwiki#vars#get_global('rxWikiLink').'$\)'
call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx, call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx,
\ line('$')+1, 1) \ line('$')+1, 1)

View File

@ -19,7 +19,7 @@ let s:textwidth = &tw
" Misc functions {{{ " Misc functions {{{
function! s:rxSep() "{{{ function! s:rxSep() "{{{
return g:vimwiki_rxTableSep return vimwiki#vars#get_syntaxlocal('rxTableSep')
endfunction "}}} endfunction "}}}
function! s:wide_len(str) "{{{ function! s:wide_len(str) "{{{

View File

@ -401,11 +401,18 @@ function! vimwiki#vars#get_bufferlocal(key)
elseif a:key ==# 'wiki_nr' elseif a:key ==# 'wiki_nr'
let b:vimwiki_wiki_nr = vimwiki#base#find_wiki(expand('%:p')) let b:vimwiki_wiki_nr = vimwiki#base#find_wiki(expand('%:p'))
return b:vimwiki_wiki_nr return b:vimwiki_wiki_nr
elseif a:key ==# 'subdir'
let b:vimwiki_subdir = vimwiki#base#current_subdir()
return b:vimwiki_subdir
elseif a:key ==# 'invsubdir'
let subdir = vimwiki#vars#get_bufferlocal('subdir')
let b:vimwiki_invsubdir = vimwiki#base#invsubdir(subdir)
return b:vimwiki_invsubdir
endif endif
endfunction endfunction
function! vimwiki#vars#set_buffer_var(key, value) function! vimwiki#vars#set_bufferlocal(key, value)
let b:vimwiki_{a:key} = a:value let b:vimwiki_{a:key} = a:value
endfunction endfunction

View File

@ -86,7 +86,7 @@ function! Complete_wikifiles(findstart, base)
let prefix = matchstr(a:base, '^diary:\zs.*') let prefix = matchstr(a:base, '^diary:\zs.*')
let scheme = matchstr(a:base, '^diary:\ze') let scheme = matchstr(a:base, '^diary:\ze')
else " current wiki else " current wiki
let wikinumber = g:vimwiki_current_idx let wikinumber = vimwiki#vars#get_bufferlocal('wiki_nr')
let prefix = a:base let prefix = a:base
let scheme = '' let scheme = ''
endif endif
@ -168,12 +168,12 @@ function! VimwikiFoldLevel(lnum) "{{{
let line = getline(a:lnum) let line = getline(a:lnum)
" Header/section folding... " Header/section folding...
if line =~# g:vimwiki_rxHeader if line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
return '>'.vimwiki#u#count_first_sym(line) return '>'.vimwiki#u#count_first_sym(line)
" Code block folding... " Code block folding...
elseif line =~# g:vimwiki_rxPreStart elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
return 'a1' return 'a1'
elseif line =~# g:vimwiki_rxPreEnd elseif line =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
return 's1' return 's1'
else else
return "=" return "="
@ -219,7 +219,7 @@ function! VimwikiFoldText() "{{{
let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '') let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '')
let fold_len = v:foldend - v:foldstart + 1 let fold_len = v:foldend - v:foldstart + 1
let len_text = ' ['.fold_len.'] ' let len_text = ' ['.fold_len.'] '
if line !~# g:vimwiki_rxPreStart if line !~# vimwiki#vars#get_syntaxlocal('rxPreStart')
let [main_text, spare_len] = s:shorten_text(main_text, 50) let [main_text, spare_len] = s:shorten_text(main_text, 50)
return main_text.len_text return main_text.len_text
else else

View File

@ -1,35 +0,0 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
" Vimwiki syntax file
" Desc: Syntax definitions which are always available
" Home: https://github.com/vimwiki/vimwiki/
" Define Regexes of anchors for every syntax.
" This has to be separated from vimwiki_default.vim, vimwiki_markdown.vim, etc.
" because the latter are only loaded and available if the current wiki has the
" corresponding syntax
let g:vimwiki_default_header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
let g:vimwiki_default_header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
let g:vimwiki_default_bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_default_bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_default_wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
let g:vimwiki_default_tag_search = '\(^\|\s\)\zs:\([^:''[:space:]]\+:\)\+\ze\(\s\|$\)'
let g:vimwiki_default_tag_match = '\(^\|\s\):\([^:''[:space:]]\+:\)*__Tag__:\([^:[:space:]]\+:\)*\(\s\|$\)'
let g:vimwiki_markdown_header_search = '^\s*\(#\{1,6}\)\([^#].*\)$'
let g:vimwiki_markdown_header_match = '^\s*\(#\{1,6}\)#\@!\s*__Header__\s*$'
let g:vimwiki_markdown_bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_markdown_bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_markdown_wikilink = g:vimwiki_default_wikilink "XXX plus markdown-style links
let g:vimwiki_markdown_tag_search = g:vimwiki_default_tag_search
let g:vimwiki_markdown_tag_match = g:vimwiki_default_tag_match
let g:vimwiki_media_header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
let g:vimwiki_media_header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
let g:vimwiki_media_bold_search = "'''\\zs[^']\\+\\ze'''"
let g:vimwiki_media_bold_match = '''''''__Text__'''''''
" ^- this strange looking thing is equivalent to "'''__Text__'''" but since we later
" want to call escape() on this string, we must keep it in single quotes
let g:vimwiki_media_wikilink = g:vimwiki_default_wikilink
let g:vimwiki_media_tag_search = g:vimwiki_default_tag_search " XXX rework to mediawiki categories format?
let g:vimwiki_media_tag_match = g:vimwiki_default_tag_match " XXX rework to mediawiki categories format?

View File

@ -3,86 +3,97 @@
" Desc: Defines markdown syntax " Desc: Defines markdown syntax
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" see the comments in vimwiki_default.vim for some info about this file
let s:markdown_syntax = g:vimwiki_syntax_variables['markdown']
" text: $ equation_inline $ " text: $ equation_inline $
let g:vimwiki_rxEqIn = '\$[^$`]\+\$' let s:markdown_syntax.rxEqIn = '\$[^$`]\+\$'
let g:vimwiki_char_eqin = '\$' let s:markdown_syntax.char_eqin = '\$'
" text: *strong* " text: *strong*
" let g:vimwiki_rxBold = '\*[^*]\+\*' " let s:markdown_syntax.rxBold = '\*[^*]\+\*'
let g:vimwiki_rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*'. \'\*'.
\'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'. \'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'.
\'\*'. \'\*'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_bold = '*' let s:markdown_syntax.char_bold = '*'
" text: _emphasis_ " text: _emphasis_
" let g:vimwiki_rxItalic = '_[^_]\+_' " let s:markdown_syntax.rxItalic = '_[^_]\+_'
let g:vimwiki_rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_'. \'_'.
\'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'. \'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'.
\'_'. \'_'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_italic = '_' let s:markdown_syntax.char_italic = '_'
" text: *_bold italic_* or _*italic bold*_ " text: *_bold italic_* or _*italic bold*_
let g:vimwiki_rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*_'. \'\*_'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'_\*'. \'_\*'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_bolditalic = '\*_' let s:markdown_syntax.char_bolditalic = '\*_'
let g:vimwiki_rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='. let s:markdown_syntax.rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_\*'. \'_\*'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'. \'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\*_'. \'\*_'.
\'\%([[:punct:]]\|\s\|$\)\@=' \'\%([[:punct:]]\|\s\|$\)\@='
let g:vimwiki_char_italicbold = '_\*' let s:markdown_syntax.char_italicbold = '_\*'
" text: `code` " text: `code`
let g:vimwiki_rxCode = '`[^`]\+`' let s:markdown_syntax.rxCode = '`[^`]\+`'
let g:vimwiki_char_code = '`' let s:markdown_syntax.char_code = '`'
" text: ~~deleted text~~ " text: ~~deleted text~~
let g:vimwiki_rxDelText = '\~\~[^~`]\+\~\~' let s:markdown_syntax.rxDelText = '\~\~[^~`]\+\~\~'
let g:vimwiki_char_deltext = '\~\~' let s:markdown_syntax.char_deltext = '\~\~'
" text: ^superscript^ " text: ^superscript^
let g:vimwiki_rxSuperScript = '\^[^^`]\+\^' let s:markdown_syntax.rxSuperScript = '\^[^^`]\+\^'
let g:vimwiki_char_superscript = '^' let s:markdown_syntax.char_superscript = '^'
" text: ,,subscript,, " text: ,,subscript,,
let g:vimwiki_rxSubScript = ',,[^,`]\+,,' let s:markdown_syntax.rxSubScript = ',,[^,`]\+,,'
let g:vimwiki_char_subscript = ',,' let s:markdown_syntax.char_subscript = ',,'
" generic headers " generic headers
let g:vimwiki_rxH = '#' let s:markdown_syntax.rxH = '#'
let g:vimwiki_symH = 0 let s:markdown_syntax.symH = 0
" <hr>, horizontal rule " <hr>, horizontal rule
let g:vimwiki_rxHR = '^-----*$' let s:markdown_syntax.rxHR = '^-----*$'
" Tables. Each line starts and ends with '|'; each cell is separated by '|' " Tables. Each line starts and ends with '|'; each cell is separated by '|'
let g:vimwiki_rxTableSep = '|' let s:markdown_syntax.rxTableSep = '|'
" Lists " Lists
let g:vimwiki_bullet_types = ['-', '*', '+'] let s:markdown_syntax.bullet_types = ['-', '*', '+']
let s:media_syntax.recurring_bullets = 0 let s:markdown_syntax.recurring_bullets = 0
let g:vimwiki_number_types = ['1.'] let s:markdown_syntax.number_types = ['1.']
let g:vimwiki_list_markers = ['-', '*', '+', '1.'] let s:markdown_syntax.list_markers = ['-', '*', '+', '1.']
let g:vimwiki_rxListDefine = '::\%(\s\|$\)' let s:markdown_syntax.rxListDefine = '::\%(\s\|$\)'
call vimwiki#lst#setup_marker_infos()
" Preformatted text " Preformatted text
let g:vimwiki_rxPreStart = '```' let s:markdown_syntax.rxPreStart = '```'
let g:vimwiki_rxPreEnd = '```' let s:markdown_syntax.rxPreEnd = '```'
" Math block " Math block
let g:vimwiki_rxMathStart = '\$\$' let s:markdown_syntax.rxMathStart = '\$\$'
let g:vimwiki_rxMathEnd = '\$\$' let s:markdown_syntax.rxMathEnd = '\$\$'
let g:vimwiki_rxComment = '^\s*%%.*$' let s:markdown_syntax.rxComment = '^\s*%%.*$'
let g:vimwiki_rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@=' let s:markdown_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
let s:markdown_syntax.header_search = '^\s*\(#\{1,6}\)\([^#].*\)$'
let s:markdown_syntax.header_match = '^\s*\(#\{1,6}\)#\@!\s*__Header__\s*$'
let s:markdown_syntax.bold_search = '\%(^\|\s\|[[:punct:]]\)\@<=\*\zs\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)\ze\*\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.bold_match = '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]' "XXX plus markdown-style links
let s:markdown_syntax.tag_search = '\(^\|\s\)\zs:\([^:''[:space:]]\+:\)\+\ze\(\s\|$\)'
let s:markdown_syntax.tag_match = '\(^\|\s\):\([^:''[:space:]]\+:\)*__Tag__:\([^:[:space:]]\+:\)*\(\s\|$\)'

View File

@ -3,67 +3,80 @@
" Desc: Defines mediaWiki syntax " Desc: Defines mediaWiki syntax
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" see the comments in vimwiki_default.vim for some info about this file
let s:media_syntax = g:vimwiki_syntax_variables['media']
" text: $ equation_inline $ " text: $ equation_inline $
let g:vimwiki_rxEqIn = '\$[^$`]\+\$' let s:media_syntax.rxEqIn = '\$[^$`]\+\$'
let g:vimwiki_char_eqin = '\$' let s:media_syntax.char_eqin = '\$'
" text: '''strong''' " text: '''strong'''
let g:vimwiki_rxBold = "'''[^']\\+'''" let s:media_syntax.rxBold = "'''[^']\\+'''"
let g:vimwiki_char_bold = "'''" let s:media_syntax.char_bold = "'''"
" text: ''emphasis'' " text: ''emphasis''
let g:vimwiki_rxItalic = "''[^']\\+''" let s:media_syntax.rxItalic = "''[^']\\+''"
let g:vimwiki_char_italic = "''" let s:media_syntax.char_italic = "''"
" text: '''''strong italic''''' " text: '''''strong italic'''''
let g:vimwiki_rxBoldItalic = "'''''[^']\\+'''''" let s:media_syntax.rxBoldItalic = "'''''[^']\\+'''''"
let g:vimwiki_rxItalicBold = g:vimwiki_rxBoldItalic let s:media_syntax.rxItalicBold = s:media_syntax.rxBoldItalic
let g:vimwiki_char_bolditalic = "'''''" let s:media_syntax.char_bolditalic = "'''''"
let g:vimwiki_char_italicbold = g:vimwiki_char_bolditalic let s:media_syntax.char_italicbold = s:media_syntax.char_bolditalic
" text: `code` " text: `code`
let g:vimwiki_rxCode = '`[^`]\+`' let s:media_syntax.rxCode = '`[^`]\+`'
let g:vimwiki_char_code = '`' let s:media_syntax.char_code = '`'
" text: ~~deleted text~~ " text: ~~deleted text~~
let g:vimwiki_rxDelText = '\~\~[^~]\+\~\~' let s:media_syntax.rxDelText = '\~\~[^~]\+\~\~'
let g:vimwiki_char_deltext = '\~\~' let s:media_syntax.char_deltext = '\~\~'
" text: ^superscript^ " text: ^superscript^
let g:vimwiki_rxSuperScript = '\^[^^]\+\^' let s:media_syntax.rxSuperScript = '\^[^^]\+\^'
let g:vimwiki_char_superscript = '^' let s:media_syntax.char_superscript = '^'
" text: ,,subscript,, " text: ,,subscript,,
let g:vimwiki_rxSubScript = ',,[^,]\+,,' let s:media_syntax.rxSubScript = ',,[^,]\+,,'
let g:vimwiki_char_subscript = ',,' let s:media_syntax.char_subscript = ',,'
" generic headers " generic headers
let g:vimwiki_rxH = '=' let s:media_syntax.rxH = '='
let g:vimwiki_symH = 1 let s:media_syntax.symH = 1
" <hr>, horizontal rule " <hr>, horizontal rule
let g:vimwiki_rxHR = '^-----*$' let s:media_syntax.rxHR = '^-----*$'
" Tables. Each line starts and ends with '|'; each cell is separated by '|' " Tables. Each line starts and ends with '|'; each cell is separated by '|'
let g:vimwiki_rxTableSep = '|' let s:media_syntax.rxTableSep = '|'
" Lists " Lists
let g:vimwiki_bullet_types = ['*', '#'] let s:media_syntax.bullet_types = ['*', '#']
let s:media_syntax.recurring_bullets = 1 let s:media_syntax.recurring_bullets = 1
let g:vimwiki_number_types = [] let s:media_syntax.number_types = []
let g:vimwiki_list_markers = ['*', '#'] let s:media_syntax.list_markers = ['*', '#']
let g:vimwiki_rxListDefine = '^\%(;\|:\)\s' let s:media_syntax.rxListDefine = '^\%(;\|:\)\s'
call vimwiki#lst#setup_marker_infos()
" Preformatted text " Preformatted text
let g:vimwiki_rxPreStart = '<pre>' let s:media_syntax.rxPreStart = '<pre>'
let g:vimwiki_rxPreEnd = '<\/pre>' let s:media_syntax.rxPreEnd = '<\/pre>'
" Math block " Math block
let g:vimwiki_rxMathStart = '{{\$' let s:media_syntax.rxMathStart = '{{\$'
let g:vimwiki_rxMathEnd = '}}\$' let s:media_syntax.rxMathEnd = '}}\$'
let g:vimwiki_rxComment = '^\s*%%.*$' let s:media_syntax.rxComment = '^\s*%%.*$'
let g:vimwiki_rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@=' let s:media_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
let s:media_syntax.header_search = '^\s*\(=\{1,6}\)\([^=].*[^=]\)\1\s*$'
let s:media_syntax.header_match = '^\s*\(=\{1,6}\)=\@!\s*__Header__\s*\1=\@!\s*$'
let s:media_syntax.bold_search = "'''\\zs[^']\\+\\ze'''"
let s:media_syntax.bold_match = '''''''__Text__'''''''
" ^- this strange looking thing is equivalent to "'''__Text__'''" but since we later
" want to call escape() on this string, we must keep it in single quotes
let s:media_syntax.wikilink = '\[\[\zs[^\\\]|]\+\ze\%(|[^\\\]]\+\)\?\]\]'
let s:media_syntax.tag_search = '\(^\|\s\)\zs:\([^:''[:space:]]\+:\)\+\ze\(\s\|$\)' " XXX rework to mediawiki categories format?
let s:media_syntax.tag_match = '\(^\|\s\):\([^:''[:space:]]\+:\)*__Tag__:\([^:[:space:]]\+:\)*\(\s\|$\)' " XXX rework to mediawiki categories format?