Cherry-pick the changes from dev -- part8

This commit is contained in:
EinfachToll 2018-02-19 07:44:19 +01:00
parent 1e858b50cb
commit 2757a7826a
3 changed files with 55 additions and 28 deletions

View File

@ -8,6 +8,13 @@ if exists("g:loaded_vimwiki_auto") || &cp
endif endif
let g:loaded_vimwiki_auto = 1 let g:loaded_vimwiki_auto = 1
" s:safesubstitute
function! s:safesubstitute(text, search, replace, mode) "{{{
" Substitute regexp but do not interpret replace
let escaped = escape(a:replace, '\&')
return substitute(a:text, a:search, escaped, a:mode)
endfunction " }}}
" s:vimwiki_get_known_syntaxes " s:vimwiki_get_known_syntaxes
function! s:vimwiki_get_known_syntaxes() " {{{ function! s:vimwiki_get_known_syntaxes() " {{{
" Getting all syntaxes that different wikis could have " Getting all syntaxes that different wikis could have
@ -312,7 +319,8 @@ function! vimwiki#base#generate_links() "{{{
let abs_filepath = vimwiki#path#abs_path_of_link(link) let abs_filepath = vimwiki#path#abs_path_of_link(link)
if !s:is_diary_file(abs_filepath) if !s:is_diary_file(abs_filepath)
call add(lines, bullet. call add(lines, bullet.
\ substitute(vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', '\='."'".link."'", '')) \ s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
\ '__LinkUrl__', link, ''))
endif endif
endfor endfor
@ -525,15 +533,15 @@ function! s:jump_to_anchor(anchor) "{{{
for segment in segments for segment in segments
let anchor_header = substitute( let anchor_header = s:safesubstitute(
\ vimwiki#vars#get_syntaxlocal('header_match'), \ vimwiki#vars#get_syntaxlocal('header_match'),
\ '__Header__', "\\='".segment."'", '') \ '__Header__', segment, '')
let anchor_bold = substitute( let anchor_bold = s:safesubstitute(
\ vimwiki#vars#get_syntaxlocal('bold_match'), \ vimwiki#vars#get_syntaxlocal('bold_match'),
\ '__Text__', "\\='".segment."'", '') \ '__Text__', segment, '')
let anchor_tag = substitute( let anchor_tag = s:safesubstitute(
\ vimwiki#vars#get_syntaxlocal('tag_match'), \ vimwiki#vars#get_syntaxlocal('tag_match'),
\ '__Tag__', "\\='".segment."'", '') \ '__Tag__', segment, '')
if !search(anchor_tag, 'Wc') if !search(anchor_tag, 'Wc')
\ && !search(anchor_header, 'Wc') \ && !search(anchor_header, 'Wc')
@ -690,7 +698,7 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{
" then " then
" [[test*file]]... " [[test*file]]...
" you'll have E77: Too many file names " you'll have E77: Too many file names
let fname = escape(a:filename, '% *|#') let fname = escape(a:filename, '% *|#`')
let dir = fnamemodify(a:filename, ":p:h") let dir = fnamemodify(a:filename, ":p:h")
let ok = vimwiki#path#mkdir(dir, 1) let ok = vimwiki#path#mkdir(dir, 1)
@ -1032,8 +1040,8 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
" write new listing " write new listing
let new_header = whitespaces_in_first_line let new_header = whitespaces_in_first_line
\ . substitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'), \ . s:safesubstitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'),
\ '__Header__', '\='."'".a:start_header."'", '') \ '__Header__', a:start_header, '')
call append(start_lnum - 1, new_header) call append(start_lnum - 1, new_header)
let start_lnum += 1 let start_lnum += 1
let lines_diff += 1 + len(a:strings) let lines_diff += 1 + len(a:strings)
@ -1182,7 +1190,13 @@ function! vimwiki#base#goto_index(wnum, ...) "{{{
endif endif
if a:0 if a:0
let cmd = 'tabedit' if a:1 == 1
let cmd = 'tabedit'
elseif a:1 == 2
let cmd = 'split'
elseif a:1 == 3
let cmd = 'vsplit'
endif
else else
let cmd = 'edit' let cmd = 'edit'
endif endif
@ -1682,9 +1696,9 @@ function! vimwiki#base#table_of_contents(create)
for [lvl, link, desc] in headers for [lvl, link, desc] in headers
let esc_link = substitute(link, "'", "''", 'g') let esc_link = substitute(link, "'", "''", 'g')
let esc_desc = substitute(desc, "'", "''", 'g') let esc_desc = substitute(desc, "'", "''", 'g')
let link = substitute(vimwiki#vars#get_global('WikiLinkTemplate2'), '__LinkUrl__', let link = s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate2'), '__LinkUrl__',
\ '\='."'".'#'.esc_link."'", '') \ '#'.esc_link, '')
let link = substitute(link, '__LinkDescription__', '\='."'".esc_desc."'", '') let link = s:safesubstitute(link, '__LinkDescription__', esc_desc, '')
call add(lines, startindent.repeat(indentstring, lvl-1).bullet.link) call add(lines, startindent.repeat(indentstring, lvl-1).bullet.link)
endfor endfor
@ -1705,13 +1719,13 @@ endfunction
function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle) "{{{ function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle) "{{{
let lnk = a:template let lnk = a:template
if a:rxUrl != "" if a:rxUrl != ""
let lnk = substitute(lnk, '__LinkUrl__', '\='."'".a:rxUrl."'", 'g') let lnk = s:safesubstitute(lnk, '__LinkUrl__', a:rxUrl, 'g')
endif endif
if a:rxDesc != "" if a:rxDesc != ""
let lnk = substitute(lnk, '__LinkDescription__', '\='."'".a:rxDesc."'", 'g') let lnk = s:safesubstitute(lnk, '__LinkDescription__', a:rxDesc, 'g')
endif endif
if a:rxStyle != "" if a:rxStyle != ""
let lnk = substitute(lnk, '__LinkStyle__', '\='."'".a:rxStyle."'", 'g') let lnk = s:safesubstitute(lnk, '__LinkStyle__', a:rxStyle, 'g')
endif endif
return lnk return lnk
endfunction " }}} endfunction " }}}
@ -1750,8 +1764,8 @@ function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) " {{{
if descr == "" if descr == ""
let descr = s:clean_url(url) let descr = s:clean_url(url)
endif endif
let lnk = substitute(template, '__LinkDescription__', '\="'.descr.'"', '') let lnk = s:safesubstitute(template, '__LinkDescription__', descr, '')
let lnk = substitute(lnk, '__LinkUrl__', '\="'.url.'"', '') let lnk = s:safesubstitute(lnk, '__LinkUrl__', url, '')
return lnk return lnk
endfunction " }}} endfunction " }}}
@ -1759,7 +1773,7 @@ endfunction " }}}
function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template) "{{{ function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template) "{{{
let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template) let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template)
let style = matchstr(a:str, a:rxStyle) let style = matchstr(a:str, a:rxStyle)
let lnk = substitute(lnk, '__LinkStyle__', '\="'.style.'"', '') let lnk = s:safesubstitute(lnk, '__LinkStyle__', style, '')
return lnk return lnk
endfunction " }}} endfunction " }}}
@ -1851,8 +1865,8 @@ function! s:normalize_link_syntax_v() " {{{
if s:is_diary_file(expand("%:p")) if s:is_diary_file(expand("%:p"))
let sub = s:normalize_link_in_diary(@") let sub = s:normalize_link_in_diary(@")
else else
let sub = substitute(vimwiki#vars#get_global('WikiLinkTemplate1'), let sub = s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
\ '__LinkUrl__', '\=' . "'" . @" . "'", '') \ '__LinkUrl__', @", '')
endif endif
" Put substitution in register " and change text " Put substitution in register " and change text

View File

@ -174,10 +174,15 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx)) call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx))
if a:0 && a:1 == 1 let cmd = 'edit'
let cmd = 'tabedit' if a:0
else if a:1 == 1
let cmd = 'edit' let cmd = 'tabedit'
elseif a:1 == 2
let cmd = 'split'
elseif a:1 == 3
let cmd = 'vsplit'
endif
endif endif
if a:0>1 if a:0>1
let link = 'diary:'.a:2 let link = 'diary:'.a:2

View File

@ -6,6 +6,13 @@
" MISC helper functions {{{ " MISC helper functions {{{
" s:safesubstitute
function! s:safesubstitute(text, search, replace, mode) "{{{
" Substitute regexp but do not interpret replace
let escaped = escape(a:replace, '\&')
return substitute(a:text, a:search, escaped, a:mode)
endfunction " }}}
" vimwiki#markdown_base#scan_reflinks " vimwiki#markdown_base#scan_reflinks
function! vimwiki#markdown_base#scan_reflinks() " {{{ function! vimwiki#markdown_base#scan_reflinks() " {{{
let mkd_refs = {} let mkd_refs = {}
@ -117,8 +124,9 @@ function! s:normalize_link_syntax_v() " {{{
try try
norm! gvy norm! gvy
let visual_selection = @" let visual_selection = @"
let link = substitute(vimwiki#vars#get_syntaxlocal('Weblink1Template'), '__LinkUrl__', '\='."'".visual_selection."'", '') let link = s:safesubstitute(vimwiki#vars#get_syntaxlocal('Weblink1Template'),
let link = substitute(link, '__LinkDescription__', '\='."'".visual_selection."'", '') \ '__LinkUrl__', visual_selection, '')
let link = s:safesubstitute(link, '__LinkDescription__', visual_selection, '')
call setreg('"', link, 'v') call setreg('"', link, 'v')