Conf: #1060 Get configurable schemes_web

Permit opening file with name "ssh: name with spaces.md"
This commit is contained in:
Tinmarino
2021-01-10 13:00:54 -03:00
parent e7124290a2
commit 850aace465
6 changed files with 60 additions and 30 deletions
+9 -1
View File
@@ -182,7 +182,12 @@ function! vimwiki#base#resolve_link(link_text, ...) abort
endif
" Check if absolute or relative path
" TODO Clean that => just one call
let is_absolute = 0
if vimwiki#path#is_absolute(link_text)
let is_absolute = 1
let link_text = expand(link_text)
endif
if is_wiki_link && link_text[0] ==# '/'
if link_text !=# '/'
if link_text !=# '//' && link_text[0:1] ==# '//'
@@ -234,8 +239,9 @@ function! vimwiki#base#resolve_link(link_text, ...) abort
return link_infos
endif
endif
if is_absolute
let root_dir = ''
let root_dir = ''
elseif !is_relative || link_infos.index != source_wiki
let root_dir = vimwiki#vars#get_wikilocal('path', link_infos.index)
endif
@@ -262,8 +268,10 @@ function! vimwiki#base#resolve_link(link_text, ...) abort
\ vimwiki#vars#get_wikilocal('diary_rel_path', link_infos.index) .
\ link_text .
\ vimwiki#vars#get_wikilocal('ext', link_infos.index)
elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local') && is_relative
let link_infos.filename = simplify(root_dir . link_text)
else " absolute file link
" collapse repeated leading "/"'s within a link
let link_text = substitute(link_text, '\m^/\+', '/', '')
+11 -2
View File
@@ -204,11 +204,20 @@ endfunction
function! vimwiki#path#is_absolute(path) abort
" Check: if path is absolute
let res=0
" Match 'C:' or '/' or '~'
if vimwiki#u#is_windows()
return a:path =~? '\m^\a:'
let res += a:path =~? '\m^\a:'
else
return a:path =~# '\m^/\|\~/'
let res += a:path =~# '\m^/\|\~/'
endif
" Do not prepent root_path to scp files
" See: https://vim.fandom.com/wiki/Editing_remote_files_via_scp_in_vim
let res += a:path =~# '\m^scp:'
return res
endfunction
+17 -14
View File
@@ -172,6 +172,13 @@ function! s:get_default_global() abort
\ 'map_prefix': {'type': type(''), 'default': '<Leader>w'},
\ 'markdown_header_style': {'type': type(0), 'default': 1, 'min':0, 'max': 2},
\ 'menu': {'type': type(''), 'default': 'Vimwiki'},
\ 'schemes_web': {'type': type([]), 'default':
\ [
\ 'http', 'https', 'file', 'ftp', 'gopher', 'telnet', 'nntp', 'ldap',
\ 'rsync', 'imap', 'pop', 'irc', 'ircs', 'cvs', 'svn', 'svn+ssh',
\ 'git', 'ssh', 'fish', 'sftp',
\ ]},
\ 'schemes_any': {'type': type([]), 'default': ['mailto', 'news', 'xmpp', 'sip', 'sips', 'doi', 'urn', 'tel', 'data']},
\ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'table_reduce_last_col': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'table_mappings': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
@@ -205,22 +212,18 @@ function! s:internal_global_settings() abort
" able to <leader>w<leader>w without opening any vimwiki file first
" Know internal schemes
let g:vimwiki_global_vars.schemes = join(['wiki\d\+', 'diary', 'local'], '\|')
" Are used in markdown for image links
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'], '\|')
" Other possible schemes
let web_schemes2 =
\ join(['mailto', 'news', 'xmpp', 'sip', 'sips', 'doi', 'urn', 'tel', 'data'], '\|')
let g:vimwiki_global_vars.schemes_web =
\ join(vimwiki#vars#get_global('schemes_web'), '\|')
let g:vimwiki_global_vars.schemes_any =
\ join(vimwiki#vars#get_global('schemes_any'), '\|')
let g:vimwiki_global_vars.schemes_local = join(['wiki\d\+', 'diary', 'local'], '\|')
" Concatenate known schemes => regex
let g:vimwiki_global_vars.rxSchemes = '\%('.
\ g:vimwiki_global_vars.schemes . '\|'.
\ g:vimwiki_global_vars.web_schemes1 . '\|'.
\ web_schemes2 .
\ g:vimwiki_global_vars.schemes_local . '\|'.
\ g:vimwiki_global_vars.schemes_web . '\|'.
\ g:vimwiki_global_vars.schemes_any .
\ '\)'
" Match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme
@@ -228,11 +231,11 @@ function! s:internal_global_settings() abort
let rxWebProtocols =
\ '\%('.
\ '\%('.
\ '\%('.g:vimwiki_global_vars.web_schemes1 . '\):'.
\ '\%('. g:vimwiki_global_vars.schemes_web . '\):'.
\ '\%(//\)'.
\ '\)'.
\ '\|'.
\ '\%('.web_schemes2.'\):'.
\ '\%('. g:vimwiki_global_vars.schemes_any .'\):'.
\ '\)'
let g:vimwiki_global_vars.rxWeblinkUrl = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\='