Save compiler output from :make to a file

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Save compiler output from :make to a file

Benjamin Fritz

I would like to call :make from Vim and view the errors in the
quickfix window, but also have the output saved for later use. Is
there a way to do this?

I though maybe 'makeef' would allow me to do this, except
that :help :make says that the errorfile is deleted (item 8 in the
described sequence).

I'm thinking about making a QuickFixCmdPost autocmd that will take the
file name in makeef and make a copy of it, but I didn't see any
obvious file copy utility in the vimscript functions. I could use a
shell command, of course...but I wanted to make sure there wasn't a
more elegant solution.

Also, I do a lot of my building on a system with Vim 6.1.5...so the
QuickFixCmdPost autocmd isn't an option there.

For now, I could just :w the quickfix window, but that's already been
parsed using the errorformat and isn't all that useful.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Save compiler output from :make to a file

Matt Wozniski-2

On Thu, Feb 26, 2009 at 11:38 AM, Ben Fritz wrote:
>
> I would like to call :make from Vim and view the errors in the
> quickfix window, but also have the output saved for later use. Is
> there a way to do this?
>
> I though maybe 'makeef' would allow me to do this, except
> that :help :make says that the errorfile is deleted (item 8 in the
> described sequence).

Well, it's hardly elegant, but it's a quick hack that will work: Make
a quickfixcmdpre autocmd that calls tempname() twice, touches the
first name, and makes the second a link to it.  Set 'makeef' to the
second, vim writes through the link to the second one and then unlinks
it, leaving the first.  Hopefully.  I haven't tested that that works,
but hopefully it does...  If I just wanted a quick hack so that I
could use it and get back to work, that's what I'd try.

~Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Save compiler output from :make to a file

Gary Johnson-4
In reply to this post by Benjamin Fritz

On 2009-02-26, Ben Fritz wrote:
> I would like to call :make from Vim and view the errors in the
> quickfix window, but also have the output saved for later use. Is
> there a way to do this?

Following the examples in ":help makeprg", how about this:

    :set makeprg=make\ $*\ \\\|\ tee\ make.out

I tested this on Cygwin, so it should work on any Unix-like system.
I don't know about pure Windows.

Regards,
Gary



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Save compiler output from :make to a file

scott-268

On Thursday 26 February 2009 11:46 am, Gary Johnson wrote:

>
> On 2009-02-26, Ben Fritz wrote:
> > I would like to call :make from Vim and view the errors in the
> > quickfix window, but also have the output saved for later use. Is
> > there a way to do this?
>
> Following the examples in ":help makeprg", how about this:
>
>     :set makeprg=make\ $*\ \\\|\ tee\ make.out
>
> I tested this on Cygwin, so it should work on any Unix-like system.
> I don't know about pure Windows.

i have good reason to believe there's a tee.exe in unxutils

sc


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Save compiler output from :make to a file

Benjamin Fritz
In reply to this post by Gary Johnson-4



On Feb 26, 11:46 am, Gary Johnson <[hidden email]> wrote:

>
> Following the examples in ":help makeprg", how about this:
>
>     :set makeprg=make\ $*\ \\\|\ tee\ make.out
>

Hmm, that looks promising for my needs.

Might it be better to append make.out to the shellpipe option on a
unix system? The default for unix uses tee already.

I used this to try it out, and it seems to work okay:

    if has('unix')
      autocmd VimEnter * let &shellpipe = &shellpipe . ' make.out'
    endif

I had to use the VimEnter event because shellpipe is set after reading
all the init files. Unfortunately, this means I can't use "-c make!"
to do the compile.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Save compiler output from :make to a file

Gary Johnson-4

On 2009-02-27, Ben Fritz wrote:

> On Feb 26, 11:46 am, Gary Johnson <[hidden email]> wrote:
>
> >
> > Following the examples in ":help makeprg", how about this:
> >
> >     :set makeprg=make\ $*\ \\\|\ tee\ make.out
> >
>
> Hmm, that looks promising for my needs.
>
> Might it be better to append make.out to the shellpipe option on a
> unix system? The default for unix uses tee already.
>
> I used this to try it out, and it seems to work okay:
>
>     if has('unix')
>       autocmd VimEnter * let &shellpipe = &shellpipe . ' make.out'
>     endif

I think you're right--that does seem cleaner and uses one fewer
processes.

> I had to use the VimEnter event because shellpipe is set after reading
> all the init files. Unfortunately, this means I can't use "-c make!"
> to do the compile.

That I don't understand.  ":help shellpipe" says,

    The initialization of this option is done after reading the
    ".vimrc" and the other initializations, so that when the 'shell'
    option is set there, the 'shellpipe' option changes
    automatically, unless it was explicitly set before.

I guess -c may be in the set of "other initializations", but it
seems to me that if you set 'shellpipe' in your ~/.vimrc, that would
make it "explicitly set before" and immune from being re-initialized
by vim.

In fact, I tried the following experiment.  I added this line to my
~/.vimrc:

    let &shellpipe.=" make.out"

and then started vim like this:

    vim -c 'set shellpipe?'

and when vim opened, this string was in the command/status line:

    shellpipe=| tee make.out

Oh, OK, so 'shellpipe' wasn't initialized before it was accessed by
the let command, so it was set to "| tee" instead of "2>&1| tee".

Next I put this command in my ~/.vimrc instead:

    let &shellpipe="2>&1| tee make.out"

Then I created a hello.c file in the current directory, with an
error in it, and executed

    vim -c 'make! hello'

The quickfix list contained the error and make.out contained the
full output of make.

So, you don't need to use an autocommand to set 'shellpipe' unless
you want vim to determine the initial value according to your
'shell'.  If you set it as I did, you can continue to use "-c
make!".

Regards,
Gary



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Save compiler output from :make to a file

Benjamin Fritz



On Feb 27, 1:58 pm, Gary Johnson <[hidden email]> wrote:

>
> So, you don't need to use an autocommand to set 'shellpipe' unless
> you want vim to determine the initial value according to your
> 'shell'.

Yes, that was the idea. I didn't want to bother figuring out the
current value of 'shellpipe' or figuring out why 'make' wasn't working
if I ever switch shells or use my .vimrc on another machine.

> If you set it as I did, you can continue to use "-c
> make!".
>

This is true...but I found another workaround. Instead of "-c make!" I
just use '-c "autocmd VimEnter * make!"' (it's actually done inside an
alias so it takes no more effort this way).
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---