* Setting shell type in sh-mode
@ 2002-10-17 15:12 Glenn Morris
2002-10-17 17:00 ` Kevin Rodgers
0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2002-10-17 15:12 UTC (permalink / raw)
sh-mode has a few different settings that it implements (font-lock
keywords, indentation, etc), according to the type of shell being edited
(bash, csh, etc).
The way it detects which type of shell is in use is to either look for an
interpreter at the start of the script (eg #!/bin/bash), or if that fails,
it falls back on the value of the variable sh-shell-file.
So how can I get my .tcshrc file recognised as a tcsh script?
If I add #!/usr/bin/tcsh to the top, firstly that's changing the file just to
keep Emacs happy; and secondly the file then gets made executable, since I
have executable-make-buffer-file-executable-if-script-p in after-save-hook
(which I rather like).
I can't use
# -*- sh-shell-file "/usr/bin/tcsh" -*-
since local variables are hacked after the mode setup (including any hook)
has finished, and my default sh-shell-file is "/bin/bash". It seems that
adding after advice to sh-mode suffers from the same problem.
I could use
# -*- eval: (sh-set-shell "tcsh") -*-
but this means I have to set enable-local-eval to t if I'm not to be driven
mad by prompts, and I'd rather not have that setting, as a general rule.
Any ideas gratefully received (no doubt I've missed something obvious!).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Setting shell type in sh-mode
2002-10-17 15:12 Setting shell type in sh-mode Glenn Morris
@ 2002-10-17 17:00 ` Kevin Rodgers
2002-10-17 17:07 ` Glenn Morris
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2002-10-17 17:00 UTC (permalink / raw)
Glenn Morris wrote:
> I can't use
>
> # -*- sh-shell-file "/usr/bin/tcsh" -*-
I thought the syntax had to be
# -*- mode: sh-mode; sh-shell-file: "/usr/bin/tcsh"; -*-
> since local variables are hacked after the mode setup (including any hook)
> has finished, and my default sh-shell-file is "/bin/bash". It seems that
> adding after advice to sh-mode suffers from the same problem.
Did you try adding a local variables list at the end of the file?
# Local Variables:
# sh-shell-file: "/usr/bin/tcsh"
# End:
--
<a href="mailto:<kevinr@ihs.com>">Kevin Rodgers</a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Setting shell type in sh-mode
2002-10-17 17:00 ` Kevin Rodgers
@ 2002-10-17 17:07 ` Glenn Morris
2002-10-17 21:41 ` Kevin Rodgers
0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2002-10-17 17:07 UTC (permalink / raw)
Kevin Rodgers wrote:
> I thought the syntax had to be
>
> # -*- mode: sh-mode; sh-shell-file: "/usr/bin/tcsh"; -*-
Yes, I used to think that too, but then I read this in the info node "Local
Variables in Files":
_If `mode' is used to set a major mode, it should be the first
"variable" in the list._
This implies to me (though not very clearly), that the "mode" statement is
optional, but if present it must go at the front.
Anyway, I can confirm that sh-shell-file is set to the "tcsh" value whether
or not I put the "mode" keyword in; but it happens after the mode setup and
so has no effect.
> Did you try adding a local variables list at the end of the file?
Just tried that now, no luck - same effect as putting the variable at the
top of the file.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Setting shell type in sh-mode
2002-10-17 17:07 ` Glenn Morris
@ 2002-10-17 21:41 ` Kevin Rodgers
2002-10-17 22:38 ` Glenn Morris
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2002-10-17 21:41 UTC (permalink / raw)
Glenn Morris wrote:
> Kevin Rodgers wrote:
>
>
>>I thought the syntax had to be
>>
>># -*- mode: sh-mode; sh-shell-file: "/usr/bin/tcsh"; -*-
>>
>
> Yes, I used to think that too, but then I read this in the info node "Local
> Variables in Files":
>
> _If `mode' is used to set a major mode, it should be the first
> "variable" in the list._
>
> This implies to me (though not very clearly), that the "mode" statement is
> optional, but if present it must go at the front.
>
> Anyway, I can confirm that sh-shell-file is set to the "tcsh" value whether
> or not I put the "mode" keyword in; but it happens after the mode setup and
> so has no effect.
What happens if you set sh-shell to the `tcsh' symbol there, instead of (or in
addition to) setting sh-shell-file to the "/usr/bin/tcsh" string?
--
<a href="mailto:<kevinr@ihs.com>">Kevin Rodgers</a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Setting shell type in sh-mode
2002-10-17 21:41 ` Kevin Rodgers
@ 2002-10-17 22:38 ` Glenn Morris
0 siblings, 0 replies; 5+ messages in thread
From: Glenn Morris @ 2002-10-17 22:38 UTC (permalink / raw)
Kevin Rodgers wrote:
> What happens if you set sh-shell to the `tcsh' symbol there, instead of
> (or in addition to) setting sh-shell-file to the "/usr/bin/tcsh" string?
# -*- sh-shell: tcsh -*-
is mostly successful. It gets the correct font-locking, and skeleton
statements, (presumably because sh-mode picks the appropriate values from
generic lists when needed, rather than setting them when the mode is
started). It leaves "Shell-script[bash]" in the mode-line, though, and
leaves the message "Indentation setup for shell type bash" in the echo
area, so it probably isn't setting _everything_ correct for tcsh. Looking
at what sh-set-shell does, it looks like imenu would also not be set up
correctly.
But since there aren't any special indentation or imenu settings for
non-bash shells (I think), and the mode-line can easily be fixed with
mode-line-process: "[tcsh]" in the file local variables, I can probably
live with that.
Many thanks for your help.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-10-17 22:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-17 15:12 Setting shell type in sh-mode Glenn Morris
2002-10-17 17:00 ` Kevin Rodgers
2002-10-17 17:07 ` Glenn Morris
2002-10-17 21:41 ` Kevin Rodgers
2002-10-17 22:38 ` Glenn Morris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).