comparison lisp/font-lock.el @ 11467:bb7c9db199ae

(font-lock-make-faces): Determine font-lock-background-mode from color values of background color. (font-lock-make-faces-done): New variable. (font-lock-make-faces): Set font-lock-make-faces-done to t. Don't call it when loading the file. (font-lock-mode): Call font-lock-make-faces if not yet done.
author Richard M. Stallman <rms@gnu.org>
date Sun, 16 Apr 1995 05:41:53 +0000
parents 73ce8261c2ce
children 0ebfc7701ebf
comparison
equal deleted inserted replaced
11466:8fb524439d09 11467:bb7c9db199ae
207 207
208 Resources can be used to over-ride these face attributes. For example, the 208 Resources can be used to over-ride these face attributes. For example, the
209 resource `Emacs.font-lock-comment-face.attributeUnderline' can be used to 209 resource `Emacs.font-lock-comment-face.attributeUnderline' can be used to
210 specify the UNDERLINE-P attribute for face `font-lock-comment-face'.") 210 specify the UNDERLINE-P attribute for face `font-lock-comment-face'.")
211 211
212 (defvar font-lock-make-faces-done nil
213 "Non-nil if have already set up the faces for Font-Lock mode.")
214
212 (defun font-lock-make-faces () 215 (defun font-lock-make-faces ()
213 "Make faces from `font-lock-face-attributes'. 216 "Make faces from `font-lock-face-attributes'.
214 A default list is used if this is nil. 217 A default list is used if this is nil.
215 See `font-lock-make-face' and `list-faces-display'." 218 See `font-lock-make-face' and `list-faces-display'."
216 ;; We don't need to `setq' any of these variables, but the user can see what 219 ;; We don't need to `setq' any of these variables, but the user can see what
227 (setq font-lock-background-mode 230 (setq font-lock-background-mode
228 (let ((bg-resource (x-get-resource ".backgroundMode" 231 (let ((bg-resource (x-get-resource ".backgroundMode"
229 "BackgroundMode")) 232 "BackgroundMode"))
230 (params (frame-parameters))) 233 (params (frame-parameters)))
231 (cond (bg-resource (intern (downcase bg-resource))) 234 (cond (bg-resource (intern (downcase bg-resource)))
232 ((or (string-equal "white" 235 ((< (apply '+ (x-color-values
233 (downcase (cdr (assq 'foreground-color params)))) 236 (cdr (assq 'background-color params))))
234 (string-equal "black" 237 (/ (apply '+ (x-color-values "white")) 3))
235 (downcase (cdr (assq 'background-color params)))))
236 'dark) 238 'dark)
237 (t 'light))))) 239 (t 'light)))))
238 (if (null font-lock-face-attributes) 240 (if (null font-lock-face-attributes)
239 (setq font-lock-face-attributes 241 (setq font-lock-face-attributes
240 (let ((light-bg (eq font-lock-background-mode 'light))) 242 (let ((light-bg (eq font-lock-background-mode 'light)))
289 (font-lock-keyword-face "LightSteelBlue") 291 (font-lock-keyword-face "LightSteelBlue")
290 (font-lock-function-name-face "LightSkyBlue") 292 (font-lock-function-name-face "LightSkyBlue")
291 (font-lock-variable-name-face "LightGoldenrod") 293 (font-lock-variable-name-face "LightGoldenrod")
292 (font-lock-type-face "PaleGreen") 294 (font-lock-type-face "PaleGreen")
293 (font-lock-reference-face "Aquamarine"))))))) 295 (font-lock-reference-face "Aquamarine")))))))
294 (mapcar 'font-lock-make-face font-lock-face-attributes)) 296 (mapcar 'font-lock-make-face font-lock-face-attributes)
297 (setq font-lock-make-faces-done t))
295 298
296 (defun font-lock-make-face (face-attributes) 299 (defun font-lock-make-face (face-attributes)
297 "Make a face from FACE-ATTRIBUTES. 300 "Make a face from FACE-ATTRIBUTES.
298 FACE-ATTRIBUTES should be like an element `font-lock-face-attributes', so that 301 FACE-ATTRIBUTES should be like an element `font-lock-face-attributes', so that
299 the face name is the first item in the list. A variable with the same name as 302 the face name is the first item in the list. A variable with the same name as
581 When you turn Font Lock mode on/off the buffer is fontified/defontified, though 584 When you turn Font Lock mode on/off the buffer is fontified/defontified, though
582 fontification occurs only if the buffer is less than `font-lock-maximum-size'. 585 fontification occurs only if the buffer is less than `font-lock-maximum-size'.
583 To fontify a buffer without turning on Font Lock mode, and regardless of buffer 586 To fontify a buffer without turning on Font Lock mode, and regardless of buffer
584 size, you can use \\[font-lock-fontify-buffer]." 587 size, you can use \\[font-lock-fontify-buffer]."
585 (interactive "P") 588 (interactive "P")
589
590 (or font-lock-make-faces-done
591 (font-lock-make-faces))
592
586 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) (not font-lock-mode)))) 593 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) (not font-lock-mode))))
587 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp... 594 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp...
588 (setq on-p nil)) 595 (setq on-p nil))
589 (if (not on-p) 596 (if (not on-p)
590 (remove-hook 'after-change-functions 'font-lock-after-change-function) 597 (remove-hook 'after-change-functions 'font-lock-after-change-function)
926 font-lock-syntax-table) 933 font-lock-syntax-table)
927 (setq slist (cdr slist)))))))) 934 (setq slist (cdr slist))))))))
928 935
929 ;; Install ourselves: 936 ;; Install ourselves:
930 937
931 (if purify-flag
932 (add-hook 'after-init-hook 'font-lock-make-faces)
933 (font-lock-make-faces))
934
935 (or (assq 'font-lock-mode minor-mode-alist) 938 (or (assq 'font-lock-mode minor-mode-alist)
936 (setq minor-mode-alist (cons '(font-lock-mode " Font") minor-mode-alist))) 939 (setq minor-mode-alist (cons '(font-lock-mode " Font") minor-mode-alist)))
937 940
938 ;; Provide ourselves: 941 ;; Provide ourselves:
939 942