Cherry-pick the changes from dev -- part2
This commit is contained in:
parent
19f398c73e
commit
7d4254a75d
@ -98,7 +98,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
|||||||
let source_file = a:1
|
let source_file = a:1
|
||||||
else
|
else
|
||||||
let source_wiki = vimwiki#vars#get_bufferlocal('wiki_nr')
|
let source_wiki = vimwiki#vars#get_bufferlocal('wiki_nr')
|
||||||
let source_file = expand('%:p')
|
let source_file = vimwiki#path#current_wiki_file()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let link_text = a:link_text
|
let link_text = a:link_text
|
||||||
@ -257,7 +257,7 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{
|
|||||||
\ || link_infos.scheme =~# 'diary'
|
\ || link_infos.scheme =~# 'diary'
|
||||||
|
|
||||||
let update_prev_link = is_wiki_link &&
|
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 = []
|
let vimwiki_prev_link = []
|
||||||
" update previous link for wiki pages
|
" update previous link for wiki pages
|
||||||
@ -265,7 +265,7 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{
|
|||||||
if a:0
|
if a:0
|
||||||
let vimwiki_prev_link = [a:1, []]
|
let vimwiki_prev_link = [a:1, []]
|
||||||
elseif &ft ==# 'vimwiki'
|
elseif &ft ==# 'vimwiki'
|
||||||
let vimwiki_prev_link = [expand('%:p'), getpos('.')]
|
let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')]
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -1076,36 +1076,17 @@ function! vimwiki#base#find_prev_link() "{{{
|
|||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
" vimwiki#base#follow_link
|
" vimwiki#base#follow_link
|
||||||
function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pass
|
function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
|
||||||
" to VimwikiLinkHandler, or failing that, the default open_link handler
|
" Parse link at cursor and pass to VimwikiLinkHandler, or failing that, the
|
||||||
if exists('*vimwiki#'.vimwiki#vars#get_wikilocal('syntax').'_base#follow_link')
|
" default open_link handler
|
||||||
" 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)
|
|
||||||
endif
|
|
||||||
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
|
" try WikiLink
|
||||||
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
|
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
|
||||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
|
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
|
||||||
" try WikiIncl
|
" try WikiIncl
|
||||||
if lnk == ""
|
if lnk == ""
|
||||||
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')),
|
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiIncl')),
|
||||||
\ vimwiki#vars#get_global('rxWikiInclMatchUrl'))
|
\ vimwiki#vars#get_syntaxlocal('rxWikiInclMatchUrl'))
|
||||||
endif
|
endif
|
||||||
" try Weblink
|
" try Weblink
|
||||||
if lnk == ""
|
if lnk == ""
|
||||||
@ -1113,20 +1094,63 @@ function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pas
|
|||||||
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
|
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if lnk != ""
|
if lnk != "" " cursor is indeed on a link
|
||||||
if !VimwikiLinkHandler(lnk)
|
let processed_by_user_defined_handler = VimwikiLinkHandler(lnk)
|
||||||
call vimwiki#base#open_link(cmd, lnk)
|
if processed_by_user_defined_handler
|
||||||
endif
|
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if a:split ==# "hsplit"
|
||||||
|
let cmd = ":split "
|
||||||
|
elseif a:split ==# "vsplit"
|
||||||
|
let cmd = ":vsplit "
|
||||||
|
elseif a:split ==# "tab"
|
||||||
|
let cmd = ":tabnew "
|
||||||
|
else
|
||||||
|
let cmd = ":e "
|
||||||
|
endif
|
||||||
|
|
||||||
|
" 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
|
||||||
|
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
|
if a:0 > 0
|
||||||
execute "normal! ".a:1
|
execute "normal! ".a:1
|
||||||
else
|
else
|
||||||
call vimwiki#base#normalize_link(0)
|
call vimwiki#base#normalize_link(0)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
" vimwiki#base#go_back_link
|
" vimwiki#base#go_back_link
|
||||||
|
@ -48,61 +48,6 @@ endfunction " }}}
|
|||||||
|
|
||||||
" WIKI link following functions {{{
|
" 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 {{{
|
" LINK functions {{{
|
||||||
|
|
||||||
" s:normalize_link_syntax_n
|
" s:normalize_link_syntax_n
|
||||||
|
@ -75,7 +75,7 @@ function! vimwiki#path#path_common_pfx(path1, path2) "{{{
|
|||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! vimwiki#path#wikify_path(path) "{{{
|
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()
|
if vimwiki#u#is_windows()
|
||||||
let result = substitute(result, '\\', '/', 'g')
|
let result = substitute(result, '\\', '/', 'g')
|
||||||
endif
|
endif
|
||||||
@ -83,6 +83,12 @@ function! vimwiki#path#wikify_path(path) "{{{
|
|||||||
return result
|
return result
|
||||||
endfunction "}}}
|
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
|
" Returns: the relative path from a:dir to a:file
|
||||||
function! vimwiki#path#relpath(dir, file) "{{{
|
function! vimwiki#path#relpath(dir, file) "{{{
|
||||||
let result = []
|
let result = []
|
||||||
|
@ -363,7 +363,7 @@ glh Decrease the level of a list item.
|
|||||||
gLh Decrease the level of a list item and all child items.
|
gLh Decrease the level of a list item and all child items.
|
||||||
To remap: >
|
To remap: >
|
||||||
:map << <Plug>VimwikiDecreaseLvlSingleItem
|
:map << <Plug>VimwikiDecreaseLvlSingleItem
|
||||||
:map >>> <Plug>VimwikiDecreaseLvlWholeItem
|
:map <<< <Plug>VimwikiDecreaseLvlWholeItem
|
||||||
<
|
<
|
||||||
*vimwiki_glr* *vimwiki_gLr*
|
*vimwiki_glr* *vimwiki_gLr*
|
||||||
glr Renumber list items if the cursor is on a numbered
|
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*
|
4.2. Local commands *vimwiki-local-commands*
|
||||||
|
|
||||||
|
These commands are only available (and meaningful) when you are currently in a
|
||||||
|
Vimwiki file.
|
||||||
|
|
||||||
*:VimwikiFollowLink*
|
*:VimwikiFollowLink*
|
||||||
Follow wiki link (or create target wiki page if needed).
|
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
|
their instances. Supports |cmdline-completion|. If
|
||||||
no arguments (tags) are specified, outputs all tags.
|
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*
|
5. Wiki syntax *vimwiki-syntax*
|
||||||
@ -850,7 +881,7 @@ Raw URLs are also supported: >
|
|||||||
|
|
||||||
External files~
|
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: >
|
resources using absolute or relative paths: >
|
||||||
[[file:/home/somebody/a/b/c/music.mp3]]
|
[[file:/home/somebody/a/b/c/music.mp3]]
|
||||||
[[file:C:/Users/somebody/d/e/f/music.mp3]]
|
[[file:C:/Users/somebody/d/e/f/music.mp3]]
|
||||||
|
@ -255,14 +255,14 @@ command! -buffer VimwikiNextLink call vimwiki#base#find_next_link()
|
|||||||
command! -buffer VimwikiPrevLink call vimwiki#base#find_prev_link()
|
command! -buffer VimwikiPrevLink call vimwiki#base#find_prev_link()
|
||||||
command! -buffer VimwikiDeleteLink call vimwiki#base#delete_link()
|
command! -buffer VimwikiDeleteLink call vimwiki#base#delete_link()
|
||||||
command! -buffer VimwikiRenameLink call vimwiki#base#rename_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 VimwikiGoBackLink call vimwiki#base#go_back_link()
|
||||||
command! -buffer VimwikiSplitLink call vimwiki#base#follow_link('split')
|
command! -buffer VimwikiSplitLink call vimwiki#base#follow_link('hsplit', 0, 1)
|
||||||
command! -buffer VimwikiVSplitLink call vimwiki#base#follow_link('vsplit')
|
command! -buffer VimwikiVSplitLink call vimwiki#base#follow_link('vsplit', 0, 1)
|
||||||
|
|
||||||
command! -buffer -nargs=? VimwikiNormalizeLink call vimwiki#base#normalize_link(<f-args>)
|
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()
|
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')
|
if vimwiki#vars#get_global('use_mouse')
|
||||||
nmap <buffer> <S-LeftMouse> <NOP>
|
nmap <buffer> <S-LeftMouse> <NOP>
|
||||||
nmap <buffer> <C-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> <S-2-LeftMouse> <LeftMouse>:VimwikiSplitLink<CR>
|
||||||
nnoremap <silent><buffer> <C-2-LeftMouse> <LeftMouse>:VimwikiVSplitLink<CR>
|
nnoremap <silent><buffer> <C-2-LeftMouse> <LeftMouse>:VimwikiVSplitLink<CR>
|
||||||
nnoremap <silent><buffer> <RightMouse><LeftMouse> :VimwikiGoBackLink<CR>
|
nnoremap <silent><buffer> <RightMouse><LeftMouse> :VimwikiGoBackLink<CR>
|
||||||
|
Loading…
Reference in New Issue
Block a user