Skip to content

Commit c452d2c

Browse files
authored
Merge pull request #65 from obcat/improve-K
Improve <Plug>(ref-keyword)
2 parents 7c91a10 + c0b480a commit c452d2c

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

autoload/ref.vim

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ endfunction
9999
function! ref#K(mode)
100100
try
101101
call ref#jump(a:mode)
102-
catch /^ref:/
102+
catch /^ref: The source is not registered:/
103103
if a:mode ==# 'visual'
104104
call feedkeys('gvK', 'n')
105105
else
106106
call feedkeys('K', 'n')
107107
endif
108+
catch /^ref:/
109+
call s:echoerr(v:exception)
108110
endtry
109111
endfunction
110112

@@ -524,9 +526,18 @@ endfunction
524526
function! s:get_query(mode, source)
525527
let [source, query] = [a:source, '']
526528
if a:mode ==# 'normal'
527-
let pos = getpos('.')
528-
let res = s:sources[source].get_keyword()
529-
call setpos('.', pos)
529+
try
530+
let pos = getpos('.')
531+
let res = s:sources[source].get_keyword()
532+
catch
533+
let mes = v:exception
534+
if mes =~# '^Vim'
535+
let mes .= "\n" . v:throwpoint
536+
endif
537+
throw printf('ref: %s: %s', source, mes)
538+
finally
539+
call setpos('.', pos)
540+
endtry
530541
if type(res) == s:T.list && len(res) == 2
531542
let [source, query] = res
532543
else

doc/ref.jax

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ get_keyword() *ref-source-attr-get_keyword()*
337337
[{source-name}, {keyword}] の形式のリストを返すことも
338338
できます。この場合指定されたソースでキーワードが開かれ
339339
ます。
340+
キーワードが見つからない場合はエラーメッセージと共に例
341+
外を投げます。
340342

341343
complete({query}) *ref-source-attr-complete()*
342344
任意。コマンドラインの補完リストを返します。

doc/ref.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ get_keyword() *ref-source-attr-get_keyword()*
342342
The list of the form of [{source-name}, {keyword}] can
343343
be returned. In this case, the keyword is opened by
344344
the specified source.
345+
Throws an exception with an error message if keyword
346+
is not found.
345347

346348
complete({query}) *ref-source-attr-complete()*
347349
Optional. Return the completion list for command-line.

0 commit comments

Comments
 (0)