Skip to content

Commit e465a0a

Browse files
committed
Make :SearchNotes work properly without vim-shell (fixes #53)
This follows the initial suggestion of removing the try/catch construct. I still haven't a clue what the hell is going on here, but I'm done fighting Vim (script) and just want this to work now! :-)
1 parent 08b9747 commit e465a0a

File tree

3 files changed

+40
-70
lines changed

3 files changed

+40
-70
lines changed

README.md

-7
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,6 @@ If you write your git commit messages in Vim and want to use the notes file type
376376

377377
This is not a complete solution (there are more types of commit messages that the pattern above won't match) but that is outside the scope of this document. For inspiration you can take a look at the [runtime/filetype.vim] [filetype.vim] file in Vim's Mercurial repository.
378378

379-
## Troubleshooting
380-
381-
### Searching notes does not work
382-
383-
There is a known problem where keyword searching of notes is broken when my [vim-shell plug-in] [shell] is not installed (even though vim-shell is supposed to be an optional dependency). The easiest way to work around this is to simply install the vim-shell plug-in, if that is an option for you. Alternatively you can help me debug the problem discussed in [issue 85] [85] :-).
384-
385379
## Contact
386380

387381
If you have questions, bug reports, suggestions, etc. the author can be contacted at <[email protected]>. The latest version is available at <http://peterodding.com/code/vim/notes/> and <http://github.com/xolox/vim-notes>. If you like the script please vote for it on [Vim Online] [vim_online].
@@ -392,7 +386,6 @@ This software is licensed under the [MIT license] [mit].
392386
© 2015 Peter Odding &lt;<[email protected]>&gt;.
393387

394388

395-
[85]: https://github.com/xolox/vim-session/issues/85
396389
[ctrlwf]: http://vimdoc.sourceforge.net/htmldoc/windows.html#CTRL-W_f
397390
[ctrlwgf]: http://vimdoc.sourceforge.net/htmldoc/windows.html#CTRL-W_gf
398391
[edit]: http://vimdoc.sourceforge.net/htmldoc/editing.html#:edit

autoload/xolox/notes.vim

+33-39
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" Vim auto-load script
22
" Author: Peter Odding <[email protected]>
3-
" Last Change: November 1, 2015
3+
" Last Change: November 4, 2015
44
" URL: http://peterodding.com/code/vim/notes/
55

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

@@ -471,46 +471,40 @@ endfunction
471471

472472
function! xolox#notes#search(bang, input) " {{{1
473473
" Search all notes for the pattern or keywords {input} (current word if none given).
474-
try
475-
let starttime = xolox#misc#timer#start()
476-
let input = a:input
474+
let starttime = xolox#misc#timer#start()
475+
let input = a:input
476+
if input == ''
477+
let input = s:tag_under_cursor()
477478
if input == ''
478-
let input = s:tag_under_cursor()
479-
if input == ''
480-
call xolox#misc#msg#warn("notes.vim %s: No string under cursor", g:xolox#notes#version)
481-
return
482-
endif
479+
call xolox#misc#msg#warn("notes.vim %s: No string under cursor", g:xolox#notes#version)
480+
return
483481
endif
484-
if input =~ '^/.\+/$'
485-
call xolox#misc#msg#debug("notes.vim %s: Performing pattern search (%s) ..", g:xolox#notes#version, input)
486-
call s:internal_search(a:bang, input, '', '')
487-
call s:set_quickfix_title([], input)
488-
else
489-
let keywords = split(input)
490-
let all_keywords = s:match_all_keywords(keywords)
491-
let any_keyword = s:match_any_keyword(keywords)
492-
call xolox#misc#msg#debug("notes.vim %s: Performing keyword search (%s) ..", g:xolox#notes#version, input)
493-
call s:internal_search(a:bang, all_keywords, input, any_keyword)
494-
if &buftype == 'quickfix'
495-
" Enable line wrapping in the quick-fix window.
496-
setlocal wrap
497-
" Resize the quick-fix window to 1/3 of the screen height.
498-
let max_height = &lines / 3
499-
execute 'resize' max_height
500-
" Make it smaller if the content doesn't fill the window.
501-
normal G$
502-
let preferred_height = winline()
503-
execute 'resize' min([max_height, preferred_height])
504-
normal gg
505-
call s:set_quickfix_title(keywords, '')
506-
endif
482+
endif
483+
if input =~ '^/.\+/$'
484+
call xolox#misc#msg#debug("notes.vim %s: Performing pattern search (%s) ..", g:xolox#notes#version, input)
485+
call s:internal_search(a:bang, input, '', '')
486+
call s:set_quickfix_title([], input)
487+
else
488+
let keywords = split(input)
489+
let all_keywords = s:match_all_keywords(keywords)
490+
let any_keyword = s:match_any_keyword(keywords)
491+
call xolox#misc#msg#debug("notes.vim %s: Performing keyword search (%s) ..", g:xolox#notes#version, input)
492+
call s:internal_search(a:bang, all_keywords, input, any_keyword)
493+
if &buftype == 'quickfix'
494+
" Enable line wrapping in the quick-fix window.
495+
setlocal wrap
496+
" Resize the quick-fix window to 1/3 of the screen height.
497+
let max_height = &lines / 3
498+
execute 'resize' max_height
499+
" Make it smaller if the content doesn't fill the window.
500+
normal G$
501+
let preferred_height = winline()
502+
execute 'resize' min([max_height, preferred_height])
503+
normal gg
504+
call s:set_quickfix_title(keywords, '')
507505
endif
508-
call xolox#misc#timer#stop("notes.vim %s: Searched notes in %s.", g:xolox#notes#version, starttime)
509-
catch /^Vim\%((\a\+)\)\=:E480/
510-
call xolox#misc#msg#warn("notes.vim %s: No matches", g:xolox#notes#version)
511-
catch
512-
call xolox#misc#msg#warn("notes.vim %s: Encountered error during search: %s (%s)", g:xolox#notes#version, v:exception, v:throwpoint)
513-
endtry
506+
endif
507+
call xolox#misc#timer#stop("notes.vim %s: Searched notes in %s.", g:xolox#notes#version, starttime)
514508
endfunction
515509

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

doc/notes.txt

+7-24
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ Contents ~
5252
3. VOoM |notes-voom|
5353
4. Txtfmt |notes-txtfmt|
5454
8. Using the notes file type for git commit messages |using-notes-file-type-for-git-commit-messages|
55-
9. Troubleshooting |notes-troubleshooting|
56-
1. Searching notes does not work |searching-notes-does-not-work|
57-
10. Contact |notes-contact|
58-
11. License |notes-license|
59-
12. References |notes-references|
55+
9. Contact |notes-contact|
56+
10. License |notes-license|
57+
11. References |notes-references|
6058

6159
===============================================================================
6260
*notes-introduction*
@@ -754,34 +752,20 @@ the pattern above won't match) but that is outside the scope of this document.
754752
For inspiration you can take a look at the runtime/filetype.vim [17] file in
755753
Vim's Mercurial repository.
756754

757-
===============================================================================
758-
*notes-troubleshooting*
759-
Troubleshooting ~
760-
761-
-------------------------------------------------------------------------------
762-
*searching-notes-does-not-work*
763-
Searching notes does not work ~
764-
765-
There is a known problem where keyword searching of notes is broken when my
766-
vim-shell plug-in [14] is not installed (even though vim-shell is supposed to
767-
be an optional dependency). The easiest way to work around this is to simply
768-
install the vim-shell plug-in, if that is an option for you. Alternatively you
769-
can help me debug the problem discussed in issue 85 [18] :-).
770-
771755
===============================================================================
772756
*notes-contact*
773757
Contact ~
774758

775759
If you have questions, bug reports, suggestions, etc. the author can be
776760
contacted at [email protected]. The latest version is available at
777761
http://peterodding.com/code/vim/notes/ and http://github.com/xolox/vim-notes.
778-
If you like the script please vote for it on Vim Online [19].
762+
If you like the script please vote for it on Vim Online [18].
779763

780764
===============================================================================
781765
*notes-license*
782766
License ~
783767

784-
This software is licensed under the MIT license [20]. © 2015 Peter Odding
768+
This software is licensed under the MIT license [19]. © 2015 Peter Odding
785769
786770

787771
===============================================================================
@@ -805,8 +789,7 @@ References ~
805789
[15] http://www.vim.org/scripts/script.php?script_id=2657
806790
[16] http://www.vim.org/scripts/script.php?script_id=2208
807791
[17] https://code.google.com/p/vim/source/browse/runtime/filetype.vim?r=fbc1131f0ba5be4ec74fb2ccdfb3559b446a2b1e#778
808-
[18] https://github.com/xolox/vim-session/issues/85
809-
[19] http://www.vim.org/scripts/script.php?script_id=3375
810-
[20] http://en.wikipedia.org/wiki/MIT_License
792+
[18] http://www.vim.org/scripts/script.php?script_id=3375
793+
[19] http://en.wikipedia.org/wiki/MIT_License
811794

812795
vim: ft=help

0 commit comments

Comments
 (0)