How to "make" in a separate window?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to "make" in a separate window?

Goli, Rajesh (Rajesh)
Hi,

How can I run make from within vim using the command :make and not block my
editing? Can make ouptput be redirected to a new window? (or the output of
any other program). The ability to run make from within vim is something
that I cannot imagine being without, but this small extension will really
make the feature awesome.

Thanks in advance,
Rajesh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to "make" in a separate window?

Groleo Marius
On 5/26/05, Goli, Rajesh (Rajesh) <[hidden email]> wrote:

> Hi,
>
> How can I run make from within vim using the command :make and not block my
> editing? Can make ouptput be redirected to a new window? (or the output of
> any other program). The ability to run make from within vim is something
> that I cannot imagine being without, but this small extension will really
> make the feature awesome.
>
> Thanks in advance,
> Rajesh
>

Well , here Is what is have in my .vimrc

" No text is displayed when :make. Use :copen
set shellpipe=2>&1\|\ cat\ >

So, after you :make, use :copen to see the errors that apeard in the
make-ing process.



--
Regards, Groleo!

# touch universe
# chmod +x universe
# ./universe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to "make" in a separate window?

A.J.Mechelynck
Groleo Marius wrote:

> On 5/26/05, Goli, Rajesh (Rajesh) <[hidden email]> wrote:
>
>>Hi,
>>
>>How can I run make from within vim using the command :make and not block my
>>editing? Can make ouptput be redirected to a new window? (or the output of
>>any other program). The ability to run make from within vim is something
>>that I cannot imagine being without, but this small extension will really
>>make the feature awesome.
>>
>>Thanks in advance,
>>Rajesh
>>
>
>
> Well , here Is what is have in my .vimrc
>
> " No text is displayed when :make. Use :copen
> set shellpipe=2>&1\|\ cat\ >
>
> So, after you :make, use :copen to see the errors that apeard in the
> make-ing process.
>
>
>

What the OP wanted is to have "make" run in the background while being
able to edit some other file in vim.

I believe that in order to achieve that, make would have to be run as a
separate process (started from the shell, not from vim); then, after
make finished, the output can be imported by setting 'errorfile' (and
possibly 'errorformat') then using quickfix commands.

Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to "make" in a separate window?

Eric Arnold
In reply to this post by Goli, Rajesh (Rajesh)


This has been annoying me too.  It probably requires writing a simple
program to fork/exec the "make" commands.  Unfortunately, I can only
get you started, since my memory is hazy about that stuff.  I think I
wrote something that should work on native Unix, but MS WIN is always a
challenge.


The Perl script should be something like the below script, and used as
   :!perl filename   if stuff hard coded inside or

        :!perl tstbg.pl "echo blah >tempx 2>&1" '

You'll have to get the quoting right, depending on your   &shellquote
and   &shellxquote   values.  The MSWin version of Vim does different
interpretations of  "\"  at different stages (is it an escape char?
is it a directory slash? am I still Vim?  am I the shell yet?  am I
dos shell? etc etc etc ), so using

        :!perl echo blah \> 2\%\1

isn't likely to work.  

On MSWin, it still keeps the "command" window open saying "Press any
key", even though it it gets to that point immediately (before the
sleep).  However, the windows command shell doesn't actually take "any
key" and quit.  It probably has something to do with how "setpgrp()"
is emulated in MSWIN.  I think it's working correctly in my Cywgin
shell, to it's probably close to working if not working for Unix.  All
this is rusty, but almost works on MSWIN.  





#!/bin/perl # need the correct thingy here

use English '-no_match_vars';

if ( fork() ){;}
else
{
    setpgrp( $PROCESS_ID, 0 );
    close STDOUT; close STDIN; close STDERR;

    #open( STDOUT, ">/dev/tty" ); # not a good idea if call from Vim
    #open( STDIN, "/dev/tty" );

    sleep 5; # test that it's returning from :! immediately

    open(FH, ">tempx");
    print FH "testing\n";
    close FH;

    # This is where the "make" command would go:
    # system("@ARGV"); # if given   "make >out 2>&1"   on the command line
    # or do it here
    #system( 'make >out 2>&1' );
}

print "exiting, ppid=" . getppid() . "\n";

# Perl's getppid() on MSWIN returns "1" from inside Vim.
#kill -9, getppid();




The C version of this is similar, but I don't have a compiler these
days.  'And besides, writing in Perl is a lot faster.

In case you're wondering what it does:  it forks off a child process
that removes itself from the parent process group, so the parent can't
wait for it to complete, and returns immediately to it's caller (i.e.
Vim).  I think it's also required to close STDIN and STDOUT, and
re-open them if desired.


If somebody knows any trick to keep the dos command shell from waiting
on a child of its child that has removed it self from the process
group, that would be a help.  I can't find where the behavior of
the dos shell can be configured.  This also is another avenue to solve
the problem, I suppose.





--- "A. J. Mechelynck" <[hidden email]> wrote:

> Groleo Marius wrote:
> > On 5/26/05, Goli, Rajesh (Rajesh) <[hidden email]> wrote:
> >
> >>Hi,
> >>
> >>How can I run make from within vim using the command :make and not block my
> >>editing? Can make ouptput be redirected to a new window? (or the output of
> >>any other program). The ability to run make from within vim is something
> >>that I cannot imagine being without, but this small extension will really
> >>make the feature awesome.
> >>
> >>Thanks in advance,
> >>Rajesh
> >>
> >
> >
> > Well , here Is what is have in my .vimrc
> >
> > " No text is displayed when :make. Use :copen
> > set shellpipe=2>&1\|\ cat\ >
> >
> > So, after you :make, use :copen to see the errors that apeard in the
> > make-ing process.
> >
> >
> >
>
> What the OP wanted is to have "make" run in the background while being
> able to edit some other file in vim.
>
> I believe that in order to achieve that, make would have to be run as a
> separate process (started from the shell, not from vim); then, after
> make finished, the output can be imported by setting 'errorfile' (and
> possibly 'errorformat') then using quickfix commands.
>
> Best regards,
> Tony.
>
>



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to "make" in a separate window?

A.J.Mechelynck
Eric Arnold wrote:
[...]
> If somebody knows any trick to keep the dos command shell from waiting
> on a child of its child that has removed it self from the process
> group, that would be a help.  I can't find where the behavior of
> the dos shell can be configured.  This also is another avenue to solve
> the problem, I suppose.
[...]

On systems where the "start" command works (I think it is internal to
CMD.EXE but unknown to COMMAND.COM) you can use it (IIUC) to fork a
child process and return immediately. See the output of "start /?"
(without quotes, from the CMD.EXE prompt) for details.


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to "make" in a separate window?

Goli, Rajesh (Rajesh)
In reply to this post by Goli, Rajesh (Rajesh)
I tried doing something on the very same lines.
First I changed my .gvimrc to include

set shellpipe=\   " Shellpipe is just a space so the errorfile is an
argument to makeprogram
set mp=/home/rajesh/scripts/mkvi.pl

So when I executed :make it actually executed something like
/home/rajesh/scripts/mkvi.pl   /tmp/errorfile

My script looked something like:

#!/usr/bin/perl

use POSIX ":sys_wait_h";

if (!defined($kidpid = fork()))
{
        # fork returned undef, so failed
        die "Cannot fork: $!";
}
elsif ($kidpid != 0)
{
        # Parent exits
        exit(0);
}

open STDOUT, ">" . $ARGV[0] or die "Can't write to " . $ARGV[0] . ": $!";
open STDERR, ">" . $ARGV[0] or die "Can't write to " . $ARGV[0] . ": $!";

exec("make");

This works to the extent that I get the prompt back immediately, but vim
cribs saying it cant open the errorfile. Can you see something that I am not
doing right?

Thanks,
Rajesh

-----Original Message-----
From: Eric Arnold [mailto:[hidden email]]
Sent: Friday, May 27, 2005 6:28 AM
To: A. J. Mechelynck; Groleo Marius
Cc: Goli, Rajesh (Rajesh); [hidden email]
Subject: Re: How to "make" in a separate window?




This has been annoying me too.  It probably requires writing a simple
program to fork/exec the "make" commands.  Unfortunately, I can only
get you started, since my memory is hazy about that stuff.  I think I
wrote something that should work on native Unix, but MS WIN is always a
challenge.


The Perl script should be something like the below script, and used as
   :!perl filename   if stuff hard coded inside or

        :!perl tstbg.pl "echo blah >tempx 2>&1" '

You'll have to get the quoting right, depending on your   &shellquote
and   &shellxquote   values.  The MSWin version of Vim does different
interpretations of  "\"  at different stages (is it an escape char?
is it a directory slash? am I still Vim?  am I the shell yet?  am I
dos shell? etc etc etc ), so using

        :!perl echo blah \> 2\%\1

isn't likely to work.  

On MSWin, it still keeps the "command" window open saying "Press any
key", even though it it gets to that point immediately (before the
sleep).  However, the windows command shell doesn't actually take "any
key" and quit.  It probably has something to do with how "setpgrp()"
is emulated in MSWIN.  I think it's working correctly in my Cywgin
shell, to it's probably close to working if not working for Unix.  All
this is rusty, but almost works on MSWIN.  





#!/bin/perl # need the correct thingy here

use English '-no_match_vars';

if ( fork() ){;}
else
{
    setpgrp( $PROCESS_ID, 0 );
    close STDOUT; close STDIN; close STDERR;

    #open( STDOUT, ">/dev/tty" ); # not a good idea if call from Vim
    #open( STDIN, "/dev/tty" );

    sleep 5; # test that it's returning from :! immediately

    open(FH, ">tempx");
    print FH "testing\n";
    close FH;

    # This is where the "make" command would go:
    # system("@ARGV"); # if given   "make >out 2>&1"   on the command line
    # or do it here
    #system( 'make >out 2>&1' );
}

print "exiting, ppid=" . getppid() . "\n";

# Perl's getppid() on MSWIN returns "1" from inside Vim.
#kill -9, getppid();




The C version of this is similar, but I don't have a compiler these
days.  'And besides, writing in Perl is a lot faster.

In case you're wondering what it does:  it forks off a child process
that removes itself from the parent process group, so the parent can't
wait for it to complete, and returns immediately to it's caller (i.e.
Vim).  I think it's also required to close STDIN and STDOUT, and
re-open them if desired.


If somebody knows any trick to keep the dos command shell from waiting
on a child of its child that has removed it self from the process
group, that would be a help.  I can't find where the behavior of
the dos shell can be configured.  This also is another avenue to solve
the problem, I suppose.





--- "A. J. Mechelynck" <[hidden email]> wrote:
> Groleo Marius wrote:
> > On 5/26/05, Goli, Rajesh (Rajesh) <[hidden email]> wrote:
> >
> >>Hi,
> >>
> >>How can I run make from within vim using the command :make and not block
my
> >>editing? Can make ouptput be redirected to a new window? (or the output
of
> >>any other program). The ability to run make from within vim is something
> >>that I cannot imagine being without, but this small extension will
really

> >>make the feature awesome.
> >>
> >>Thanks in advance,
> >>Rajesh
> >>
> >
> >
> > Well , here Is what is have in my .vimrc
> >
> > " No text is displayed when :make. Use :copen
> > set shellpipe=2>&1\|\ cat\ >
> >
> > So, after you :make, use :copen to see the errors that apeard in the
> > make-ing process.
> >
> >
> >
>
> What the OP wanted is to have "make" run in the background while being
> able to edit some other file in vim.
>
> I believe that in order to achieve that, make would have to be run as a
> separate process (started from the shell, not from vim); then, after
> make finished, the output can be imported by setting 'errorfile' (and
> possibly 'errorformat') then using quickfix commands.
>
> Best regards,
> Tony.
>
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to "make" in a separate window?

hermitte
Hello.

"Goli, Rajesh (Rajesh)" <[hidden email]> wrote:

> I tried doing something on the very same lines.
> First I changed my .gvimrc to include
>
> set shellpipe=\   " Shellpipe is just a space so the errorfile is an
> argument to makeprogram
> set mp=/home/rajesh/scripts/mkvi.pl
>
> So when I executed :make it actually executed something like
> /home/rajesh/scripts/mkvi.pl   /tmp/errorfile
>
> My script looked something like:
>  [...]
> This works to the extent that I get the prompt back immediately,
> but vim cribs saying it cant open the errorfile. Can you see
> something that I am not doing right?

Save the result of the compilation in a file.
Then, once the compilation is finished, load the file with:
    :let mp=&makeprg
    :set makeprg=cat\ $*
    :make name-of-the-file
    :let &makeprg=mp

If Vim supports |+clientserver|, you should be able to send thoose
commands to vim from your perl script.


--
Luc Hermitte
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: How to "make" in a separate window?

Goli, Rajesh (Rajesh)
In reply to this post by Goli, Rajesh (Rajesh)
Thanks a lot Eric, Luc.
This is a asynchronous way of doing things. But this works almost the way I
wanted it to.

This is what I did:

.gvimrc:

noremap <F9> <ESC>:!/home/rajesh/scripts/mkvi.pl<CR>

This way is not exactly the same as typing :make, but I just have to tap F9
to begin make.

/home/rajesh/scripts/mkvi.pl:
#!/usr/bin/perl

use POSIX ":sys_wait_h";

$errorFile = '/home/rajesh/bldlog.log';
$vim = '/opt/exp/bin/gvim';

print $ARGV[0] . "\n";

if (!defined($kidpid = fork()))
{
        # fork returned undef, so failed
        die "Cannot fork: $!";
}
elsif ($kidpid != 0)
{
        # Parent exits
        exit(0);
}

system("make " . '>' . " $errorFile " . '2>&1');

sendVimCommand("let mp=&makeprg");
sendVimCommand("set makeprg=cat\ /home/golirajesh/bldlog.log");
sendVimCommand("make! $errorFile");
sendVimCommand("let &makeprg=mp");
sendVimCommand("cwin");

sub sendVimCommand {
        $command = shift;
        system($vim,"--remote-send","<ESC>:$command<CR>");
}

-Rajesh

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
Sent: Friday, May 27, 2005 5:07 PM
To: Goli, Rajesh (Rajesh)
Cc: Eric Arnold; [hidden email]
Subject: RE: How to "make" in a separate window?


Hello.

"Goli, Rajesh (Rajesh)" <[hidden email]> wrote:

> I tried doing something on the very same lines.
> First I changed my .gvimrc to include
>
> set shellpipe=\   " Shellpipe is just a space so the errorfile is an
> argument to makeprogram
> set mp=/home/rajesh/scripts/mkvi.pl
>
> So when I executed :make it actually executed something like
> /home/rajesh/scripts/mkvi.pl   /tmp/errorfile
>
> My script looked something like:
>  [...]
> This works to the extent that I get the prompt back immediately,
> but vim cribs saying it cant open the errorfile. Can you see
> something that I am not doing right?

Save the result of the compilation in a file.
Then, once the compilation is finished, load the file with:
    :let mp=&makeprg
    :set makeprg=cat\ $*
    :make name-of-the-file
    :let &makeprg=mp

If Vim supports |+clientserver|, you should be able to send thoose
commands to vim from your perl script.


--
Luc Hermitte
Loading...