Thursday, October 15, 2015

Re: Capture output of :make

On 2015-10-15, Nicola wrote:
> Is it possible to capture the output of :make in order to show it
> in a buffer (when there are no errors)?
>
> My use case is as follows: I have some files that I want to process
> to produce reports. But the files may contain syntax errors, in which
> case I'd like such errors to be sent to a quickfix window.
>
> What I am doing now is setting the global errorformat and using cexpr,
> along these lines:
>
> let output = system(cmd)
> if v:shell_error
> set errorformat=%f:%l:%m
> cexpr output
> copen
> else
> bo new
> call append(0, output)
> endif
>
> This works, but I have to set the global errorformat, which I am not
> sure is a good thing (say, if I want to distribute the code as a plugin).
> Is there a better way?

To solve the particular problem of setting 'errorformat' without
disturbing the global setting, you could either set the value for
just the current buffer like this:

setlocal errorformat=%f:%l:%m

or you could save and restore the global value like this:

let l:efm = &efm
set errorformat=%f:%l:%m
cexpr output
let &efm = l:efm

Regards,
Gary

--
--
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