]> code.delx.au - gnu-emacs/blobdiff - lisp/font-core.el
(ibuffer-update): Call `minibufferp' with argument
[gnu-emacs] / lisp / font-core.el
index 4447ecd4e7b8498dcdec84764c53c4b2c5aadeb8..0554d65749791438859461e10e87c6122ac8869a 100644 (file)
@@ -25,6 +25,9 @@
 
 ;;; Code:
 
+(defvar font-lock-maximum-size)
+(defvar font-lock-verbose)
+
 ;; This variable is used by mode packages that support Font Lock mode by
 ;; defining their own keywords to use for `font-lock-keywords'.  (The mode
 ;; command should make it buffer-local and set it to provide the set up.)
@@ -67,7 +70,7 @@ around a text block relevant to that mode).
 
 Other variables include that for syntactic keyword fontification,
 `font-lock-syntactic-keywords'
-and those for buffer-specialised fontification functions,
+and those for buffer-specialized fontification functions,
 `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',
 `font-lock-fontify-region-function', `font-lock-unfontify-region-function',
 `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.")
@@ -136,13 +139,11 @@ Major/minor modes can set this variable if they know which option applies.")
 
 (defvar font-lock-fontified nil)       ; Whether we have fontified the buffer.
 
-(defvar font-lock-category-alist nil
-  "An alist of (CATEGORY-SYMBOL . FACE-PROP) controlled by Font Lock.
-This variable is intended to be used by special modes which construct
-buffer text for display to the user (i.e. buffer-menu, occur), but
-wish to have fontification turned on and off by Font Lock.  If this
-variable is non-nil, then calling `font-lock-mode' will simply toggle
-the symbol property `face' of CATEGORY-SYMBOL.")
+(defvar font-lock-function 'font-lock-default-function
+  "A function which is called when `font-lock-mode' is toggled.
+It will be passed one argument, which is the current value of
+`font-lock-mode'.")
+(make-variable-buffer-local 'font-lock-function)
 
 (define-minor-mode font-lock-mode
   "Toggle Font Lock mode.
@@ -198,18 +199,53 @@ syntactic change on other lines, you can use \\[font-lock-fontify-block].
 
 See the variable `font-lock-defaults-alist' for the Font Lock mode default
 settings.  You can set your own default settings for some mode, by setting a
-buffer local value for `font-lock-defaults', via its mode hook."
+buffer local value for `font-lock-defaults', via its mode hook.
+
+The above is the default behavior of `font-lock-mode'; you may specify
+your own function which is called when `font-lock-mode' is toggled via
+`font-lock-function'. "
   nil nil nil
   ;; Don't turn on Font Lock mode if we don't have a display (we're running a
   ;; batch job) or if the buffer is invisible (the name starts with a space).
   (when (or noninteractive (eq (aref (buffer-name) 0) ?\ ))
     (setq font-lock-mode nil))
-
+  (funcall font-lock-function font-lock-mode)
+  ;; Arrange to unfontify this buffer if we change major mode later.
+  (if font-lock-mode
+      (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t)
+    (remove-hook 'change-major-mode-hook 'font-lock-change-mode t)))
+
+;; Get rid of fontification for the old major mode.
+;; We do this when changing major modes.
+(defun font-lock-change-mode ()
+  (font-lock-mode -1))
+
+(defun font-lock-defontify ()
+  "Clear out all `font-lock-face' properties in current buffer.
+A major mode that uses `font-lock-face' properties should put
+this function onto `change-major-mode-hook'."
+  (let ((modp (buffer-modified-p))
+       (inhibit-read-only t))
+    (save-restriction
+      (widen)
+      (remove-list-of-text-properties (point-min) (point-max)
+                                     '(font-lock-face)))
+    (set-buffer-modified-p modp)))
+
+(defun font-lock-default-function (mode)
   ;; Turn on Font Lock mode.
-  (when font-lock-mode
+  (when mode
     (font-lock-set-defaults)
-    (dolist (elt font-lock-category-alist)
-      (put (car elt) 'face (cdr elt)))
+    (set (make-local-variable 'char-property-alias-alist)
+        (copy-tree char-property-alias-alist))
+    ;; Add `font-lock-face' as an alias for the `face' property.
+    (let ((elt (assq 'face char-property-alias-alist)))
+      (if elt
+         (unless (memq 'font-lock-face (cdr elt))
+           (setcdr elt (nconc (cdr elt) (list 'font-lock-face))))
+       (push (list 'face 'font-lock-face) char-property-alias-alist)))
+    ;; Only do hard work if the mode has specified stuff in
+    ;; `font-lock-defaults'.
     (when font-lock-defaults
       (add-hook 'after-change-functions 'font-lock-after-change-function t t)
       (font-lock-turn-on-thing-lock)
@@ -223,9 +259,15 @@ buffer local value for `font-lock-defaults', via its mode hook."
               (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
                        (buffer-name)))))))
   ;; Turn off Font Lock mode.
-  (unless font-lock-mode
-    (dolist (elt font-lock-category-alist)
-      (put (car elt) 'face nil))
+  (unless mode
+    ;; Remove `font-lock-face' as an alias for the `face' property.
+    (set (make-local-variable 'char-property-alias-alist)
+        (copy-tree char-property-alias-alist))
+    (let ((elt (assq 'face char-property-alias-alist)))
+      (when elt
+       (setcdr elt (remq 'font-lock-face (cdr elt)))
+       (when (null (cdr elt))
+         (setq char-property-alias-alist (delq elt char-property-alias-alist)))))
     (when font-lock-defaults
       (remove-hook 'after-change-functions 'font-lock-after-change-function t)
       (font-lock-unfontify-buffer)
@@ -246,12 +288,11 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
     (set (make-local-variable 'font-lock-set-defaults) t)
     (make-local-variable 'font-lock-fontified)
     (make-local-variable 'font-lock-multiline)
-    ;; Detect if this is a simple mode, which doesn't use any
-    ;; syntactic fontification functions.
-    (when (or font-lock-defaults
-             (assq major-mode font-lock-defaults-alist))
-      (require 'font-lock)
-      (font-lock-set-defaults-1))))
+    (let ((defaults (or font-lock-defaults
+                       (cdr (assq major-mode font-lock-defaults-alist)))))
+      (when defaults
+       (require 'font-lock)
+       (font-lock-set-defaults-1)))))
 
 ;;; Global Font Lock mode.
 
@@ -273,7 +314,7 @@ Sets various variables using `font-lock-defaults' (or, if nil, using
 ;; hook is run, the major mode is in the process of being changed and we do not
 ;; know what the final major mode will be.  So, `font-lock-change-major-mode'
 ;; only (a) notes the name of the current buffer, and (b) adds our function
-;; `turn-on-font-lock-if-enabled' to the hook variables `find-file-hooks' and
+;; `turn-on-font-lock-if-enabled' to the hook variables `find-file-hook' and
 ;; `post-command-hook' (for buffers that are not visiting files).  By the time
 ;; the functions on the first of these hooks to be run are run, the new major
 ;; mode is assumed to be in place.  This way we get a Font Lock function run
@@ -325,13 +366,8 @@ means that Font Lock mode is turned on for buffers in C and C++ modes only."
   :group 'font-lock)
 
 (defun turn-on-font-lock-if-enabled ()
-  (when (and (or font-lock-defaults
-                font-lock-category-alist
-                (assq major-mode font-lock-defaults-alist))
-            (or (eq font-lock-global-modes t)
-                (if (eq (car-safe font-lock-global-modes) 'not)
-                    (not (memq major-mode (cdr font-lock-global-modes)))
-                  (memq major-mode font-lock-global-modes))))
+  (unless (and (eq (car-safe font-lock-global-modes) 'not)
+              (memq major-mode (cdr font-lock-global-modes)))
     (let (inhibit-quit)
       (turn-on-font-lock))))