Cherry-pick the changes from dev -- part2

This commit is contained in:
EinfachToll 2018-02-16 17:47:32 +01:00
parent 19f398c73e
commit 7d4254a75d
5 changed files with 105 additions and 99 deletions

View File

@ -98,7 +98,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
let source_file = a:1
else
let source_wiki = vimwiki#vars#get_bufferlocal('wiki_nr')
let source_file = expand('%:p')
let source_file = vimwiki#path#current_wiki_file()
endif
let link_text = a:link_text
@ -257,7 +257,7 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{
\ || link_infos.scheme =~# 'diary'
let update_prev_link = is_wiki_link &&
\ !vimwiki#path#is_equal(link_infos.filename, expand('%:p'))
\ !vimwiki#path#is_equal(link_infos.filename, vimwiki#path#current_wiki_file())
let vimwiki_prev_link = []
" update previous link for wiki pages
@ -265,7 +265,7 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{
if a:0
let vimwiki_prev_link = [a:1, []]
elseif &ft ==# 'vimwiki'
let vimwiki_prev_link = [expand('%:p'), getpos('.')]
let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')]
endif
endif
@ -1076,57 +1076,81 @@ function! vimwiki#base#find_prev_link() "{{{
endfunction " }}}
" vimwiki#base#follow_link
function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pass
" to VimwikiLinkHandler, or failing that, the default open_link handler
if exists('*vimwiki#'.vimwiki#vars#get_wikilocal('syntax').'_base#follow_link')
" Syntax-specific links
" XXX: @Stuart: do we still need it?
" XXX: @Maxim: most likely! I am still working on a seemless way to
" integrate regexp's without complicating syntax/vimwiki.vim
if a:0
call vimwiki#{vimwiki#vars#get_wikilocal('syntax')}_base#follow_link(a:split, a:1)
else
call vimwiki#{vimwiki#vars#get_wikilocal('syntax')}_base#follow_link(a:split)
function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
" Parse link at cursor and pass to VimwikiLinkHandler, or failing that, the
" default open_link handler
" try WikiLink
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
" try WikiIncl
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiIncl')),
\ vimwiki#vars#get_syntaxlocal('rxWikiInclMatchUrl'))
endif
" try Weblink
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif
if lnk != "" " cursor is indeed on a link
let processed_by_user_defined_handler = VimwikiLinkHandler(lnk)
if processed_by_user_defined_handler
return
endif
else
if a:split ==# "split"
if a:split ==# "hsplit"
let cmd = ":split "
elseif a:split ==# "vsplit"
let cmd = ":vsplit "
elseif a:split ==# "tabnew"
elseif a:split ==# "tab"
let cmd = ":tabnew "
else
let cmd = ":e "
endif
" try WikiLink
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
" try WikiIncl
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')),
\ vimwiki#vars#get_global('rxWikiInclMatchUrl'))
endif
" try Weblink
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif
if lnk != ""
if !VimwikiLinkHandler(lnk)
call vimwiki#base#open_link(cmd, lnk)
" if we want to and can reuse a split window, jump to that window and open
" the new file there
if (a:split ==# 'hsplit' || a:split ==# 'vsplit') && a:reuse
let previous_window_nr = winnr('#')
if previous_window_nr > 0 && previous_window_nr != winnr()
execute previous_window_nr . 'wincmd w'
let cmd = ':e'
endif
return
endif
if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
let processed_by_markdown_reflink = vimwiki#markdown_base#open_reflink(lnk)
if processed_by_markdown_reflink
return
endif
" remove the extension from the filename if exists, because non-vimwiki
" markdown files usually include the extension in links
let lnk = substitute(lnk, vimwiki#vars#get_wikilocal('ext').'$', '', '')
endif
let current_tab_page = tabpagenr()
call vimwiki#base#open_link(cmd, lnk)
if !a:move_cursor
if (a:split ==# 'hsplit' || a:split ==# 'vsplit')
execute 'wincmd p'
elseif a:split ==# 'tab'
execute 'tabnext ' . current_tab_page
endif
endif
else
if a:0 > 0
execute "normal! ".a:1
else
call vimwiki#base#normalize_link(0)
endif
endif
endfunction " }}}
" vimwiki#base#go_back_link

View File

@ -48,61 +48,6 @@ endfunction " }}}
" WIKI link following functions {{{
" vimwiki#markdown_base#follow_link
function! vimwiki#markdown_base#follow_link(split, ...) "{{{ Parse link at cursor and pass
" to VimwikiLinkHandler, or failing that, the default open_link handler
" echom "markdown_base#follow_link"
if 0
" Syntax-specific links
" XXX: @Stuart: do we still need it?
" XXX: @Maxim: most likely! I am still working on a seemless way to
" integrate regexp's without complicating syntax/vimwiki.vim
else
if a:split ==# "split"
let cmd = ":split "
elseif a:split ==# "vsplit"
let cmd = ":vsplit "
elseif a:split ==# "tabnew"
let cmd = ":tabnew "
else
let cmd = ":e "
endif
" try WikiLink
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
" try WikiIncl
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')),
\ vimwiki#vars#get_global('rxWikiInclMatchUrl'))
endif
" try Weblink
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif
if lnk != ""
if !VimwikiLinkHandler(lnk)
if !vimwiki#markdown_base#open_reflink(lnk)
" remove the extension from the filename if exists
let lnk = substitute(lnk, vimwiki#vars#get_wikilocal('ext').'$', '', '')
call vimwiki#base#open_link(cmd, lnk)
endif
endif
return
endif
if a:0 > 0
execute "normal! ".a:1
else
call vimwiki#base#normalize_link(0)
endif
endif
endfunction " }}}
" LINK functions {{{
" s:normalize_link_syntax_n

View File

@ -75,7 +75,7 @@ function! vimwiki#path#path_common_pfx(path1, path2) "{{{
endfunction "}}}
function! vimwiki#path#wikify_path(path) "{{{
let result = resolve(expand(a:path, ':p'))
let result = resolve(fnamemodify(a:path, ':p'))
if vimwiki#u#is_windows()
let result = substitute(result, '\\', '/', 'g')
endif
@ -83,6 +83,12 @@ function! vimwiki#path#wikify_path(path) "{{{
return result
endfunction "}}}
function! vimwiki#path#current_wiki_file()
return vimwiki#path#wikify_path(expand('%:p'))
endfunction
" Returns: the relative path from a:dir to a:file
function! vimwiki#path#relpath(dir, file) "{{{
let result = []

View File

@ -363,7 +363,7 @@ glh Decrease the level of a list item.
gLh Decrease the level of a list item and all child items.
To remap: >
:map << <Plug>VimwikiDecreaseLvlSingleItem
:map >>> <Plug>VimwikiDecreaseLvlWholeItem
:map <<< <Plug>VimwikiDecreaseLvlWholeItem
<
*vimwiki_glr* *vimwiki_gLr*
glr Renumber list items if the cursor is on a numbered
@ -594,6 +594,9 @@ il A single list item.
------------------------------------------------------------------------------
4.2. Local commands *vimwiki-local-commands*
These commands are only available (and meaningful) when you are currently in a
Vimwiki file.
*:VimwikiFollowLink*
Follow wiki link (or create target wiki page if needed).
@ -742,6 +745,34 @@ il A single list item.
their instances. Supports |cmdline-completion|. If
no arguments (tags) are specified, outputs all tags.
------------------------------------------------------------------------------
4.3. Functions *vimwiki-functions*
Functions to interact with Vimwiki. (It's intended that most commands will be
replaced with corresponding function calls in the future.)
Warning: this is currently unstable and likely to change.
To map them to a key, use >
nnoremap <C-K> :call vimwiki#base#function_name(arg1, arg2)<CR>
vimwiki#base#follow_link({split}, {reuse}, {move_cursor}) *follow_link*
Open the link under the cursor. {split} can have the following values:
'nosplit' open the link in the current window
'vsplit' open in a vertically split window
'hsplit' open in a horizontally split window
'tab' open in a new tab
If {reuse} is 1 and {split} one of 'vsplit' or 'hsplit', open the link in
a possibly existing split window instead of making a new split.
If {move_cursor} is 1 the cursor moves to the window or tab with the
opened link, otherwise, it stays in the window or tab with the link.
For example, <CR> is per default mapped to
vimwiki#base#follow_link('nosplit', 0, 1)
==============================================================================
5. Wiki syntax *vimwiki-syntax*
@ -850,7 +881,7 @@ Raw URLs are also supported: >
External files~
The "file:" and "local:" schemes allow you to directly link to arbitray
The "file:" and "local:" schemes allow you to directly link to arbitrary
resources using absolute or relative paths: >
[[file:/home/somebody/a/b/c/music.mp3]]
[[file:C:/Users/somebody/d/e/f/music.mp3]]

View File

@ -255,14 +255,14 @@ command! -buffer VimwikiNextLink call vimwiki#base#find_next_link()
command! -buffer VimwikiPrevLink call vimwiki#base#find_prev_link()
command! -buffer VimwikiDeleteLink call vimwiki#base#delete_link()
command! -buffer VimwikiRenameLink call vimwiki#base#rename_link()
command! -buffer VimwikiFollowLink call vimwiki#base#follow_link('nosplit')
command! -buffer VimwikiFollowLink call vimwiki#base#follow_link('nosplit', 0, 1)
command! -buffer VimwikiGoBackLink call vimwiki#base#go_back_link()
command! -buffer VimwikiSplitLink call vimwiki#base#follow_link('split')
command! -buffer VimwikiVSplitLink call vimwiki#base#follow_link('vsplit')
command! -buffer VimwikiSplitLink call vimwiki#base#follow_link('hsplit', 0, 1)
command! -buffer VimwikiVSplitLink call vimwiki#base#follow_link('vsplit', 0, 1)
command! -buffer -nargs=? VimwikiNormalizeLink call vimwiki#base#normalize_link(<f-args>)
command! -buffer VimwikiTabnewLink call vimwiki#base#follow_link('tabnew')
command! -buffer VimwikiTabnewLink call vimwiki#base#follow_link('tab', 0, 1)
command! -buffer VimwikiGenerateLinks call vimwiki#base#generate_links()
@ -322,7 +322,7 @@ command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags
if vimwiki#vars#get_global('use_mouse')
nmap <buffer> <S-LeftMouse> <NOP>
nmap <buffer> <C-LeftMouse> <NOP>
nnoremap <silent><buffer> <2-LeftMouse> :call vimwiki#base#follow_link("nosplit", "\<lt>2-LeftMouse>")<CR>
nnoremap <silent><buffer> <2-LeftMouse> :call vimwiki#base#follow_link('nosplit', 0, 1, "\<lt>2-LeftMouse>")<CR>
nnoremap <silent><buffer> <S-2-LeftMouse> <LeftMouse>:VimwikiSplitLink<CR>
nnoremap <silent><buffer> <C-2-LeftMouse> <LeftMouse>:VimwikiVSplitLink<CR>
nnoremap <silent><buffer> <RightMouse><LeftMouse> :VimwikiGoBackLink<CR>