/[emacs]/emacs/lisp/font-core.el
ViewVC logotype

Diff of /emacs/lisp/font-core.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by walters, Sun Jun 9 02:27:43 2002 UTC revision 1.7.2.1 by miles, Fri Apr 4 06:20:05 2003 UTC
# Line 25  Line 25 
25    
26  ;;; Code:  ;;; Code:
27    
28    (defvar font-lock-maximum-size)
29    (defvar font-lock-verbose)
30    
31  ;; This variable is used by mode packages that support Font Lock mode by  ;; This variable is used by mode packages that support Font Lock mode by
32  ;; defining their own keywords to use for `font-lock-keywords'.  (The mode  ;; defining their own keywords to use for `font-lock-keywords'.  (The mode
33  ;; command should make it buffer-local and set it to provide the set up.)  ;; command should make it buffer-local and set it to provide the set up.)
# Line 67  around a text block relevant to that mod Line 70  around a text block relevant to that mod
70    
71  Other variables include that for syntactic keyword fontification,  Other variables include that for syntactic keyword fontification,
72  `font-lock-syntactic-keywords'  `font-lock-syntactic-keywords'
73  and those for buffer-specialised fontification functions,  and those for buffer-specialized fontification functions,
74  `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',  `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',
75  `font-lock-fontify-region-function', `font-lock-unfontify-region-function',  `font-lock-fontify-region-function', `font-lock-unfontify-region-function',
76  `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.")  `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.")
77  (make-variable-buffer-local 'font-lock-defaults)  (make-variable-buffer-local 'font-lock-defaults)
78    
 (defvar font-lock-core-only nil  
   "If non-nil, then don't load font-lock.el unless necessary.")  
   
79  ;; This variable is used where font-lock.el itself supplies the  ;; This variable is used where font-lock.el itself supplies the
80  ;; keywords.  Really, this shouldn't need to be in font-core.el, but  ;; keywords.  Really, this shouldn't need to be in font-core.el, but
81  ;; we can't avoid it.  In the future, this stuff will hopefully be  ;; we can't avoid it.  In the future, this stuff will hopefully be
# Line 143  Major/minor modes can set this variable Line 143  Major/minor modes can set this variable
143    "A function which is called when `font-lock-mode' is toggled.    "A function which is called when `font-lock-mode' is toggled.
144  It will be passed one argument, which is the current value of  It will be passed one argument, which is the current value of
145  `font-lock-mode'.")  `font-lock-mode'.")
146  (make-variable-buffer-local 'font-lock-default-function)  (make-variable-buffer-local 'font-lock-function)
147    
148  (define-minor-mode font-lock-mode  (define-minor-mode font-lock-mode
149    "Toggle Font Lock mode.    "Toggle Font Lock mode.
# Line 209  your own function which is called when ` Line 209  your own function which is called when `
209    ;; batch job) or if the buffer is invisible (the name starts with a space).    ;; batch job) or if the buffer is invisible (the name starts with a space).
210    (when (or noninteractive (eq (aref (buffer-name) 0) ?\ ))    (when (or noninteractive (eq (aref (buffer-name) 0) ?\ ))
211      (setq font-lock-mode nil))      (setq font-lock-mode nil))
212    (funcall font-lock-function font-lock-mode))    (funcall font-lock-function font-lock-mode)
213      ;; Arrange to unfontify this buffer if we change major mode later.
214      (if font-lock-mode
215          (add-hook 'change-major-mode-hook 'font-lock-change-mode nil t)
216        (remove-hook 'change-major-mode-hook 'font-lock-change-mode t)))
217    
218    ;; Get rid of fontification for the old major mode.
219    ;; We do this when changing major modes.
220    (defun font-lock-change-mode ()
221      (font-lock-mode -1))
222    
223    (defun font-lock-defontify ()
224      "Clear out all `font-lock-face' properties in current buffer.
225    A major mode that uses `font-lock-face' properties should put
226    this function onto `change-major-mode-hook'."
227      (let ((modp (buffer-modified-p))
228            (inhibit-read-only t))
229        (save-restriction
230          (widen)
231          (remove-list-of-text-properties (point-min) (point-max)
232                                          '(font-lock-face)))
233        (restore-buffer-modified-p modp)))
234    
235  (defun font-lock-default-function (font-lock-mode)  (defun font-lock-default-function (mode)
236    ;; Turn on Font Lock mode.    ;; Turn on Font Lock mode.
237    (when font-lock-mode    (when mode
238      (font-lock-set-defaults)      (font-lock-set-defaults)
239      (set (make-local-variable 'char-property-alias-alist)      (set (make-local-variable 'char-property-alias-alist)
240           (copy-tree char-property-alias-alist))           (copy-tree char-property-alias-alist))
# Line 225  your own function which is called when ` Line 246  your own function which is called when `
246          (push (list 'face 'font-lock-face) char-property-alias-alist)))          (push (list 'face 'font-lock-face) char-property-alias-alist)))
247      ;; Only do hard work if the mode has specified stuff in      ;; Only do hard work if the mode has specified stuff in
248      ;; `font-lock-defaults'.      ;; `font-lock-defaults'.
249      (when (and font-lock-defaults      (when font-lock-defaults
                (not font-lock-core-only))  
250        (add-hook 'after-change-functions 'font-lock-after-change-function t t)        (add-hook 'after-change-functions 'font-lock-after-change-function t t)
251        (font-lock-turn-on-thing-lock)        (font-lock-turn-on-thing-lock)
252        ;; Fontify the buffer if we have to.        ;; Fontify the buffer if we have to.
# Line 239  your own function which is called when ` Line 259  your own function which is called when `
259                 (message "Fontifying %s...buffer size greater than font-lock-maximum-size"                 (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
260                          (buffer-name)))))))                          (buffer-name)))))))
261    ;; Turn off Font Lock mode.    ;; Turn off Font Lock mode.
262    (unless font-lock-mode    (unless mode
263      ;; Remove `font-lock-face' as an alias for the `face' property.      ;; Remove `font-lock-face' as an alias for the `face' property.
264      (set (make-local-variable 'char-property-alias-alist)      (set (make-local-variable 'char-property-alias-alist)
265           (copy-tree char-property-alias-alist))           (copy-tree char-property-alias-alist))
# Line 248  your own function which is called when ` Line 268  your own function which is called when `
268          (setcdr elt (remq 'font-lock-face (cdr elt)))          (setcdr elt (remq 'font-lock-face (cdr elt)))
269          (when (null (cdr elt))          (when (null (cdr elt))
270            (setq char-property-alias-alist (delq elt char-property-alias-alist)))))            (setq char-property-alias-alist (delq elt char-property-alias-alist)))))
271      (when (and font-lock-defaults      (when font-lock-defaults
                (not font-lock-core-only))  
272        (remove-hook 'after-change-functions 'font-lock-after-change-function t)        (remove-hook 'after-change-functions 'font-lock-after-change-function t)
273        (font-lock-unfontify-buffer)        (font-lock-unfontify-buffer)
274        (font-lock-turn-off-thing-lock))))        (font-lock-turn-off-thing-lock))))
275      
276  (defun turn-on-font-lock ()  (defun turn-on-font-lock ()
277    "Turn on Font Lock mode (only if the terminal can display it)."    "Turn on Font Lock mode (only if the terminal can display it)."
278    (unless font-lock-mode    (unless font-lock-mode
# Line 271  Sets various variables using `font-lock- Line 290  Sets various variables using `font-lock-
290      (make-local-variable 'font-lock-multiline)      (make-local-variable 'font-lock-multiline)
291      (let ((defaults (or font-lock-defaults      (let ((defaults (or font-lock-defaults
292                          (cdr (assq major-mode font-lock-defaults-alist)))))                          (cdr (assq major-mode font-lock-defaults-alist)))))
293        ;; Variable alist?        (when defaults
       (dolist (x (nthcdr 5 defaults))  
         (set (make-local-variable (car x)) (cdr x)))  
       (when (and defaults  
                  ;; Detect if this is a simple mode, which doesn't use  
                  ;; any syntactic fontification functions.  
                  (not font-lock-core-only))  
294          (require 'font-lock)          (require 'font-lock)
295          (font-lock-set-defaults-1)))))          (font-lock-set-defaults-1)))))
296    
# Line 301  Sets various variables using `font-lock- Line 314  Sets various variables using `font-lock-
314  ;; hook is run, the major mode is in the process of being changed and we do not  ;; hook is run, the major mode is in the process of being changed and we do not
315  ;; know what the final major mode will be.  So, `font-lock-change-major-mode'  ;; know what the final major mode will be.  So, `font-lock-change-major-mode'
316  ;; only (a) notes the name of the current buffer, and (b) adds our function  ;; only (a) notes the name of the current buffer, and (b) adds our function
317  ;; `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
318  ;; `post-command-hook' (for buffers that are not visiting files).  By the time  ;; `post-command-hook' (for buffers that are not visiting files).  By the time
319  ;; the functions on the first of these hooks to be run are run, the new major  ;; the functions on the first of these hooks to be run are run, the new major
320  ;; mode is assumed to be in place.  This way we get a Font Lock function run  ;; mode is assumed to be in place.  This way we get a Font Lock function run
# Line 353  means that Font Lock mode is turned on f Line 366  means that Font Lock mode is turned on f
366    :group 'font-lock)    :group 'font-lock)
367    
368  (defun turn-on-font-lock-if-enabled ()  (defun turn-on-font-lock-if-enabled ()
369    (when (and (or font-lock-defaults    (unless (and (eq (car-safe font-lock-global-modes) 'not)
370                   (assq major-mode font-lock-defaults-alist))                 (memq major-mode (cdr font-lock-global-modes)))
              (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))))  
371      (let (inhibit-quit)      (let (inhibit-quit)
372        (turn-on-font-lock))))        (turn-on-font-lock))))
373    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.7.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26