Skip to content

Commit 14838be

Browse files
committed
Translate Vim's awkward E480 stack trace into a clean error message
See issue #47 on GitHub: #47
1 parent 1e55003 commit 14838be

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

autoload/xolox/notes.vim

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

9-
let g:xolox#notes#version = '0.23.3'
9+
let g:xolox#notes#version = '0.23.4'
1010
let g:xolox#notes#url_pattern = '\<\(mailto:\|javascript:\|\w\{3,}://\)\(\S*\w\)\+/\?'
1111
let s:scriptdir = expand('<sfile>:p:h')
1212

@@ -430,38 +430,42 @@ endfunction
430430

431431
function! xolox#notes#search(bang, input) " {{{1
432432
" Search all notes for the pattern or keywords {input} (current word if none given).
433-
let starttime = xolox#misc#timer#start()
434-
let input = a:input
435-
if input == ''
436-
let input = s:tag_under_cursor()
433+
try
434+
let starttime = xolox#misc#timer#start()
435+
let input = a:input
437436
if input == ''
438-
call xolox#misc#msg#warn("notes.vim %s: No string under cursor", g:xolox#notes#version)
439-
return
437+
let input = s:tag_under_cursor()
438+
if input == ''
439+
call xolox#misc#msg#warn("notes.vim %s: No string under cursor", g:xolox#notes#version)
440+
return
441+
endif
440442
endif
441-
endif
442-
if input =~ '^/.\+/$'
443-
call s:internal_search(a:bang, input, '', '')
444-
call s:set_quickfix_title([], input)
445-
else
446-
let keywords = split(input)
447-
let all_keywords = s:match_all_keywords(keywords)
448-
let any_keyword = s:match_any_keyword(keywords)
449-
call s:internal_search(a:bang, all_keywords, input, any_keyword)
450-
if &buftype == 'quickfix'
451-
" Enable line wrapping in the quick-fix window.
452-
setlocal wrap
453-
" Resize the quick-fix window to 1/3 of the screen height.
454-
let max_height = &lines / 3
455-
execute 'resize' max_height
456-
" Make it smaller if the content doesn't fill the window.
457-
normal G$
458-
let preferred_height = winline()
459-
execute 'resize' min([max_height, preferred_height])
460-
normal gg
461-
call s:set_quickfix_title(keywords, '')
443+
if input =~ '^/.\+/$'
444+
call s:internal_search(a:bang, input, '', '')
445+
call s:set_quickfix_title([], input)
446+
else
447+
let keywords = split(input)
448+
let all_keywords = s:match_all_keywords(keywords)
449+
let any_keyword = s:match_any_keyword(keywords)
450+
call s:internal_search(a:bang, all_keywords, input, any_keyword)
451+
if &buftype == 'quickfix'
452+
" Enable line wrapping in the quick-fix window.
453+
setlocal wrap
454+
" Resize the quick-fix window to 1/3 of the screen height.
455+
let max_height = &lines / 3
456+
execute 'resize' max_height
457+
" Make it smaller if the content doesn't fill the window.
458+
normal G$
459+
let preferred_height = winline()
460+
execute 'resize' min([max_height, preferred_height])
461+
normal gg
462+
call s:set_quickfix_title(keywords, '')
463+
endif
462464
endif
463-
endif
464-
call xolox#misc#timer#stop("notes.vim %s: Searched notes in %s.", g:xolox#notes#version, starttime)
465+
call xolox#misc#timer#stop("notes.vim %s: Searched notes in %s.", g:xolox#notes#version, starttime)
466+
catch /^Vim\%((\a\+)\)\=:E480/
467+
call xolox#misc#msg#warn("notes.vim %s: No matches", g:xolox#notes#version)
468+
endtry
465469
endfunction
466470

467471
function! s:tag_under_cursor() " {{{2

0 commit comments

Comments
 (0)