]> code.delx.au - gnu-emacs/blobdiff - lisp/font-lock.el
(menu-bar-help-menu): Add menu item for non-English
[gnu-emacs] / lisp / font-lock.el
index c0dab76b0c8680866934e383cfceceae721a43fc..bb2aad830dfffa04f52e576f743e68fdd803d89d 100644 (file)
@@ -1,8 +1,9 @@
 ;;; font-lock.el --- Electric font lock mode
 
-;; Copyright (C) 1992-1999 Free Software Foundation, Inc.
+;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000
+;;  Free Software Foundation, Inc.
 
-;; Author: jwz, then rms, then sm <simon@gnu.org>
+;; Author: jwz, then rms, then sm
 ;; Maintainer: FSF
 ;; Keywords: languages, faces
 
 ;;
 ;; Efficient regexps for use as MATCHERs for `font-lock-keywords' and
 ;; `font-lock-syntactic-keywords' can be generated via the function
-;; `regexp-opt', and their depth counted via the function `regexp-opt-depth'.
+;; `regexp-opt'.
 
 ;;; Adding patterns for modes that already support Font Lock:
 
@@ -331,10 +332,10 @@ MATCH-HIGHLIGHT should be of the form:
 where MATCHER can be either the regexp to search for, or the function name to
 call to make the search (called with one argument, the limit of the search) and
 return non-nil if it succeeds (and set `match-data' appropriately).
-MATCHER regexps can be generated via the function `regexp-opt'.  MATCH is the
-subexpression of MATCHER to be highlighted.  MATCH can be calculated via the
-function `regexp-opt-depth'.  FACENAME is an expression whose value is the face
-name to use.  Face default attributes can be modified via \\[customize].
+MATCHER regexps can be generated via the function `regexp-opt'.  MATCH is
+the subexpression of MATCHER to be highlighted.  FACENAME is an expression
+whose value is the face name to use.  Face default attributes can be
+modified via \\[customize].
 
 OVERRIDE and LAXMATCH are flags.  If OVERRIDE is t, existing fontification can
 be overwritten.  If `keep', only parts not already fontified are highlighted.
@@ -388,9 +389,10 @@ PRE-MATCH-FORM is evaluated, that position is used as the limit of the search.
 It is generally a bad idea to return a position greater than the end of the
 line, i.e., cause the MATCHER search to span lines.
 
-These regular expressions should not match text which spans lines.  While
-\\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating
-when you edit the buffer does not, since it considers text one line at a time.
+These regular expressions can match text which spans lines, although
+it is better to avoid it if possible since updating them while editing
+text is slower, and it is not guaranteed to be always correct when using
+support modes like jit-lock or lazy-lock.
 
 This variable is set by major modes via the variable `font-lock-defaults'.
 Be careful when composing regexps for this list; a poorly written pattern can
@@ -530,9 +532,10 @@ the differences are listed below.  MATCH-HIGHLIGHT should be of the form:
 
  (MATCH SYNTAX OVERRIDE LAXMATCH)
 
-where SYNTAX can be of the form (SYNTAX-CODE . MATCHING-CHAR), the name of a
-syntax table, or an expression whose value is such a form or a syntax table.
-OVERRIDE cannot be `prepend' or `append'.
+where SYNTAX can be of the form (SYNTAX-CODE . MATCHING-CHAR) (see
+also `string-to-syntax'), the name of a syntax table, or an expression
+whose value is such a form or a syntax table.  OVERRIDE cannot be
+`prepend' or `append'.
 
 For example, an element of the form highlights syntactically:
 
@@ -636,6 +639,7 @@ Major/minor modes can set this variable if they know which option applies.")
         (when (and (not modified) (buffer-modified-p))
           (set-buffer-modified-p nil)))))
   (put 'save-buffer-state 'lisp-indent-function 1)
+  (def-edebug-spec save-buffer-state let)
   ;;
   ;; Shut up the byte compiler.
   (defvar global-font-lock-mode)       ; Now a defcustom.
@@ -729,7 +733,7 @@ buffer local value for `font-lock-defaults', via its mode hook."
 (defun turn-on-font-lock ()
   "Turn on Font Lock mode conditionally.
 Turn on only if the terminal can display it."
-  (when (and (not font-lock-mode) (or window-system (tty-display-color-p)))
+  (unless font-lock-mode
     (font-lock-mode)))
 
 ;;;###autoload
@@ -767,11 +771,12 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
         ;; 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-mode
-        ;; Otherwise if Font Lock mode is on, set or add the keywords now.
-        (if (eq append 'set)
-            (setq font-lock-keywords keywords)
-          (font-lock-remove-keywords mode keywords)
+       (t
+        ;; Otherwise set or add the keywords now.
+        (font-lock-set-defaults)
+        (if (eq append '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)))
@@ -779,9 +784,9 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
                                          (append old keywords)
                                        (append keywords old))))))))
 
-(defun font-lock-update-removed-keyword-alist (major-mode keywords append)
+(defun font-lock-update-removed-keyword-alist (mode keywords append)
   ;; Update `font-lock-removed-keywords-alist' when adding new
-  ;; KEYWORDS to MAJOR-MODE.
+  ;; 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
@@ -789,7 +794,7 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
   ;; keyword was once added, removed, and then added again it must be
   ;; removed from the removed-keywords list.  Otherwise the second add
   ;; will not take effect.
-  (let ((cell (assq major-mode font-lock-removed-keywords-alist)))
+  (let ((cell (assq mode font-lock-removed-keywords-alist)))
     (if cell
        (if (eq append 'set)
            ;; A new set of keywords is defined.  Forget all about
@@ -799,7 +804,7 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
          ;; Delete all previously removed keywords.
          (dolist (kword keywords)
            (setcdr cell (delete kword (cdr cell))))
-         ;; Delete the major-mode cell if empty.
+         ;; Delete the mode cell if empty.
          (if (null (cdr cell))
              (setq font-lock-removed-keywords-alist
                    (delq cell font-lock-removed-keywords-alist)))))))
@@ -824,16 +829,16 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
 ;;
 ;; (II) The keywords are removed from the current buffer.
 ;;;###autoload
-(defun font-lock-remove-keywords (major-mode keywords)
-  "Remove highlighting KEYWORDS for MAJOR-MODE.
+(defun font-lock-remove-keywords (mode keywords)
+  "Remove highlighting KEYWORDS for MODE.
 
-MAJOR-MODE should be a symbol, the major mode command name, such as `c-mode'
+MODE should be a symbol, the major mode command name, such as `c-mode'
 or nil.  If nil, highlighting keywords are removed for the current buffer."
-  (dolist (keyword keywords)
-    ;; Remove one keyword at the time.
-    (cond (major-mode
-          (let ((top-cell (assq major-mode font-lock-keywords-alist)))
-            ;; If MAJOR-MODE is non-nil, remove the KEYWORD from
+  (cond (mode
+        ;; Remove one keyword at the time.
+        (dolist (keyword keywords)
+          (let ((top-cell (assq mode font-lock-keywords-alist)))
+            ;; If MODE is non-nil, remove the KEYWORD from
             ;; `font-lock-keywords-alist'.
             (when top-cell
               (dolist (keyword-list-append-pair (cdr top-cell))
@@ -858,19 +863,22 @@ or nil.  If nil, highlighting keywords are removed for the current buffer."
                   (setq font-lock-keywords-alist
                         (delq top-cell font-lock-keywords-alist))))
             ;; Remember the keyword in case it is not local.
-            (let ((cell (assq major-mode font-lock-removed-keywords-alist)))
+            (let ((cell (assq mode font-lock-removed-keywords-alist)))
               (if cell
                   (unless (member keyword (cdr cell))
                     (nconc cell (list keyword)))
-                (push (cons major-mode (list keyword))
-                      font-lock-removed-keywords-alist)))))
-         (font-lock-mode
-          ;; Otherwise if Font Lock mode is on, remove it immediately.
-          (setq font-lock-keywords (delete keyword font-lock-keywords))
-          ;; The keywords might be compiled.
+                (push (cons mode (list keyword))
+                      font-lock-removed-keywords-alist))))))
+       (t
+        ;; Otherwise remove it immediately.
+        (font-lock-set-defaults)
+        (setq font-lock-keywords (copy-sequence font-lock-keywords))
+        (dolist (keyword keywords)
           (setq font-lock-keywords
-                (delete (font-lock-compile-keyword keyword)
-                        font-lock-keywords))))))
+                (delete keyword
+                        ;; The keywords might be compiled.
+                        (delete (font-lock-compile-keyword keyword)
+                                font-lock-keywords)))))))
 \f
 ;;; Global Font Lock mode.
 
@@ -1384,8 +1392,10 @@ see `font-lock-syntactic-keywords'."
         (start (match-beginning match)) (end (match-end match))
         (value (nth 1 highlight))
         (override (nth 2 highlight)))
-    (unless (numberp (car-safe value))
-      (setq value (eval value)))
+    (cond ((stringp value)
+          (setq value (string-to-syntax value)))
+         ((not (numberp (car-safe value)))
+          (setq value (eval value))))
     (cond ((not start)
           ;; No match but we might not signal an error.
           (or (nth 3 highlight)
@@ -1411,7 +1421,7 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM."
     ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
     (if (and (numberp pre-match-value) (> pre-match-value (point)))
        (setq limit pre-match-value)
-      (save-excursion (end-of-line) (setq limit (point))))
+      (setq limit (line-end-position)))
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
       (while (if (stringp matcher)
@@ -1560,20 +1570,21 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM."
        (pre-match-value (eval (nth 1 keywords))))
     ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
     (if (not (and (numberp pre-match-value) (> pre-match-value (point))))
-       (save-excursion (end-of-line) (setq limit (point)))
+       (setq limit (line-end-position))
       (setq limit pre-match-value)
       (when (and font-lock-multiline
                 (funcall (if (eq font-lock-multiline t) '>= '>)
                          pre-match-value
                          (save-excursion (forward-line 1) (point))))
        ;; this is a multiline anchored match
-       (set (make-local-variable 'font-lock-multiline) t)
+       (setq font-lock-multiline t)
        (put-text-property (point) limit 'font-lock-multiline t)))
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
-      (while (if (stringp matcher)
-                (re-search-forward matcher limit t)
-              (funcall matcher limit))
+      (while (and (< (point) limit)
+                 (if (stringp matcher)
+                     (re-search-forward matcher limit t)
+                   (funcall matcher limit)))
        ;; Apply each highlight to this instance of `matcher'.
        (setq highlights lowdarks)
        (while highlights
@@ -1611,7 +1622,7 @@ START should be at the beginning of a line."
                            (save-excursion (goto-char (match-beginning 0))
                                            (forward-line 1) (point))))
          ;; this is a multiline regexp match
-         (set (make-local-variable 'font-lock-multiline) t)
+         (setq font-lock-multiline t)
          (put-text-property (match-beginning 0) (point)
                             'font-lock-multiline t))
        ;; Apply each highlight to this instance of `matcher', which may be
@@ -1689,13 +1700,13 @@ A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
   "Set fontification defaults appropriately for this mode.
 Sets various variables using `font-lock-defaults' (or, if nil, using
 `font-lock-defaults-alist') and `font-lock-maximum-decoration'."
-  ;; Set fontification defaults.
-  (make-local-variable 'font-lock-fontified)
-  ;; Set iff not previously set.
+  ;; Set fontification defaults iff not previously set.
   (unless font-lock-set-defaults
     (set (make-local-variable 'font-lock-set-defaults)         t)
     (set (make-local-variable 'font-lock-cache-state)          nil)
     (set (make-local-variable 'font-lock-cache-position)       (make-marker))
+    (make-local-variable 'font-lock-fontified)
+    (make-local-variable 'font-lock-multiline)
     (let* ((defaults (or font-lock-defaults
                         (cdr (assq major-mode font-lock-defaults-alist))))
           (keywords
@@ -2078,9 +2089,9 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
                   ;; Function declarations.
                   "\\(advice\\|alias\\|generic\\|macro\\*?\\|method\\|"
                    "setf\\|subst\\*?\\|un\\*?\\|"
-                   "ine-\\(condition\\|derived-mode\\|function\\|"
+                   "ine-\\(condition\\|\\(?:derived\\|minor\\)-mode\\|"
                    "method-combination\\|setf-expander\\|skeleton\\|widget\\|"
-                   "\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
+                   "function\\|\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
                   ;; Variable declarations.
                   "\\(const\\(ant\\)?\\|custom\\|face\\|parameter\\|var\\)\\|"
                   ;; Structure declarations.
@@ -2088,7 +2099,7 @@ This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
                   "\\)\\)\\>"
                   ;; Any whitespace and defined object.
                   "[ \t'\(]*"
-                  "\\(\\sw+\\)?")
+                  "\\(setf[ \t]+\\sw+)\\|\\sw+\\)?")
           '(1 font-lock-keyword-face)
           '(9 (cond ((match-beginning 3) font-lock-function-name-face)
                     ((match-beginning 6) font-lock-variable-name-face)
@@ -3089,8 +3100,13 @@ See also `java-font-lock-extra-types'.")
     '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-constant-face)
     ;;
     ;; Javadoc tags within comments.
-    '("@\\(author\\|deprecated\\|link\\|return\\|see\\|version\\)\\>"
-      (1 font-lock-constant-face prepend))
+    (list
+     (concat "@\\("
+            "author\\|deprecated\\|exception"
+            "\\|link\\|return\\|see\\|serial\\|serialData\\|serialField"
+            "\\|since\\|throws"
+            "\\|version"
+            "\\)\\>"))
     '("@\\(param\\)\\>[ \t]*\\(\\sw+\\)?"
       (1 font-lock-constant-face prepend)
       (2 font-lock-variable-name-face prepend t))