From: jct@se33.wg2.waii.com (Jim Thompson)
Newsgroups: comp.emacs
Subject: Re: shell command and macro completion
Date: 8 Sep 92 13:19:31 GMT
Reply-To: thompson@wg2.waii.com
Organization: Western Geophysical Exploration Products
In-reply-to: garye@TorreyPinesCA.ncr.com's message of 3 Sep 92 17:14:17 GMT

In article <1992Sep3.171417.21110@TorreyPinesCA.ncr.com> garye@TorreyPinesCA.ncr.com (Gary Engebretson 3793) writes:

> 1. I use csh and have a large .cshrc file. This means that when I do 'M-x shell'
> I have to wait while .cshrc is executed. No problem there. But when I do 'ESC !'
> .cshrc is also executed which takes a lot of time for no real purpose. The
> question is : how can I get 'M-x shell' to execute .cshrc but 'ESC !' to NOT
> execute .cshrc?
> 
> Ideas that didn't work :
> 	1. setting SHELL to '/bin/csh -f'
> 	2. setting SHELL to '/home/ccsh' where /home/ccsh contained
> 	   '/bin/csh -f'
> 	3. fooling around with env. variables and then checking for specific
> 	   values of this variable within .cshrc. This 'kinda' works but
> 	   it is very kludgey.
>         4. turn on/off protections on .cshrc -- works but annoying

I think the best solution is to determine why your .cshrc takes so
long and do something to make it quicker.  I once had this problem,
because I was setting my PATH and MANPATH inside of .cshrc; I had
about twenty directories to search, and I added them to PATH one at a
time.  It took forever.

Finally it occurred to me that PATH and all environment variables are
inherited, so they can go in .login.  I moved ALL my environment setup
to .login and kept in .cshrc only the few aliases and sets I use.
This sped things up tremendously.

Your attempt #3 sounds like the best solution to me;  an environment
variable is appropriate because the buffer in which your shell runs
(*shell* vs. *Shell Command Output*) is part of that shell's
environment.   That's how I would do it.

There is another way, but it assumes that your shell-mode uses ptys
rather than pipes to communicate with your shell (this is the default).
If so, then you can put the following construct in your .cshrc:

if ("`/bin/tty`" != "not a tty") then
   # everything your .cshrc does for shell-mode goes here.
else
   # everything your .cshrc does for M-! goes here
endif

This works because M-! uses a pipe to communicate with the shell, and
the tty command will return the string "not a tty" when called from a
shell that's running on a pipe.  The string might be different on your
system; to find out what it is, do the following:

  1. Switch to the *scratch* buffer and type

       (setq process-connection-type nil) C-j

     where C-j is control-j or the linefeed key.

  2. M-x shell

  3. (In *shell* buffer) tty

     The string that `tty` spits out is the string you want to put in
     the if statement at the beginning of your .cshrc.

One warning though: this solution will also apply outside of Emacs, so
that if you type "csh some-script < some-file" outside of Emacs, the
shell that you start is going to take the M-! path through your .cshrc!

Jim
--
   _    Jim Thompson           |  Wanted:
 _| ~-  thompson@wg2.waii.com  |	Nick Park's "Grand Day Out"
 \,  _} Western Geophysical    |	on VHS-format videotape
   \(   Houston, Texas         |  Email me if you know where I can buy it.