From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: Re: sh-script.el and magic numbers Date: Mon, 20 Jan 2003 18:45:02 -0600 (CST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200301210045.SAA16966@eel.dms.auburn.edu> References: <200301190324.VAA14671@eel.dms.auburn.edu> <8del78n1ks.fsf@ast.cam.ac.uk> <200301200759.h0K7xGOH007624@beta.mvs.co.il> NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1043110477 3412 80.91.224.249 (21 Jan 2003 00:54:37 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 21 Jan 2003 00:54:37 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18amgV-0000su-00 for ; Tue, 21 Jan 2003 01:54:35 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18amrd-0003be-00 for ; Tue, 21 Jan 2003 02:06:05 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18amho-0008B8-03 for emacs-devel@quimby.gnus.org; Mon, 20 Jan 2003 19:55:57 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18amgK-0007bU-00 for emacs-devel@gnu.org; Mon, 20 Jan 2003 19:54:24 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18amWl-00047M-00 for emacs-devel@gnu.org; Mon, 20 Jan 2003 19:44:34 -0500 Original-Received: from manatee.dms.auburn.edu ([131.204.53.104]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18amWh-0003r1-00 for emacs-devel@gnu.org; Mon, 20 Jan 2003 19:44:27 -0500 Original-Received: from eel.dms.auburn.edu (eel.dms.auburn.edu [131.204.53.108]) by manatee.dms.auburn.edu (8.9.1a/8.9.1) with ESMTP id SAA01522; Mon, 20 Jan 2003 18:44:22 -0600 (CST) Original-Received: (from teirllm@localhost) by eel.dms.auburn.edu (8.9.3+Sun/8.9.3) id SAA16966; Mon, 20 Jan 2003 18:45:02 -0600 (CST) X-Authentication-Warning: eel.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: ehud@unix.mvs.co.il In-reply-to: <200301200759.h0K7xGOH007624@beta.mvs.co.il> (ehud@unix.mvs.co.il) Original-cc: gmorris+mail@ast.cam.ac.uk X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:10922 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:10922 Ehud Karni wrote: The solution to that is simple. Don't put the "#!" magic number, instead change the 1st line to something like this: # -*- mode: sh -*- In certain situations it can get somewhat less simple. There is a problem here that is still relevant, even though (actually especially since) a decision has been made on the #! problem. A problem I referred to but did not elaborate on, because I thought (like you) that it could trivially be solved with file local variables is, in fact, not really as easily solved (for people not familiar with the sh-script.el source code) as I thought. Please remember in the following that people could be experienced shell programmers and even experienced Emacs users without knowing any Elisp beyond routine customization. Suppose your default sh-shell-file is bash and are working on a script intended for csh. You do not want to use a magic number and maybe do not want to make the file executable, but you still want all of sh-script.el to know that you are programming for csh. The problem is that C-c : will not allow to change sh-shell-file without inserting a magic number. Somebody familiar with the sh-script.el source code can get around this by executing, say M-: (sh-set-shell "/bin/csh"), but this is not mentioned in the mode documentation. It is also does not persist through different Emacs sessions, anyway. Do not try to add .csh or similar to the file name, it is going to be ignored. So obviously we try file local variables: # -*- mode: sh; sh-shell-file: /bin/csh; -*- Does not work. sh-shell-file gets set after sh-mode has ran. The mode line still says [bash] and indeed, just try, for instance: C-c C-c, you get bash's version of case, not csh's switch. What you have to do is: # -*- mode: sh; eval: (sh-set-shell "/bin/csh"); -*- So it probably would be useful to mention in the mode documentation that, to tell sh-mode the shell you are programming for, without using a magic number, you have to do something like M-: (sh-set-shell "/bin/csh") if you want it on a temporary basis and (probably more relevantly), you have to put something like the previously mentioned line at the beginning of the script, if you want it to persist. There still is the problem that enable-local-eval has to be non-nil (t or maybe) for the line to work. I do not know what to do about that. At least, the value does not need to be t. One could, of course, make clear that using a magic number is way simpler and, in nearly all situations, vastly preferable. Sincerely, Luc.