Le mardi 13 décembre 2016 23:19:00 UTC+1, Bryan Richter a écrit :
> On Tue, Dec 13, 2016 at 10:04:53AM -0800, Ni Va wrote:
> > Hi,
> >
> > I am using a useful tool rigrep to search content through dirs and
> > files.
> >
> > Then I have applied it to makeprg and set errorformat to display found
> > informations like this :
> >
> >
> > let &makeprg = expand("$VIM").'\vim80\rg.exe -n ' . l:args
> > let &errorformat = '%f:%l:%m'
> > make
> > copen
> >
> > It works perfectly and found items are well displayed with copen. Now
> > I would like to job_start the command make and retrieve same display
> > in the copened list.
> >
> > How can I do that ?
> > Thanks by advance
>
> There are two bits of advice I have.
>
> First, vim is very familiar with tools for searching through dirs and
> files. The most well-known is called grep (perhaps you also know it).
> vim has a command specifically for doing these searches: ":grep". You
> can control it with 'grepprg' just like you can control ":make" with
> 'makeprg'. I suggest you get comfortable using those ones!
>
> (I also use ripgrep. Here are the relevant configurations for me on
> Linux):
>
> set grepprg=rg\ --vimgrep
> set grepformat=%f:%l:%c:%m
>
> Second, you can use the AsyncRun plugin in order to run 'grepprg'
> asynchronously. The syntax is a bit cumbersome, but it looks like:
>
> :AsyncRun -program=grep SEARCH_TERMS
>
> That will run 'grepprg' in the background and populate the errorlist
> as you desire.
>
> https://github.com/skywind3000/asyncrun.vim
>
> I hope someone has a better solution than this plugin. :) Maybe one
> day :grep will automatically be async?
Thank you Bryan for advices.
Applying that example
" From http://andrewvos.com/2016/09/14/writing-async-jobs-in-vim-8
I have done this code.
function! BackgroundCommandClose(channel)
" Read the output from the command into the quickfix window
execute "cfile! " . g:backgroundCommandOutput
" Open the quickfix window
copen
unlet g:backgroundCommandOutput
endfunction
fun! utils#Search(args) "{{{
"
"
"
let prgPath = expand("$vimruntime")."/rg.exe"
if !file_readable(prgPath)
echoerr "rigrep tool not found in ".$vimruntime
return -1
endif
let l:args = empty(a:args) ? expand("<cword>") : a:args
let cmd = prgPath . ' -n ' . l:args
" Async func
let g:backgroundCommandOutput = tempname()
let j = job_start(cmd, {'close_cb': 'BackgroundCommandClose', 'out_io': 'file', 'out_name': g:backgroundCommandOutput})
endfu
command! -bang -nargs=* -complete=file Search call utils#Search(<q-args>)
It works very well in background and copen the cfile well formatted.
Maybe you can advise me how optimizing BackgroundCommandClose func declaration in order to declare it within the utilsSearch func.
But thank for your advices.
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment