Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!littlei!ogcvax!schaefer
From: schaefer@ogcvax.UUCP (Barton E. Schaefer)
Newsgroups: comp.unix.wizards
Subject: Re: Emacs csh alias
Message-ID: <1508@ogcvax.UUCP>
Date: Sun, 6-Dec-87 18:37:10 EST
Article-I.D.: ogcvax.1508
Posted: Sun Dec  6 18:37:10 1987
Date-Received: Sat, 12-Dec-87 12:49:17 EST
References: 
Reply-To: schaefer@ogcvax.UUCP (Barton E. Schaefer)
Organization: Oregon Graduate Center, Beaverton, OR
Lines: 46

[ I'd have liked to mail this, but our mailer dislikes mixed !-%-@ syntax. ]

In article  dsill@NSWC-OAS.arpa (Dave Sill) writes:
>I've been trying to set up a C-Shell (4.2 BSD) alias for Emacs (GNU
>17.64, not that it matters) which, when run the first time will
>actually run Emacs, but after suspending Emacs with C-z, will bring
>the background Emacs job to the foreground.  The catch is that I'd
>also like the alias to re-load emacs if I exit with C-x C-c.
>
>I know I could do this with a script (if I assume the Emacs job is
>always job %1), but I'd prefer an alias since they're faster.

First, a general point.  Almost anything you can do in a csh script can be
caused to happen in the current shell by:
1)  Write and debug the csh script.
2)  In .cshrc, include a line like
    alias script_name "set argv=(\!*:p) ; source path_to_script/script_name"
Please remember that any variables set/modified in the script will be those
in your current shell.  This may or may not be desirable.

Now, as to the specific question.  The script looks like

    jobs >! /tmp/j$$
    if ( "`grep emacs /tmp/j$$`" != "" ) then
	fg %emacs
    else
	\emacs $*
    endif

assuming this is saved in ~/lib/emacs, the alias is

    alias emacs "set argv=(\!*:p) ; source ~/lib/emacs"

and you're all set.

The fun stuff with "jobs" and "grep" is necessary because "source" quits if
any command in the sourced file fails, so you have to make sure "fg" will
work before you try it.   The script won't work if you happen to have more
than one suspended emacs ("grep ..." would be ambiguous) or if you have some
other suspended job with "emacs" in the command string.

-- 
Bart Schaefer			CSNET:	schaefer@cse.ogc.edu
				UUCP:	...{tektronix,verdix}!ogcvax!schaefer
"A band of BIG, DUMB, LOUDMOUTHED, BUNGLING OGRES is a GREAT ASSET to the
neighbohood.  It keeps out the RIFF-RAFF."		-- Wormy