From xemacs-m  Thu Jun 19 04:15:28 1997
Received: from steadfast.teradyne.com (steadfast.teradyne.com [131.101.1.200])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id EAA22684
	for <xemacs-beta@xemacs.org>; Thu, 19 Jun 1997 04:15:27 -0500 (CDT)
Received: from engine.ecf.teradyne.com (engine.ecf.teradyne.com [131.101.192.6]) by steadfast.teradyne.com (8.7.1/8.7.1) with ESMTP id FAA03238; Thu, 19 Jun 1997 05:19:05 -0400 (EDT)
Received: from midnight.eng.ecf.teradyne.com (midnight.ecf.teradyne.com [131.101.192.49]) by engine.ecf.teradyne.com (8.7.1/8.7.1) with SMTP id LAA24969; Thu, 19 Jun 1997 11:14:15 +0200 (MET DST)
Received: by midnight.eng.ecf.teradyne.com (SMI-8.6/SMI-SVR4)
	id LAA06160; Thu, 19 Jun 1997 11:14:14 +0200
To: Martin Buchholz <mrb@Eng.Sun.COM>
Cc: XEmacs Beta Test <xemacs-beta@xemacs.org>,
        Daniel.Pfeiffer@Informatik.START.dbp.de
Subject: Re: sh-script.el sh-mode is broken
References: <199706182306.QAA04260@xemacs.eng.sun.com>
X-Face: 4[iHdXiTu\V3u[~\I)<f9HC);%~nG8`oUqv#uzvs6=\V{AjN6Sn
 c/qi;YLwRmEbt8Y*=j5n(urqY@chPh@J'D"QlqD!C8>*}#kYF[-tYl3VZga/HSOP|K,{L
 Rtu@f0y/=O&Cu}\:~d|P$JON?pn?j,&CnPb1z#/TL9bkAJwyol&a:SvYj-VYbM=Dtxhk9
 =w|R6U3_;SH&B<Mfy6Q%#
Mime-Version: 1.0 (generated by tm-edit 7.108)
Content-Type: multipart/mixed;
 boundary="Multipart_Thu_Jun_19_11:14:12_1997-1"
Content-Transfer-Encoding: 7bit
From: Adrian Aichner <aichner@ecf.teradyne.com>
Date: 19 Jun 1997 11:14:13 +0200
In-Reply-To: Martin Buchholz's message of "Wed, 18 Jun 1997 16:06:52 -0700"
Message-ID: <rxsu3iv3qfu.fsf@midnight.ecf.teradyne.com>
Lines: 162
X-Mailer: Gnus v5.4.56/XEmacs 20.3(beta7) - "Oslo"

--Multipart_Thu_Jun_19_11:14:12_1997-1
Content-Type: text/plain; charset=US-ASCII

>>>>> "MB" == Martin Buchholz <mrb@Eng.Sun.COM> writes:

    MB> A comment in sh-mode explains that syntax tables are not used
    MB> for font-locking because then $# ends up fontifying
    MB> incorrectly.  But using "$#" instead of unadorned $# is an
    MB> acceptable workaround, while the current implementation loses
    MB> on # embedded in a quoted string, in my opinion a worse
    MB> problem.

    MB> I didn't think sh-mode was at all usable until I came up with

I thought so too, until I came up with some magic to select the
correct sh-shell for the script syntax at hand. Out of the can
sh-script.el will set sh-shell to whatever your env var SHELL is set
to. Let's say your interactive shell is csh and you start editing
x.sh, you'll get csh syntax template in x.sh. Not very handy. Here's
my fix for that:

(setq interpreter-mode-alist
      (cons '("^#!.*/csh\\b" . csh-sh-mode) interpreter-mode-alist))
(setq interpreter-mode-alist
      (cons '("^#!.*/ksh\\b" . ksh-sh-mode) interpreter-mode-alist))
(setq interpreter-mode-alist
      (cons '("^#!.*/sh\\b" . sh-sh-mode) interpreter-mode-alist))

(setq auto-mode-alist
      (append '(
;;; It's not the extension, it's the magic number that counts!
;;; Ideally they agree.
		("\\.csh$" . csh-sh-mode)
		("\\.ksh$" . ksh-sh-mode)
		("\\.sh$" . sh-sh-mode)
;;; .cshrc, .login and .profile are magic-number-less and have a known
;;; syntax for a given Operating System. 
                ("\\.?\\(cshrc\\|login\\)\\(\\..*\\)?" . csh-sh-mode)
                ("\\.?\\(profile\\)\\(\\..*\\)?" . sh-sh-mode)
                ) auto-mode-alist))

(defun csh-sh-mode ()
  (setq sh-mode-hook
        '(lambda ()
           (sh-set-shell "/bin/csh")))
  (sh-mode))
(defun ksh-sh-mode ()
  (setq sh-mode-hook
        '(lambda ()
           (sh-set-shell "/bin/ksh")))
  (sh-mode))
(defun sh-sh-mode ()
  (setq sh-mode-hook
        '(lambda ()
           (sh-set-shell "/bin/sh")))
  (sh-mode))
(autoload 'sh-mode "sh-script" "Major mode for editing shell
scripts.")

    MB> the following hacks in my .emacs:

I combined your fixes with mine to:


--Multipart_Thu_Jun_19_11:14:12_1997-1
Content-Type: application/octet-stream; type=emacs-lisp
Content-Disposition: attachment; filename="sh-mode-fix.el"
Content-Transfer-Encoding: 7bit

(setq interpreter-mode-alist
      (cons '("^#!.*/csh\\b" . csh-sh-mode) interpreter-mode-alist))
(setq interpreter-mode-alist
      (cons '("^#!.*/ksh\\b" . ksh-sh-mode) interpreter-mode-alist))
(setq interpreter-mode-alist
      (cons '("^#!.*/sh\\b" . sh-sh-mode) interpreter-mode-alist))

(setq auto-mode-alist
      (append '(
;;; It's not the extension, it's the magic number that counts!
;;; Ideally they agree.
		("\\.csh$" . csh-sh-mode)
		("\\.ksh$" . ksh-sh-mode)
		("\\.sh$" . sh-sh-mode)
;;; .cshrc, .login and .profile are magic-number-less and have a known
;;; syntax for a given Operating System. 
                ("\\.?\\(cshrc\\|login\\)\\(\\..*\\)?" . csh-sh-mode)
                ("\\.?\\(profile\\)\\(\\..*\\)?" . sh-sh-mode)
                ) auto-mode-alist))

(defun csh-sh-mode ()
  (add-hook 'sh-mode-hook
        '(lambda ()
           (sh-set-shell "/bin/csh")))
  (sh-mode))
(defun ksh-sh-mode ()
  (add-hook 'sh-mode-hook
        '(lambda ()
           (sh-set-shell "/bin/ksh")))
  (sh-mode))
(defun sh-sh-mode ()
  (add-hook 'sh-mode-hook
        '(lambda ()
           (sh-set-shell "/bin/sh")))
  (sh-mode))
(autoload 'sh-mode "sh-script" "Major mode for editing shell
scripts.")

;; Begin of fixes for sh-script by Martin Buchholz
(require 'sh-script)
(setq sh-font-lock-keywords-only nil)

(defun sh-font-lock-keywords (&optional keywords)
  "Function to get simple fontification based on `sh-font-lock-keywords'.
This adds rules for comments and assignments."
  (sh-feature sh-font-lock-keywords
	      (lambda (list)
		`((,(sh-feature sh-assignment-regexp)
		   1 font-lock-variable-name-face)
		  ,@keywords
		  ,@list))))

(add-hook 'sh-mode-hook 'my-sh-mode-syntax-table)

(defun my-sh-mode-syntax-table ()
  (set-syntax-table (make-syntax-table (standard-syntax-table)))
  (modify-syntax-entry ?\# "<")
  (modify-syntax-entry ?\n ">")
  (modify-syntax-entry ?\" "\"")
  (modify-syntax-entry ?\' "\"")
  (modify-syntax-entry ?\` "$")
  (modify-syntax-entry ?_ "_")
  (modify-syntax-entry ?$ "_"))
;; End of fixes for sh-script by Martin Buchholz

--Multipart_Thu_Jun_19_11:14:12_1997-1
Content-Type: text/plain; charset=US-ASCII



and sh-mode works better than ever before.

More problems:

sh-mode defines
    (substitute-key-definition 'beginning-of-defun
			       'sh-beginning-of-compound-command
			       map (current-global-map))
but sh-beginning-of-compound-command does not exist!


C-M-e (end-of-defun) is not available in sh-mode
C-M-q (indent-sexp) is not available in sh-mode

Indentation is strictly rigid, although there is an
indent-line-function and an indent-region-function.

Regards,

Adrian


--Multipart_Thu_Jun_19_11:14:12_1997-1--

