11" Vim auto-load script
22" Author: Peter Odding <peter@peterodding.com>
3- " Last Change: August 19 , 2013
3+ " Last Change: September 2 , 2013
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.23.2 '
9+ let g: xolox #notes#version = ' 0.23.3 '
1010let g: xolox #notes#url_pattern = ' \<\(mailto:\|javascript:\|\w\{3,}://\)\(\S*\w\)\+/\?'
1111let s: scriptdir = expand (' <sfile>:p:h' )
1212
@@ -649,10 +649,6 @@ function! s:internal_search(bang, pattern, keywords, phase2) " {{{2
649649 let notes = []
650650 let phase2_needed = 1
651651 if a: keywords != ' ' && s: run_scanner (a: keywords , notes)
652- if notes == []
653- call xolox#misc#msg#warn (" notes.vim %s: No matches" , g: xolox #notes#version )
654- return
655- endif
656652 if a: phase2 != ' '
657653 let pattern = a: phase2
658654 endif
@@ -665,6 +661,10 @@ function! s:internal_search(bang, pattern, keywords, phase2) " {{{2
665661 let phase2_needed = 0
666662 endif
667663 endif
664+ if empty (notes)
665+ call xolox#misc#msg#warn (" notes.vim %s: No matches" , g: xolox #notes#version )
666+ return
667+ endif
668668 " If we performed a keyword search using the scanner.py script we need to
669669 " run :vimgrep to populate the quick-fix list. If we're emulating keyword
670670 " search using :vimgrep we need to run :vimgrep another time to get the
@@ -713,27 +713,28 @@ endfunction
713713function ! s: run_scanner (keywords, matches) " {{{2
714714 " Try to run scanner.py script to find notes matching {keywords}.
715715 call xolox#misc#msg#info (" notes.vim %s: Searching notes using keyword index .." , g: xolox #notes#version )
716- let lines = s: python_command (a: keywords )
717- if type ( lines ) == type ([])
718- call xolox#misc#msg#debug (" notes.vim %s: Search script reported %i matching note%s." , g: xolox #notes#version , len (lines ), len (lines ) == 1 ? ' ' : ' s' )
719- call extend (a: matches , lines )
716+ let [success, notes] = s: python_command (a: keywords )
717+ if success
718+ call xolox#misc#msg#debug (" notes.vim %s: Search script reported %i matching note%s." , g: xolox #notes#version , len (notes ), len (notes ) == 1 ? ' ' : ' s' )
719+ call extend (a: matches , notes )
720720 return 1
721721 endif
722722endfunction
723723
724724function ! xolox#notes#keyword_complete (arglead, cmdline, cursorpos) " {{{2
725725 " Search keyword completion for the :SearchNotes command.
726- let first_run = ! filereadable (g: notes_indexfile )
727- if first_run | call inputsave () | endif
728- let keywords = s: python_command (' --list=' . a: arglead )
729- if first_run | call inputrestore () | endif
730- return type (keywords) == type ([]) ? keywords : []
726+ call inputsave ()
727+ let [success, keywords] = s: python_command (' --list=' . a: arglead )
728+ call inputrestore ()
729+ return keywords
731730endfunction
732731
733732function ! s: python_command (... ) " {{{2
734733 " Vim function to interface with the "search-notes.py" script.
735734 let script = xolox#misc#path#absolute (g: notes_indexscript )
736735 let python = executable (' python2' ) ? ' python2' : ' python'
736+ let output = []
737+ let success = 0
737738 if ! (executable (python ) && filereadable (script ))
738739 call xolox#misc#msg#debug (" notes.vim %s: We can't execute the %s script!" , g: xolox #notes#version , script )
739740 else
@@ -752,16 +753,20 @@ function! s:python_command(...) " {{{2
752753 endif
753754 let result = xolox#misc#os#exec ({' command' : command , ' check' : 0 })
754755 if result[' exit_code' ] != 0
755- call xolox#misc#msg#warn (" notes.vim %s: Search script failed!" , g: xolox #notes#version )
756+ call xolox#misc#msg#warn (" notes.vim %s: Search script failed! Context: %s " , g: xolox #notes#version , string (result) )
756757 else
757758 let lines = result[' stdout' ]
758- call xolox#misc#msg#debug (" notes.vim %s: Search script output: %s" , g: xolox #notes#version , string (lines ))
759+ call xolox#misc#msg#debug (" notes.vim %s: Search script output (raw) : %s" , g: xolox #notes#version , string (lines ))
759760 if ! empty (lines ) && lines [0 ] == ' Python works fine!'
760- return lines [1 :]
761+ let output = lines [1 :]
762+ let success = 1
763+ call xolox#misc#msg#debug (" notes.vim %s: Search script output (processed): %s" , g: xolox #notes#version , string (output))
764+ else
765+ call xolox#misc#msg#warn (" notes.vim %s: Search script returned invalid output :-(" , g: xolox #notes#version )
761766 endif
762- call xolox#misc#msg#warn (" notes.vim %s: Search script returned invalid output :-(" , g: xolox #notes#version )
763767 endif
764768 endif
769+ return [success, output]
765770endfunction
766771
767772" Getters for filenames & titles of existing notes. {{{2
0 commit comments