From xemacs-m  Sun Feb 23 16:37:41 1997
Received: from CNRI.Reston.VA.US (CNRI.Reston.VA.US [132.151.1.1])
	by xemacs.org (8.8.5/8.8.5) with SMTP id QAA10993
	for <xemacs-beta@xemacs.org>; Sun, 23 Feb 1997 16:37:40 -0600 (CST)
Received: from newcnri.cnri.reston.va.us by CNRI.Reston.VA.US id aa16005;
          23 Feb 97 17:32 EST
Received: from anthem.CNRI.Reston.Va.US by newcnri.CNRI.Reston.Va.US (SMI-8.6/SMI-SVR4)
	id RAA07677; Sun, 23 Feb 1997 17:32:48 -0500
Received: by anthem.CNRI.Reston.Va.US (SMI-8.6/SMI-SVR4)
	id RAA02836; Sun, 23 Feb 1997 17:32:47 -0500
Date: Sun, 23 Feb 1997 17:32:47 -0500
Message-Id: <199702232232.RAA02836@anthem.CNRI.Reston.Va.US>
From: "Barry A. Warsaw" <bwarsaw@anthem.cnri.reston.va.us>
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="bCLdZFg6opfnUaLTw8foFpSBjJGYEsKZ0MLc4ogA"
Content-Transfer-Encoding: 7bit
To: xemacs-beta@xemacs.org
Subject: Better shell.el faces?
Reply-To: "Barry A. Warsaw" <bwarsaw@CNRI.Reston.VA.US>
X-Attribution: BAW
X-Oblique-Strategy: Faced with a choice - do both (given by Dieter Rot)
X-WWW-Homepage: http://www.python.org/~bwarsaw


--bCLdZFg6opfnUaLTw8foFpSBjJGYEsKZ0MLc4ogA
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


I hacked on shell.el to provide what I think are better font-locking
faces.  If the rest of y'all like these changes, then I think they
should be added to XEmacs.  One thing I really disliked was using the
standard font-lock-*-face's rather than defining new faces for
shell.el and inheriting their default attributes from the standard.

One other thing, there is a weird dependency between modes that want
to define faces based on the standard ones, and font-lock.el.  For
example, in this patch, I use copy-face but only if the
face-differs-from-default-p.  Of course the old faces are only defined
once font-lock.el is loaded in and I didn't want to do a
(require 'font-lock) at the top level just to get the face
definitions.

The solution I came up with is to add a hook to font-lock-mode-hook so
that the faces get initialized the first time font-lock mode is turned
on for a shell buffer.  This hook removes itself the first time it's
run.  It's probably not a great solution, so feel free to suggest a
different way.

This patch is against b93's comint/shell.el.

-Barry

--bCLdZFg6opfnUaLTw8foFpSBjJGYEsKZ0MLc4ogA
Content-Type: text/plain
Content-Disposition: inline;
	filename="shell.diff"
Content-Transfer-Encoding: 7bit

*** shell.el	1997/02/22 18:36:29	1.1
--- shell.el	1997/02/23 19:42:18
***************
*** 251,261 ****
    "*Hook for customising Shell mode.")
  
  (defvar shell-font-lock-keywords
!   (list (cons shell-prompt-pattern 'font-lock-keyword-face)
! 	'("[ \t]\\([+-][^ \t\n]+\\)" 1 font-lock-comment-face)
! 	'("^[^ \t\n]+:.*" . font-lock-string-face)
! 	'("^\\[[1-9][0-9]*\\]" . font-lock-string-face))
    "Additional expressions to highlight in Shell mode.")
  (put 'shell-mode 'font-lock-defaults '(shell-font-lock-keywords t))
  
  ;;; Basic Procedures
--- 251,301 ----
    "*Hook for customising Shell mode.")
  
+ 
+ ;; font-locking
+ (defvar shell-prompt-face 'shell-prompt-face
+   "Face for shell prompts.")
+ (defvar shell-option-face 'shell-option-face
+   "Face for command line options.")
+ (defvar shell-output-face 'shell-output-face
+   "Face for generic shell output.")
+ (defvar shell-output-2-face 'shell-output-2-face
+   "Face for grep-like output.")
+ (defvar shell-output-3-face 'shell-output-3-face
+   "Face for [N] output where N is a number.")
+ 
+ (make-face shell-prompt-face)
+ (make-face shell-option-face)
+ (make-face shell-output-face)
+ (make-face shell-output-2-face)
+ (make-face shell-output-3-face)
+ 
+ (defun shell-font-lock-mode-hook ()
+   (or (face-differs-from-default-p shell-prompt-face)
+       (copy-face 'font-lock-keyword-face shell-prompt-face))
+   (or (face-differs-from-default-p shell-option-face)
+       (copy-face 'font-lock-comment-face shell-option-face))
+   (or (face-differs-from-default-p shell-output-face)
+       (copy-face 'italic shell-output-face))
+   (or (face-differs-from-default-p shell-output-2-face)
+       (copy-face 'font-lock-string-face shell-output-2-face))
+   (or (face-differs-from-default-p shell-output-3-face)
+       (copy-face 'font-lock-string-face shell-output-3-face))
+   ;; we only need to do this once
+   (remove-hook 'font-lock-mode-hook 'shell-font-lock-mode-hook))
+ (add-hook 'font-lock-mode-hook 'shell-font-lock-mode-hook)
+ 
+ (defvar shell-prompt-pattern-for-font-lock shell-prompt-pattern
+   "Pattern to use to font-lock the prompt.
+ Defaults to `shell-prompt-pattern'.")
+ 
  (defvar shell-font-lock-keywords
!   (list (cons shell-prompt-pattern-for-font-lock shell-prompt-face)
! 	'("[ \t]\\([+-][^ \t\n]+\\)" 1 shell-option-face)
! 	'("^[^ \t\n]+:.*" . shell-output-2-face)
! 	'("^\\[[1-9][0-9]*\\]" . shell-output-3-face)
! 	'("^[^\n]+.*$" . shell-output-face))
    "Additional expressions to highlight in Shell mode.")
  (put 'shell-mode 'font-lock-defaults '(shell-font-lock-keywords t))
+ 
  
  ;;; Basic Procedures

--bCLdZFg6opfnUaLTw8foFpSBjJGYEsKZ0MLc4ogA--

