@@ -49,6 +49,7 @@ function! s:apply_mappings() abort
49
49
for key in keys (s: qf_mappings )
50
50
execute " nnoremap <buffer> <silent> " . key . ' ' . s: qf_mappings [key ]
51
51
endfor
52
+
52
53
endfunction
53
54
54
55
" }}}
@@ -123,14 +124,24 @@ if exists('*jobstart')
123
124
call s: bettergrep_pre (grep_cmd)
124
125
125
126
let s: cmd = a: cmd
127
+ let s: is_error = 0
126
128
127
129
function ! s: on_out (job_id, data, event ) dict
128
- execute s: cmd . ' join(a:data, "\n")'
130
+ if len (a: data ) == 1 && s: is_error == 0
131
+ echohl WarningMsg
132
+ echomsg " bettergrep: No results found."
133
+ echohl None
134
+ else
135
+ if s: is_error == 0
136
+ execute s: cmd . ' join(a:data, "\n")'
137
+ endif
138
+ endif
129
139
endfunction
130
140
131
141
function ! s: on_error (job_id, data, event ) dict
142
+ let s: is_error = 1
132
143
if len (a: data ) > 1
133
- echoerr ' bettergrep E : ' . join (a: data , " \n " )
144
+ echoerr ' bettergrep ERR : ' . join (a: data , " \n " )
134
145
endif
135
146
endfunction
136
147
@@ -165,21 +176,27 @@ elseif exists('*job_start')
165
176
166
177
let s: cmd = a: cmd
167
178
let s: data = ' '
179
+ let s: is_error = 0
168
180
169
181
function ! s: on_out (job_id, data)
170
182
let s: data .= a: data . " \n "
171
183
endfunction
172
184
173
185
function ! s: on_error (job_id, data)
186
+ let s: is_error = 1
174
187
if len (a: data ) > 1
175
- echoerr ' bettergrep E : ' . join ([a: data ], " \n " )
188
+ echoerr ' bettergrep ERR : ' . join ([a: data ], " \n " )
176
189
endif
177
190
endfunction
178
191
179
192
function ! s: on_exit (job_id, status)
180
193
let job_to_kill = s: grep_job
181
194
if len (s: data ) > 1
182
195
execute s: cmd . ' join([s:data], "\n")'
196
+ elseif s: is_error == 0
197
+ echohl WarningMsg
198
+ echomsg " bettergrep: No results found."
199
+ echohl None
183
200
endif
184
201
call s: bettergrep_post ()
185
202
call job_stop (job_to_kill)
@@ -192,9 +209,9 @@ elseif exists('*job_start')
192
209
\ ' in_io' : ' null'
193
210
\ }
194
211
195
- let cmd = split (&shell ) + split (&shellcmdflag ) + [grep_cmd]
196
- echomsg " bettergrep: " . cmd
197
- let s: grep_job = job_start (cmd , s: callbacks )
212
+ let shell_cmd = split (&shell ) + split (&shellcmdflag ) + [grep_cmd]
213
+ echomsg " bettergrep: " . join (shell_cmd, ' ' )
214
+ let s: grep_job = job_start (shell_cmd , s: callbacks )
198
215
199
216
endfunction
200
217
0 commit comments