1 ;;; faces.el --- Lisp interface to the c "face" structure
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
24 ;; Mostly derived from Lucid.
29 ;; These used to be defsubsts, now they're subrs. Avoid losing if we're
30 ;; being compiled with an old Emacs that still has defsubrs in it.
31 (put 'face-name
'byte-optimizer nil
)
32 (put 'face-id
'byte-optimizer nil
)
33 (put 'face-font
'byte-optimizer nil
)
34 (put 'face-font-explicit
'byte-optimizer nil
)
35 (put 'face-foreground
'byte-optimizer nil
)
36 (put 'face-background
'byte-optimizer nil
)
37 (put 'face-stipple
'byte-optimizer nil
)
38 (put 'face-underline-p
'byte-optimizer nil
)
39 (put 'set-face-font
'byte-optimizer nil
)
40 (put 'set-face-font-auto
'byte-optimizer nil
)
41 (put 'set-face-foreground
'byte-optimizer nil
)
42 (put 'set-face-background
'byte-optimizer nil
)
43 (put 'set-face-stipple
'byte-optimizer nil
)
44 (put 'set-face-underline-p
'byte-optimizer nil
))
46 ;;;; Functions for manipulating face vectors.
48 ;;; A face vector is a vector of the form:
49 ;;; [face NAME ID FONT FOREGROUND BACKGROUND STIPPLE
50 ;;; UNDERLINE-P INVERSE-VIDEO-P FONT-EXPLICIT-P BOLD-P ITALIC-P]
53 (defsubst internal-facep
(x)
54 (and (vectorp x
) (= (length x
) 12) (eq (aref x
0) 'face
)))
57 "Return t if X is a face name or an internal face vector."
58 (and (or (internal-facep x
)
59 (and (symbolp x
) (assq x global-face-data
)))
62 (defmacro internal-check-face
(face)
63 (` (or (internal-facep (, face
))
64 (signal 'wrong-type-argument
(list 'internal-facep
(, face
))))))
67 (defun face-name (face)
68 "Return the name of face FACE."
69 (aref (internal-get-face face
) 1))
72 "Return the internal ID number of face FACE."
73 (aref (internal-get-face face
) 2))
75 (defun face-font (face &optional frame
)
76 "Return the font name of face FACE, or nil if it is unspecified.
77 If the optional argument FRAME is given, report on face FACE in that frame.
78 If FRAME is t, report on the defaults for face FACE (for new frames).
79 The font default for a face is either nil, or a list
80 of the form (bold), (italic) or (bold italic).
81 If FRAME is omitted or nil, use the selected frame."
82 (aref (internal-get-face face frame
) 3))
84 (defun face-foreground (face &optional frame
)
85 "Return the foreground color name of face FACE, or nil if unspecified.
86 If the optional argument FRAME is given, report on face FACE in that frame.
87 If FRAME is t, report on the defaults for face FACE (for new frames).
88 If FRAME is omitted or nil, use the selected frame."
89 (aref (internal-get-face face frame
) 4))
91 (defun face-background (face &optional frame
)
92 "Return the background color name of face FACE, or nil if unspecified.
93 If the optional argument FRAME is given, report on face FACE in that frame.
94 If FRAME is t, report on the defaults for face FACE (for new frames).
95 If FRAME is omitted or nil, use the selected frame."
96 (aref (internal-get-face face frame
) 5))
98 (defun face-stipple (face &optional frame
)
99 "Return the stipple pixmap name of face FACE, or nil if unspecified.
100 If the optional argument FRAME is given, report on face FACE in that frame.
101 If FRAME is t, report on the defaults for face FACE (for new frames).
102 If FRAME is omitted or nil, use the selected frame."
103 (aref (internal-get-face face frame
) 6))
105 (defalias 'face-background-pixmap
'face-stipple
)
107 (defun face-underline-p (face &optional frame
)
108 "Return t if face FACE is underlined.
109 If the optional argument FRAME is given, report on face FACE in that frame.
110 If FRAME is t, report on the defaults for face FACE (for new frames).
111 If FRAME is omitted or nil, use the selected frame."
112 (aref (internal-get-face face frame
) 7))
114 (defun face-inverse-video-p (face &optional frame
)
115 "Return t if face FACE is in inverse video.
116 If the optional argument FRAME is given, report on face FACE in that frame.
117 If FRAME is t, report on the defaults for face FACE (for new frames).
118 If FRAME is omitted or nil, use the selected frame."
119 (aref (internal-get-face face frame
) 8))
121 (defun face-font-explicit (face &optional frame
)
122 "Return non-nil if this face's font was explicitly specified."
123 (aref (internal-get-face face frame
) 9))
125 (defun face-bold-p (face &optional frame
)
126 "Return non-nil if the font of FACE is bold.
127 If the optional argument FRAME is given, report on face FACE in that frame.
128 If FRAME is t, report on the defaults for face FACE (for new frames).
129 If FRAME is omitted or nil, use the selected frame."
130 (aref (internal-get-face face frame
) 10))
132 (defun face-italic-p (face &optional frame
)
133 "Return non-nil if the font of FACE is italic.
134 If the optional argument FRAME is given, report on face FACE in that frame.
135 If FRAME is t, report on the defaults for face FACE (for new frames).
136 If FRAME is omitted or nil, use the selected frame."
137 (aref (internal-get-face face frame
) 11))
139 (defalias 'face-doc-string
'face-documentation
)
140 (defun face-documentation (face)
141 "Get the documentation string for FACE."
142 (get face
'face-documentation
))
146 (defun set-face-font (face font
&optional frame
)
147 "Change the font of face FACE to FONT (a string).
148 If the optional FRAME argument is provided, change only
149 in that frame; otherwise change each frame."
150 (interactive (internal-face-interactive "font"))
152 (setq font
(or (query-fontset font
)
153 (x-resolve-font-name font
'default frame
))))
154 (internal-set-face-1 face
'font font
3 frame
)
155 ;; Record that this face's font was set explicitly, not automatically,
156 ;; unless we are setting it to nil.
157 (internal-set-face-1 face nil
(not (null font
)) 9 frame
))
159 (defun set-face-font-auto (face font
&optional frame
)
160 "Change the font of face FACE to FONT (a string), for an automatic change.
161 An automatic change means that we don't change the \"explicit\" flag;
162 if the font was derived from the frame font before, it is now.
163 If the optional FRAME argument is provided, change only
164 in that frame; otherwise change each frame."
165 (interactive (internal-face-interactive "font"))
167 (setq font
(or (and (fontset-name-p font
)
168 (or (query-fontset font
)
169 (instanciate-fontset font
)))
170 (x-resolve-font-name font
'default frame
))))
171 (internal-set-face-1 face
'font font
3 frame
))
173 (defun set-face-font-explicit (face flag
&optional frame
)
174 "Set the explicit-font flag of face FACE to FLAG.
175 If the optional FRAME argument is provided, change only
176 in that frame; otherwise change each frame."
177 (internal-set-face-1 face nil flag
9 frame
))
179 (defun set-face-foreground (face color
&optional frame
)
180 "Change the foreground color of face FACE to COLOR (a string).
181 If the optional FRAME argument is provided, change only
182 in that frame; otherwise change each frame."
183 (interactive (internal-face-interactive "foreground" 'color
))
184 (internal-set-face-1 face
'foreground color
4 frame
))
186 (defvar face-default-stipple
"gray3"
187 "Default stipple pattern used on monochrome displays.
188 This stipple pattern is used on monochrome displays
189 instead of shades of gray for a face background color.
190 See `set-face-stipple' for possible values for this variable.")
192 (defun face-color-gray-p (color &optional frame
)
193 "Return t if COLOR is a shade of gray (or white or black).
194 FRAME specifies the frame and thus the display for interpreting COLOR."
195 (let* ((values (x-color-values color frame
))
200 (< (abs (- r g
)) (/ (max 1 (abs r
) (abs g
)) 20))
201 (< (abs (- g b
)) (/ (max 1 (abs g
) (abs b
)) 20))
202 (< (abs (- b r
)) (/ (max 1 (abs b
) (abs r
)) 20)))))
204 (defun set-face-background (face color
&optional frame
)
205 "Change the background color of face FACE to COLOR (a string).
206 If the optional FRAME argument is provided, change only
207 in that frame; otherwise change each frame."
208 (interactive (internal-face-interactive "background" 'color
))
209 ;; For a specific frame, use gray stipple instead of gray color
210 ;; if the display does not support a gray color.
211 (if (and frame
(not (eq frame t
)) color
212 ;; Check for support for foreground, not for background!
213 ;; face-color-supported-p is smart enough to know
214 ;; that grays are "supported" as background
215 ;; because we are supposed to use stipple for them!
216 (not (face-color-supported-p frame color nil
)))
217 (set-face-stipple face face-default-stipple frame
)
219 (let ((frames (frame-list)))
221 (set-face-background (face-name face
) color
(car frames
))
222 (setq frames
(cdr frames
)))
223 (set-face-background face color t
)
225 (internal-set-face-1 face
'background color
5 frame
))))
227 (defun set-face-stipple (face pixmap
&optional frame
)
228 "Change the stipple pixmap of face FACE to PIXMAP.
229 PIXMAP should be a string, the name of a file of pixmap data.
230 The directories listed in the `x-bitmap-file-path' variable are searched.
232 Alternatively, PIXMAP may be a list of the form (WIDTH HEIGHT DATA)
233 where WIDTH and HEIGHT are the size in pixels,
234 and DATA is a string, containing the raw bits of the bitmap.
236 If the optional FRAME argument is provided, change only
237 in that frame; otherwise change each frame."
238 (interactive (internal-face-interactive-stipple "stipple"))
239 (internal-set-face-1 face
'background-pixmap pixmap
6 frame
))
241 (defalias 'set-face-background-pixmap
'set-face-stipple
)
243 (defun set-face-underline-p (face underline-p
&optional frame
)
244 "Specify whether face FACE is underlined. (Yes if UNDERLINE-P is non-nil.)
245 If the optional FRAME argument is provided, change only
246 in that frame; otherwise change each frame."
247 (interactive (internal-face-interactive "underline-p" "underlined"))
248 (internal-set-face-1 face
'underline underline-p
7 frame
))
250 (defun set-face-inverse-video-p (face inverse-video-p
&optional frame
)
251 "Specify whether face FACE is in inverse video.
252 \(Yes if INVERSE-VIDEO-P is non-nil.)
253 If the optional FRAME argument is provided, change only
254 in that frame; otherwise change each frame."
255 (interactive (internal-face-interactive "inverse-video-p" "inverse-video"))
256 (internal-set-face-1 face
'inverse-video inverse-video-p
8 frame
))
258 (defun set-face-bold-p (face bold-p
&optional frame
)
259 "Specify whether face FACE is bold. (Yes if BOLD-P is non-nil.)
260 If the optional FRAME argument is provided, change only
261 in that frame; otherwise change each frame."
262 (cond ((eq bold-p nil
) (make-face-unbold face frame t
))
263 (t (make-face-bold face frame t
))))
265 (defun set-face-italic-p (face italic-p
&optional frame
)
266 "Specify whether face FACE is italic. (Yes if ITALIC-P is non-nil.)
267 If the optional FRAME argument is provided, change only
268 in that frame; otherwise change each frame."
269 (cond ((eq italic-p nil
) (make-face-unitalic face frame t
))
270 (t (make-face-italic face frame t
))))
272 (defalias 'set-face-doc-string
'set-face-documentation
)
273 (defun set-face-documentation (face string
)
274 "Set the documentation string for FACE to STRING."
275 (put face
'face-documentation string
))
277 (defun modify-face-read-string (face default name alist
)
281 (format "Set face %s %s (default %s): "
282 face name
(downcase default
))
283 (format "Set face %s %s: " face name
))
285 (cond ((equal value
"none")
291 (defun modify-face (face foreground background stipple
292 bold-p italic-p underline-p
&optional inverse-p frame
)
293 "Change the display attributes for face FACE.
294 If the optional FRAME argument is provided, change only
295 in that frame; otherwise change each frame.
297 FOREGROUND and BACKGROUND should be a colour name string (or list of strings to
298 try) or nil. STIPPLE should be a stipple pattern name string or nil.
299 If nil, means do not change the display attribute corresponding to that arg.
301 BOLD-P, ITALIC-P, UNDERLINE-P, and INVERSE-P specify whether
302 the face should be set bold, italic, underlined or in inverse-video,
303 respectively. If one of these arguments is neither nil or t, it means do not
304 change the display attribute corresponding to that argument.
306 If called interactively, prompts for a face name and face attributes."
308 (let* ((completion-ignore-case t
)
309 (face (symbol-name (read-face-name "Modify face: ")))
310 (colors (mapcar 'list x-colors
))
311 (stipples (mapcar 'list
(apply 'nconc
312 (mapcar 'directory-files
313 x-bitmap-file-path
))))
314 (foreground (modify-face-read-string
315 face
(face-foreground (intern face
))
316 "foreground" colors
))
317 (background (modify-face-read-string
318 face
(face-background (intern face
))
319 "background" colors
))
320 ;; If the stipple value is a list (WIDTH HEIGHT DATA),
321 ;; represent that as a string by printing it out.
323 (if (stringp (face-stipple (intern face
)))
324 (face-stipple (intern face
))
325 (if (face-stipple (intern face
))
326 (prin1-to-string (face-stipple (intern face
))))))
328 (modify-face-read-string
329 face old-stipple-string
331 ;; Convert the stipple value text we read
332 ;; back to a list if it looks like one.
333 ;; This makes the assumption that a pixmap file name
334 ;; won't start with an open-paren.
336 (and new-stipple-string
337 (if (string-match "^(" new-stipple-string
)
338 (read new-stipple-string
)
339 new-stipple-string
)))
340 (bold-p (y-or-n-p (concat "Should face " face
" be bold ")))
341 (italic-p (y-or-n-p (concat "Should face " face
" be italic ")))
342 (underline-p (y-or-n-p (concat "Should face " face
" be underlined ")))
343 (inverse-p (y-or-n-p (concat "Should face " face
" be inverse-video ")))
344 (all-frames-p (y-or-n-p (concat "Modify face " face
" in all frames "))))
345 (message "Face %s: %s" face
348 (list (and foreground
(concat (downcase foreground
) " foreground"))
349 (and background
(concat (downcase background
) " background"))
350 (and stipple
(concat (downcase new-stipple-string
) " stipple"))
351 (and bold-p
"bold") (and italic-p
"italic")
352 (and inverse-p
"inverse")
353 (and underline-p
"underline"))) ", "))
354 (list (intern face
) foreground background stipple
355 bold-p italic-p underline-p inverse-p
356 (if all-frames-p nil
(selected-frame)))))
357 ;; Clear this before we install the new foreground and background;
358 ;; otherwise, clearing it after would swap them!
359 (when (and (or foreground background
) (face-inverse-video-p face
))
360 (set-face-inverse-video-p face nil frame
)
361 ;; Arrange to restore it after, if we are not setting it now.
362 (or (memq inverse-p
'(t nil
))
365 (face-try-color-list 'set-face-foreground face foreground frame
)
368 (face-try-color-list 'set-face-background face background frame
)
371 (set-face-stipple face stipple frame
)
373 ;; Now that we have the new colors,
374 (if (memq inverse-p
'(nil t
))
375 (set-face-inverse-video-p face inverse-p frame
))
376 (cond ((eq bold-p nil
)
377 (if (face-font face frame
)
378 (make-face-unbold face frame t
)))
380 (make-face-bold face frame t
)))
381 (cond ((eq italic-p nil
)
382 (if (face-font face frame
)
383 (make-face-unitalic face frame t
)))
384 ((eq italic-p t
) (make-face-italic face frame t
)))
385 (if (memq underline-p
'(nil t
))
386 (set-face-underline-p face underline-p frame
))
387 (and (interactive-p) (redraw-display)))
389 ;;;; Associating face names (symbols) with their face vectors.
391 (defvar global-face-data nil
392 "Internal data for face support functions. Not for external use.
393 This is an alist associating face names with the default values for
394 their parameters. Newly created frames get their data from here.")
397 "Returns a list of all defined face names."
398 (mapcar 'car global-face-data
))
400 (defun internal-find-face (name &optional frame
)
401 "Retrieve the face named NAME. Return nil if there is no such face.
402 If the optional argument FRAME is given, this gets the face NAME for
403 that frame; otherwise, it uses the selected frame.
404 If FRAME is the symbol t, then the global, non-frame face is returned.
405 If NAME is already a face, it is simply returned."
406 (if (and (eq frame t
) (not (symbolp name
)))
407 (setq name
(face-name name
)))
412 (frame-face-alist (or frame
(selected-frame))))))
413 (internal-check-face name
)
416 (defun internal-get-face (name &optional frame
)
417 "Retrieve the face named NAME; error if there is none.
418 If the optional argument FRAME is given, this gets the face NAME for
419 that frame; otherwise, it uses the selected frame.
420 If FRAME is the symbol t, then the global, non-frame face is returned.
421 If NAME is already a face, it is simply returned."
422 (or (internal-find-face name frame
)
423 (internal-check-face name
)))
426 (defun internal-set-face-1 (face name value index frame
)
427 (let ((inhibit-quit t
))
429 (let ((frames (frame-list)))
431 (internal-set-face-1 (face-name face
) name value index
(car frames
))
432 (setq frames
(cdr frames
)))
433 (aset (internal-get-face (if (symbolp face
) face
(face-name face
)) t
)
436 (let ((internal-face (internal-get-face face frame
)))
438 (if (eq name
'inverse-video
)
439 (or (eq value
(aref internal-face index
))
440 (invert-face face frame
))
441 (and name
(fboundp 'set-face-attribute-internal
)
442 (set-face-attribute-internal (face-id face
)
444 (aset internal-face index value
)))))
447 (defun read-face-name (prompt)
449 (while (= (length face
) 0)
450 (setq face
(completing-read prompt
451 (mapcar '(lambda (x) (list (symbol-name x
)))
456 (defun internal-face-interactive (what &optional bool
)
457 (let* ((fn (intern (concat "face-" what
)))
458 (prompt (concat "Set " what
" of face"))
459 (face (read-face-name (concat prompt
": ")))
460 (default (if (fboundp fn
)
461 (or (funcall fn face
(selected-frame))
462 (funcall fn
'default
(selected-frame)))))
465 (cond ((eq bool
'color
)
466 (completing-read (concat prompt
" " (symbol-name face
) " to: ")
467 (mapcar (function (lambda (color)
470 nil nil nil nil default
))
472 (y-or-n-p (concat "Should face " (symbol-name face
)
475 (read-string (concat prompt
" " (symbol-name face
) " to: ")
477 (list face
(if (equal value
"") nil value
))))
479 (defun internal-face-interactive-stipple (what)
480 (let* ((fn (intern (concat "face-" what
)))
481 (prompt (concat "Set " what
" of face"))
482 (face (read-face-name (concat prompt
": ")))
483 (default (if (fboundp fn
)
484 (or (funcall fn face
(selected-frame))
485 (funcall fn
'default
(selected-frame)))))
486 ;; If the stipple value is a list (WIDTH HEIGHT DATA),
487 ;; represent that as a string by printing it out.
489 (if (stringp (face-stipple face
))
491 (if (null (face-stipple face
))
493 (prin1-to-string (face-stipple face
)))))
496 (concat prompt
" " (symbol-name face
) " to: ")
498 ;; Convert the stipple value text we read
499 ;; back to a list if it looks like one.
500 ;; This makes the assumption that a pixmap file name
501 ;; won't start with an open-paren.
503 (if (string-match "^(" new-stipple-string
)
504 (read new-stipple-string
)
505 new-stipple-string
)))
506 (list face
(if (equal stipple
"") nil stipple
))))
508 (defun make-face (name &optional no-resources
)
509 "Define a new FACE on all frames.
510 You can modify the font, color, etc of this face with the set-face- functions.
511 If NO-RESOURCES is non-nil, then we ignore X resources
512 and always make a face whose attributes are all nil.
514 If the face already exists, it is unmodified."
515 (interactive "SMake face: ")
516 (or (internal-find-face name
)
517 (let ((face (make-vector 12 nil
)))
520 (let* ((frames (frame-list))
522 (id (internal-next-face-id)))
523 (if (fboundp 'make-face-internal
)
524 (make-face-internal id
))
527 (set-frame-face-alist (car frames
)
528 (cons (cons name
(copy-sequence face
))
529 (frame-face-alist (car frames
))))
530 (setq frames
(cdr frames
)))
531 (setq global-face-data
(cons (cons name face
) global-face-data
)))
532 ;; When making a face after frames already exist
534 (if (memq window-system
'(x w32
))
535 (make-face-x-resource-internal face
)))
536 ;; Add to menu of faces.
537 (if (fboundp 'facemenu-add-new-face
)
538 (facemenu-add-new-face name
))
542 (defun make-empty-face (face)
543 "Define a new FACE on all frames, which initially reflects the defaults.
544 You can modify the font, color, etc of this face with the set-face- functions.
545 If the face already exists, it is unmodified."
546 (interactive "SMake empty face: ")
549 ;; Fill in a face by default based on X resources, for all existing frames.
550 ;; This has to be done when a new face is made.
551 (defun make-face-x-resource-internal (face &optional frame set-anyway
)
553 (let ((frames (frame-list)))
555 (if (memq (framep (car frames
)) '(x w32
))
556 (make-face-x-resource-internal (face-name face
)
557 (car frames
) set-anyway
))
558 (setq frames
(cdr frames
)))))
560 (setq face
(internal-get-face (face-name face
) frame
))
562 ;; These are things like "attributeForeground" instead of simply
563 ;; "foreground" because people tend to do things like "*foreground",
564 ;; which would cause all faces to be fully qualified, making faces
565 ;; inherit attributes in a non-useful way. So we've made them slightly
566 ;; less obvious to specify in order to make them work correctly in
567 ;; more random environments.
569 ;; I think these should be called "face.faceForeground" instead of
570 ;; "face.attributeForeground", but they're the way they are for
571 ;; hysterical reasons.
573 (let* ((name (symbol-name (face-name face
)))
574 (fn (or (x-get-resource (concat name
".attributeFont")
575 "Face.AttributeFont")
576 (and set-anyway
(face-font face
))))
577 (fg (or (x-get-resource (concat name
".attributeForeground")
578 "Face.AttributeForeground")
579 (and set-anyway
(face-foreground face
))))
580 (bg (or (x-get-resource (concat name
".attributeBackground")
581 "Face.AttributeBackground")
582 (and set-anyway
(face-background face
))))
583 (bgp (or (x-get-resource (concat name
".attributeStipple")
584 "Face.AttributeStipple")
585 (x-get-resource (concat name
".attributeBackgroundPixmap")
586 "Face.AttributeBackgroundPixmap")
587 (and set-anyway
(face-stipple face
))))
588 (ulp (let ((resource (x-get-resource
589 (concat name
".attributeUnderline")
590 "Face.AttributeUnderline")))
592 (member (downcase resource
) '("on" "true"))
593 (and set-anyway
(face-underline-p face
)))))
597 (cond ((string= fn
"italic")
598 (make-face-italic face
))
600 (make-face-bold face
))
601 ((string= fn
"bold-italic")
602 (make-face-bold-italic face
))
604 (set-face-font face fn frame
)))
606 (if (member fn
'("italic" "bold" "bold-italic"))
607 (message "no %s version found for face `%s'" fn name
)
608 (message "font `%s' not found for face `%s'" fn name
)))))
611 (set-face-foreground face fg frame
)
612 (error (message "color `%s' not allocated for face `%s'" fg name
))))
615 (set-face-background face bg frame
)
616 (error (message "color `%s' not allocated for face `%s'" bg name
))))
619 (set-face-stipple face bgp frame
)
620 (error (message "pixmap `%s' not found for face `%s'" bgp name
))))
621 (if (or ulp set-anyway
)
622 (set-face-underline-p face ulp frame
))
626 (defun copy-face (old-face new-face
&optional frame new-frame
)
627 "Define a face just like OLD-FACE, with name NEW-FACE.
628 If NEW-FACE already exists as a face, it is modified to be like OLD-FACE.
629 If it doesn't already exist, it is created.
631 If the optional argument FRAME is given as a frame,
632 NEW-FACE is changed on FRAME only.
633 If FRAME is t, the frame-independent default specification for OLD-FACE
634 is copied to NEW-FACE.
635 If FRAME is nil, copying is done for the frame-independent defaults
636 and for each existing frame.
637 If the optional fourth argument NEW-FRAME is given,
638 copy the information from face OLD-FACE on frame FRAME
639 to NEW-FACE on frame NEW-FRAME."
640 (or new-frame
(setq new-frame frame
))
641 (let ((inhibit-quit t
))
643 (let ((frames (frame-list)))
645 (copy-face old-face new-face
(car frames
))
646 (setq frames
(cdr frames
)))
647 (copy-face old-face new-face t
))
648 (setq old-face
(internal-get-face old-face frame
))
649 (setq new-face
(or (internal-find-face new-face new-frame
)
650 (make-face new-face
)))
652 ;; A face that has a global symbolic font modifier such as `bold'
653 ;; might legitimately get an error here.
654 ;; Use the frame's default font in that case.
655 (set-face-font new-face
(face-font old-face frame
) new-frame
)
657 (set-face-font new-face nil new-frame
)))
658 (set-face-font-explicit new-face
(face-font-explicit old-face frame
)
660 (set-face-foreground new-face
(face-foreground old-face frame
) new-frame
)
661 (set-face-background new-face
(face-background old-face frame
) new-frame
)
662 (set-face-stipple new-face
663 (face-stipple old-face frame
)
665 (set-face-underline-p new-face
(face-underline-p old-face frame
)
669 (defun face-equal (face1 face2
&optional frame
)
670 "True if the faces FACE1 and FACE2 display in the same way."
671 (setq face1
(internal-get-face face1 frame
)
672 face2
(internal-get-face face2 frame
))
673 (and (equal (face-foreground face1 frame
) (face-foreground face2 frame
))
674 (equal (face-background face1 frame
) (face-background face2 frame
))
675 (equal (face-font face1 frame
) (face-font face2 frame
))
676 (eq (face-underline-p face1 frame
) (face-underline-p face2 frame
))
677 (equal (face-stipple face1 frame
)
678 (face-stipple face2 frame
))))
680 (defun face-differs-from-default-p (face &optional frame
)
681 "True if face FACE displays differently from the default face, on FRAME.
682 A face is considered to be ``the same'' as the default face if it is
683 actually specified in the same way (equivalent fonts, etc) or if it is
684 fully unspecified, and thus inherits the attributes of any face it
685 is displayed on top of.
687 The optional argument FRAME specifies which frame to test;
688 if FRAME is t, test the default for new frames.
689 If FRAME is nil or omitted, test the selected frame."
690 (let ((default (internal-get-face 'default frame
)))
691 (setq face
(internal-get-face face frame
))
692 (not (and (or (equal (face-foreground default frame
)
693 (face-foreground face frame
))
694 (null (face-foreground face frame
)))
695 (or (equal (face-background default frame
)
696 (face-background face frame
))
697 (null (face-background face frame
)))
698 (or (null (face-font face frame
))
699 (equal (face-font face frame
)
700 (or (face-font default frame
)
702 (cdr (assq 'font
(frame-parameters frame
)))))))
703 (or (equal (face-stipple default frame
)
704 (face-stipple face frame
))
705 (null (face-stipple face frame
)))
706 (equal (face-underline-p default frame
)
707 (face-underline-p face frame
))
710 (defun face-nontrivial-p (face &optional frame
)
711 "True if face FACE has some non-nil attribute.
712 The optional argument FRAME specifies which frame to test;
713 if FRAME is t, test the default for new frames.
714 If FRAME is nil or omitted, test the selected frame."
715 (setq face
(internal-get-face face frame
))
716 (or (face-foreground face frame
)
717 (face-background face frame
)
718 (face-font face frame
)
719 (face-stipple face frame
)
720 (face-underline-p face frame
)))
723 (defun invert-face (face &optional frame
)
724 "Swap the foreground and background colors of face FACE.
725 If the face doesn't specify both foreground and background, then
726 set its foreground and background to the default background and foreground."
727 (interactive (list (read-face-name "Invert face: ")))
728 (setq face
(internal-get-face face frame
))
729 (let ((fg (face-foreground face frame
))
730 (bg (face-background face frame
)))
733 (set-face-foreground face bg frame
)
734 (set-face-background face fg frame
))
735 (let* ((frame-bg (cdr (assq 'background-color
(frame-parameters frame
))))
736 (default-bg (or (face-background 'default frame
)
738 (frame-fg (cdr (assq 'foreground-color
(frame-parameters frame
))))
739 (default-fg (or (face-foreground 'default frame
)
741 (set-face-foreground face default-bg frame
)
742 (set-face-background face default-fg frame
))))
746 (defun internal-try-face-font (face font
&optional frame
)
747 "Like set-face-font, but returns nil on failure instead of an error."
749 (set-face-font-auto face font frame
)
752 ;; Manipulating font names.
754 (defvar x-font-regexp nil
)
755 (defvar x-font-regexp-head nil
)
756 (defvar x-font-regexp-weight nil
)
757 (defvar x-font-regexp-slant nil
)
759 (defconst x-font-regexp-weight-subnum
1)
760 (defconst x-font-regexp-slant-subnum
2)
761 (defconst x-font-regexp-swidth-subnum
3)
762 (defconst x-font-regexp-adstyle-subnum
4)
764 ;;; Regexps matching font names in "Host Portable Character Representation."
769 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
770 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
771 (weight\? "\\([^-]*\\)") ; 1
772 (slant "\\([ior]\\)") ; 2
773 ; (slant\? "\\([ior?*]?\\)") ; 2
774 (slant\? "\\([^-]?\\)") ; 2
775 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
776 (swidth "\\([^-]*\\)") ; 3
777 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
778 (adstyle "\\([^-]*\\)") ; 4
780 (pointsize "[0-9][0-9]+")
789 (concat "\\`\\*?[-?*]"
790 foundry - family - weight
\? - slant
\? - swidth - adstyle -
791 pixelsize - pointsize - resx - resy - spacing - avgwidth -
792 registry - encoding
"\\*?\\'"
794 (setq x-font-regexp-head
795 (concat "\\`[-?*]" foundry - family - weight
\? - slant
\?
796 "\\([-*?]\\|\\'\\)"))
797 (setq x-font-regexp-slant
(concat - slant -
))
798 (setq x-font-regexp-weight
(concat - weight -
))
801 (defun x-resolve-font-name (pattern &optional face frame
)
802 "Return a font name matching PATTERN.
803 All wildcards in PATTERN become substantiated.
804 If PATTERN is nil, return the name of the frame's base font, which never
806 Given optional arguments FACE and FRAME, return a font which is
807 also the same size as FACE on FRAME, or fail."
809 (setq face
(face-name face
)))
813 ;; Note that x-list-fonts has code to handle a face with nil as its font.
814 (let ((fonts (x-list-fonts pattern face frame
1)))
817 (if (string-match "\\*" pattern
)
818 (if (null (face-font face
))
819 (error "No matching fonts are the same height as the frame default font")
820 (error "No matching fonts are the same height as face `%s'" face
))
821 (if (null (face-font face
))
822 (error "Height of font `%s' doesn't match the frame default font"
824 (error "Height of font `%s' doesn't match face `%s'"
826 (error "No fonts match `%s'" pattern
)))
828 (cdr (assq 'font
(frame-parameters (selected-frame))))))
830 (defun x-frob-font-weight (font which
)
831 (let ((case-fold-search t
))
832 (cond ((string-match x-font-regexp font
)
833 (concat (substring font
0
834 (match-beginning x-font-regexp-weight-subnum
))
836 (substring font
(match-end x-font-regexp-weight-subnum
)
837 (match-beginning x-font-regexp-adstyle-subnum
))
838 ;; Replace the ADD_STYLE_NAME field with *
839 ;; because the info in it may not be the same
840 ;; for related fonts.
842 (substring font
(match-end x-font-regexp-adstyle-subnum
))))
843 ((string-match x-font-regexp-head font
)
844 (concat (substring font
0 (match-beginning 1)) which
845 (substring font
(match-end 1))))
846 ((string-match x-font-regexp-weight font
)
847 (concat (substring font
0 (match-beginning 1)) which
848 (substring font
(match-end 1)))))))
850 (defun x-frob-font-slant (font which
)
851 (let ((case-fold-search t
))
852 (cond ((string-match x-font-regexp font
)
853 (concat (substring font
0
854 (match-beginning x-font-regexp-slant-subnum
))
856 (substring font
(match-end x-font-regexp-slant-subnum
)
857 (match-beginning x-font-regexp-adstyle-subnum
))
858 ;; Replace the ADD_STYLE_NAME field with *
859 ;; because the info in it may not be the same
860 ;; for related fonts.
862 (substring font
(match-end x-font-regexp-adstyle-subnum
))))
863 ((string-match x-font-regexp-head font
)
864 (concat (substring font
0 (match-beginning 2)) which
865 (substring font
(match-end 2))))
866 ((string-match x-font-regexp-slant font
)
867 (concat (substring font
0 (match-beginning 1)) which
868 (substring font
(match-end 1)))))))
870 (defun x-make-font-bold (font)
871 "Given an X font specification, make a bold version of it.
872 If that can't be done, return nil."
873 (x-frob-font-weight font
"bold"))
875 (defun x-make-font-demibold (font)
876 "Given an X font specification, make a demibold version of it.
877 If that can't be done, return nil."
878 (x-frob-font-weight font
"demibold"))
880 (defun x-make-font-unbold (font)
881 "Given an X font specification, make a non-bold version of it.
882 If that can't be done, return nil."
883 (x-frob-font-weight font
"medium"))
885 (defun x-make-font-italic (font)
886 "Given an X font specification, make an italic version of it.
887 If that can't be done, return nil."
888 (x-frob-font-slant font
"i"))
890 (defun x-make-font-oblique (font) ; you say tomayto...
891 "Given an X font specification, make an oblique version of it.
892 If that can't be done, return nil."
893 (x-frob-font-slant font
"o"))
895 (defun x-make-font-unitalic (font)
896 "Given an X font specification, make a non-italic version of it.
897 If that can't be done, return nil."
898 (x-frob-font-slant font
"r"))
900 (defun x-make-font-bold-italic (font)
901 "Given an X font specification, make a bold and italic version of it.
902 If that can't be done, return nil."
903 (and (setq font
(x-make-font-bold font
))
904 (x-make-font-italic font
)))
906 ;;; non-X-specific interface
908 (defun make-face-bold (face &optional frame noerror
)
909 "Make the font of the given face be bold, if possible.
910 If NOERROR is non-nil, return nil on failure."
911 (interactive (list (read-face-name "Make which face bold: ")))
912 ;; Set the bold-p flag, first of all.
913 (internal-set-face-1 face nil t
10 frame
)
914 (if (and (eq frame t
) (listp (face-font face t
)))
915 (set-face-font face
(if (memq 'italic
(face-font face t
))
916 '(bold italic
) '(bold))
920 (let ((frames (frame-list)))
921 ;; Make this face bold in global-face-data.
922 (make-face-bold face t noerror
)
923 ;; Make this face bold in each frame.
925 (make-face-bold face
(car frames
) noerror
)
926 (setq frames
(cdr frames
))))
927 (setq face
(internal-get-face face frame
))
928 (setq font
(or (face-font face frame
)
933 (face-font 'default frame
)
934 (cdr (assq 'font
(frame-parameters frame
)))))
935 (or (and font
(make-face-bold-internal face frame font
))
936 ;; We failed to find a bold version of the font.
938 (error "No bold version of %S" font
))))))
940 (defun make-face-bold-internal (face frame font
)
942 (or (and (setq f2
(x-make-font-bold font
))
943 (internal-try-face-font face f2 frame
))
944 (and (setq f2
(x-make-font-demibold font
))
945 (internal-try-face-font face f2 frame
)))))
947 (defun make-face-italic (face &optional frame noerror
)
948 "Make the font of the given face be italic, if possible.
949 If NOERROR is non-nil, return nil on failure."
950 (interactive (list (read-face-name "Make which face italic: ")))
951 ;; Set the italic-p flag, first of all.
952 (internal-set-face-1 face nil t
11 frame
)
953 (if (and (eq frame t
) (listp (face-font face t
)))
954 (set-face-font face
(if (memq 'bold
(face-font face t
))
955 '(bold italic
) '(italic))
959 (let ((frames (frame-list)))
960 ;; Make this face italic in global-face-data.
961 (make-face-italic face t noerror
)
962 ;; Make this face italic in each frame.
964 (make-face-italic face
(car frames
) noerror
)
965 (setq frames
(cdr frames
))))
966 (setq face
(internal-get-face face frame
))
967 (setq font
(or (face-font face frame
)
972 (face-font 'default frame
)
973 (cdr (assq 'font
(frame-parameters frame
)))))
974 (or (and font
(make-face-italic-internal face frame font
))
975 ;; We failed to find an italic version of the font.
977 (error "No italic version of %S" font
))))))
979 (defun make-face-italic-internal (face frame font
)
981 (or (and (setq f2
(x-make-font-italic font
))
982 (internal-try-face-font face f2 frame
))
983 (and (setq f2
(x-make-font-oblique font
))
984 (internal-try-face-font face f2 frame
)))))
986 (defun make-face-bold-italic (face &optional frame noerror
)
987 "Make the font of the given face be bold and italic, if possible.
988 If NOERROR is non-nil, return nil on failure."
989 (interactive (list (read-face-name "Make which face bold-italic: ")))
990 ;; Set the bold-p and italic-p flags, first of all.
991 (internal-set-face-1 face nil t
10 frame
)
992 (internal-set-face-1 face nil t
11 frame
)
993 (if (and (eq frame t
) (listp (face-font face t
)))
994 (set-face-font face
'(bold italic
) t
)
997 (let ((frames (frame-list)))
998 ;; Make this face bold-italic in global-face-data.
999 (make-face-bold-italic face t noerror
)
1000 ;; Make this face bold in each frame.
1002 (make-face-bold-italic face
(car frames
) noerror
)
1003 (setq frames
(cdr frames
))))
1004 (setq face
(internal-get-face face frame
))
1005 (setq font
(or (face-font face frame
)
1006 (face-font face t
)))
1010 (face-font 'default frame
)
1011 (cdr (assq 'font
(frame-parameters frame
)))))
1012 (or (and font
(make-face-bold-italic-internal face frame font
))
1013 ;; We failed to find a bold italic version.
1015 (error "No bold italic version of %S" font
))))))
1017 (defun make-face-bold-italic-internal (face frame font
)
1019 (or (and (setq f2
(x-make-font-italic font
))
1020 (not (equal font f2
))
1021 (setq f3
(x-make-font-bold f2
))
1023 (internal-try-face-font face f3 frame
))
1024 (and (setq f2
(x-make-font-oblique font
))
1025 (not (equal font f2
))
1026 (setq f3
(x-make-font-bold f2
))
1028 (internal-try-face-font face f3 frame
))
1029 (and (setq f2
(x-make-font-italic font
))
1030 (not (equal font f2
))
1031 (setq f3
(x-make-font-demibold f2
))
1033 (internal-try-face-font face f3 frame
))
1034 (and (setq f2
(x-make-font-oblique font
))
1035 (not (equal font f2
))
1036 (setq f3
(x-make-font-demibold f2
))
1038 (internal-try-face-font face f3 frame
)))))
1040 (defun make-face-unbold (face &optional frame noerror
)
1041 "Make the font of the given face be non-bold, if possible.
1042 If NOERROR is non-nil, return nil on failure."
1043 (interactive (list (read-face-name "Make which face non-bold: ")))
1044 ;; Clear the bold-p flag, first of all.
1045 (internal-set-face-1 face nil nil
10 frame
)
1046 (if (and (eq frame t
) (listp (face-font face t
)))
1047 (set-face-font face
(if (memq 'italic
(face-font face t
))
1052 (let ((frames (frame-list)))
1053 ;; Make this face unbold in global-face-data.
1054 (make-face-unbold face t noerror
)
1055 ;; Make this face unbold in each frame.
1057 (make-face-unbold face
(car frames
) noerror
)
1058 (setq frames
(cdr frames
))))
1059 (setq face
(internal-get-face face frame
))
1060 (setq font1
(or (face-font face frame
)
1061 (face-font face t
)))
1064 (setq font1
(or font1
1065 (face-font 'default frame
)
1066 (cdr (assq 'font
(frame-parameters frame
)))))
1067 (setq font
(and font1
(x-make-font-unbold font1
)))
1068 (or (if font
(internal-try-face-font face font frame
))
1070 (error "No unbold version of %S" font1
))))))
1072 (defun make-face-unitalic (face &optional frame noerror
)
1073 "Make the font of the given face be non-italic, if possible.
1074 If NOERROR is non-nil, return nil on failure."
1075 (interactive (list (read-face-name "Make which face non-italic: ")))
1076 ;; Clear the italic-p flag, first of all.
1077 (internal-set-face-1 face nil nil
11 frame
)
1078 (if (and (eq frame t
) (listp (face-font face t
)))
1079 (set-face-font face
(if (memq 'bold
(face-font face t
))
1084 (let ((frames (frame-list)))
1085 ;; Make this face unitalic in global-face-data.
1086 (make-face-unitalic face t noerror
)
1087 ;; Make this face unitalic in each frame.
1089 (make-face-unitalic face
(car frames
) noerror
)
1090 (setq frames
(cdr frames
))))
1091 (setq face
(internal-get-face face frame
))
1092 (setq font1
(or (face-font face frame
)
1093 (face-font face t
)))
1096 (setq font1
(or font1
1097 (face-font 'default frame
)
1098 (cdr (assq 'font
(frame-parameters frame
)))))
1099 (setq font
(and font1
(x-make-font-unitalic font1
)))
1100 (or (if font
(internal-try-face-font face font frame
))
1102 (error "No unitalic version of %S" font1
))))))
1104 (defvar list-faces-sample-text
1105 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1106 "*Text string to display as the sample text for `list-faces-display'.")
1108 ;; The name list-faces would be more consistent, but let's avoid a conflict
1109 ;; with Lucid, which uses that name differently.
1110 (defun list-faces-display ()
1111 "List all faces, using the same sample text in each.
1112 The sample text is a string that comes from the variable
1113 `list-faces-sample-text'.
1115 It is possible to give a particular face name different appearances in
1116 different frames. This command shows the appearance in the
1119 (let ((faces (sort (face-list) (function string-lessp
)))
1121 (frame (selected-frame))
1123 (with-output-to-temp-buffer "*Faces*"
1125 (set-buffer standard-output
)
1126 (setq truncate-lines t
)
1128 (setq face
(car faces
))
1129 (setq faces
(cdr faces
))
1130 (insert (format "%25s " (symbol-name face
)))
1131 (let ((beg (point)))
1132 (insert list-faces-sample-text
)
1134 (put-text-property beg
(1- (point)) 'face face
)
1135 ;; If the sample text has multiple lines, line up all of them.
1141 (goto-char (point-min))))
1142 ;; If the *Faces* buffer appears in a different frame,
1143 ;; copy all the face definitions from FRAME,
1144 ;; so that the display will reflect the frame that was selected.
1145 (setq window
(get-buffer-window (get-buffer "*Faces*") t
))
1146 (setq disp-frame
(if window
(window-frame window
)
1147 (car (frame-list))))
1148 (or (eq frame disp-frame
)
1149 (let ((faces (face-list)))
1151 (copy-face (car faces
) (car faces
) frame disp-frame
)
1152 (setq faces
(cdr faces
)))))))
1154 (defun describe-face (face)
1155 "Display the properties of face FACE."
1156 (interactive (list (read-face-name "Describe face: ")))
1157 (with-output-to-temp-buffer "*Help*"
1158 (princ "Properties of face `")
1159 (princ (face-name face
))
1160 (princ "':") (terpri)
1161 (princ "Foreground: ") (princ (face-foreground face
)) (terpri)
1162 (princ "Background: ") (princ (face-background face
)) (terpri)
1163 (princ " Font: ") (princ (face-font face
)) (terpri)
1164 (princ "Underlined: ") (princ (if (face-underline-p face
) "yes" "no")) (terpri)
1165 (princ " Stipple: ") (princ (or (face-stipple face
) "none")) (terpri)
1167 (princ "Documentation:") (terpri)
1168 (let ((doc (face-documentation face
)))
1171 (princ "not documented as a face.")))))
1173 ;;; Setting a face based on a SPEC.
1175 (defun face-attr-match-p (face attrs
&optional frame
)
1176 (or frame
(setq frame
(selected-frame)))
1177 (and (face-attr-match-1 face frame attrs
':inverse-video
1178 'face-inverse-video-p
)
1179 (if (face-inverse-video-p face frame
)
1181 (face-attr-match-1 face frame attrs
1182 ':foreground
'face-background
1183 (cdr (assq 'foreground-color
1184 (frame-parameters frame
))))
1185 (face-attr-match-1 face frame attrs
1186 ':background
'face-foreground
1187 (cdr (assq 'background-color
1188 (frame-parameters frame
)))))
1190 (face-attr-match-1 face frame attrs
':foreground
'face-foreground
)
1191 (face-attr-match-1 face frame attrs
':background
'face-background
)))
1192 (face-attr-match-1 face frame attrs
':stipple
'face-stipple
)
1193 (face-attr-match-1 face frame attrs
':bold
'face-bold-p
)
1194 (face-attr-match-1 face frame attrs
':italic
'face-italic-p
)
1195 (face-attr-match-1 face frame attrs
':underline
'face-underline-p
)
1198 (defun face-attr-match-1 (face frame plist property function
1199 &optional defaultval
)
1200 (while (and plist
(not (eq (car plist
) property
)))
1201 (setq plist
(cdr (cdr plist
))))
1202 (eq (funcall function face frame
)
1206 (funcall function
'default frame
)))))
1208 (defun face-spec-match-p (face spec
&optional frame
)
1209 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1210 (face-attr-match-p face
(face-spec-choose spec frame
) frame
))
1212 (defun face-attr-construct (face &optional frame
)
1213 "Return a defface-style attribute list for FACE, as it exists on FRAME."
1215 (if (face-inverse-video-p face frame
)
1217 (setq result
(cons ':inverse-video
(cons t result
)))
1218 (or (face-attr-match-1 face frame nil
1219 ':foreground
'face-background
1220 (cdr (assq 'foreground-color
1221 (frame-parameters frame
))))
1222 (setq result
(cons ':foreground
1223 (cons (face-foreground face frame
) result
))))
1224 (or (face-attr-match-1 face frame nil
1225 ':background
'face-foreground
1226 (cdr (assq 'background-color
1227 (frame-parameters frame
))))
1228 (setq result
(cons ':background
1229 (cons (face-background face frame
) result
)))))
1230 (if (face-foreground face frame
)
1231 (setq result
(cons ':foreground
1232 (cons (face-foreground face frame
) result
))))
1233 (if (face-background face frame
)
1234 (setq result
(cons ':background
1235 (cons (face-background face frame
) result
)))))
1236 (if (face-stipple face frame
)
1237 (setq result
(cons ':stipple
1238 (cons (face-stipple face frame
) result
))))
1239 (if (face-bold-p face frame
)
1240 (setq result
(cons ':bold
1241 (cons (face-bold-p face frame
) result
))))
1242 (if (face-italic-p face frame
)
1243 (setq result
(cons ':italic
1244 (cons (face-italic-p face frame
) result
))))
1245 (if (face-underline-p face frame
)
1246 (setq result
(cons ':underline
1247 (cons (face-underline-p face frame
) result
))))
1250 ;; Choose the proper attributes for FRAME, out of SPEC.
1251 (defun face-spec-choose (spec &optional frame
)
1252 (or frame
(setq frame
(selected-frame)))
1256 (let* ((entry (car tail
))
1257 (display (nth 0 entry
))
1258 (attrs (nth 1 entry
)))
1259 (setq tail
(cdr tail
))
1260 (when (face-spec-set-match-display display frame
)
1261 (setq result attrs tail nil
))))
1264 (defun face-spec-set (face spec
&optional frame
)
1265 "Set FACE's face attributes according to the first matching entry in SPEC.
1266 If optional FRAME is non-nil, set it for that frame only.
1267 If it is nil, then apply SPEC to each frame individually.
1268 See `defface' for information about SPEC."
1270 (let ((attrs (face-spec-choose spec frame
)))
1272 ;; If the font was set automatically, clear it out
1273 ;; to allow it to be set it again.
1274 (unless (face-font-explicit face frame
)
1275 (set-face-font face nil frame
))
1276 (modify-face face
'(nil) '(nil) nil nil nil nil nil frame
)
1277 (face-spec-set-1 face frame attrs
':foreground
'set-face-foreground
)
1278 (face-spec-set-1 face frame attrs
':background
'set-face-background
)
1279 (face-spec-set-1 face frame attrs
':stipple
'set-face-stipple
)
1280 (face-spec-set-1 face frame attrs
':bold
'set-face-bold-p
)
1281 (face-spec-set-1 face frame attrs
':italic
'set-face-italic-p
)
1282 (face-spec-set-1 face frame attrs
':underline
'set-face-underline-p
)
1283 (face-spec-set-1 face frame attrs
':inverse-video
1284 'set-face-inverse-video-p
)))
1285 (let ((frames (frame-list))
1288 (setq frame
(car frames
)
1289 frames
(cdr frames
))
1290 (face-spec-set face
(or (get face
'saved-face
)
1291 (get face
'face-defface-spec
))
1293 (face-spec-set face spec frame
)))))
1295 (defun face-spec-set-1 (face frame plist property function
)
1296 (while (and plist
(not (eq (car plist
) property
)))
1297 (setq plist
(cdr (cdr plist
))))
1299 (funcall function face
(nth 1 plist
) frame
)))
1301 (defun face-spec-set-match-display (display frame
)
1302 "Non-nil iff DISPLAY matches FRAME.
1303 DISPLAY is part of a spec such as can be used in `defface'.
1304 If FRAME is nil, the current FRAME is used."
1305 (let* ((conjuncts display
)
1306 conjunct req options
1307 ;; t means we have succeeded against all
1308 ;; the conjunts in DISPLAY that have been tested so far.
1310 (if (eq conjuncts t
)
1311 (setq conjuncts nil
))
1312 (while (and conjuncts match
)
1313 (setq conjunct
(car conjuncts
)
1314 conjuncts
(cdr conjuncts
)
1316 options
(cdr conjunct
)
1317 match
(cond ((eq req
'type
)
1318 (memq window-system options
))
1320 (memq (frame-parameter frame
'display-type
) options
))
1321 ((eq req
'background
)
1322 (memq (frame-parameter frame
'background-mode
)
1325 (error "Unknown req `%S' with options `%S'"
1329 ;; Like x-create-frame but also set up the faces.
1331 (defun x-create-frame-with-faces (&optional parameters
)
1332 ;; Read this frame's geometry resource, if it has an explicit name,
1333 ;; and put the specs into PARAMETERS.
1334 (let* ((name (or (cdr (assq 'name parameters
))
1335 (cdr (assq 'name default-frame-alist
))))
1336 (x-resource-name name
)
1337 (res-geometry (if name
(x-get-resource "geometry" "Geometry"))))
1339 (let ((parsed (x-parse-geometry res-geometry
)))
1340 ;; If the resource specifies a position,
1341 ;; call the position and size "user-specified".
1342 (if (or (assq 'top parsed
) (assq 'left parsed
))
1343 (setq parsed
(append '((user-position . t
) (user-size . t
))
1345 ;; Put the geometry parameters at the end.
1346 ;; Copy default-frame-alist so that they go after it.
1347 (setq parameters
(append parameters default-frame-alist parsed
)))))
1349 (if (null global-face-data
)
1351 (setq frame
(x-create-frame parameters
))
1352 (frame-set-background-mode frame
))
1353 (let* ((visibility-spec (assq 'visibility parameters
))
1355 (setq frame
(x-create-frame (cons '(visibility . nil
) parameters
)))
1358 ;; Copy the face alist, copying the face vectors
1359 ;; and emptying out their attributes.
1361 (mapcar '(lambda (elt)
1364 (face-name (cdr elt
))
1370 (set-frame-face-alist frame faces
)
1372 ;; Handle the reverse-video frame parameter
1373 ;; and X resource. x-create-frame does not handle this one.
1374 (if (cdr (or (assq 'reverse parameters
)
1375 (assq 'reverse default-frame-alist
)
1376 (let ((resource (x-get-resource "reverseVideo"
1379 (cons nil
(member (downcase resource
)
1380 '("on" "true")))))))
1381 (let* ((params (frame-parameters frame
))
1382 (bg (cdr (assq 'foreground-color params
)))
1383 (fg (cdr (assq 'background-color params
))))
1384 (modify-frame-parameters frame
1385 (list (cons 'foreground-color fg
)
1386 (cons 'background-color bg
)))
1387 (if (equal bg
(cdr (assq 'border-color params
)))
1388 (modify-frame-parameters frame
1389 (list (cons 'border-color fg
))))
1390 (if (equal bg
(cdr (assq 'mouse-color params
)))
1391 (modify-frame-parameters frame
1392 (list (cons 'mouse-color fg
))))
1393 (if (equal bg
(cdr (assq 'cursor-color params
)))
1394 (modify-frame-parameters frame
1395 (list (cons 'cursor-color fg
))))))
1397 (frame-set-background-mode frame
)
1399 (face-set-after-frame-default frame
)
1401 ;; Make the frame visible, if desired.
1402 (if (null visibility-spec
)
1403 (make-frame-visible frame
)
1404 (modify-frame-parameters frame
(list visibility-spec
)))
1407 (delete-frame frame
)))))
1410 ;; Update a frame's faces after the frame font changes.
1411 ;; This is called from modify-frame-parameters
1412 ;; as well as from elsewhere in this file.
1413 (defun face-set-after-frame-default (frame)
1414 (let ((rest (frame-face-alist frame
)))
1416 ;; Set up each face, first from the defface information,
1417 ;; then the global face data, and then the X resources.
1418 (let* ((face (car (car rest
)))
1419 (spec (or (get face
'saved-face
)
1420 (get face
'face-defface-spec
)))
1421 (global (cdr (assq face global-face-data
)))
1422 (local (cdr (car rest
))))
1424 (face-spec-set face spec frame
))
1425 (face-fill-in face global frame
)
1426 (make-face-x-resource-internal local frame
))
1427 (setq rest
(cdr rest
)))))
1429 (defcustom frame-background-mode nil
1430 "*The brightness of the background.
1431 Set this to the symbol dark if your background color is dark, light if
1432 your background is light, or nil (default) if you want Emacs to
1433 examine the brightness for you."
1435 :type
'(choice (choice-item dark
)
1437 (choice-item :tag
"default" nil
)))
1439 (defun frame-set-background-mode (frame)
1440 "Set up the `background-mode' and `display-type' frame parameters for FRAME."
1441 (let ((bg-resource (x-get-resource ".backgroundMode"
1443 (params (frame-parameters frame
))
1446 (cond (frame-background-mode)
1447 (bg-resource (intern (downcase bg-resource
)))
1448 ((< (apply '+ (x-color-values
1449 (cdr (assq 'background-color params
))
1451 ;; Just looking at the screen,
1452 ;; colors whose values add up to .6 of the white total
1453 ;; still look dark to me.
1454 (* (apply '+ (x-color-values "white" frame
)) .6))
1457 (modify-frame-parameters frame
1458 (list (cons 'background-mode bg-mode
)
1460 (cond ((x-display-color-p frame
)
1462 ((x-display-grayscale-p frame
)
1466 ;; Update a frame's faces when we change its default font.
1467 (defun frame-update-faces (frame) nil
)
1469 ;; Update the colors of FACE, after FRAME's own colors have been changed.
1470 ;; This applies only to faces with global color specifications
1471 ;; that are not simple constants.
1472 (defun frame-update-face-colors (frame)
1473 (let ((faces global-face-data
))
1476 (let* ((data (cdr (car faces
)))
1477 (face (car (car faces
)))
1478 (foreground (face-foreground data
))
1479 (background (face-background data
)))
1480 ;; If the global spec is a specific color,
1481 ;; which doesn't depend on the frame's attributes,
1482 ;; we don't need to recalculate it now.
1483 (or (listp foreground
)
1484 (setq foreground nil
))
1485 (or (listp background
)
1486 (setq background nil
))
1487 ;; If we are going to frob this face at all,
1488 ;; reinitialize it first.
1489 (if (or foreground background
)
1490 (progn (set-face-foreground face nil frame
)
1491 (set-face-background face nil frame
)))
1493 (face-try-color-list 'set-face-foreground
1494 face foreground frame
))
1496 (face-try-color-list 'set-face-background
1497 face background frame
)))
1499 (setq faces
(cdr faces
)))))
1501 ;; Fill in the face FACE from frame-independent face data DATA.
1502 ;; DATA should be the non-frame-specific ("global") face vector
1503 ;; for the face. FACE should be a face name or face object.
1504 ;; FRAME is the frame to act on; it must be an actual frame, not nil or t.
1505 (defun face-fill-in (face data frame
)
1507 (let ((foreground (face-foreground data
))
1508 (background (face-background data
))
1509 (font (face-font data
))
1510 (stipple (face-stipple data
)))
1511 (if (face-underline-p data
)
1512 (set-face-underline-p face
(face-underline-p data
) frame
))
1514 (face-try-color-list 'set-face-foreground
1515 face foreground frame
))
1517 (face-try-color-list 'set-face-background
1518 face background frame
))
1520 (let ((bold (memq 'bold font
))
1521 (italic (memq 'italic font
)))
1522 (cond ((and bold italic
)
1523 (make-face-bold-italic face frame
))
1525 (make-face-bold face frame
))
1527 (make-face-italic face frame
))))
1529 (set-face-font face font frame
)))
1531 (set-face-stipple face stipple frame
)))
1534 ;; Assuming COLOR is a valid color name,
1535 ;; return t if it can be displayed on FRAME.
1536 (defun face-color-supported-p (frame color background-p
)
1538 (or (x-display-color-p frame
)
1539 ;; A black-and-white display can implement these.
1540 (member color
'("black" "white"))
1541 ;; A black-and-white display can fake gray for background.
1543 (face-color-gray-p color frame
))
1544 ;; A grayscale display can implement colors that are gray (more or less).
1545 (and (x-display-grayscale-p frame
)
1546 (face-color-gray-p color frame
)))))
1548 ;; Use FUNCTION to store a color in FACE on FRAME.
1549 ;; COLORS is either a single color or a list of colors.
1550 ;; If it is a list, try the colors one by one until one of them
1551 ;; succeeds. We signal an error only if all the colors failed.
1552 ;; t as COLORS or as an element of COLORS means to invert the face.
1553 ;; That can't fail, so any subsequent elements after the t are ignored.
1554 (defun face-try-color-list (function face colors frame
)
1555 (if (stringp colors
)
1556 (if (face-color-supported-p frame colors
1557 (eq function
'set-face-background
))
1558 (funcall function face colors frame
))
1560 (set-face-inverse-video-p face t frame
)
1562 (while (and colors
(not done
))
1563 (if (or (memq (car colors
) '(t underline
))
1564 (face-color-supported-p frame
(car colors
)
1565 (eq function
'set-face-background
)))
1567 ;; If there are more colors to try, catch errors
1568 ;; and set `done' if we succeed.
1571 (cond ((eq (car colors
) t
)
1572 (set-face-inverse-video-p face t frame
))
1573 ((eq (car colors
) 'underline
)
1574 (set-face-underline-p face t frame
))
1576 (funcall function face
(car colors
) frame
)))
1579 ;; If this is the last color, let the error get out if it fails.
1580 ;; If it succeeds, we will exit anyway after this iteration.
1581 (cond ((eq (car colors
) t
)
1582 (set-face-inverse-video-p face t frame
))
1583 ((eq (car colors
) 'underline
)
1584 (set-face-underline-p face t frame
))
1586 (funcall function face
(car colors
) frame
)))))
1587 (setq colors
(cdr colors
)))))))
1589 ;;; Make the standard faces.
1590 ;;; The C code knows the default and modeline faces as faces 0 and 1,
1591 ;;; so they must be the first two faces made.
1592 (make-face 'default
)
1593 (make-face 'modeline
)
1594 (make-face 'highlight
)
1596 ;; These aren't really special in any way, but they're nice to have around.
1600 (make-face 'bold-italic
)
1602 (make-face 'secondary-selection
)
1603 (make-face 'underline
)
1605 (setq region-face
(face-id 'region
))
1607 ;; Specify how these faces look, and their documentation.
1608 (let ((all '((bold "Use bold font." ((t (:bold t
))))
1609 (bold-italic "Use bold italic font." ((t (:bold t
:italic t
))))
1610 (italic "Use italic font." ((t (:italic t
))))
1611 (underline "Underline text." ((t (:underline t
))))
1612 (default "Used for text not covered by other faces." ((t nil
)))
1613 (highlight "Highlight text in some way."
1614 ((((class color
) (background light
))
1615 (:background
"darkseagreen2"))
1616 (((class color
) (background dark
))
1617 (:background
"darkolivegreen"))
1618 (t (:inverse-video t
))))
1619 (modeline "Used for displaying the modeline."
1620 ((t (:inverse-video t
))))
1621 (region "Used for displaying the region."
1622 ((((class color
) (background dark
))
1623 (:background
"blue"))
1624 (t (:background
"gray"))))
1625 (secondary-selection
1626 "Used for displaying the secondary selection."
1627 ((((class color
) (background light
))
1628 (:background
"paleturquoise"))
1629 (((class color
) (background dark
))
1630 (:background
"darkslateblue"))
1631 (t (:inverse-video t
))))))
1632 entry symbol doc spec
)
1634 (setq entry
(car all
)
1636 symbol
(nth 0 entry
)
1639 (put symbol
'face-documentation doc
)
1640 (put symbol
'face-defface-spec spec
)))
1644 ;;; faces.el ends here