Refactoring: simplify and remove some regexes
This commit is contained in:
parent
946b3feb12
commit
9a8854756e
@ -116,11 +116,6 @@ function! vimwiki#base#resolve_link(link_text, ...)
|
||||
|
||||
let link_text = a:link_text
|
||||
|
||||
" if link is schemeless add wikiN: scheme
|
||||
if link_text !~# vimwiki#vars#get_global('rxSchemeUrl')
|
||||
let link_text = 'wiki'.source_wiki.':'.link_text
|
||||
endif
|
||||
|
||||
|
||||
let link_infos = {
|
||||
\ 'index': -1,
|
||||
@ -129,18 +124,23 @@ function! vimwiki#base#resolve_link(link_text, ...)
|
||||
\ 'anchor': '',
|
||||
\ }
|
||||
|
||||
|
||||
" extract scheme
|
||||
let link_infos.scheme = matchstr(link_text, vimwiki#vars#get_global('rxSchemeUrlMatchScheme'))
|
||||
if link_infos.scheme == '' || link_text == ''
|
||||
let link_infos.filename = '' " malformed link
|
||||
if link_text == ''
|
||||
return link_infos
|
||||
endif
|
||||
|
||||
let scheme = matchstr(link_text, '^\zs'.vimwiki#vars#get_global('rxSchemes').'\ze:')
|
||||
if scheme == ''
|
||||
let link_infos.scheme = 'wiki'.source_wiki
|
||||
else
|
||||
let link_infos.scheme = scheme
|
||||
|
||||
if link_infos.scheme !~# '\mwiki\d\+\|diary\|local\|file'
|
||||
let link_infos.filename = link_text " unknown scheme, may be a weblink
|
||||
return link_infos
|
||||
endif
|
||||
let link_text = matchstr(link_text, vimwiki#vars#get_global('rxSchemeUrlMatchUrl'))
|
||||
|
||||
let link_text = matchstr(link_text, '^'.vimwiki#vars#get_global('rxSchemes').':\zs.*\ze')
|
||||
endif
|
||||
|
||||
let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme ==# 'diary'
|
||||
|
||||
|
@ -77,31 +77,29 @@ function! s:populate_global_variables()
|
||||
|
||||
" Scheme regexes must be defined even if syntax file is not loaded yet cause users should be
|
||||
" able to <leader>w<leader>w without opening any vimwiki file first
|
||||
let g:vimwiki_global_vars.schemes = 'wiki\d\+,diary,local'
|
||||
let g:vimwiki_global_vars.web_schemes1 = 'http,https,file,ftp,gopher,telnet,nntp,ldap,rsync'.
|
||||
\ ',imap,pop,irc,ircs,cvs,svn,svn+ssh,git,ssh,fish,sftp'
|
||||
let web_schemes2 = 'mailto,news,xmpp,sip,sips,doi,urn,tel,data'
|
||||
let g:vimwiki_global_vars.schemes = join(['wiki\d\+', 'diary', 'local'], '\|')
|
||||
let g:vimwiki_global_vars.web_schemes1 = join(['http', 'https', 'file', 'ftp', 'gopher',
|
||||
\ 'telnet', 'nntp', 'ldap', 'rsync', 'imap', 'pop', 'irc', 'ircs', 'cvs', 'svn', 'svn+ssh',
|
||||
\ 'git', 'ssh', 'fish', 'sftp'], '\|')
|
||||
let web_schemes2 =
|
||||
\ join(['mailto', 'news', 'xmpp', 'sip', 'sips', 'doi', 'urn', 'tel', 'data'], '\|')
|
||||
|
||||
let rx_schemes = '\%('.
|
||||
\ join(split(g:vimwiki_global_vars.schemes, '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(g:vimwiki_global_vars.web_schemes1, '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(web_schemes2, '\s*,\s*'), '\|').
|
||||
let g:vimwiki_global_vars.rxSchemes = '\%('.
|
||||
\ g:vimwiki_global_vars.schemes . '\|'.
|
||||
\ g:vimwiki_global_vars.web_schemes1 . '\|'.
|
||||
\ web_schemes2 .
|
||||
\ '\)'
|
||||
|
||||
let g:vimwiki_global_vars.rxSchemeUrl = rx_schemes.':.*'
|
||||
let g:vimwiki_global_vars.rxSchemeUrlMatchScheme = '\zs'.rx_schemes.'\ze:.*'
|
||||
let g:vimwiki_global_vars.rxSchemeUrlMatchUrl = rx_schemes.':\zs.*\ze'
|
||||
|
||||
" match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme
|
||||
" http://tools.ietf.org/html/rfc3986
|
||||
let rxWebProtocols =
|
||||
\ '\%('.
|
||||
\ '\%('.
|
||||
\ '\%('.join(split(g:vimwiki_global_vars.web_schemes1, '\s*,\s*'), '\|').'\):'.
|
||||
\ '\%('.g:vimwiki_global_vars.web_schemes1 . '\):'.
|
||||
\ '\%(//\)'.
|
||||
\ '\)'.
|
||||
\ '\|'.
|
||||
\ '\%('.join(split(web_schemes2, '\s*,\s*'), '\|').'\):'.
|
||||
\ '\%('.web_schemes2.'\):'.
|
||||
\ '\)'
|
||||
|
||||
let g:vimwiki_global_vars.rxWeblinkUrl = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\='
|
||||
|
@ -106,8 +106,8 @@ call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink'), 'VimwikiL
|
||||
" WikiLink
|
||||
" All remaining schemes are highlighted automatically
|
||||
let s:rxSchemes = '\%('.
|
||||
\ join(split(vimwiki#vars#get_global('schemes'), '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(vimwiki#vars#get_global('web_schemes1'), '\s*,\s*'), '\|').
|
||||
\ vimwiki#vars#get_global('schemes') . '\|'.
|
||||
\ vimwiki#vars#get_global('web_schemes1').
|
||||
\ '\):'
|
||||
|
||||
" a) match [[nonwiki-scheme-URL]]
|
||||
|
@ -104,8 +104,8 @@ call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink1'), 'Vimwiki
|
||||
" WikiLink
|
||||
" All remaining schemes are highlighted automatically
|
||||
let s:rxSchemes = '\%('.
|
||||
\ join(split(vimwiki#vars#get_global('schemes'), '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(vimwiki#vars#get_global('web_schemes1'), '\s*,\s*'), '\|').
|
||||
\ vimwiki#vars#get_global('schemes') . '\|'.
|
||||
\ vimwiki#vars#get_global('web_schemes1').
|
||||
\ '\):'
|
||||
|
||||
" a) match [nonwiki-scheme-URL]
|
||||
|
Loading…
Reference in New Issue
Block a user