Path: utzoo!mnetor!uunet!husc6!linus!philabs!ttidca!retix!derrell
From: derrell@retix.retix.COM (Derrell Lipman)
Newsgroups: comp.emacs
Subject: Re: Emacs csh alias
Message-ID: <238@retix.retix.COM>
Date: 9 Dec 87 18:05:58 GMT
References: <8712041951.AA21105@ucbvax.Berkeley.EDU>
Organization: Retix, Santa Monica CA
Lines: 43
In-reply-to: dsill@NSWC-OAS.ARPA's message of 4 Dec 87 19:33:42 GMT

Posting-Front-End: GNU Emacs 18.41.14 of Sun Jun 14 1987 on retix (berkeley-unix)



> ...
> Simply stated, I want an alias named "emacs" which will load
> Emacs if it isn't already loaded, but will foreground a
> background Emacs if one exists.
> ...

Try this:

alias emacs 'jobs > temp_file;
	     grep -s emacs temp_file;
	     set estatus = $status;
	     rm temp_file;
	     if ($status) /usr/local/emacs;
	     if (! $status) fg ?emacs'


A couple of comments about this:

	1. you may not have been familiar with the option of
'fg' to search for a pattern in the job names, e.g. ?emacs

	2. the file 'temp_file' will always have only a few
lines in it, so it would be a bit faster to substitute 'temp_file'
with something like '~/.emacs_jobs'.  if you do this, you
wouldn't need to remove the file each time, which would make
it a bit quicker.  Also, the storage of the status variable
could be eliminated.  (an even better way to do this would be
to pipe the output from 'jobs' to 'grep -s emacs'.  the
problem is that $status gets set wrongly, as 'jobs' is a
builtin command.  i didn't spend the time to see if this
could be gotten around.)

	3. i put each of the commands within the alias on
separate lines, above, to make it easier to see what was
going on, but in actual use, the whole alias should be
entered on one line.

	4. substitute '/usr/local/emacs' with the actual
full path name of your emacs code file.  this is necessary
because 'emacs' has been aliased.  alternatively, you could
use ''emacs, where the two initial single quotes eliminate
the alias expansion.