[comp.emacs] Summary of Emacs csh alias replies

dsill@NSWC-OAS.ARPA (Dave Sill) (12/09/87)

My question was: how can one set up a csh alias for emacs that will
run emacs if there isn't one in the background or foreground it if it
is in the background.

I received many replies of the form "%emacs will foreground a
background emacs so you don't have to assume emacs is job %1."  I
vaguely remember reading that in the csh man page but it didn't stick
with me.

Most "solutions" involved grepping the output of jobs to determine if
there was a background emacs job, followed by an if-then-else to
either run or foreground emacs.  I've never been able to get an
if-then-else to work in an alias.  Some suggested putting the if-then-
else in a file to be sourced by the alias.  This works, but requires
reading the file each time the alias is invoked, so I might as well
use a script.

Another problem with some of these solutions was that they used the
jobs command in a pipe.  This doesn't work because the piped jobs
command is run in a subshell that has no jobs.  The alternative is to
redirect the output of jobs to a temporary file, which involves a bit
of file I/O overhead.

Another person suggested modifying the kill-emacs and suspend-emacs
commands to redefine the alias as required.  This works fine in emacs,
which is what I wanted it for, but is not applicable to other editors
or programs.

One person suggested that this should be handled by the shell.  I.e.,
%emacs should foreground emacs if it's there, otherwise invoke emacs.

One person suggested I should put up with the occasional "No such
job." message.

I'd like to thank everyone who took the time to reply to my query.

==============
"Don't let existing sub-optimal solutions cloud your vision."
					-- Fred Fish