Start refactoring the rest -- part 6

Ref #256
This commit is contained in:
EinfachToll 2017-01-12 21:45:09 +01:00
parent b61ff8b5ee
commit ce5c822072
6 changed files with 185 additions and 226 deletions

View File

@ -1103,8 +1103,8 @@ function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pas
endif
" try Weblink
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWeblink')),
\ vimwiki#vars#get_global('rxWeblinkMatchUrl'))
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif
if lnk != ""
@ -1766,7 +1766,7 @@ function! s:normalize_link_syntax_n() " {{{
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'))
if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk,
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_global('rxWikiLinkMatchDescr'),
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
\ vimwiki#vars#get_global('WikiLinkTemplate2'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'), sub)
return
@ -1780,11 +1780,11 @@ function! s:normalize_link_syntax_n() " {{{
endif
" try Weblink
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWeblink'))
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'))
if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk,
\ lnk, '', vimwiki#vars#get_global('WikiLinkTemplate2'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_global('rxWeblink'), sub)
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'), sub)
return
endif

View File

@ -375,8 +375,8 @@ endfunction "}}}
function! s:tag_weblink(value) "{{{
" Weblink Template -> <a href="url">descr</a>
let str = a:value
let url = matchstr(str, vimwiki#vars#get_global('rxWeblinkMatchUrl'))
let descr = matchstr(str, vimwiki#vars#get_global('rxWeblinkMatchDescr'))
let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'))
let line = vimwiki#html#linkify_link(url, descr)
return line
endfunction "}}}
@ -425,7 +425,7 @@ function! s:tag_wikilink(value) "{{{
" [[#a1#a2]] -> <a href="#a1-a2">#a1#a2</a>
let str = a:value
let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
let descr = matchstr(str, vimwiki#vars#get_global('rxWikiLinkMatchDescr'))
let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'))
let descr = (substitute(descr,'^\s*\(.*\)\s*$','\1','') != '' ? descr : url)
let line = VimwikiLinkConverter(url, s:current_wiki_file,
@ -573,7 +573,7 @@ function! s:process_tags_links(line) " {{{
let line = a:line
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWikiLink'), 's:tag_wikilink')
let line = s:make_tag(line, vimwiki#vars#get_global('rxWikiIncl'), 's:tag_wikiincl')
let line = s:make_tag(line, vimwiki#vars#get_global('rxWeblink'), 's:tag_weblink')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWeblink'), 's:tag_weblink')
return line
endfunction " }}}

View File

@ -101,8 +101,8 @@ function! vimwiki#markdown_base#follow_link(split, ...) "{{{ Parse link at curso
endif
" try Weblink
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWeblink')),
\ vimwiki#vars#get_global('rxWeblinkMatchUrl'))
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif
if lnk != ""
@ -142,7 +142,7 @@ function! s:normalize_link_syntax_n() " {{{
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'))
if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk,
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_global('rxWikiLinkMatchDescr'),
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
\ vimwiki#vars#get_syntaxlocal('WikiLink1Template2'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'), sub)
return
@ -152,19 +152,19 @@ function! s:normalize_link_syntax_n() " {{{
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'))
if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk,
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_global('rxWikiLinkMatchDescr'),
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
\ vimwiki#vars#get_global('WikiLinkTemplate2'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), sub)
return
endif
" try Weblink
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWeblink'))
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'))
if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk,
\ vimwiki#vars#get_global('rxWeblinkMatchUrl'), vimwiki#vars#get_global('rxWeblinkMatchDescr'),
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'), vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'),
\ vimwiki#vars#get_syntaxlocal('Weblink1Template'))
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_global('rxWeblink'), sub)
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'), sub)
return
endif

View File

@ -79,7 +79,7 @@ function! s:populate_global_variables()
\ '\%('.join(split(web_schemes2, '\s*,\s*'), '\|').'\):'.
\ '\)'
let g:vimwiki_global_vars['rxWeblinkUrl'] = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\='
let g:vimwiki_global_vars.rxWeblinkUrl = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\='
let wikilink_prefix = '[['
let wikilink_suffix = ']]'
@ -105,12 +105,6 @@ function! s:populate_global_variables()
" non-Ascii characters
let g:vimwiki_global_vars.rxWord = '[^[:blank:]!"$%&''()*+,:;<=>?\[\]\\^`{}]\+'
" [[URL]], or [[URL|DESCRIPTION]]
" c) match DESCRIPTION within [[URL|DESCRIPTION]]
let g:vimwiki_global_vars.rxWikiLinkMatchDescr = g:vimwiki_global_vars.rx_wikilink_prefix.
\ g:vimwiki_global_vars.rxWikiLinkUrl . g:vimwiki_global_vars.rx_wikilink_separator.'\%('.
\ '\zs'. g:vimwiki_global_vars.rxWikiLinkDescr. '\ze\)\?'. g:vimwiki_global_vars.rx_wikilink_suffix
let g:vimwiki_global_vars.rx_wikilink_prefix1 = g:vimwiki_global_vars.rx_wikilink_prefix . g:vimwiki_global_vars.rxWikiLinkUrl .
\ g:vimwiki_global_vars.rx_wikilink_separator
let g:vimwiki_global_vars.rx_wikilink_suffix1 = g:vimwiki_global_vars.rx_wikilink_suffix
@ -147,15 +141,6 @@ function! s:populate_global_variables()
let g:vimwiki_global_vars.rxWikiInclSuffix1 = g:vimwiki_global_vars.rxWikiInclArgs.
\ g:vimwiki_global_vars.rxWikiInclSuffix
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
" let g:vimwiki_rxWeblink = '[\["(|]\@<!'. g:vimwiki_rxWeblinkUrl .
" \ '\%([),:;.!?]\=\%([ \t]\|$\)\)\@='
let g:vimwiki_global_vars.rxWeblink = '\<'. g:vimwiki_global_vars.rxWeblinkUrl . '\S*'
" 0a) match URL within URL
let g:vimwiki_global_vars.rxWeblinkMatchUrl = g:vimwiki_global_vars.rxWeblink
" 0b) match DESCRIPTION within URL
let g:vimwiki_global_vars.rxWeblinkMatchDescr = ''
let g:vimwiki_global_vars.rxTodo = '\C\%(TODO:\|DONE:\|STARTED:\|FIXME:\|FIXED:\|XXX:\)'
" default colors when headers of different levels are highlighted differently
@ -348,6 +333,15 @@ function! vimwiki#vars#populate_syntax_vars(syntax)
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\|'.g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\s\+\['.g:vimwiki_syntax_variables[a:syntax].listsyms_list[4].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
endif
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
" let g:vimwiki_rxWeblink = '[\["(|]\@<!'. g:vimwiki_rxWeblinkUrl .
" \ '\%([),:;.!?]\=\%([ \t]\|$\)\)\@='
let g:vimwiki_syntax_variables[a:syntax].rxWeblink = '\<'. g:vimwiki_global_vars.rxWeblinkUrl . '\S*'
" 0a) match URL within URL
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchUrl = g:vimwiki_syntax_variables[a:syntax].rxWeblink
" 0b) match DESCRIPTION within URL
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchDescr = ''
" template for matching all wiki links with a given target file
let g:vimwiki_syntax_variables[a:syntax].WikiLinkMatchUrlTemplate =
\ g:vimwiki_global_vars.rx_wikilink_prefix .
@ -365,11 +359,15 @@ function! vimwiki#vars#populate_syntax_vars(syntax)
\ g:vimwiki_global_vars.rxWikiLinkUrl.'\%('.g:vimwiki_global_vars.rx_wikilink_separator.
\ g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
let g:vimwiki_syntax_variables[a:syntax].rxAnyLink = g:vimwiki_syntax_variables[a:syntax].rxWikiLink.'\|'.
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.g:vimwiki_global_vars.rxWeblink
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.g:vimwiki_syntax_variables[a:syntax].rxWeblink
" b) match URL within [[URL|DESCRIPTION]]
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchUrl = g:vimwiki_global_vars.rx_wikilink_prefix.
\ '\zs'. g:vimwiki_global_vars.rxWikiLinkUrl.'\ze\%('. g:vimwiki_global_vars.rx_wikilink_separator.
\ g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
" c) match DESCRIPTION within [[URL|DESCRIPTION]]
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchDescr = g:vimwiki_global_vars.rx_wikilink_prefix.
\ g:vimwiki_global_vars.rxWikiLinkUrl . g:vimwiki_global_vars.rx_wikilink_separator.'\%('.
\ '\zs'. g:vimwiki_global_vars.rxWikiLinkDescr. '\ze\)\?'. g:vimwiki_global_vars.rx_wikilink_suffix
if a:syntax ==# 'markdown'
call s:populate_extra_markdown_vars()
@ -381,11 +379,11 @@ function! s:populate_extra_markdown_vars()
let mkd_syntax = g:vimwiki_syntax_variables['markdown']
" 0a) match [[URL|DESCRIPTION]]
let mkd_syntax.vimwiki_rxWikiLink0 = mkd_syntax.rxWikiLink
let mkd_syntax.rxWikiLink0 = mkd_syntax.rxWikiLink
" 0b) match URL within [[URL|DESCRIPTION]]
let mkd_syntax.vimwiki_rxWikiLink0MatchUrl = mkd_syntax.rxWikiLinkMatchUrl
let mkd_syntax.rxWikiLink0MatchUrl = mkd_syntax.rxWikiLinkMatchUrl
" 0c) match DESCRIPTION within [[URL|DESCRIPTION]]
let mkd_syntax.vimwiki_rxWikiLink0MatchDescr = g:vimwiki_global_vars.rxWikiLinkMatchDescr
let mkd_syntax.rxWikiLink0MatchDescr = g:vimwiki_global_vars.rxWikiLinkMatchDescr
let wikilink_md_prefix = '['
let wikilink_md_suffix = ']'
@ -447,13 +445,78 @@ let mkd_syntax.rxWikiLink1Suffix1 = mkd_syntax.rx_wikilink_md_separator.
\ mkd_syntax.rxWikiLink1Url . mkd_syntax.rx_wikilink_md_suffix
" 1. match ANY wikilink
let mkd_syntax.rxWikiLink = ''.
\ mkd_syntax.rxWikiLink0.'\|'.
\ mkd_syntax.rxWikiLink1
let mkd_syntax.rxWikiLink = mkd_syntax.rxWikiLink0 . '\|' . mkd_syntax.rxWikiLink1
" 2. match URL within ANY wikilink
let mkd_syntax.rxWikiLinkMatchUrl = ''.
\ g:vimwiki_rxWikiLink0MatchUrl.'\|'.
\ g:vimwiki_rxWikiLink1MatchUrl
let mkd_syntax.rxWikiLinkMatchUrl = mkd_syntax.rxWikiLink0MatchUrl . '\|' .
\ mkd_syntax.rxWikiLink1MatchUrl
" 3. match DESCRIPTION within ANY wikilink
let mkd_syntax.rxWikiLinkMatchDescr = mkd_syntax.rxWikiLink0MatchDescr . '\|' .
\ mkd_syntax.rxWikiLink1MatchDescr
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
let mkd_syntax.rxWeblink0 = mkd_syntax.rxWeblink
" 0a) match URL within URL
let mkd_syntax.rxWeblinkMatchUrl0 = mkd_syntax.rxWeblinkMatchUrl
" 0b) match DESCRIPTION within URL
let mkd_syntax.rxWeblinkMatchDescr0 = mkd_syntax.rxWeblinkMatchDescr
let mkd_syntax.rxWeblink1Prefix = '['
let mkd_syntax.rxWeblink1Suffix = ')'
let mkd_syntax.rxWeblink1Separator = ']('
" [DESCRIPTION](URL)
let mkd_syntax.Weblink1Template = mkd_syntax.rxWeblink1Prefix . '__LinkDescription__'.
\ mkd_syntax.rxWeblink1Separator. '__LinkUrl__'.
\ mkd_syntax.rxWeblink1Suffix
let valid_chars = '[^\\]'
let mkd_syntax.rxWeblink1Prefix = vimwiki#u#escape(mkd_syntax.rxWeblink1Prefix)
let mkd_syntax.rxWeblink1Suffix = vimwiki#u#escape(mkd_syntax.rxWeblink1Suffix)
let mkd_syntax.rxWeblink1Separator = vimwiki#u#escape(mkd_syntax.rxWeblink1Separator)
let mkd_syntax.rxWeblink1Url = valid_chars.'\{-}'
let mkd_syntax.rxWeblink1Descr = valid_chars.'\{-}'
" 1. [DESCRIPTION](URL)
" 1a) match [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1 = mkd_syntax.rxWeblink1Prefix.
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Descr . mkd_syntax.rxWeblink1Suffix
" 1b) match URL within [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1MatchUrl = mkd_syntax.rxWeblink1Prefix.
\ mkd_syntax.rxWeblink1Descr. mkd_syntax.rxWeblink1Separator.
\ '\zs' . mkd_syntax.rxWeblink1Url . '\ze' . mkd_syntax.rxWeblink1Suffix
" 1c) match DESCRIPTION within [DESCRIPTION](URL)
let mkd_syntax.rxWeblink1MatchDescr = mkd_syntax.rxWeblink1Prefix.
\ '\zs'.mkd_syntax.rxWeblink1Descr.'\ze'. mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url. mkd_syntax.rxWeblink1Suffix
" TODO: image links too !!
let mkd_syntax.rxWeblink1Prefix1 = mkd_syntax.rxWeblink1Prefix
let mkd_syntax.rxWeblink1Suffix1 = mkd_syntax.rxWeblink1Separator.
\ mkd_syntax.rxWeblink1Url . mkd_syntax.rxWeblink1Suffix
" *a) match ANY weblink
let mkd_syntax.rxWeblink = ''.
\ mkd_syntax.rxWeblink1.'\|'.
\ mkd_syntax.rxWeblink0
" *b) match URL within ANY weblink
let mkd_syntax.rxWeblinkMatchUrl = ''.
\ mkd_syntax.rxWeblink1MatchUrl.'\|'.
\ mkd_syntax.rxWeblinkMatchUrl0
" *c) match DESCRIPTION within ANY weblink
let mkd_syntax.rxWeblinkMatchDescr = ''.
\ mkd_syntax.rxWeblink1MatchDescr.'\|'.
\ mkd_syntax.rxWeblinkMatchDescr0
let g:vimwiki_rxAnyLink = g:vimwiki_rxWikiLink.'\|'.
\ g:vimwiki_rxWikiIncl.'\|'.mkd_syntax.rxWeblink
let mkd_syntax.rxMkdRef = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
\ mkd_syntax.rxWeblink0
let g:vimwiki_rxMkdRefMatchDescr = '\[\zs'.g:vimwiki_global_vars.rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'.
\ mkd_syntax.rxWeblink0
let g:vimwiki_rxMkdRefMatchUrl = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
\ mkd_syntax.rxWeblink0.'\ze'
endfunction
@ -492,6 +555,14 @@ function! vimwiki#vars#get_bufferlocal(key)
let subdir = vimwiki#vars#get_bufferlocal('subdir')
let b:vimwiki_invsubdir = vimwiki#base#invsubdir(subdir)
return b:vimwiki_invsubdir
elseif a:key ==# 'existing_wikifiles'
let b:vimwiki_existing_wikifiles =
\ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 1)
return b:vimwiki_existing_wikifiles
elseif a:key ==# 'existing_wikidirs'
let b:vimwiki_existing_wikidirs =
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr'))
return b:vimwiki_existing_wikidirs
endif
endfunction

View File

@ -10,13 +10,6 @@ elseif exists("b:current_syntax")
endif
if vimwiki#vars#get_wikilocal('maxhi')
let b:existing_wikifiles =
\ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 1)
let b:existing_wikidirs =
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr'))
endif
let s:current_syntax = vimwiki#vars#get_wikilocal('syntax')
call vimwiki#vars#populate_syntax_vars(s:current_syntax)
@ -46,10 +39,10 @@ function! s:highlight_existing_links() "{{{
" Conditional highlighting that depends on the existence of a wiki file or
" directory is only available for *schemeless* wiki links
" Links are set up upon BufEnter (see plugin/...)
let safe_links = '\%('.vimwiki#base#file_pattern(b:existing_wikifiles) .
let safe_links = '\%('.vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikifiles')) .
\ '\%(#[^|]*\)\?\|#[^|]*\)'
" Wikilink Dirs set up upon BufEnter (see plugin/...)
let safe_dirs = vimwiki#base#file_pattern(b:existing_wikidirs)
let safe_dirs = vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikidirs'))
" match [[URL]]
let target = vimwiki#base#apply_template(
@ -102,7 +95,7 @@ else
endif
" Weblink
call s:add_target_syntax_ON(vimwiki#vars#get_global('rxWeblink'), 'VimwikiLink')
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink'), 'VimwikiLink')
" WikiLink
" All remaining schemes are highlighted automatically

View File

@ -1,114 +1,9 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
" Vimwiki syntax file
" Desc: Special stuff for markdown syntax
" Home: https://github.com/vimwiki/vimwiki/
" LINKS: assume this is common to all syntaxes "{{{
" }}}
" -------------------------------------------------------------------------
" Load concrete Wiki syntax: sets regexes and templates for headers and links
" -------------------------------------------------------------------------
" LINKS: setup of larger regexes {{{
" *. ANY wikilink {{{
" *c) match DESCRIPTION within ANY wikilink
let g:vimwiki_rxWikiLinkMatchDescr = ''.
\ g:vimwiki_rxWikiLink0MatchDescr.'\|'.
\ g:vimwiki_rxWikiLink1MatchDescr
" }}}
" LINKS: Setup weblink0 regexps {{{
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
let g:vimwiki_rxWeblink0 = g:vimwiki_rxWeblink
" 0a) match URL within URL
let g:vimwiki_rxWeblinkMatchUrl0 = g:vimwiki_rxWeblinkMatchUrl
" 0b) match DESCRIPTION within URL
let g:vimwiki_rxWeblinkMatchDescr0 = g:vimwiki_rxWeblinkMatchDescr
" }}}
" LINKS: Setup weblink1 regexps {{{
let g:vimwiki_rxWeblink1Prefix = '['
let g:vimwiki_rxWeblink1Suffix = ')'
let g:vimwiki_rxWeblink1Separator = ']('
" [DESCRIPTION](URL)
let g:vimwiki_Weblink1Template = g:vimwiki_rxWeblink1Prefix . '__LinkDescription__'.
\ g:vimwiki_rxWeblink1Separator. '__LinkUrl__'.
\ g:vimwiki_rxWeblink1Suffix
let s:valid_chars = '[^\\]'
let g:vimwiki_rxWeblink1Prefix = vimwiki#u#escape(g:vimwiki_rxWeblink1Prefix)
let g:vimwiki_rxWeblink1Suffix = vimwiki#u#escape(g:vimwiki_rxWeblink1Suffix)
let g:vimwiki_rxWeblink1Separator = vimwiki#u#escape(g:vimwiki_rxWeblink1Separator)
let g:vimwiki_rxWeblink1Url = s:valid_chars.'\{-}'
let g:vimwiki_rxWeblink1Descr = s:valid_chars.'\{-}'
"
" " 2012-02-04 TODO not starting with [[ or ][ ? ... prefix = '[\[\]]\@<!\['
" 1. [DESCRIPTION](URL)
" 1a) match [DESCRIPTION](URL)
let g:vimwiki_rxWeblink1 = g:vimwiki_rxWeblink1Prefix.
\ g:vimwiki_rxWeblink1Url.g:vimwiki_rxWeblink1Separator.
\ g:vimwiki_rxWeblink1Descr.g:vimwiki_rxWeblink1Suffix
" 1b) match URL within [DESCRIPTION](URL)
let g:vimwiki_rxWeblink1MatchUrl = g:vimwiki_rxWeblink1Prefix.
\ g:vimwiki_rxWeblink1Descr. g:vimwiki_rxWeblink1Separator.
\ '\zs'.g:vimwiki_rxWeblink1Url.'\ze'. g:vimwiki_rxWeblink1Suffix
" 1c) match DESCRIPTION within [DESCRIPTION](URL)
let g:vimwiki_rxWeblink1MatchDescr = g:vimwiki_rxWeblink1Prefix.
\ '\zs'.g:vimwiki_rxWeblink1Descr.'\ze'. g:vimwiki_rxWeblink1Separator.
\ g:vimwiki_rxWeblink1Url. g:vimwiki_rxWeblink1Suffix
" }}}
" Syntax helper {{{
" TODO: image links too !!
" let g:vimwiki_rxWeblink1Prefix1 = '!\?'. g:vimwiki_rxWeblink1Prefix
let g:vimwiki_rxWeblink1Prefix1 = g:vimwiki_rxWeblink1Prefix
let g:vimwiki_rxWeblink1Suffix1 = g:vimwiki_rxWeblink1Separator.
\ g:vimwiki_rxWeblink1Url.g:vimwiki_rxWeblink1Suffix
" }}}
" *. ANY weblink {{{
" *a) match ANY weblink
let g:vimwiki_rxWeblink = ''.
\ g:vimwiki_rxWeblink1.'\|'.
\ g:vimwiki_rxWeblink0
" *b) match URL within ANY weblink
let g:vimwiki_rxWeblinkMatchUrl = ''.
\ g:vimwiki_rxWeblink1MatchUrl.'\|'.
\ g:vimwiki_rxWeblinkMatchUrl0
" *c) match DESCRIPTION within ANY weblink
let g:vimwiki_rxWeblinkMatchDescr = ''.
\ g:vimwiki_rxWeblink1MatchDescr.'\|'.
\ g:vimwiki_rxWeblinkMatchDescr0
" }}}
" LINKS: Setup anylink regexps {{{
let g:vimwiki_rxAnyLink = g:vimwiki_rxWikiLink.'\|'.
\ g:vimwiki_rxWikiIncl.'\|'.g:vimwiki_rxWeblink
" }}}
" LINKS: setup wikilink1 reference link definitions {{{
let g:vimwiki_rxMkdRef = '\['.g:vimwiki_rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
\ g:vimwiki_rxWeblink0
let g:vimwiki_rxMkdRefMatchDescr = '\[\zs'.g:vimwiki_rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'.
\ g:vimwiki_rxWeblink0
let g:vimwiki_rxMkdRefMatchUrl = '\['.g:vimwiki_rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
\ g:vimwiki_rxWeblink0.'\ze'
" }}}
" }}} end of Links
" LINKS: highlighting is complicated due to "nonexistent" links feature {{{
function! s:add_target_syntax_ON(target, type) " {{{
@ -130,8 +25,8 @@ function! s:add_target_syntax_OFF(target, type) " {{{
endfunction "}}}
function! s:wrap_wikilink1_rx(target) "{{{
return g:vimwiki_rxWikiLink1InvalidPrefix.a:target.
\ g:vimwiki_rxWikiLink1InvalidSuffix
return vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidPrefix') . a:target.
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidSuffix')
endfunction "}}}
function! s:existing_mkd_refs() "{{{
@ -144,45 +39,45 @@ function! s:highlight_existing_links() "{{{
" Conditional highlighting that depends on the existence of a wiki file or
" directory is only available for *schemeless* wiki links
" Links are set up upon BufEnter (see plugin/...)
let safe_links = '\%('.vimwiki#base#file_pattern(b:existing_wikifiles) .
let safe_links = '\%('.vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikifiles')) .
\ '\%(#[^|]*\)\?\|#[^|]*\)'
" Wikilink1 Dirs set up upon BufEnter (see plugin/...)
let safe_dirs = vimwiki#base#file_pattern(b:existing_wikidirs)
let safe_dirs = vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikidirs'))
" Ref links are cached
let safe_reflinks = vimwiki#base#file_pattern(s:existing_mkd_refs())
" match [URL][]
let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1),
\ safe_links, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DESCRIPTION][URL]
let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2),
\ safe_links, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DIRURL][]
let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1),
\ safe_dirs, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DESCRIPTION][DIRURL]
let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2),
\ safe_dirs, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [MKDREF][]
let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1),
\ safe_reflinks, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DESCRIPTION][MKDREF]
let target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2),
\ safe_reflinks, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
endfunction "}}}
@ -190,17 +85,17 @@ endfunction "}}}
" use max highlighting - could be quite slow if there are too many wikifiles
if vimwiki#vars#get_wikilocal('maxhi')
" WikiLink
call s:add_target_syntax_OFF(g:vimwiki_rxWikiLink1, 'VimwikiWikiLink1')
call s:add_target_syntax_OFF(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
" Subsequently, links verified on vimwiki's path are highlighted as existing
call s:highlight_existing_links()
else
" Wikilink
call s:add_target_syntax_ON(g:vimwiki_rxWikiLink1, 'VimwikiWikiLink1')
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
endif
" Weblink
call s:add_target_syntax_ON(g:vimwiki_rxWeblink1, 'VimwikiWeblink1')
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink1'), 'VimwikiWeblink1')
" WikiLink
" All remaining schemes are highlighted automatically
@ -211,13 +106,13 @@ let s:rxSchemes = '\%('.
" a) match [nonwiki-scheme-URL]
let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template1),
\ s:rxSchemes.g:vimwiki_rxWikiLink1Url, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
\ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'), vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
" b) match [DESCRIPTION][nonwiki-scheme-URL]
let s:target = vimwiki#base#apply_template(
\ vimwiki#u#escape(g:vimwiki_WikiLink1Template2),
\ s:rxSchemes.g:vimwiki_rxWikiLink1Url, g:vimwiki_rxWikiLink1Descr, '')
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
\ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'), vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
" }}}
@ -226,7 +121,7 @@ call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
" Header levels, 1-6
for s:i in range(1,6)
execute 'syntax match VimwikiHeader'.s:i.' /'.g:vimwiki_rxH{s:i}.'/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell'
execute 'syntax match VimwikiHeader'.s:i.' /'.vimwiki#vars#get_syntaxlocalg('rxH'.s:i).'/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell'
endfor
" }}}
@ -242,8 +137,8 @@ syntax spell toplevel
" is present) and may be concealed
let s:options = ' contained transparent contains=NONE'
" conceal wikilink1
execute 'syn match VimwikiWikiLink1Char /'.s:rx_wikilink_md_prefix.'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.s:rx_wikilink_md_suffix.'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.vimwiki#vars#get_syntaxlocal('rx_wikilink_md_prefix').'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.vimwiki#vars#get_syntaxlocal('rx_wikilink_md_suffix').'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.vimwiki#vars#get_syntaxlocal('rxWikiLink1Prefix1').'/'.s:options
execute 'syn match VimwikiWikiLink1Char /'.vimwiki#vars#get_syntaxlocal('rxWikiLink1Suffix1').'/'.s:options