-;; Colour etc. support.
-
-;; This section of code is crying out for revision.
-
-;; To begin with, `display-type' and `background-mode' are `frame-parameters'
-;; so we don't have to calculate them here anymore. But all the face stuff
-;; should be frame-local (and thus display-local) anyway. Because we're not
-;; sure what support Emacs is going to have for general frame-local face
-;; attributes, we leave this section of code as it is. For now. --sm.
-
-(defvar font-lock-display-type nil
- "A symbol indicating the display Emacs is running under.
-The symbol should be one of `color', `grayscale' or `mono'.
-If Emacs guesses this display attribute wrongly, either set this variable in
-your `~/.emacs' or set the resource `Emacs.displayType' in your `~/.Xdefaults'.
-See also `font-lock-background-mode' and `font-lock-face-attributes'.")
-
-(defvar font-lock-background-mode nil
- "A symbol indicating the Emacs background brightness.
-The symbol should be one of `light' or `dark'.
-If Emacs guesses this frame attribute wrongly, either set this variable in
-your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
-`~/.Xdefaults'.
-See also `font-lock-display-type' and `font-lock-face-attributes'.")
-
-(defvar font-lock-face-attributes nil
- "A list of default attributes to use for face attributes.
-Each element of the list should be of the form
-
- (FACE FOREGROUND BACKGROUND BOLD-P ITALIC-P UNDERLINE-P)
-
-where FACE should be one of the face symbols `font-lock-comment-face',
-`font-lock-string-face', `font-lock-keyword-face', `font-lock-type-face',
-`font-lock-function-name-face', `font-lock-variable-name-face', and
-`font-lock-reference-face'. A form for each of these face symbols should be
-provided in the list, but other face symbols and attributes may be given and
-used in highlighting. See `font-lock-keywords'.
-
-Subsequent element items should be the attributes for the corresponding
-Font Lock mode faces. Attributes FOREGROUND and BACKGROUND should be strings
-\(default if nil), while BOLD-P, ITALIC-P, and UNDERLINE-P should specify the
-corresponding face attributes (yes if non-nil).
-
-Emacs uses default attributes based on display type and background brightness.
-See variables `font-lock-display-type' and `font-lock-background-mode'.
-
-Resources can be used to over-ride these face attributes. For example, the
-resource `Emacs.font-lock-comment-face.attributeUnderline' can be used to
-specify the UNDERLINE-P attribute for face `font-lock-comment-face'.")
-
-(defun font-lock-make-faces (&optional override)
- "Make faces from `font-lock-face-attributes'.
-A default list is used if this is nil.
-If optional OVERRIDE is non-nil, faces that already exist are reset.
-See `font-lock-make-face' and `list-faces-display'."
- ;; We don't need to `setq' any of these variables, but the user can see what
- ;; is being used if we do.
- (if (null font-lock-display-type)
- (setq font-lock-display-type
- (let ((display-resource (x-get-resource ".displayType"
- "DisplayType")))
- (cond (display-resource (intern (downcase display-resource)))
- ((x-display-color-p) 'color)
- ((x-display-grayscale-p) 'grayscale)
- (t 'mono)))))
- (if (null font-lock-background-mode)
- (setq font-lock-background-mode
- (let ((bg-resource (x-get-resource ".backgroundMode"
- "BackgroundMode"))
- (params (frame-parameters)))
- (cond (bg-resource (intern (downcase bg-resource)))
- ((eq system-type 'ms-dos)
- (if (string-match "light"
- (cdr (assq 'background-color params)))
- 'light
- 'dark))
- ((< (apply '+ (x-color-values
- (cdr (assq 'background-color params))))
- (/ (apply '+ (x-color-values "white")) 3))
- 'dark)
- (t 'light)))))
- (if (null font-lock-face-attributes)
- (setq font-lock-face-attributes
- (let ((light-bg (eq font-lock-background-mode 'light)))
- (cond ((memq font-lock-display-type '(mono monochrome))
- ;; Emacs 19.25's font-lock defaults:
- ;;'((font-lock-comment-face nil nil nil t nil)
- ;; (font-lock-string-face nil nil nil nil t)
- ;; (font-lock-keyword-face nil nil t nil nil)
- ;; (font-lock-function-name-face nil nil t t nil)
- ;; (font-lock-type-face nil nil nil t nil))
- (list '(font-lock-comment-face nil nil t t nil)
- '(font-lock-string-face nil nil nil t nil)
- '(font-lock-keyword-face nil nil t nil nil)
- (list
- 'font-lock-function-name-face
- (cdr (assq 'background-color (frame-parameters)))
- (cdr (assq 'foreground-color (frame-parameters)))
- t nil nil)
- '(font-lock-variable-name-face nil nil t t nil)
- '(font-lock-type-face nil nil t nil t)
- '(font-lock-reference-face nil nil t nil t)))
- ((memq font-lock-display-type '(grayscale greyscale
- grayshade greyshade))
- (list
- (list 'font-lock-comment-face
- nil (if light-bg "Gray80" "DimGray") t t nil)
- (list 'font-lock-string-face
- nil (if light-bg "Gray50" "LightGray") nil t nil)
- (list 'font-lock-keyword-face
- nil (if light-bg "Gray90" "DimGray") t nil nil)
- (list 'font-lock-function-name-face
- (cdr (assq 'background-color (frame-parameters)))
- (cdr (assq 'foreground-color (frame-parameters)))
- t nil nil)
- (list 'font-lock-variable-name-face
- nil (if light-bg "Gray90" "DimGray") t t nil)
- (list 'font-lock-type-face
- nil (if light-bg "Gray80" "DimGray") t nil t)
- (list 'font-lock-reference-face
- nil (if light-bg "LightGray" "Gray50") t nil t)))
- (light-bg ; light colour background
- '((font-lock-comment-face "Firebrick")
- (font-lock-string-face "RosyBrown")
- (font-lock-keyword-face "Purple")
- (font-lock-function-name-face "Blue")
- (font-lock-variable-name-face "DarkGoldenrod")
- (font-lock-type-face "DarkOliveGreen")
- (font-lock-reference-face "CadetBlue")))
- (t ; dark colour background
- '((font-lock-comment-face "OrangeRed")
- (font-lock-string-face "LightSalmon")
- (font-lock-keyword-face "LightSteelBlue")
- (font-lock-function-name-face "LightSkyBlue")
- (font-lock-variable-name-face "LightGoldenrod")
- (font-lock-type-face "PaleGreen")
- (font-lock-reference-face "Aquamarine")))))))
- ;; Now make the faces if we have to.
- (mapcar (function
- (lambda (face-attributes)
- (let ((face (nth 0 face-attributes)))
- (cond (override
- ;; We can stomp all over it anyway. Get outta my face!
- (font-lock-make-face face-attributes))
- ((and (boundp face) (facep (symbol-value face)))
- ;; The variable exists and is already bound to a face.
- nil)
- ((facep face)
- ;; We already have a face so we bind the variable to it.
- (set face face))
- (t
- ;; No variable or no face.
- (font-lock-make-face face-attributes))))))
- font-lock-face-attributes))
-
-(defun font-lock-make-face (face-attributes)
- "Make a face from FACE-ATTRIBUTES.
-FACE-ATTRIBUTES should be like an element `font-lock-face-attributes', so that
-the face name is the first item in the list. A variable with the same name as
-the face is also set; its value is the face name."
- (let* ((face (nth 0 face-attributes))
- (face-name (symbol-name face))
- (set-p (function (lambda (face-name resource)
- (x-get-resource (concat face-name ".attribute" resource)
- (concat "Face.Attribute" resource)))))
- (on-p (function (lambda (face-name resource)
- (let ((set (funcall set-p face-name resource)))
- (and set (member (downcase set) '("on" "true"))))))))
- (make-face face)
- (add-to-list 'facemenu-unlisted-faces face)
- ;; Set attributes not set from X resources (and therefore `make-face').
- (or (funcall set-p face-name "Foreground")
- (condition-case nil
- (set-face-foreground face (nth 1 face-attributes))
- (error nil)))
- (or (funcall set-p face-name "Background")
- (condition-case nil
- (set-face-background face (nth 2 face-attributes))
- (error nil)))
- (if (funcall set-p face-name "Bold")
- (and (funcall on-p face-name "Bold") (make-face-bold face nil t))
- (and (nth 3 face-attributes) (make-face-bold face nil t)))
- (if (funcall set-p face-name "Italic")
- (and (funcall on-p face-name "Italic") (make-face-italic face nil t))
- (and (nth 4 face-attributes) (make-face-italic face nil t)))
- (or (funcall set-p face-name "Underline")
- (set-face-underline-p face (nth 5 face-attributes)))
- (set face face)))
+;;; Colour etc. support.
+
+;; Originally these variable values were face names such as `bold' etc.
+;; Now we create our own faces, but we keep these variables for compatibility
+;; and they give users another mechanism for changing face appearance.
+;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
+;; returns a face. So the easiest thing is to continue using these variables,
+;; rather than sometimes evaling FACENAME and sometimes not. sm.
+(defvar font-lock-comment-face 'font-lock-comment-face
+ "Face name to use for comments.")
+
+(defvar font-lock-string-face 'font-lock-string-face
+ "Face name to use for strings.")
+
+(defvar font-lock-keyword-face 'font-lock-keyword-face
+ "Face name to use for keywords.")
+
+(defvar font-lock-builtin-face 'font-lock-builtin-face
+ "Face name to use for builtins.")
+
+(defvar font-lock-function-name-face 'font-lock-function-name-face
+ "Face name to use for function names.")
+
+(defvar font-lock-variable-name-face 'font-lock-variable-name-face
+ "Face name to use for variable names.")
+
+(defvar font-lock-type-face 'font-lock-type-face
+ "Face name to use for type names.")
+
+(defvar font-lock-reference-face 'font-lock-reference-face
+ "Face name to use for reference names.")
+
+(defvar font-lock-warning-face 'font-lock-warning-face
+ "Face name to use for things that should stand out.")
+
+;; Originally face attributes were specified via `font-lock-face-attributes'.
+;; Users then changed the default face attributes by setting that variable.
+;; However, we try and be back-compatible and respect its value if set except
+;; for faces where M-x customize has been used to save changes for the face.
+(when (boundp 'font-lock-face-attributes)
+ (let ((face-attributes font-lock-face-attributes))
+ (while face-attributes
+ (let* ((face-attribute (pop face-attributes))
+ (face (car face-attribute)))
+ ;; Rustle up a `defface' SPEC from a `font-lock-face-attributes' entry.
+ (unless (get face 'saved-face)
+ (let ((foreground (nth 1 face-attribute))
+ (background (nth 2 face-attribute))
+ (bold-p (nth 3 face-attribute))
+ (italic-p (nth 4 face-attribute))
+ (underline-p (nth 5 face-attribute))
+ face-spec)
+ (when foreground
+ (setq face-spec (cons ':foreground (cons foreground face-spec))))
+ (when background
+ (setq face-spec (cons ':background (cons background face-spec))))
+ (when bold-p
+ (setq face-spec (append '(:bold t) face-spec)))
+ (when italic-p
+ (setq face-spec (append '(:italic t) face-spec)))
+ (when underline-p
+ (setq face-spec (append '(:underline t) face-spec)))
+ (custom-declare-face face (list (list t face-spec)) nil)))))))
+
+;; But now we do it the custom way. Note that `defface' will not overwrite any
+;; faces declared above via `custom-declare-face'.
+(defface font-lock-comment-face
+ '((((class grayscale) (background light))
+ (:foreground "DimGray" :bold t :italic t))
+ (((class grayscale) (background dark))
+ (:foreground "LightGray" :bold t :italic t))
+ (((class color) (background light)) (:foreground "Firebrick"))
+ (((class color) (background dark)) (:foreground "OrangeRed"))
+ (t (:bold t :italic t)))
+ "Font Lock mode face used to highlight comments."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-string-face
+ '((((class grayscale) (background light)) (:foreground "DimGray" :italic t))
+ (((class grayscale) (background dark)) (:foreground "LightGray" :italic t))
+ (((class color) (background light)) (:foreground "RosyBrown"))
+ (((class color) (background dark)) (:foreground "LightSalmon"))
+ (t (:italic t)))
+ "Font Lock mode face used to highlight strings."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-keyword-face
+ '((((class grayscale) (background light)) (:foreground "LightGray" :bold t))
+ (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
+ (((class color) (background light)) (:foreground "Purple"))
+ (((class color) (background dark)) (:foreground "Cyan"))
+ (t (:bold t)))
+ "Font Lock mode face used to highlight keywords."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-builtin-face
+ '((((class grayscale) (background light)) (:foreground "LightGray" :bold t))
+ (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
+ (((class color) (background light)) (:foreground "Orchid"))
+ (((class color) (background dark)) (:foreground "LightSteelBlue"))
+ (t (:bold t)))
+ "Font Lock mode face used to highlight builtins."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-function-name-face
+ '((((class color) (background light)) (:foreground "Blue"))
+ (((class color) (background dark)) (:foreground "LightSkyBlue"))
+ (t (:inverse-video t :bold t)))
+ "Font Lock mode face used to highlight function names."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-variable-name-face
+ '((((class grayscale) (background light))
+ (:foreground "Gray90" :bold t :italic t))
+ (((class grayscale) (background dark))
+ (:foreground "DimGray" :bold t :italic t))
+ (((class color) (background light)) (:foreground "DarkGoldenrod"))
+ (((class color) (background dark)) (:foreground "LightGoldenrod"))
+ (t (:bold t :italic t)))
+ "Font Lock mode face used to highlight variable names."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-type-face
+ '((((class grayscale) (background light)) (:foreground "Gray90" :bold t))
+ (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
+ (((class color) (background light)) (:foreground "ForestGreen"))
+ (((class color) (background dark)) (:foreground "PaleGreen"))
+ (t (:bold t :underline t)))
+ "Font Lock mode face used to highlight types."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-reference-face
+ '((((class grayscale) (background light))
+ (:foreground "LightGray" :bold t :underline t))
+ (((class grayscale) (background dark))
+ (:foreground "Gray50" :bold t :underline t))
+ (((class color) (background light)) (:foreground "CadetBlue"))
+ (((class color) (background dark)) (:foreground "Aquamarine"))
+ (t (:bold t :underline t)))
+ "Font Lock mode face used to highlight references."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-warning-face
+ '((((class color) (background light)) (:foreground "Red" :bold t))
+ (((class color) (background dark)) (:foreground "Pink" :bold t))
+ (t (:inverse-video t :bold t)))
+ "Font Lock mode face used to highlight warnings."
+ :group 'font-lock-highlighting-faces)
+
+;;; End of Colour etc. support.
+\f
+;;; Menu support.
+
+;; This section of code is commented out because Emacs does not have real menu
+;; buttons. (We can mimic them by putting "( ) " or "(X) " at the beginning of
+;; the menu entry text, but with Xt it looks both ugly and embarrassingly
+;; amateur.) If/When Emacs gets real menus buttons, put in menu-bar.el after
+;; the entry for "Text Properties" something like:
+;;
+;; (define-key menu-bar-edit-menu [font-lock]
+;; '("Syntax Highlighting" . font-lock-menu))
+;;
+;; and remove a single ";" from the beginning of each line in the rest of this
+;; section. Probably the mechanism for telling the menu code what are menu
+;; buttons and when they are on or off needs tweaking. I have assumed that the
+;; mechanism is via `menu-toggle' and `menu-selected' symbol properties. sm.
+
+;;;;###autoload
+;(progn
+; ;; Make the Font Lock menu.
+; (defvar font-lock-menu (make-sparse-keymap "Syntax Highlighting"))
+; ;; Add the menu items in reverse order.
+; (define-key font-lock-menu [fontify-less]
+; '("Less In Current Buffer" . font-lock-fontify-less))
+; (define-key font-lock-menu [fontify-more]
+; '("More In Current Buffer" . font-lock-fontify-more))
+; (define-key font-lock-menu [font-lock-sep]
+; '("--"))
+; (define-key font-lock-menu [font-lock-mode]
+; '("In Current Buffer" . font-lock-mode))
+; (define-key font-lock-menu [global-font-lock-mode]
+; '("In All Buffers" . global-font-lock-mode)))
+;
+;;;;###autoload
+;(progn
+; ;; We put the appropriate `menu-enable' etc. symbol property values on when
+; ;; font-lock.el is loaded, so we don't need to autoload the three variables.
+; (put 'global-font-lock-mode 'menu-toggle t)
+; (put 'font-lock-mode 'menu-toggle t)
+; (put 'font-lock-fontify-more 'menu-enable '(identity))
+; (put 'font-lock-fontify-less 'menu-enable '(identity)))
+;
+;;; Put the appropriate symbol property values on now. See above.
+;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode))
+;(put 'font-lock-mode 'menu-selected 'font-lock-mode)
+;(put 'font-lock-fontify-more 'menu-enable '(nth 2 font-lock-fontify-level))
+;(put 'font-lock-fontify-less 'menu-enable '(nth 1 font-lock-fontify-level))
+;
+;(defvar font-lock-fontify-level nil) ; For less/more fontification.
+;
+;(defun font-lock-fontify-level (level)
+; (let ((font-lock-maximum-decoration level))
+; (when font-lock-mode
+; (font-lock-mode))
+; (font-lock-mode)
+; (when font-lock-verbose
+; (message "Fontifying %s... level %d" (buffer-name) level))))
+;
+;(defun font-lock-fontify-less ()
+; "Fontify the current buffer with less decoration.
+;See `font-lock-maximum-decoration'."
+; (interactive)
+; ;; Check in case we get called interactively.
+; (if (nth 1 font-lock-fontify-level)
+; (font-lock-fontify-level (1- (car font-lock-fontify-level)))
+; (error "No less decoration")))
+;
+;(defun font-lock-fontify-more ()
+; "Fontify the current buffer with more decoration.
+;See `font-lock-maximum-decoration'."
+; (interactive)
+; ;; Check in case we get called interactively.
+; (if (nth 2 font-lock-fontify-level)
+; (font-lock-fontify-level (1+ (car font-lock-fontify-level)))
+; (error "No more decoration")))
+;
+;;; This should be called by `font-lock-set-defaults'.
+;(defun font-lock-set-menu ()
+; ;; Activate less/more fontification entries if there are multiple levels for
+; ;; the current buffer. Sets `font-lock-fontify-level' to be of the form
+; ;; (CURRENT-LEVEL IS-LOWER-LEVEL-P IS-HIGHER-LEVEL-P) for menu activation.
+; (let ((keywords (or (nth 0 font-lock-defaults)
+; (nth 1 (assq major-mode font-lock-defaults-alist))))
+; (level (font-lock-value-in-major-mode font-lock-maximum-decoration)))
+; (make-local-variable 'font-lock-fontify-level)
+; (if (or (symbolp keywords) (= (length keywords) 1))
+; (font-lock-unset-menu)
+; (cond ((eq level t)
+; (setq level (1- (length keywords))))
+; ((or (null level) (zerop level))
+; ;; The default level is usually, but not necessarily, level 1.
+; (setq level (- (length keywords)
+; (length (member (eval (car keywords))
+; (mapcar 'eval (cdr keywords))))))))
+; (setq font-lock-fontify-level (list level (> level 1)
+; (< level (1- (length keywords))))))))
+;
+;;; This should be called by `font-lock-unset-defaults'.
+;(defun font-lock-unset-menu ()
+; ;; Deactivate less/more fontification entries.
+; (setq font-lock-fontify-level nil))
+
+;;; End of Menu support.