aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/font-lock.el
diff options
context:
space:
mode:
authorRichard M. Stallman <[email protected]>1994-10-11 09:03:49 +0000
committerRichard M. Stallman <[email protected]>1994-10-11 09:03:49 +0000
commit2df1ee235231d56a60be2c2989969c08f58e8bc5 (patch)
treeea830f916d817c7a69553513b237813cf72ec9a3 /lisp/font-lock.el
parente87a730999bf986dae66de6c4ac020efc40dd57d (diff)
(font-lock-set-defaults): Do nothing if font-lock-keywords already non-nil.
Use font-lock-defaults. (font-lock-defaults): New variable.
Diffstat (limited to 'lisp/font-lock.el')
-rw-r--r--lisp/font-lock.el44
1 files changed, 25 insertions, 19 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 10b11ca0d0..8e6ddf3dfd 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -807,30 +807,36 @@ where both MAJOR-MODE and FONT-LOCK-KEYWORDS are symbols. If NOT-SYNTACTICALLY
is non-nil, syntactic fontification (strings and comments) is not performed.
If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying.")
+(defvar font-lock-defaults nil
+ "If set by a major mode, this specifies the defaults for Font Lock mode.")
+
(defun font-lock-set-defaults ()
"Set fontification defaults appropriately for this mode.
Sets `font-lock-keywords', `font-lock-keywords-case-fold-search' and
`font-lock-no-comments' using `font-lock-defaults-alist'.
Also sets `font-lock-syntax-table' for C and C++ modes."
- (let ((defaults (cdr (assq major-mode font-lock-defaults-alist))))
- ;; Keywords?
- (if (not font-lock-keywords) ; if not already set.
- (setq font-lock-keywords (eval (nth 0 defaults))))
- ;; Syntactic?
- (if (nth 1 defaults)
- (set (make-local-variable 'font-lock-no-comments) t))
- ;; Case fold?
- (if (nth 2 defaults)
- (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
- ;; Syntax table?
- (cond ((eq major-mode 'c-mode)
- (make-local-variable 'font-lock-syntax-table)
- (setq font-lock-syntax-table (copy-syntax-table (syntax-table)))
- (modify-syntax-entry ?_ "w" font-lock-syntax-table))
- ((eq major-mode 'c++-c-mode)
- (make-local-variable 'font-lock-syntax-table)
- (setq font-lock-syntax-table (copy-syntax-table (syntax-table)))
- (modify-syntax-entry ?_ "w" font-lock-syntax-table)))))
+ ;; If font-lock-keywords is already set, assume the major mode
+ ;; has done exactly what it wants.
+ (or font-lock-keywords
+ (let ((defaults (or font-lock-defaults
+ (cdr (assq major-mode font-lock-defaults-alist)))))
+ ;; Keywords?
+ (setq font-lock-keywords (eval (nth 0 defaults)))
+ ;; Syntactic?
+ (if (nth 1 defaults)
+ (set (make-local-variable 'font-lock-no-comments) t))
+ ;; Case fold?
+ (if (nth 2 defaults)
+ (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
+ ;; Syntax table?
+ (cond ((eq major-mode 'c-mode)
+ (make-local-variable 'font-lock-syntax-table)
+ (setq font-lock-syntax-table (copy-syntax-table (syntax-table)))
+ (modify-syntax-entry ?_ "w" font-lock-syntax-table))
+ ((eq major-mode 'c++-c-mode)
+ (make-local-variable 'font-lock-syntax-table)
+ (setq font-lock-syntax-table (copy-syntax-table (syntax-table)))
+ (modify-syntax-entry ?_ "w" font-lock-syntax-table))))))
;; Install ourselves: