aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Marshall1996-06-24 08:06:51 +0000
committerSimon Marshall1996-06-24 08:06:51 +0000
commitfd23afbeb406a28f97f5cd6cb95fd7db4c4bfe5d (patch)
tree2871eff3bdb5beb3d1cad71e48907db3800da2c7
parent6a02d88bf8b30d8920da071446ac885743e0cae2 (diff)
downloademacs-fd23afbeb406a28f97f5cd6cb95fd7db4c4bfe5d.tar.gz
emacs-fd23afbeb406a28f97f5cd6cb95fd7db4c4bfe5d.zip
Put fewer conditions in turn-on-font-lock and more in turn-on-font-lock-if-enabled, so a user can put the former on hooks.
-rw-r--r--lisp/font-lock.el54
1 files changed, 30 insertions, 24 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index e7bb9e6e3c9..baeaf1e4f04 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -403,31 +403,36 @@ the major mode's hook. For example, put in your ~/.emacs:
403 (add-hook 'c-mode-hook 'turn-on-font-lock) 403 (add-hook 'c-mode-hook 'turn-on-font-lock)
404 404
405Alternatively, you can use Global Font Lock mode to automagically turn on Font 405Alternatively, you can use Global Font Lock mode to automagically turn on Font
406Lock mode in buffers whose major mode supports it, or in buffers whose major 406Lock mode in buffers whose major mode supports it and whose major mode is one
407mode is one of `font-lock-global-modes'. For example, put in your ~/.emacs: 407of `font-lock-global-modes'. For example, put in your ~/.emacs:
408 408
409 (global-font-lock-mode t) 409 (global-font-lock-mode t)
410 410
411The default Font Lock mode faces and their attributes are defined in the 411There are a number of support modes that may be used to speed up Font Lock mode
412variable `font-lock-face-attributes', and Font Lock mode default settings in 412in various ways, specified via the variable `font-lock-support-mode'. Where
413the variable `font-lock-defaults-alist'. You can set your own default settings 413major modes support different levels of fontification, you can use the variable
414for some mode, by setting a buffer local value for `font-lock-defaults', via
415its mode hook.
416
417Font Lock mode has a number of support modes that may be used to speed up Font
418Lock mode in various ways. See the variable `font-lock-support-mode'.
419
420Where modes support different levels of fontification, you can use the variable
421`font-lock-maximum-decoration' to specify which level you generally prefer. 414`font-lock-maximum-decoration' to specify which level you generally prefer.
422When you turn Font Lock mode on/off the buffer is fontified/defontified, though 415When you turn Font Lock mode on/off the buffer is fontified/defontified, though
423fontification occurs only if the buffer is less than `font-lock-maximum-size'. 416fontification occurs only if the buffer is less than `font-lock-maximum-size'.
424 417
418For example, to specify that Font Lock mode use use Lazy Lock mode as a support
419mode and use maximum levels of fontification, put in your ~/.emacs:
420
421 (setq font-lock-support-mode 'lazy-lock-mode)
422 (setq font-lock-maximum-decoration t)
423
425To fontify a buffer, without turning on Font Lock mode and regardless of buffer 424To fontify a buffer, without turning on Font Lock mode and regardless of buffer
426size, you can use \\[font-lock-fontify-buffer]. 425size, you can use \\[font-lock-fontify-buffer].
427 426
428To fontify a block (the function or paragraph containing point, or a number of 427To fontify a block (the function or paragraph containing point, or a number of
429lines around point), perhaps because modification on the current line caused 428lines around point), perhaps because modification on the current line caused
430syntactic change on other lines, you can use \\[font-lock-fontify-block]." 429syntactic change on other lines, you can use \\[font-lock-fontify-block].
430
431The default Font Lock mode faces and their attributes are defined in the
432variable `font-lock-face-attributes', and Font Lock mode default settings in
433the variable `font-lock-defaults-alist'. You can set your own default settings
434for some mode, by setting a buffer local value for `font-lock-defaults', via
435its mode hook."
431 (interactive "P") 436 (interactive "P")
432 ;; Don't turn on Font Lock mode if we don't have a display (we're running a 437 ;; Don't turn on Font Lock mode if we don't have a display (we're running a
433 ;; batch job) or if the buffer is invisible (the name starts with a space). 438 ;; batch job) or if the buffer is invisible (the name starts with a space).
@@ -463,11 +468,9 @@ syntactic change on other lines, you can use \\[font-lock-fontify-block]."
463;;;###autoload 468;;;###autoload
464(defun turn-on-font-lock () 469(defun turn-on-font-lock ()
465 "Turn on Font Lock mode conditionally. 470 "Turn on Font Lock mode conditionally.
466Turn on only if the buffer mode supports it and the terminal can display it." 471Turn on only if the terminal can display it."
467 (if (and window-system 472 (when window-system
468 (not font-lock-mode) 473 (font-lock-mode t)))
469 (or font-lock-defaults (assq major-mode font-lock-defaults-alist)))
470 (font-lock-mode t)))
471 474
472;; Global Font Lock mode. 475;; Global Font Lock mode.
473;; 476;;
@@ -574,16 +577,19 @@ turned on in a buffer if its major mode is one of `font-lock-global-modes'."
574 577
575(defun turn-on-font-lock-if-enabled () 578(defun turn-on-font-lock-if-enabled ()
576 ;; Gross hack warning: Delicate readers should avert eyes now. 579 ;; Gross hack warning: Delicate readers should avert eyes now.
577 ;; Turn on Font Lock mode if it's one of `font-lock-global-modes'. 580 ;; Turn on Font Lock mode if it's supported by the major mode and enabled by
581 ;; the user.
578 (remove-hook 'post-command-hook 'turn-on-font-lock-if-enabled) 582 (remove-hook 'post-command-hook 'turn-on-font-lock-if-enabled)
579 (while font-lock-buffers 583 (while font-lock-buffers
580 (if (buffer-live-p (car font-lock-buffers)) 584 (if (buffer-live-p (car font-lock-buffers))
581 (save-excursion 585 (save-excursion
582 (set-buffer (car font-lock-buffers)) 586 (set-buffer (car font-lock-buffers))
583 (if (or (eq font-lock-global-modes t) 587 (if (and (or font-lock-defaults
584 (if (eq (car-safe font-lock-global-modes) 'not) 588 (assq major-mode font-lock-defaults-alist))
585 (not (memq major-mode (cdr font-lock-global-modes))) 589 (or (eq font-lock-global-modes t)
586 (memq major-mode font-lock-global-modes))) 590 (if (eq (car-safe font-lock-global-modes) 'not)
591 (not (memq major-mode (cdr font-lock-global-modes)))
592 (memq major-mode font-lock-global-modes))))
587 (let (inhibit-quit) 593 (let (inhibit-quit)
588 (turn-on-font-lock))))) 594 (turn-on-font-lock)))))
589 (setq font-lock-buffers (cdr font-lock-buffers)))) 595 (setq font-lock-buffers (cdr font-lock-buffers))))
@@ -1631,7 +1637,7 @@ the face is also set; its value is the face name."
1631 (cons (concat "\\<\\(" c++-type-types "\\)\\>") 'font-lock-type-face) 1637 (cons (concat "\\<\\(" c++-type-types "\\)\\>") 'font-lock-type-face)
1632 ;; 1638 ;;
1633 ;; Fontify operator function name overloading. 1639 ;; Fontify operator function name overloading.
1634 '("\\<\\(operator\\)\\>[ \t]*\\([][)(><!=+-][][)(><!=+-]?\\)?" 1640 '("\\<\\(operator\\)\\>[ \t]*\\([[(><!=+-][])><=+-]?\\)?"
1635 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t)) 1641 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
1636 ;; 1642 ;;
1637 ;; Fontify case/goto keywords and targets, and case default/goto tags. 1643 ;; Fontify case/goto keywords and targets, and case default/goto tags.