]> code.delx.au - gnu-emacs/blobdiff - lisp/font-lock.el
Merged from miles@gnu.org--gnu-2005 (patch 678-680)
[gnu-emacs] / lisp / font-lock.el
index e14ee8164736d9b8fc6934a32399eaa08a6426e6..de366997a93f2495930facad021c9ec5305e96e9 100644 (file)
 ;;
 ;;  (add-hook 'foo-mode-hook
 ;;   (lambda ()
-;;     (make-local-variable 'font-lock-defaults)
-;;     (setq font-lock-defaults '(foo-font-lock-keywords t))))
+;;     (set (make-local-variable 'font-lock-defaults)
+;;          '(foo-font-lock-keywords t))))
 
 ;;; Adding Font Lock support for modes:
 
 ;;
 ;; and within `bar-mode' there could be:
 ;;
-;;  (make-local-variable 'font-lock-defaults)
-;;  (setq font-lock-defaults '(bar-font-lock-keywords nil t))
+;;  (set (make-local-variable 'font-lock-defaults)
+;;       '(bar-font-lock-keywords nil t))
 \f
 ;; What is fontification for?  You might say, "It's to make my code look nice."
 ;; I think it should be for adding information in the form of cues.  These cues
 ;; Define core `font-lock' group.
 (defgroup font-lock '((jit-lock custom-group))
   "Font Lock mode text highlighting package."
-  :link '(custom-manual "(emacs)Font Lock")
-  :link '(custom-manual "(elisp)Font Lock Mode")
+  :link '(custom-manual :tag "Emacs Manual" "(emacs)Font Lock")
+  :link '(custom-manual :tag "Elisp Manual" "(elisp)Font Lock Mode")
   :group 'faces)
 
 (defgroup font-lock-faces nil
@@ -463,13 +463,13 @@ optimized.")
 (defvar font-lock-keywords-alist nil
   "Alist of additional `font-lock-keywords' elements for major modes.
 
-Each element has the form (MODE KEYWORDS . APPEND).
+Each element has the form (MODE KEYWORDS . HOW).
 `font-lock-set-defaults' adds the elements in the list KEYWORDS to
 `font-lock-keywords' when Font Lock is turned on in major mode MODE.
 
-If APPEND is nil, KEYWORDS are added at the beginning of
+If HOW is nil, KEYWORDS are added at the beginning of
 `font-lock-keywords'.  If it is `set', they are used to replace the
-value of `font-lock-keywords'.  If APPEND is any other non-nil value,
+value of `font-lock-keywords'.  If HOW is any other non-nil value,
 they are added at the end.
 
 This is normally set via `font-lock-add-keywords' and
@@ -650,15 +650,15 @@ Major/minor modes can set this variable if they know which option applies.")
     (font-lock-unfontify-buffer)
     (font-lock-turn-off-thing-lock)))
 
-(defun font-lock-add-keywords (mode keywords &optional append)
+(defun font-lock-add-keywords (mode keywords &optional how)
   "Add highlighting KEYWORDS for MODE.
 
 MODE should be a symbol, the major mode command name, such as `c-mode'
 or nil.  If nil, highlighting keywords are added for the current buffer.
 KEYWORDS should be a list; see the variable `font-lock-keywords'.
 By default they are added at the beginning of the current highlighting list.
-If optional argument APPEND is `set', they are used to replace the current
-highlighting list.  If APPEND is any other non-nil value, they are added at the
+If optional argument HOW is `set', they are used to replace the current
+highlighting list.  If HOW is any other non-nil value, they are added at the
 end of the current highlighting list.
 
 For example:
@@ -691,17 +691,17 @@ Note that some modes have specialized support for additional patterns, e.g.,
 see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
 `objc-font-lock-extra-types' and `java-font-lock-extra-types'."
   (cond (mode
-        ;; If MODE is non-nil, add the KEYWORDS and APPEND spec to
+        ;; If MODE is non-nil, add the KEYWORDS and HOW spec to
         ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them.
-        (let ((spec (cons keywords append)) cell)
+        (let ((spec (cons keywords how)) cell)
           (if (setq cell (assq mode font-lock-keywords-alist))
-              (if (eq append 'set)
+              (if (eq how 'set)
                   (setcdr cell (list spec))
                 (setcdr cell (append (cdr cell) (list spec))))
             (push (list mode spec) font-lock-keywords-alist)))
         ;; Make sure that `font-lock-removed-keywords-alist' does not
         ;; contain the new keywords.
-        (font-lock-update-removed-keyword-alist mode keywords append))
+        (font-lock-update-removed-keyword-alist mode keywords how))
        (t
         ;; Otherwise set or add the keywords now.
         ;; This is a no-op if it has been done already in this buffer
@@ -712,21 +712,21 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
           (if was-compiled
               (setq font-lock-keywords (cadr font-lock-keywords)))
           ;; Now modify or replace them.
-          (if (eq append 'set)
+          (if (eq how 'set)
               (setq font-lock-keywords keywords)
             (font-lock-remove-keywords nil keywords) ;to avoid duplicates
             (let ((old (if (eq (car-safe font-lock-keywords) t)
                            (cdr font-lock-keywords)
                          font-lock-keywords)))
-              (setq font-lock-keywords (if append
+              (setq font-lock-keywords (if how
                                            (append old keywords)
                                          (append keywords old)))))
           ;; If the keywords were compiled before, compile them again.
           (if was-compiled
-              (set (make-local-variable 'font-lock-keywords)
-                   (font-lock-compile-keywords font-lock-keywords t)))))))
+              (setq font-lock-keywords
+                     (font-lock-compile-keywords font-lock-keywords t)))))))
 
-(defun font-lock-update-removed-keyword-alist (mode keywords append)
+(defun font-lock-update-removed-keyword-alist (mode keywords how)
   "Update `font-lock-removed-keywords-alist' when adding new KEYWORDS to MODE."
   ;; When font-lock is enabled first all keywords in the list
   ;; `font-lock-keywords-alist' are added, then all keywords in the
@@ -736,7 +736,7 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
   ;; will not take effect.
   (let ((cell (assq mode font-lock-removed-keywords-alist)))
     (if cell
-       (if (eq append 'set)
+       (if (eq how 'set)
            ;; A new set of keywords is defined.  Forget all about
            ;; our old keywords that should be removed.
            (setq font-lock-removed-keywords-alist
@@ -786,14 +786,14 @@ happens, so the major mode can be corrected."
             ;; If MODE is non-nil, remove the KEYWORD from
             ;; `font-lock-keywords-alist'.
             (when top-cell
-              (dolist (keyword-list-append-pair (cdr top-cell))
-                ;; `keywords-list-append-pair' is a cons with a list of
-                ;; keywords in the car top-cell and the original append
+              (dolist (keyword-list-how-pair (cdr top-cell))
+                ;; `keywords-list-how-pair' is a cons with a list of
+                ;; keywords in the car top-cell and the original how
                 ;; argument in the cdr top-cell.
-                (setcar keyword-list-append-pair
-                        (delete keyword (car keyword-list-append-pair))))
-              ;; Remove keyword list/append pair when the keyword list
-              ;; is empty and append doesn't specify `set'.  (If it
+                (setcar keyword-list-how-pair
+                        (delete keyword (car keyword-list-how-pair))))
+              ;; Remove keyword list/how pair when the keyword list
+              ;; is empty and how doesn't specify `set'.  (If it
               ;; should be deleted then previously deleted keywords
               ;; would appear again.)
               (let ((cell top-cell))
@@ -830,8 +830,8 @@ happens, so the major mode can be corrected."
 
           ;; If the keywords were compiled before, compile them again.
           (if was-compiled
-              (set (make-local-variable 'font-lock-keywords)
-                   (font-lock-compile-keywords font-lock-keywords t)))))))
+              (setq font-lock-keywords
+                     (font-lock-compile-keywords font-lock-keywords t)))))))
 \f
 ;;; Font Lock Support mode.
 
@@ -1001,8 +1001,7 @@ The value of this variable is used when Font Lock mode is turned on."
        (when verbose
          (format "Fontifying %s..." (buffer-name)))
       ;; Make sure we have the right `font-lock-keywords' etc.
-      (unless font-lock-mode
-       (font-lock-set-defaults))
+      (font-lock-set-defaults)
       ;; Make sure we fontify etc. in the whole buffer.
       (save-restriction
        (widen)
@@ -1574,9 +1573,9 @@ A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
   (cond ((not (and (listp keywords) (symbolp (car keywords))))
         keywords)
        ((numberp level)
-        (or (nth level keywords) (car (reverse keywords))))
+        (or (nth level keywords) (car (last keywords))))
        ((eq level t)
-        (car (reverse keywords)))
+        (car (last keywords)))
        (t
         (car keywords))))
 
@@ -1642,8 +1641,8 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
        (font-lock-remove-keywords nil removed-keywords))
       ;; Now compile the keywords.
       (unless (eq (car font-lock-keywords) t)
-       (set (make-local-variable 'font-lock-keywords)
-            (font-lock-compile-keywords font-lock-keywords t))))))
+       (setq font-lock-keywords
+              (font-lock-compile-keywords font-lock-keywords t))))))
 \f
 ;;; Colour etc. support.
 
@@ -1967,7 +1966,8 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
                ;; Function declarations.
                "\\(advice\\|varalias\\|alias\\|generic\\|macro\\*?\\|method\\|"
                "setf\\|subst\\*?\\|un\\*?\\|"
-               "ine-\\(condition\\|\\(?:derived\\|minor\\|generic\\)-mode\\|"
+               "ine-\\(condition\\|"
+               "\\(?:derived\\|\\(?:global-\\)?minor\\|generic\\)-mode\\|"
                "method-combination\\|setf-expander\\|skeleton\\|widget\\|"
                "function\\|\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
                ;; Variable declarations.
@@ -1995,7 +1995,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
      `(;; Control structures.  Emacs Lisp forms.
        (,(concat
          "(" (regexp-opt
-              '("cond" "if" "while" "while-no-input" "let" "let*"
+              '("cond" "if" "while" "while-no-input" "let" "let*" "let-environment"
                 "prog" "progn" "progv" "prog1" "prog2" "prog*"
                 "inline" "lambda" "save-restriction" "save-excursion"
                 "save-window-excursion" "save-selected-window"
@@ -2007,7 +2007,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
                 "with-current-buffer" "with-electric-help"
                 "with-local-quit" "with-no-warnings"
                 "with-output-to-string" "with-output-to-temp-buffer"
-                "with-selected-window" "with-syntax-table"
+                "with-selected-window" "with-selected-frame" "with-syntax-table"
                 "with-temp-buffer" "with-temp-file" "with-temp-message"
                 "with-timeout" "with-timeout-handler") t)
          "\\>")