From afc868929d8119a4169c3cf55289125421862c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Tue, 2 Jun 2020 01:33:06 +0200 Subject: [PATCH] Bugfix: file extension for markdown is syntax wide (#895) populate_extra_markdown_vars() contained uses of the file-extension via vimwiki#vars#get_wikilocal. Since the first is syntax-wide and the second is wikilocal and no wiki is specified or open at the moment of the call, the file extension of the first markdown wiki will be used for all markdown wikis. Further problems will occur when adding new wikilocal options, that depend on the syntax. This commit is working towards separating wiki and syntax, which is needed for several feature requests. --- autoload/vimwiki/base.vim | 16 ++++++++++------ autoload/vimwiki/vars.vim | 14 +++++++------- syntax/vimwiki.vim | 20 ++++++++++---------- syntax/vimwiki_markdown_custom.vim | 16 ++++++++-------- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 4a13da8..3fc0c5b 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1023,8 +1023,8 @@ function! s:update_wiki_links(wiki_nr, dir, old_url, new_url) abort let old_url_r = '\%(\.[/\\]\)\?' . old_url_r " Compute old url regex with filename between \zs and \ze let old_url_r = vimwiki#base#apply_template( - \ vimwiki#vars#get_syntaxlocal('WikiLinkMatchUrlTemplate', - \ vimwiki#vars#get_wikilocal('syntax', a:wiki_nr)), old_url_r, '', '') + \ vimwiki#vars#get_syntaxlocal('WikiLinkMatchUrlTemplate', vimwiki#vars#get_wikilocal('syntax', a:wiki_nr)) + \, old_url_r, '', '', vimwiki#vars#get_wikilocal('ext', a:wiki_nr)) return old_url_r endfunction @@ -2110,10 +2110,11 @@ endfunction " Construct a regular expression matching from template (with special " characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc -" for __LinkDescription__, and rxStyle for __LinkStyle__. The three -" arguments rxUrl, rxDesc, and rxStyle are copied verbatim, without any -" special character escapes or substitutions. -function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle) abort +" for __LinkDescription__, rxStyle for __LinkStyle__ and rxExtension for +" __FileExtention__. The four arguments rxUrl, rxDesc, rxStyle and +" rxExtension are copied verbatim, without any special character escapes or +" substitutions. +function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle, rxExtension) abort let lnk = a:template if a:rxUrl !=? '' let lnk = s:safesubstitute(lnk, '__LinkUrl__', a:rxUrl, 'g') @@ -2124,6 +2125,9 @@ function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle) abort if a:rxStyle !=? '' let lnk = s:safesubstitute(lnk, '__LinkStyle__', a:rxStyle, 'g') endif + if a:rxExtension !=? '' + let lnk = s:safesubstitute(lnk, '__FileExtention__', a:rxExtension, 'g') + endif return lnk endfunction diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim index f98ddef..4087710 100644 --- a/autoload/vimwiki/vars.vim +++ b/autoload/vimwiki/vars.vim @@ -787,20 +787,20 @@ function! s:populate_extra_markdown_vars() abort let mkd_syntax.rxWeblink1Suffix = ')' let mkd_syntax.rxWeblink1EscapeCharsSuffix = '\(\\\)\@