Nivamail wrote:
> 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.
This looks like a good start for a very useful plugin.  One that I would
like to include in Vim.
What I would prefer is something that works just like :make, but in the
background.  It would have the same arguments as :make and use the
'makeprg' option.  Only that the quickfix list is set much later.
Could call it :MakeBackground.
My wishlist:
- When using it again before the previous job is finished, prompt the
  user if he wants to abort the already running job.  I quite often run
  :make and than realize I forgot one change.
- Open the quickfix window when the --copen argument is given.
- Give a non-intrusive message when the work is done.
Anyone who would be willing to make this work and maintain it?
-- 
hundred-and-one symptoms of being an internet addict:
116. You are living with your boyfriend who networks your respective
     computers so you can sit in separate rooms and email each other
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
-- 
-- 
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