@@ -50,6 +50,17 @@ function! s:create_grep_options(word) abort
50
50
endfunction
51
51
52
52
53
+ function ! s: show_result () abort
54
+ let results = getqflist ()
55
+ call codequery#query#prettify_qf_layout_and_map_keys (results)
56
+ if ! empty (results)
57
+ echom ' Found ' . len (results) . ' result' . (len (results) > 1 ? ' s' : ' ' )
58
+ else
59
+ echom ' Result Not Found'
60
+ endif
61
+ endfunction
62
+
63
+
53
64
54
65
" =============================================================================
55
66
" Entries
@@ -183,31 +194,61 @@ function! codequery#query#do_query(word) abort
183
194
return
184
195
endif
185
196
186
- " TODO: Rewrite it when Vim8 is coming
187
- " ----------------------------------------------------------------
188
- let grepcmd = g: codequery_append_to_qf ? ' grepadd!' : ' grep!'
189
- let l: grepprg_bak = &l: grepprg
190
- let l: grepformat_bak = &grepformat
197
+ if v: version >= 800
198
+ echom ' Searching ... [' . a: word . ' ]'
199
+
200
+ let job_dict = {' is_append' : g: codequery_append_to_qf ? 1 : 0 ,
201
+ \' target_file': tempname (),
202
+ \' backup_ef': &errorformat ,
203
+ \' word' : a: word ,
204
+ \' callback': function (" codequery#query#do_query_callback" )}
205
+ let options = {' out_io' : ' file' ,
206
+ \' out_name': job_dict.target_file,
207
+ \' exit_cb': job_dict.callback}
208
+
209
+ let &errorformat = ' %f:%l%m'
210
+ let grepprg .= ' \| awk "{ sub(/.*\/\.\//,x) }1"'
211
+ let shell_cmd = substitute (grepprg , ' \\|' , ' |' , " g" )
212
+ let shell_cmd = substitute (shell_cmd, " ''" , " '" , " g" )
213
+
214
+ let s: query_job = job_start ([' /bin/sh' , ' -c' , shell_cmd], options )
215
+ let timer = timer_start (50 ,
216
+ \{ - > execute (" call job_status(s:query_job)" , " " )},
217
+ \{ ' repeat' : 200 })
218
+ else
219
+ let grepcmd = g: codequery_append_to_qf ? ' grepadd!' : ' grep!'
220
+ let l: grepprg_bak = &l: grepprg
221
+ let l: grepformat_bak = &grepformat
222
+ try
223
+ let &l: grepformat = grepformat
224
+ let &l: grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"'
225
+ silent execute grepcmd
226
+ redraw !
227
+ call s: show_result ()
228
+ finally
229
+ let &l: grepprg = l: grepprg_bak
230
+ let &grepformat = l: grepformat_bak
231
+ let g: codequery_last_query_word = a: word
232
+ let g: last_query_fuzzy = g: codequery_fuzzy
233
+ endtry
234
+ endif
235
+ endfunction
236
+
237
+
238
+ function ! codequery#query#do_query_callback (job, status) dict
191
239
try
192
- let &l: grepformat = grepformat
193
- let &l: grepprg = grepprg . ' \| awk "{ sub(/.*\/\.\//,x) }1"'
194
- silent execute grepcmd
195
- redraw !
196
-
197
- let results = getqflist ()
198
- call codequery#query#prettify_qf_layout_and_map_keys (results)
199
- if ! empty (results)
200
- echom ' Found ' . len (results) . ' results'
240
+ if self .is_append
241
+ execute " caddfile " . self .target_file
201
242
else
202
- echom ' Result Not Found '
243
+ execute " cgetfile " . self .target_file
203
244
endif
245
+ call s: show_result ()
204
246
finally
205
- let &l: grepprg = l: grepprg_bak
206
- let &grepformat = l: grepformat_bak
207
- let g: codequery_last_query_word = a: word
247
+ let g: codequery_last_query_word = self .word
208
248
let g: last_query_fuzzy = g: codequery_fuzzy
249
+ let &errorformat = self .backup_ef
250
+ call delete (self .target_file)
209
251
endtry
210
- " ----------------------------------------------------------------
211
252
endfunction
212
253
213
254
@@ -222,4 +263,3 @@ function! codequery#query#set_options(args) abort
222
263
let g: codequery_append_to_qf = 1
223
264
endif
224
265
endfunction
225
-
0 commit comments