From xemacs-m  Wed Jun 18 18:07:34 1997
Received: from mercury.Sun.COM (mercury.Sun.COM [192.9.25.1])
	by xemacs.org (8.8.5/8.8.5) with SMTP id SAA01227
	for <xemacs-beta@xemacs.org>; Wed, 18 Jun 1997 18:07:33 -0500 (CDT)
Received: from Eng.Sun.COM ([129.146.1.25]) by mercury.Sun.COM (SMI-8.6/mail.byaddr) with SMTP id QAA07929; Wed, 18 Jun 1997 16:28:47 -0700
Received: from kindra.eng.sun.com by Eng.Sun.COM (SMI-8.6/SMI-5.3)
	id QAA03198; Wed, 18 Jun 1997 16:06:55 -0700
Received: from xemacs.eng.sun.com by kindra.eng.sun.com (SMI-8.6/SMI-SVR4)
	id QAA16003; Wed, 18 Jun 1997 16:06:54 -0700
Received: by xemacs.eng.sun.com (SMI-8.6/SMI-SVR4)
	id QAA04260; Wed, 18 Jun 1997 16:06:52 -0700
Date: Wed, 18 Jun 1997 16:06:52 -0700
Message-Id: <199706182306.QAA04260@xemacs.eng.sun.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: Martin Buchholz <mrb@Eng.Sun.COM>
To: XEmacs Beta Test <xemacs-beta@xemacs.org>
Cc: Daniel.Pfeiffer@Informatik.START.dbp.de
Subject: sh-script.el sh-mode is broken
X-Mailer: VM 6.32 under 20.3 "Oslo" XEmacs Lucid (beta7)
Reply-To: Martin Buchholz <mrb@Eng.Sun.COM>

Since we're adopting this as our standard sh mode, I thought I'd take
a deeper look at it.

The syntax table when starting up in sh-mode is the standard syntax table!
This seems incredibly broken.  How can other people live with it?
Quoted strings are not fontified properly.

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

I didn't think sh-mode was at all usable until I came up with the
following hacks in my .emacs:

(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 ?$ "_"))

