Skip to content

Commit

Permalink
feat: unrecognized ref link urls set cursor to ref url
Browse files Browse the repository at this point in the history
refer: #74
  • Loading branch information
lervag committed May 20, 2020
1 parent 65bd6d9 commit 3ad5039
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 16 additions & 7 deletions autoload/wiki/link.vim
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,23 @@ endfunction

" }}}1
function! s:parser_ref(link, ...) abort dict " {{{1
let l:id = matchstr(a:link.full, self.rx_target)
let l:lnum = searchpos('^\[' . l:id . '\]: ', 'nW')[0]
if l:lnum == 0
return a:link
else
let l:url = matchstr(getline(l:lnum), s:rx_url)
return extend(a:link, call('wiki#url#parse', [l:url] + a:000))
let a:link.id = matchstr(a:link.full, self.rx_target)
let a:link.lnum = searchpos('^\[' . a:link.id . '\]: ', 'nW')[0]
if a:link.lnum == 0 | return a:link | endif

let a:link.url = matchstr(getline(a:link.lnum), s:rx_url)
if !empty(a:link.url)
return extend(a:link, call('wiki#url#parse', [a:link.url] + a:000))
endif

" The url is not recognized, so we fall back to a link to the reference
" position.
function! a:link.open(...) abort dict
normal! m'
call cursor(self.lnum, 1)
endfunction

return a:link
endfunction

" }}}1
Expand Down
1 change: 0 additions & 1 deletion autoload/wiki/url/wiki.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,3 @@ function! s:parser.open_anchor() abort dict " {{{1
endfunction

" }}}1

0 comments on commit 3ad5039

Please sign in to comment.