aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-05-13 21:24:47 +0000
committerRichard M. Stallman1994-05-13 21:24:47 +0000
commit8f261d407bc224ffbc91ef5fea10d4e6f1a1ba27 (patch)
tree63b255b349b7647662326d6fd1f3f4d7b7e0e52e
parent4624e651686399eb1aa450a58a3ed879568bc56d (diff)
downloademacs-8f261d407bc224ffbc91ef5fea10d4e6f1a1ba27.tar.gz
emacs-8f261d407bc224ffbc91ef5fea10d4e6f1a1ba27.zip
(font-lock-no-comments): New variable.
(font-lock-after-change-function): Test it. (font-lock-fontify-buffer): Test it. (font-lock-set-defaults): Set it. (font-lock-mode): Make font-lock-no-comments local. (font-lock-after-change-function): If we don't call font-lock-fontify-region, clear out face props instead. (font-lock-fontify-buffer): Don't give "syntactically" message if we aren't doing that part.
-rw-r--r--lisp/font-lock.el56
1 files changed, 32 insertions, 24 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 39e17ea8efd..4c0d4c0c379 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -85,6 +85,9 @@
85 'italic 85 'italic
86 "Face to use for data types.") 86 "Face to use for data types.")
87 87
88(defvar font-lock-no-comments nil
89 "Non-nil means Font-Lock shouldn't check for comments or strings.")
90
88(make-variable-buffer-local 'font-lock-keywords) 91(make-variable-buffer-local 'font-lock-keywords)
89(defvar font-lock-keywords nil 92(defvar font-lock-keywords nil
90 "*The keywords to highlight. 93 "*The keywords to highlight.
@@ -261,7 +264,9 @@ slow things down!")
261 ;; First scan for strings and comments. 264 ;; First scan for strings and comments.
262 ;; Must scan from line start in case of 265 ;; Must scan from line start in case of
263 ;; inserting space into `intfoo () {}'. 266 ;; inserting space into `intfoo () {}'.
264 (font-lock-fontify-region beg (1+ end)) 267 (if font-lock-no-comments
268 (remove-text-properties beg (1+ end) '(face nil))
269 (font-lock-fontify-region beg (min (1+ end) (point-max))))
265 ;; Now scan for keywords. 270 ;; Now scan for keywords.
266 (font-lock-hack-keywords beg end)))) 271 (font-lock-hack-keywords beg end))))
267 272
@@ -366,6 +371,7 @@ can use \\[font-lock-fontify-buffer]."
366 (set (make-local-variable 'after-change-function) 371 (set (make-local-variable 'after-change-function)
367 (if on-p 'font-lock-after-change-function nil)) 372 (if on-p 'font-lock-after-change-function nil))
368 (set (make-local-variable 'font-lock-mode) on-p) 373 (set (make-local-variable 'font-lock-mode) on-p)
374 (make-local-variable 'font-lock-no-comments)
369 (cond (on-p 375 (cond (on-p
370 (font-lock-set-defaults) 376 (font-lock-set-defaults)
371 (make-local-variable 'before-revert-hook) 377 (make-local-variable 'before-revert-hook)
@@ -413,11 +419,11 @@ This can take a while for large buffers."
413 ;; Turn it on to run hooks and get the right font-lock-keywords. 419 ;; Turn it on to run hooks and get the right font-lock-keywords.
414 (or was-on (font-lock-set-defaults)) 420 (or was-on (font-lock-set-defaults))
415 (font-lock-unfontify-region (point-min) (point-max)) 421 (font-lock-unfontify-region (point-min) (point-max))
416 (if font-lock-verbose (message "Fontifying %s... (syntactically...)" 422 (if (and font-lock-verbose (not font-lock-no-comments))
417 (buffer-name))) 423 (message "Fontifying %s... (syntactically...)" (buffer-name)))
418;; (buffer-syntactic-context-flush-cache)
419 (save-excursion 424 (save-excursion
420 (font-lock-fontify-region (point-min) (point-max)) 425 (or font-lock-no-comments
426 (font-lock-fontify-region (point-min) (point-max)))
421 (if font-lock-verbose (message "Fontifying %s... (regexps...)" 427 (if font-lock-verbose (message "Fontifying %s... (regexps...)"
422 (buffer-name))) 428 (buffer-name)))
423 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose)) 429 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
@@ -428,25 +434,6 @@ This can take a while for large buffers."
428 434
429;;; Various mode-specific information. 435;;; Various mode-specific information.
430 436
431(defun font-lock-set-defaults ()
432 "Set `font-lock-keywords' to something appropriate for this mode."
433 (if (not font-lock-keywords) ; if not already set.
434 (setq font-lock-keywords
435 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords)
436 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords)
437 ((eq major-mode 'c-mode) c-font-lock-keywords)
438 ((eq major-mode 'c++-c-mode) c-font-lock-keywords)
439 ((eq major-mode 'c++-mode) c++-font-lock-keywords)
440 ((eq major-mode 'perl-mode) perl-font-lock-keywords)
441 ((eq major-mode 'tex-mode) tex-font-lock-keywords)
442 ((eq major-mode 'texinfo-mode) texi-font-lock-keywords)
443 ((eq major-mode 'shell-mode) shell-font-lock-keywords)
444 ((eq major-mode 'dired-mode) dired-font-lock-keywords)
445 ((eq major-mode 'rmail-mode) rmail-font-lock-keywords)
446 ((eq major-mode 'compilation-mode)
447 compilation-mode-font-lock-keywords)
448 (t nil)))))
449
450(defconst lisp-font-lock-keywords-1 437(defconst lisp-font-lock-keywords-1
451 '(;; 438 '(;;
452 ;; highlight defining forms. This doesn't work too nicely for 439 ;; highlight defining forms. This doesn't work too nicely for
@@ -702,6 +689,27 @@ This does a lot more highlighting.")
702;;; ("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 0 font-lock-keyword-face keep) 689;;; ("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 0 font-lock-keyword-face keep)
703 "Additional expressions to highlight in Compilation mode.") 690 "Additional expressions to highlight in Compilation mode.")
704 691
692(defun font-lock-set-defaults ()
693 "Set `font-lock-keywords' to something appropriate for this mode."
694 (if (memq major-mode '(rmail-mode dired-mode compilation-mode shell-mode))
695 (setq font-lock-no-comments t))
696 (if (not font-lock-keywords) ; if not already set.
697 (setq font-lock-keywords
698 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords)
699 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords)
700 ((eq major-mode 'c-mode) c-font-lock-keywords)
701 ((eq major-mode 'c++-c-mode) c-font-lock-keywords)
702 ((eq major-mode 'c++-mode) c++-font-lock-keywords)
703 ((eq major-mode 'perl-mode) perl-font-lock-keywords)
704 ((eq major-mode 'tex-mode) tex-font-lock-keywords)
705 ((eq major-mode 'texinfo-mode) texi-font-lock-keywords)
706 ((eq major-mode 'shell-mode) shell-font-lock-keywords)
707 ((eq major-mode 'dired-mode) dired-font-lock-keywords)
708 ((eq major-mode 'rmail-mode) rmail-font-lock-keywords)
709 ((eq major-mode 'compilation-mode)
710 compilation-mode-font-lock-keywords)
711 (t nil)))))
712
705(provide 'font-lock) 713(provide 'font-lock)
706 714
707;;; font-lock.el ends here 715;;; font-lock.el ends here