*** empty log message ***
[bpt/emacs.git] / lisp / faces.el
CommitLineData
465fceed
ER
1;;; faces.el --- Lisp interface to the c "face" structure
2
b578f267 3;; Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
465fceed
ER
4
5;; This file is part of GNU Emacs.
6
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)
10;; any later version.
11
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.
16
17;; You should have received a copy of the GNU General Public License
b578f267
EN
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.
465fceed
ER
21
22;;; Commentary:
23
24;; Mostly derived from Lucid.
25
26;;; Code:
27
39b3b754
RS
28(eval-when-compile
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)
87b6ab4c 34 (put 'face-font-explicit 'byte-optimizer nil)
39b3b754
RS
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)
87b6ab4c 40 (put 'set-face-font-auto 'byte-optimizer nil)
39b3b754
RS
41 (put 'set-face-foreground 'byte-optimizer nil)
42 (put 'set-face-background 'byte-optimizer nil)
ca58b3ec 43 (put 'set-face-stipple 'byte-optimizer nil)
39b3b754 44 (put 'set-face-underline-p 'byte-optimizer nil))
bdda3754
JB
45\f
46;;;; Functions for manipulating face vectors.
47
48;;; A face vector is a vector of the form:
d343b6f1
RS
49;;; [face NAME ID FONT FOREGROUND BACKGROUND STIPPLE
50;;; UNDERLINE-P INVERSE-VIDEO-P FONT-EXPLICIT-P BOLD-P ITALIC-P]
bdda3754
JB
51
52;;; Type checkers.
465fceed 53(defsubst internal-facep (x)
1bcb155c 54 (and (vectorp x) (= (length x) 12) (eq (aref x 0) 'face)))
465fceed 55
962a60aa
RS
56(defun facep (x)
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)))
60 t))
61
465fceed 62(defmacro internal-check-face (face)
962a60aa
RS
63 (` (or (internal-facep (, face))
64 (signal 'wrong-type-argument (list 'internal-facep (, face))))))
465fceed 65
bdda3754 66;;; Accessors.
feaad827 67(defun face-name (face)
465fceed
ER
68 "Return the name of face FACE."
69 (aref (internal-get-face face) 1))
70
feaad827 71(defun face-id (face)
465fceed
ER
72 "Return the internal ID number of face FACE."
73 (aref (internal-get-face face) 2))
74
feaad827 75(defun face-font (face &optional frame)
465fceed
ER
76 "Return the font name of face FACE, or nil if it is unspecified.
77If the optional argument FRAME is given, report on face FACE in that frame.
f3f31ccf
RS
78If 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).
81If FRAME is omitted or nil, use the selected frame."
465fceed
ER
82 (aref (internal-get-face face frame) 3))
83
feaad827 84(defun face-foreground (face &optional frame)
465fceed
ER
85 "Return the foreground color name of face FACE, or nil if unspecified.
86If the optional argument FRAME is given, report on face FACE in that frame.
f3f31ccf
RS
87If FRAME is t, report on the defaults for face FACE (for new frames).
88If FRAME is omitted or nil, use the selected frame."
465fceed
ER
89 (aref (internal-get-face face frame) 4))
90
feaad827 91(defun face-background (face &optional frame)
465fceed
ER
92 "Return the background color name of face FACE, or nil if unspecified.
93If the optional argument FRAME is given, report on face FACE in that frame.
f3f31ccf
RS
94If FRAME is t, report on the defaults for face FACE (for new frames).
95If FRAME is omitted or nil, use the selected frame."
465fceed
ER
96 (aref (internal-get-face face frame) 5))
97
feaad827 98(defun face-stipple (face &optional frame)
72418504
RS
99 "Return the stipple pixmap name of face FACE, or nil if unspecified.
100If the optional argument FRAME is given, report on face FACE in that frame.
101If FRAME is t, report on the defaults for face FACE (for new frames).
102If FRAME is omitted or nil, use the selected frame."
103 (aref (internal-get-face face frame) 6))
104
105(defalias 'face-background-pixmap 'face-stipple)
465fceed 106
feaad827 107(defun face-underline-p (face &optional frame)
465fceed
ER
108 "Return t if face FACE is underlined.
109If the optional argument FRAME is given, report on face FACE in that frame.
f3f31ccf
RS
110If FRAME is t, report on the defaults for face FACE (for new frames).
111If FRAME is omitted or nil, use the selected frame."
465fceed
ER
112 (aref (internal-get-face face frame) 7))
113
e8e4cda0
RS
114(defun face-inverse-video-p (face &optional frame)
115 "Return t if face FACE is in inverse video.
116If the optional argument FRAME is given, report on face FACE in that frame.
117If FRAME is t, report on the defaults for face FACE (for new frames).
118If FRAME is omitted or nil, use the selected frame."
119 (aref (internal-get-face face frame) 8))
120
1bcb155c
RS
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))
124
d11fba25
RS
125(defun face-bold-p (face &optional frame)
126 "Return non-nil if the font of FACE is bold.
127If the optional argument FRAME is given, report on face FACE in that frame.
128If FRAME is t, report on the defaults for face FACE (for new frames).
d11fba25 129If FRAME is omitted or nil, use the selected frame."
1bcb155c 130 (aref (internal-get-face face frame) 10))
d11fba25
RS
131
132(defun face-italic-p (face &optional frame)
133 "Return non-nil if the font of FACE is italic.
134If the optional argument FRAME is given, report on face FACE in that frame.
135If FRAME is t, report on the defaults for face FACE (for new frames).
d11fba25 136If FRAME is omitted or nil, use the selected frame."
1bcb155c 137 (aref (internal-get-face face frame) 11))
d11fba25 138
02e0989b
RS
139(defalias 'face-doc-string 'face-documentation)
140(defun face-documentation (face)
d11fba25
RS
141 "Get the documentation string for FACE."
142 (get face 'face-documentation))
bdda3754
JB
143\f
144;;; Mutators.
465fceed 145
feaad827 146(defun set-face-font (face font &optional frame)
465fceed
ER
147 "Change the font of face FACE to FONT (a string).
148If the optional FRAME argument is provided, change only
87b6ab4c
RS
149in that frame; otherwise change each frame."
150 (interactive (internal-face-interactive "font"))
151 (if (stringp font)
70ccc866 152 (setq font (or (resolve-fontset-name font)
87b6ab4c
RS
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))
158
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.
161An automatic change means that we don't change the \"explicit\" flag;
162if the font was derived from the frame font before, it is now.
163If the optional FRAME argument is provided, change only
465fceed
ER
164in that frame; otherwise change each frame."
165 (interactive (internal-face-interactive "font"))
3aa3a18c 166 (if (stringp font)
70ccc866 167 (setq font (or (resolve-fontset-name font)
3aa3a18c 168 (x-resolve-font-name font 'default frame))))
10d89673 169 (internal-set-face-1 face 'font font 3 frame))
465fceed 170
87b6ab4c
RS
171(defun set-face-font-explicit (face flag &optional frame)
172 "Set the explicit-font flag of face FACE to FLAG.
173If the optional FRAME argument is provided, change only
174in that frame; otherwise change each frame."
e9e59456 175 (internal-set-face-1 face nil flag 9 frame))
87b6ab4c 176
feaad827 177(defun set-face-foreground (face color &optional frame)
465fceed
ER
178 "Change the foreground color of face FACE to COLOR (a string).
179If the optional FRAME argument is provided, change only
180in that frame; otherwise change each frame."
f60a629a 181 (interactive (internal-face-interactive "foreground" 'color))
f0138172 182 (internal-set-face-1 face 'foreground color 4 frame))
465fceed 183
ef436392
KH
184(defvar face-default-stipple "gray3"
185 "Default stipple pattern used on monochrome displays.
186This stipple pattern is used on monochrome displays
187instead of shades of gray for a face background color.
188See `set-face-stipple' for possible values for this variable.")
189
190(defun face-color-gray-p (color &optional frame)
191 "Return t if COLOR is a shade of gray (or white or black).
192FRAME specifies the frame and thus the display for interpreting COLOR."
193 (let* ((values (x-color-values color frame))
194 (r (nth 0 values))
195 (g (nth 1 values))
196 (b (nth 2 values)))
25ae394e
RS
197 (and values
198 (< (abs (- r g)) (/ (max 1 (abs r) (abs g)) 20))
ef436392
KH
199 (< (abs (- g b)) (/ (max 1 (abs g) (abs b)) 20))
200 (< (abs (- b r)) (/ (max 1 (abs b) (abs r)) 20)))))
201
feaad827 202(defun set-face-background (face color &optional frame)
465fceed
ER
203 "Change the background color of face FACE to COLOR (a string).
204If the optional FRAME argument is provided, change only
205in that frame; otherwise change each frame."
f60a629a 206 (interactive (internal-face-interactive "background" 'color))
ee09252a
RS
207 ;; For a specific frame, use gray stipple instead of gray color
208 ;; if the display does not support a gray color.
21ef90ee 209 (if (and frame (not (eq frame t)) color
a7acbbe4 210 ;; Check for support for foreground, not for background!
f1d71b2f
RS
211 ;; face-color-supported-p is smart enough to know
212 ;; that grays are "supported" as background
213 ;; because we are supposed to use stipple for them!
214 (not (face-color-supported-p frame color nil)))
ef436392 215 (set-face-stipple face face-default-stipple frame)
d0672e0d
RS
216 (if (null frame)
217 (let ((frames (frame-list)))
218 (while frames
219 (set-face-background (face-name face) color (car frames))
220 (setq frames (cdr frames)))
221 (set-face-background face color t)
222 color)
223 (internal-set-face-1 face 'background color 5 frame))))
465fceed 224
ef436392 225(defun set-face-stipple (face pixmap &optional frame)
72418504
RS
226 "Change the stipple pixmap of face FACE to PIXMAP.
227PIXMAP should be a string, the name of a file of pixmap data.
228The directories listed in the `x-bitmap-file-path' variable are searched.
465fceed 229
72418504
RS
230Alternatively, PIXMAP may be a list of the form (WIDTH HEIGHT DATA)
231where WIDTH and HEIGHT are the size in pixels,
232and DATA is a string, containing the raw bits of the bitmap.
465fceed 233
72418504
RS
234If the optional FRAME argument is provided, change only
235in that frame; otherwise change each frame."
3c5ddb48 236 (interactive (internal-face-interactive-stipple "stipple"))
ef436392 237 (internal-set-face-1 face 'background-pixmap pixmap 6 frame))
72418504
RS
238
239(defalias 'set-face-background-pixmap 'set-face-stipple)
465fceed 240
feaad827 241(defun set-face-underline-p (face underline-p &optional frame)
465fceed
ER
242 "Specify whether face FACE is underlined. (Yes if UNDERLINE-P is non-nil.)
243If the optional FRAME argument is provided, change only
244in that frame; otherwise change each frame."
245 (interactive (internal-face-interactive "underline-p" "underlined"))
f0138172 246 (internal-set-face-1 face 'underline underline-p 7 frame))
d11fba25 247
e8e4cda0
RS
248(defun set-face-inverse-video-p (face inverse-video-p &optional frame)
249 "Specify whether face FACE is in inverse video.
250\(Yes if INVERSE-VIDEO-P is non-nil.)
251If the optional FRAME argument is provided, change only
252in that frame; otherwise change each frame."
253 (interactive (internal-face-interactive "inverse-video-p" "inverse-video"))
254 (internal-set-face-1 face 'inverse-video inverse-video-p 8 frame))
255
d11fba25
RS
256(defun set-face-bold-p (face bold-p &optional frame)
257 "Specify whether face FACE is bold. (Yes if BOLD-P is non-nil.)
258If the optional FRAME argument is provided, change only
259in that frame; otherwise change each frame."
260 (cond ((eq bold-p nil) (make-face-unbold face frame t))
261 (t (make-face-bold face frame t))))
262
263(defun set-face-italic-p (face italic-p &optional frame)
264 "Specify whether face FACE is italic. (Yes if ITALIC-P is non-nil.)
265If the optional FRAME argument is provided, change only
266in that frame; otherwise change each frame."
267 (cond ((eq italic-p nil) (make-face-unitalic face frame t))
268 (t (make-face-italic face frame t))))
269
e42537fe 270(defalias 'set-face-doc-string 'set-face-documentation)
02e0989b 271(defun set-face-documentation (face string)
d11fba25
RS
272 "Set the documentation string for FACE to STRING."
273 (put face 'face-documentation string))
1c0a8710 274\f
2b979e14 275(defun modify-face-read-string (face default name alist)
6ffb01c4
RS
276 (let ((value
277 (completing-read
278 (if default
279 (format "Set face %s %s (default %s): "
280 face name (downcase default))
281 (format "Set face %s %s: " face name))
282 alist)))
283 (cond ((equal value "none")
284 nil)
285 ((equal value "")
286 default)
287 (t value))))
288
289(defun modify-face (face foreground background stipple
d343b6f1 290 bold-p italic-p underline-p &optional inverse-p frame)
1c0a8710 291 "Change the display attributes for face FACE.
905cf8f2
SM
292If the optional FRAME argument is provided, change only
293in that frame; otherwise change each frame.
294
295FOREGROUND and BACKGROUND should be a colour name string (or list of strings to
296try) or nil. STIPPLE should be a stipple pattern name string or nil.
297If nil, means do not change the display attribute corresponding to that arg.
298
d343b6f1
RS
299BOLD-P, ITALIC-P, UNDERLINE-P, and INVERSE-P specify whether
300the face should be set bold, italic, underlined or in inverse-video,
301respectively. If one of these arguments is neither nil or t, it means do not
302change the display attribute corresponding to that argument.
905cf8f2
SM
303
304If called interactively, prompts for a face name and face attributes."
1c0a8710
RS
305 (interactive
306 (let* ((completion-ignore-case t)
905cf8f2
SM
307 (face (symbol-name (read-face-name "Modify face: ")))
308 (colors (mapcar 'list x-colors))
309 (stipples (mapcar 'list (apply 'nconc
310 (mapcar 'directory-files
311 x-bitmap-file-path))))
312 (foreground (modify-face-read-string
313 face (face-foreground (intern face))
314 "foreground" colors))
315 (background (modify-face-read-string
316 face (face-background (intern face))
317 "background" colors))
e5de0238
RS
318 ;; If the stipple value is a list (WIDTH HEIGHT DATA),
319 ;; represent that as a string by printing it out.
320 (old-stipple-string
321 (if (stringp (face-stipple (intern face)))
322 (face-stipple (intern face))
3c5ddb48
RS
323 (if (face-stipple (intern face))
324 (prin1-to-string (face-stipple (intern face))))))
e5de0238
RS
325 (new-stipple-string
326 (modify-face-read-string
327 face old-stipple-string
328 "stipple" stipples))
329 ;; Convert the stipple value text we read
330 ;; back to a list if it looks like one.
331 ;; This makes the assumption that a pixmap file name
332 ;; won't start with an open-paren.
333 (stipple
3c5ddb48
RS
334 (and new-stipple-string
335 (if (string-match "^(" new-stipple-string)
336 (read new-stipple-string)
337 new-stipple-string)))
338 (bold-p (y-or-n-p (concat "Should face " face " be bold ")))
339 (italic-p (y-or-n-p (concat "Should face " face " be italic ")))
340 (underline-p (y-or-n-p (concat "Should face " face " be underlined ")))
d343b6f1 341 (inverse-p (y-or-n-p (concat "Should face " face " be inverse-video ")))
905cf8f2 342 (all-frames-p (y-or-n-p (concat "Modify face " face " in all frames "))))
1c0a8710
RS
343 (message "Face %s: %s" face
344 (mapconcat 'identity
345 (delq nil
346 (list (and foreground (concat (downcase foreground) " foreground"))
347 (and background (concat (downcase background) " background"))
e5de0238 348 (and stipple (concat (downcase new-stipple-string) " stipple"))
1c0a8710 349 (and bold-p "bold") (and italic-p "italic")
d343b6f1 350 (and inverse-p "inverse")
1c0a8710 351 (and underline-p "underline"))) ", "))
6ffb01c4 352 (list (intern face) foreground background stipple
d343b6f1 353 bold-p italic-p underline-p inverse-p
905cf8f2 354 (if all-frames-p nil (selected-frame)))))
d343b6f1
RS
355 ;; Clear this before we install the new foreground and background;
356 ;; otherwise, clearing it after would swap them!
357 (when (and (or foreground background) (face-inverse-video-p face))
573d18cb 358 (set-face-inverse-video-p face nil frame)
d343b6f1
RS
359 ;; Arrange to restore it after, if we are not setting it now.
360 (or (memq inverse-p '(t nil))
361 (setq inverse-p t)))
905cf8f2
SM
362 (condition-case nil
363 (face-try-color-list 'set-face-foreground face foreground frame)
364 (error nil))
365 (condition-case nil
366 (face-try-color-list 'set-face-background face background frame)
367 (error nil))
368 (condition-case nil
369 (set-face-stipple face stipple frame)
370 (error nil))
d343b6f1
RS
371 ;; Now that we have the new colors,
372 (if (memq inverse-p '(nil t))
373 (set-face-inverse-video-p face inverse-p frame))
e8e4cda0
RS
374 (cond ((eq bold-p nil)
375 (if (face-font face frame)
376 (make-face-unbold face frame t)))
377 ((eq bold-p t)
378 (make-face-bold face frame t)))
379 (cond ((eq italic-p nil)
380 (if (face-font face frame)
381 (make-face-unitalic face frame t)))
905cf8f2
SM
382 ((eq italic-p t) (make-face-italic face frame t)))
383 (if (memq underline-p '(nil t))
384 (set-face-underline-p face underline-p frame))
1c0a8710 385 (and (interactive-p) (redraw-display)))
bdda3754
JB
386\f
387;;;; Associating face names (symbols) with their face vectors.
388
66a5c2c6
JB
389(defvar global-face-data nil
390 "Internal data for face support functions. Not for external use.
391This is an alist associating face names with the default values for
392their parameters. Newly created frames get their data from here.")
393
bdda3754
JB
394(defun face-list ()
395 "Returns a list of all defined face names."
396 (mapcar 'car global-face-data))
397
398(defun internal-find-face (name &optional frame)
399 "Retrieve the face named NAME. Return nil if there is no such face.
400If the optional argument FRAME is given, this gets the face NAME for
401that frame; otherwise, it uses the selected frame.
402If FRAME is the symbol t, then the global, non-frame face is returned.
403If NAME is already a face, it is simply returned."
404 (if (and (eq frame t) (not (symbolp name)))
405 (setq name (face-name name)))
406 (if (symbolp name)
407 (cdr (assq name
408 (if (eq frame t)
409 global-face-data
410 (frame-face-alist (or frame (selected-frame))))))
411 (internal-check-face name)
412 name))
413
414(defun internal-get-face (name &optional frame)
415 "Retrieve the face named NAME; error if there is none.
416If the optional argument FRAME is given, this gets the face NAME for
417that frame; otherwise, it uses the selected frame.
418If FRAME is the symbol t, then the global, non-frame face is returned.
419If NAME is already a face, it is simply returned."
420 (or (internal-find-face name frame)
421 (internal-check-face name)))
422
423
424(defun internal-set-face-1 (face name value index frame)
425 (let ((inhibit-quit t))
426 (if (null frame)
427 (let ((frames (frame-list)))
428 (while frames
429 (internal-set-face-1 (face-name face) name value index (car frames))
430 (setq frames (cdr frames)))
431 (aset (internal-get-face (if (symbolp face) face (face-name face)) t)
432 index value)
433 value)
e8e4cda0
RS
434 (let ((internal-face (internal-get-face face frame)))
435 (or (eq frame t)
436 (if (eq name 'inverse-video)
437 (or (eq value (aref internal-face index))
438 (invert-face face frame))
87b6ab4c
RS
439 (and name (fboundp 'set-face-attribute-internal)
440 (set-face-attribute-internal (face-id face)
441 name value frame))))
e8e4cda0 442 (aset internal-face index value)))))
bdda3754
JB
443
444
445(defun read-face-name (prompt)
446 (let (face)
447 (while (= (length face) 0)
448 (setq face (completing-read prompt
449 (mapcar '(lambda (x) (list (symbol-name x)))
450 (face-list))
451 nil t)))
452 (intern face)))
453
454(defun internal-face-interactive (what &optional bool)
455 (let* ((fn (intern (concat "face-" what)))
456 (prompt (concat "Set " what " of face"))
457 (face (read-face-name (concat prompt ": ")))
458 (default (if (fboundp fn)
459 (or (funcall fn face (selected-frame))
460 (funcall fn 'default (selected-frame)))))
f60a629a
RS
461 value)
462 (setq value
463 (cond ((eq bool 'color)
464 (completing-read (concat prompt " " (symbol-name face) " to: ")
465 (mapcar (function (lambda (color)
466 (cons color color)))
467 x-colors)
468 nil nil nil nil default))
469 (bool
470 (y-or-n-p (concat "Should face " (symbol-name face)
471 " be " bool "? ")))
472 (t
473 (read-string (concat prompt " " (symbol-name face) " to: ")
474 nil nil default))))
bdda3754
JB
475 (list face (if (equal value "") nil value))))
476
3c5ddb48
RS
477(defun internal-face-interactive-stipple (what)
478 (let* ((fn (intern (concat "face-" what)))
479 (prompt (concat "Set " what " of face"))
480 (face (read-face-name (concat prompt ": ")))
481 (default (if (fboundp fn)
482 (or (funcall fn face (selected-frame))
483 (funcall fn 'default (selected-frame)))))
484 ;; If the stipple value is a list (WIDTH HEIGHT DATA),
485 ;; represent that as a string by printing it out.
486 (old-stipple-string
487 (if (stringp (face-stipple face))
488 (face-stipple face)
489 (if (null (face-stipple face))
490 nil
491 (prin1-to-string (face-stipple face)))))
492 (new-stipple-string
493 (read-string
494 (concat prompt " " (symbol-name face) " to: ")
495 old-stipple-string))
496 ;; Convert the stipple value text we read
497 ;; back to a list if it looks like one.
498 ;; This makes the assumption that a pixmap file name
499 ;; won't start with an open-paren.
500 (stipple
501 (if (string-match "^(" new-stipple-string)
502 (read new-stipple-string)
503 new-stipple-string)))
504 (list face (if (equal stipple "") nil stipple))))
465fceed 505
17b3a11b 506(defun make-face (name &optional no-resources)
465fceed
ER
507 "Define a new FACE on all frames.
508You can modify the font, color, etc of this face with the set-face- functions.
17b3a11b
RS
509If NO-RESOURCES is non-nil, then we ignore X resources
510and always make a face whose attributes are all nil.
511
465fceed 512If the face already exists, it is unmodified."
19fac299 513 (interactive "SMake face: ")
465fceed 514 (or (internal-find-face name)
1bcb155c 515 (let ((face (make-vector 12 nil)))
465fceed
ER
516 (aset face 0 'face)
517 (aset face 1 name)
518 (let* ((frames (frame-list))
519 (inhibit-quit t)
520 (id (internal-next-face-id)))
60a719b0
RS
521 (if (fboundp 'make-face-internal)
522 (make-face-internal id))
465fceed
ER
523 (aset face 2 id)
524 (while frames
525 (set-frame-face-alist (car frames)
526 (cons (cons name (copy-sequence face))
527 (frame-face-alist (car frames))))
528 (setq frames (cdr frames)))
529 (setq global-face-data (cons (cons name face) global-face-data)))
17b3a11b
RS
530 ;; When making a face after frames already exist
531 (or no-resources
532 (if (memq window-system '(x w32))
533 (make-face-x-resource-internal face)))
534 ;; Add to menu of faces.
33af44e8
BG
535 (if (fboundp 'facemenu-add-new-face)
536 (facemenu-add-new-face name))
7ee29ed8
RS
537 face))
538 name)
465fceed 539
17b3a11b
RS
540(defun make-empty-face (face)
541 "Define a new FACE on all frames, which initially reflects the defaults.
542You can modify the font, color, etc of this face with the set-face- functions.
543If the face already exists, it is unmodified."
544 (interactive "SMake empty face: ")
545 (make-face face t))
546
465fceed
ER
547;; Fill in a face by default based on X resources, for all existing frames.
548;; This has to be done when a new face is made.
549(defun make-face-x-resource-internal (face &optional frame set-anyway)
550 (cond ((null frame)
551 (let ((frames (frame-list)))
552 (while frames
b86b9918 553 (if (memq (framep (car frames)) '(x w32))
586ab698
RS
554 (make-face-x-resource-internal (face-name face)
555 (car frames) set-anyway))
465fceed
ER
556 (setq frames (cdr frames)))))
557 (t
558 (setq face (internal-get-face (face-name face) frame))
559 ;;
560 ;; These are things like "attributeForeground" instead of simply
561 ;; "foreground" because people tend to do things like "*foreground",
562 ;; which would cause all faces to be fully qualified, making faces
563 ;; inherit attributes in a non-useful way. So we've made them slightly
564 ;; less obvious to specify in order to make them work correctly in
565 ;; more random environments.
566 ;;
567 ;; I think these should be called "face.faceForeground" instead of
568 ;; "face.attributeForeground", but they're the way they are for
569 ;; hysterical reasons.
570 ;;
571 (let* ((name (symbol-name (face-name face)))
572 (fn (or (x-get-resource (concat name ".attributeFont")
573 "Face.AttributeFont")
574 (and set-anyway (face-font face))))
575 (fg (or (x-get-resource (concat name ".attributeForeground")
576 "Face.AttributeForeground")
577 (and set-anyway (face-foreground face))))
578 (bg (or (x-get-resource (concat name ".attributeBackground")
579 "Face.AttributeBackground")
580 (and set-anyway (face-background face))))
72418504
RS
581 (bgp (or (x-get-resource (concat name ".attributeStipple")
582 "Face.AttributeStipple")
583 (x-get-resource (concat name ".attributeBackgroundPixmap")
584 "Face.AttributeBackgroundPixmap")
585 (and set-anyway (face-stipple face))))
69718e9d
RS
586 (ulp (let ((resource (x-get-resource
587 (concat name ".attributeUnderline")
588 "Face.AttributeUnderline")))
589 (if resource
590 (member (downcase resource) '("on" "true"))
591 (and set-anyway (face-underline-p face)))))
465fceed
ER
592 )
593 (if fn
594 (condition-case ()
19deb21e
RS
595 (cond ((string= fn "italic")
596 (make-face-italic face))
597 ((string= fn "bold")
598 (make-face-bold face))
599 ((string= fn "bold-italic")
600 (make-face-bold-italic face))
601 (t
602 (set-face-font face fn frame)))
603 (error
604 (if (member fn '("italic" "bold" "bold-italic"))
605 (message "no %s version found for face `%s'" fn name)
606 (message "font `%s' not found for face `%s'" fn name)))))
465fceed
ER
607 (if fg
608 (condition-case ()
609 (set-face-foreground face fg frame)
610 (error (message "color `%s' not allocated for face `%s'" fg name))))
611 (if bg
612 (condition-case ()
613 (set-face-background face bg frame)
614 (error (message "color `%s' not allocated for face `%s'" bg name))))
72418504
RS
615 (if bgp
616 (condition-case ()
617 (set-face-stipple face bgp frame)
618 (error (message "pixmap `%s' not found for face `%s'" bgp name))))
465fceed
ER
619 (if (or ulp set-anyway)
620 (set-face-underline-p face ulp frame))
621 )))
622 face)
623
2f2ddd1e
RS
624(defun copy-face (old-face new-face &optional frame new-frame)
625 "Define a face just like OLD-FACE, with name NEW-FACE.
626If NEW-FACE already exists as a face, it is modified to be like OLD-FACE.
627If it doesn't already exist, it is created.
628
629If the optional argument FRAME is given as a frame,
630NEW-FACE is changed on FRAME only.
631If FRAME is t, the frame-independent default specification for OLD-FACE
632is copied to NEW-FACE.
633If FRAME is nil, copying is done for the frame-independent defaults
634and for each existing frame.
710e7005
RS
635If the optional fourth argument NEW-FRAME is given,
636copy the information from face OLD-FACE on frame FRAME
2f2ddd1e 637to NEW-FACE on frame NEW-FRAME."
710e7005 638 (or new-frame (setq new-frame frame))
da41135a 639 (let ((inhibit-quit t))
465fceed
ER
640 (if (null frame)
641 (let ((frames (frame-list)))
642 (while frames
2f2ddd1e 643 (copy-face old-face new-face (car frames))
465fceed 644 (setq frames (cdr frames)))
2f2ddd1e 645 (copy-face old-face new-face t))
da41135a
KH
646 (setq old-face (internal-get-face old-face frame))
647 (setq new-face (or (internal-find-face new-face new-frame)
648 (make-face new-face)))
52267b56
RS
649 (condition-case nil
650 ;; A face that has a global symbolic font modifier such as `bold'
651 ;; might legitimately get an error here.
652 ;; Use the frame's default font in that case.
653 (set-face-font new-face (face-font old-face frame) new-frame)
654 (error
655 (set-face-font new-face nil new-frame)))
87b6ab4c
RS
656 (set-face-font-explicit new-face (face-font-explicit old-face frame)
657 new-frame)
710e7005
RS
658 (set-face-foreground new-face (face-foreground old-face frame) new-frame)
659 (set-face-background new-face (face-background old-face frame) new-frame)
72418504
RS
660 (set-face-stipple new-face
661 (face-stipple old-face frame)
662 new-frame)
465fceed 663 (set-face-underline-p new-face (face-underline-p old-face frame)
710e7005 664 new-frame))
465fceed
ER
665 new-face))
666
667(defun face-equal (face1 face2 &optional frame)
ade516a1 668 "True if the faces FACE1 and FACE2 display in the same way."
465fceed
ER
669 (setq face1 (internal-get-face face1 frame)
670 face2 (internal-get-face face2 frame))
671 (and (equal (face-foreground face1 frame) (face-foreground face2 frame))
672 (equal (face-background face1 frame) (face-background face2 frame))
673 (equal (face-font face1 frame) (face-font face2 frame))
ae0249df 674 (eq (face-underline-p face1 frame) (face-underline-p face2 frame))
72418504
RS
675 (equal (face-stipple face1 frame)
676 (face-stipple face2 frame))))
465fceed
ER
677
678(defun face-differs-from-default-p (face &optional frame)
679 "True if face FACE displays differently from the default face, on FRAME.
680A face is considered to be ``the same'' as the default face if it is
681actually specified in the same way (equivalent fonts, etc) or if it is
682fully unspecified, and thus inherits the attributes of any face it
93d6fcef
RS
683is displayed on top of.
684
685The optional argument FRAME specifies which frame to test;
686if FRAME is t, test the default for new frames.
687If FRAME is nil or omitted, test the selected frame."
465fceed
ER
688 (let ((default (internal-get-face 'default frame)))
689 (setq face (internal-get-face face frame))
690 (not (and (or (equal (face-foreground default frame)
691 (face-foreground face frame))
692 (null (face-foreground face frame)))
693 (or (equal (face-background default frame)
694 (face-background face frame))
695 (null (face-background face frame)))
fbd44116
SM
696 (or (null (face-font face frame))
697 (equal (face-font face frame)
698 (or (face-font default frame)
699 (downcase
700 (cdr (assq 'font (frame-parameters frame)))))))
72418504
RS
701 (or (equal (face-stipple default frame)
702 (face-stipple face frame))
703 (null (face-stipple face frame)))
465fceed
ER
704 (equal (face-underline-p default frame)
705 (face-underline-p face frame))
706 ))))
707
93d6fcef
RS
708(defun face-nontrivial-p (face &optional frame)
709 "True if face FACE has some non-nil attribute.
710The optional argument FRAME specifies which frame to test;
711if FRAME is t, test the default for new frames.
712If FRAME is nil or omitted, test the selected frame."
713 (setq face (internal-get-face face frame))
714 (or (face-foreground face frame)
715 (face-background face frame)
716 (face-font face frame)
717 (face-stipple face frame)
718 (face-underline-p face frame)))
719
465fceed
ER
720
721(defun invert-face (face &optional frame)
722 "Swap the foreground and background colors of face FACE.
723If the face doesn't specify both foreground and background, then
8494bbf1 724set its foreground and background to the default background and foreground."
465fceed
ER
725 (interactive (list (read-face-name "Invert face: ")))
726 (setq face (internal-get-face face frame))
727 (let ((fg (face-foreground face frame))
728 (bg (face-background face frame)))
729 (if (or fg bg)
730 (progn
731 (set-face-foreground face bg frame)
732 (set-face-background face fg frame))
c5f0b2d4
RS
733 (let* ((frame-bg (cdr (assq 'background-color (frame-parameters frame))))
734 (default-bg (or (face-background 'default frame)
735 frame-bg))
736 (frame-fg (cdr (assq 'foreground-color (frame-parameters frame))))
737 (default-fg (or (face-foreground 'default frame)
738 frame-fg)))
739 (set-face-foreground face default-bg frame)
740 (set-face-background face default-fg frame))))
465fceed
ER
741 face)
742
743
744(defun internal-try-face-font (face font &optional frame)
745 "Like set-face-font, but returns nil on failure instead of an error."
746 (condition-case ()
87b6ab4c 747 (set-face-font-auto face font frame)
465fceed 748 (error nil)))
465fceed
ER
749\f
750;; Manipulating font names.
751
d7fa5aa2
RS
752(defvar x-font-regexp nil)
753(defvar x-font-regexp-head nil)
754(defvar x-font-regexp-weight nil)
755(defvar x-font-regexp-slant nil)
465fceed 756
021ca129
KH
757(defconst x-font-regexp-weight-subnum 1)
758(defconst x-font-regexp-slant-subnum 2)
759(defconst x-font-regexp-swidth-subnum 3)
760(defconst x-font-regexp-adstyle-subnum 4)
761
465fceed
ER
762;;; Regexps matching font names in "Host Portable Character Representation."
763;;;
764(let ((- "[-?]")
765 (foundry "[^-]+")
766 (family "[^-]+")
767 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
768; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
769 (weight\? "\\([^-]*\\)") ; 1
770 (slant "\\([ior]\\)") ; 2
771; (slant\? "\\([ior?*]?\\)") ; 2
772 (slant\? "\\([^-]?\\)") ; 2
773; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
774 (swidth "\\([^-]*\\)") ; 3
775; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
c8787b81 776 (adstyle "\\([^-]*\\)") ; 4
465fceed
ER
777 (pixelsize "[0-9]+")
778 (pointsize "[0-9][0-9]+")
779 (resx "[0-9][0-9]+")
780 (resy "[0-9][0-9]+")
781 (spacing "[cmp?*]")
782 (avgwidth "[0-9]+")
783 (registry "[^-]+")
784 (encoding "[^-]+")
785 )
786 (setq x-font-regexp
787 (concat "\\`\\*?[-?*]"
788 foundry - family - weight\? - slant\? - swidth - adstyle -
e20d641f
RS
789 pixelsize - pointsize - resx - resy - spacing - avgwidth -
790 registry - encoding "\\*?\\'"
465fceed
ER
791 ))
792 (setq x-font-regexp-head
793 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
794 "\\([-*?]\\|\\'\\)"))
795 (setq x-font-regexp-slant (concat - slant -))
796 (setq x-font-regexp-weight (concat - weight -))
797 nil)
798
281dc1c2
JB
799(defun x-resolve-font-name (pattern &optional face frame)
800 "Return a font name matching PATTERN.
801All wildcards in PATTERN become substantiated.
10d89673
JB
802If PATTERN is nil, return the name of the frame's base font, which never
803contains wildcards.
e17dbede
RS
804Given optional arguments FACE and FRAME, return a font which is
805also the same size as FACE on FRAME, or fail."
14e6867c
RS
806 (or (symbolp face)
807 (setq face (face-name face)))
808 (and (eq frame t)
809 (setq frame nil))
10d89673 810 (if pattern
8db93e45 811 ;; Note that x-list-fonts has code to handle a face with nil as its font.
abd89b80 812 (let ((fonts (x-list-fonts pattern face frame 1)))
10d89673
JB
813 (or fonts
814 (if face
962a60aa
RS
815 (if (string-match "\\*" pattern)
816 (if (null (face-font face))
817 (error "No matching fonts are the same height as the frame default font")
818 (error "No matching fonts are the same height as face `%s'" face))
819 (if (null (face-font face))
820 (error "Height of font `%s' doesn't match the frame default font"
821 pattern)
822 (error "Height of font `%s' doesn't match face `%s'"
823 pattern face)))
7cf6fac1 824 (error "No fonts match `%s'" pattern)))
10d89673
JB
825 (car fonts))
826 (cdr (assq 'font (frame-parameters (selected-frame))))))
281dc1c2 827
465fceed 828(defun x-frob-font-weight (font which)
b7ffee5f
SM
829 (let ((case-fold-search t))
830 (cond ((string-match x-font-regexp font)
831 (concat (substring font 0
832 (match-beginning x-font-regexp-weight-subnum))
833 which
834 (substring font (match-end x-font-regexp-weight-subnum)
835 (match-beginning x-font-regexp-adstyle-subnum))
836 ;; Replace the ADD_STYLE_NAME field with *
837 ;; because the info in it may not be the same
838 ;; for related fonts.
839 "*"
840 (substring font (match-end x-font-regexp-adstyle-subnum))))
528fbf51
RS
841 ((string-match x-font-regexp-head font)
842 (concat (substring font 0 (match-beginning 1)) which
843 (substring font (match-end 1))))
844 ((string-match x-font-regexp-weight font)
b7ffee5f
SM
845 (concat (substring font 0 (match-beginning 1)) which
846 (substring font (match-end 1)))))))
465fceed
ER
847
848(defun x-frob-font-slant (font which)
b7ffee5f
SM
849 (let ((case-fold-search t))
850 (cond ((string-match x-font-regexp font)
851 (concat (substring font 0
852 (match-beginning x-font-regexp-slant-subnum))
853 which
854 (substring font (match-end x-font-regexp-slant-subnum)
855 (match-beginning x-font-regexp-adstyle-subnum))
856 ;; Replace the ADD_STYLE_NAME field with *
857 ;; because the info in it may not be the same
858 ;; for related fonts.
859 "*"
860 (substring font (match-end x-font-regexp-adstyle-subnum))))
528fbf51
RS
861 ((string-match x-font-regexp-head font)
862 (concat (substring font 0 (match-beginning 2)) which
863 (substring font (match-end 2))))
864 ((string-match x-font-regexp-slant font)
b7ffee5f
SM
865 (concat (substring font 0 (match-beginning 1)) which
866 (substring font (match-end 1)))))))
465fceed
ER
867
868(defun x-make-font-bold (font)
f3f31ccf
RS
869 "Given an X font specification, make a bold version of it.
870If that can't be done, return nil."
465fceed
ER
871 (x-frob-font-weight font "bold"))
872
873(defun x-make-font-demibold (font)
f3f31ccf
RS
874 "Given an X font specification, make a demibold version of it.
875If that can't be done, return nil."
465fceed
ER
876 (x-frob-font-weight font "demibold"))
877
878(defun x-make-font-unbold (font)
f3f31ccf
RS
879 "Given an X font specification, make a non-bold version of it.
880If that can't be done, return nil."
465fceed
ER
881 (x-frob-font-weight font "medium"))
882
883(defun x-make-font-italic (font)
f3f31ccf
RS
884 "Given an X font specification, make an italic version of it.
885If that can't be done, return nil."
465fceed
ER
886 (x-frob-font-slant font "i"))
887
888(defun x-make-font-oblique (font) ; you say tomayto...
f3f31ccf
RS
889 "Given an X font specification, make an oblique version of it.
890If that can't be done, return nil."
465fceed
ER
891 (x-frob-font-slant font "o"))
892
893(defun x-make-font-unitalic (font)
f3f31ccf
RS
894 "Given an X font specification, make a non-italic version of it.
895If that can't be done, return nil."
465fceed 896 (x-frob-font-slant font "r"))
b7d7285c
KH
897
898(defun x-make-font-bold-italic (font)
899 "Given an X font specification, make a bold and italic version of it.
900If that can't be done, return nil."
901 (and (setq font (x-make-font-bold font))
902 (x-make-font-italic font)))
465fceed
ER
903\f
904;;; non-X-specific interface
905
bb9a81fc 906(defun make-face-bold (face &optional frame noerror)
465fceed 907 "Make the font of the given face be bold, if possible.
bb9a81fc 908If NOERROR is non-nil, return nil on failure."
465fceed 909 (interactive (list (read-face-name "Make which face bold: ")))
1bcb155c
RS
910 ;; Set the bold-p flag, first of all.
911 (internal-set-face-1 face nil t 10 frame)
534dbc97 912 (if (and (eq frame t) (listp (face-font face t)))
f3f31ccf
RS
913 (set-face-font face (if (memq 'italic (face-font face t))
914 '(bold italic) '(bold))
915 t)
488bedff 916 (let (font)
f3f31ccf
RS
917 (if (null frame)
918 (let ((frames (frame-list)))
919 ;; Make this face bold in global-face-data.
920 (make-face-bold face t noerror)
921 ;; Make this face bold in each frame.
922 (while frames
923 (make-face-bold face (car frames) noerror)
924 (setq frames (cdr frames))))
925 (setq face (internal-get-face face frame))
926 (setq font (or (face-font face frame)
927 (face-font face t)))
928 (if (listp font)
929 (setq font nil))
930 (setq font (or font
931 (face-font 'default frame)
932 (cdr (assq 'font (frame-parameters frame)))))
488bedff
RS
933 (or (and font (make-face-bold-internal face frame font))
934 ;; We failed to find a bold version of the font.
935 noerror
936 (error "No bold version of %S" font))))))
f3f31ccf 937
4b3203d9
RS
938(defun make-face-bold-internal (face frame font)
939 (let (f2)
940 (or (and (setq f2 (x-make-font-bold font))
941 (internal-try-face-font face f2 frame))
942 (and (setq f2 (x-make-font-demibold font))
943 (internal-try-face-font face f2 frame)))))
bb9a81fc
JB
944
945(defun make-face-italic (face &optional frame noerror)
465fceed 946 "Make the font of the given face be italic, if possible.
bb9a81fc 947If NOERROR is non-nil, return nil on failure."
465fceed 948 (interactive (list (read-face-name "Make which face italic: ")))
1bcb155c
RS
949 ;; Set the italic-p flag, first of all.
950 (internal-set-face-1 face nil t 11 frame)
534dbc97 951 (if (and (eq frame t) (listp (face-font face t)))
f3f31ccf
RS
952 (set-face-font face (if (memq 'bold (face-font face t))
953 '(bold italic) '(italic))
954 t)
488bedff 955 (let (font)
f3f31ccf
RS
956 (if (null frame)
957 (let ((frames (frame-list)))
958 ;; Make this face italic in global-face-data.
959 (make-face-italic face t noerror)
960 ;; Make this face italic in each frame.
961 (while frames
962 (make-face-italic face (car frames) noerror)
963 (setq frames (cdr frames))))
964 (setq face (internal-get-face face frame))
965 (setq font (or (face-font face frame)
966 (face-font face t)))
967 (if (listp font)
968 (setq font nil))
969 (setq font (or font
970 (face-font 'default frame)
971 (cdr (assq 'font (frame-parameters frame)))))
488bedff
RS
972 (or (and font (make-face-italic-internal face frame font))
973 ;; We failed to find an italic version of the font.
974 noerror
975 (error "No italic version of %S" font))))))
f3f31ccf 976
4b3203d9
RS
977(defun make-face-italic-internal (face frame font)
978 (let (f2)
979 (or (and (setq f2 (x-make-font-italic font))
980 (internal-try-face-font face f2 frame))
981 (and (setq f2 (x-make-font-oblique font))
982 (internal-try-face-font face f2 frame)))))
bb9a81fc
JB
983
984(defun make-face-bold-italic (face &optional frame noerror)
465fceed 985 "Make the font of the given face be bold and italic, if possible.
bb9a81fc 986If NOERROR is non-nil, return nil on failure."
465fceed 987 (interactive (list (read-face-name "Make which face bold-italic: ")))
1bcb155c
RS
988 ;; Set the bold-p and italic-p flags, first of all.
989 (internal-set-face-1 face nil t 10 frame)
990 (internal-set-face-1 face nil t 11 frame)
534dbc97 991 (if (and (eq frame t) (listp (face-font face t)))
f3f31ccf 992 (set-face-font face '(bold italic) t)
488bedff 993 (let (font)
f3f31ccf
RS
994 (if (null frame)
995 (let ((frames (frame-list)))
996 ;; Make this face bold-italic in global-face-data.
997 (make-face-bold-italic face t noerror)
998 ;; Make this face bold in each frame.
999 (while frames
1000 (make-face-bold-italic face (car frames) noerror)
1001 (setq frames (cdr frames))))
1002 (setq face (internal-get-face face frame))
1003 (setq font (or (face-font face frame)
1004 (face-font face t)))
1005 (if (listp font)
1006 (setq font nil))
1007 (setq font (or font
1008 (face-font 'default frame)
1009 (cdr (assq 'font (frame-parameters frame)))))
488bedff
RS
1010 (or (and font (make-face-bold-italic-internal face frame font))
1011 ;; We failed to find a bold italic version.
1012 noerror
1013 (error "No bold italic version of %S" font))))))
f3f31ccf 1014
4b3203d9 1015(defun make-face-bold-italic-internal (face frame font)
f3f31ccf
RS
1016 (let (f2 f3)
1017 (or (and (setq f2 (x-make-font-italic font))
1018 (not (equal font f2))
1019 (setq f3 (x-make-font-bold f2))
1020 (not (equal f2 f3))
1021 (internal-try-face-font face f3 frame))
1022 (and (setq f2 (x-make-font-oblique font))
1023 (not (equal font f2))
1024 (setq f3 (x-make-font-bold f2))
1025 (not (equal f2 f3))
1026 (internal-try-face-font face f3 frame))
1027 (and (setq f2 (x-make-font-italic font))
1028 (not (equal font f2))
1029 (setq f3 (x-make-font-demibold f2))
1030 (not (equal f2 f3))
1031 (internal-try-face-font face f3 frame))
1032 (and (setq f2 (x-make-font-oblique font))
1033 (not (equal font f2))
1034 (setq f3 (x-make-font-demibold f2))
1035 (not (equal f2 f3))
1036 (internal-try-face-font face f3 frame)))))
bb9a81fc
JB
1037
1038(defun make-face-unbold (face &optional frame noerror)
465fceed 1039 "Make the font of the given face be non-bold, if possible.
bb9a81fc 1040If NOERROR is non-nil, return nil on failure."
465fceed 1041 (interactive (list (read-face-name "Make which face non-bold: ")))
1bcb155c
RS
1042 ;; Clear the bold-p flag, first of all.
1043 (internal-set-face-1 face nil nil 10 frame)
534dbc97 1044 (if (and (eq frame t) (listp (face-font face t)))
f3f31ccf
RS
1045 (set-face-font face (if (memq 'italic (face-font face t))
1046 '(italic) nil)
1047 t)
488bedff 1048 (let (font font1)
f3f31ccf
RS
1049 (if (null frame)
1050 (let ((frames (frame-list)))
1051 ;; Make this face unbold in global-face-data.
1052 (make-face-unbold face t noerror)
1053 ;; Make this face unbold in each frame.
1054 (while frames
1055 (make-face-unbold face (car frames) noerror)
1056 (setq frames (cdr frames))))
1057 (setq face (internal-get-face face frame))
1058 (setq font1 (or (face-font face frame)
1059 (face-font face t)))
1060 (if (listp font1)
1061 (setq font1 nil))
1062 (setq font1 (or font1
1063 (face-font 'default frame)
1064 (cdr (assq 'font (frame-parameters frame)))))
96616c04 1065 (setq font (and font1 (x-make-font-unbold font1)))
488bedff
RS
1066 (or (if font (internal-try-face-font face font frame))
1067 noerror
1068 (error "No unbold version of %S" font1))))))
bb9a81fc
JB
1069
1070(defun make-face-unitalic (face &optional frame noerror)
465fceed 1071 "Make the font of the given face be non-italic, if possible.
bb9a81fc 1072If NOERROR is non-nil, return nil on failure."
465fceed 1073 (interactive (list (read-face-name "Make which face non-italic: ")))
1bcb155c
RS
1074 ;; Clear the italic-p flag, first of all.
1075 (internal-set-face-1 face nil nil 11 frame)
534dbc97 1076 (if (and (eq frame t) (listp (face-font face t)))
f3f31ccf
RS
1077 (set-face-font face (if (memq 'bold (face-font face t))
1078 '(bold) nil)
1079 t)
488bedff 1080 (let (font font1)
f3f31ccf
RS
1081 (if (null frame)
1082 (let ((frames (frame-list)))
1083 ;; Make this face unitalic in global-face-data.
1084 (make-face-unitalic face t noerror)
1085 ;; Make this face unitalic in each frame.
1086 (while frames
1087 (make-face-unitalic face (car frames) noerror)
1088 (setq frames (cdr frames))))
1089 (setq face (internal-get-face face frame))
1090 (setq font1 (or (face-font face frame)
1091 (face-font face t)))
1092 (if (listp font1)
1093 (setq font1 nil))
1094 (setq font1 (or font1
1095 (face-font 'default frame)
1096 (cdr (assq 'font (frame-parameters frame)))))
96616c04 1097 (setq font (and font1 (x-make-font-unitalic font1)))
488bedff
RS
1098 (or (if font (internal-try-face-font face font frame))
1099 noerror
1100 (error "No unitalic version of %S" font1))))))
465fceed 1101\f
710e7005
RS
1102(defvar list-faces-sample-text
1103 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1104 "*Text string to display as the sample text for `list-faces-display'.")
1105
1106;; The name list-faces would be more consistent, but let's avoid a conflict
1107;; with Lucid, which uses that name differently.
1108(defun list-faces-display ()
1109 "List all faces, using the same sample text in each.
1110The sample text is a string that comes from the variable
1111`list-faces-sample-text'.
1112
1113It is possible to give a particular face name different appearances in
1114different frames. This command shows the appearance in the
1115selected frame."
1116 (interactive)
1117 (let ((faces (sort (face-list) (function string-lessp)))
1118 (face nil)
1119 (frame (selected-frame))
1120 disp-frame window)
1121 (with-output-to-temp-buffer "*Faces*"
1122 (save-excursion
1123 (set-buffer standard-output)
1124 (setq truncate-lines t)
1125 (while faces
1126 (setq face (car faces))
1127 (setq faces (cdr faces))
1128 (insert (format "%25s " (symbol-name face)))
1129 (let ((beg (point)))
1130 (insert list-faces-sample-text)
1131 (insert "\n")
23b04eac
RS
1132 (put-text-property beg (1- (point)) 'face face)
1133 ;; If the sample text has multiple lines, line up all of them.
1134 (goto-char beg)
1135 (forward-line 1)
1136 (while (not (eobp))
1137 (insert " ")
1138 (forward-line 1))))
710e7005
RS
1139 (goto-char (point-min))))
1140 ;; If the *Faces* buffer appears in a different frame,
1141 ;; copy all the face definitions from FRAME,
1142 ;; so that the display will reflect the frame that was selected.
1143 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1144 (setq disp-frame (if window (window-frame window)
1145 (car (frame-list))))
1146 (or (eq frame disp-frame)
1147 (let ((faces (face-list)))
1148 (while faces
1149 (copy-face (car faces) (car faces) frame disp-frame)
1150 (setq faces (cdr faces)))))))
19deb21e
RS
1151
1152(defun describe-face (face)
1153 "Display the properties of face FACE."
1154 (interactive (list (read-face-name "Describe face: ")))
1155 (with-output-to-temp-buffer "*Help*"
1156 (princ "Properties of face `")
1157 (princ (face-name face))
1158 (princ "':") (terpri)
1159 (princ "Foreground: ") (princ (face-foreground face)) (terpri)
1160 (princ "Background: ") (princ (face-background face)) (terpri)
1161 (princ " Font: ") (princ (face-font face)) (terpri)
1162 (princ "Underlined: ") (princ (if (face-underline-p face) "yes" "no")) (terpri)
64b26d5c
RS
1163 (princ " Stipple: ") (princ (or (face-stipple face) "none")) (terpri)
1164 (terpri)
1165 (princ "Documentation:") (terpri)
02e0989b 1166 (let ((doc (face-documentation face)))
64b26d5c
RS
1167 (if doc
1168 (princ doc)
1169 (princ "not documented as a face.")))))
710e7005 1170\f
d11fba25
RS
1171;;; Setting a face based on a SPEC.
1172
95c7d3d3
RS
1173(defun face-attr-match-p (face attrs &optional frame)
1174 (or frame (setq frame (selected-frame)))
1175 (and (face-attr-match-1 face frame attrs ':inverse-video
1176 'face-inverse-video-p)
1177 (if (face-inverse-video-p face frame)
1178 (and
1179 (face-attr-match-1 face frame attrs
1180 ':foreground 'face-background
1181 (cdr (assq 'foreground-color
1182 (frame-parameters frame))))
1183 (face-attr-match-1 face frame attrs
1184 ':background 'face-foreground
1185 (cdr (assq 'background-color
1186 (frame-parameters frame)))))
1187 (and
1188 (face-attr-match-1 face frame attrs ':foreground 'face-foreground)
1189 (face-attr-match-1 face frame attrs ':background 'face-background)))
1190 (face-attr-match-1 face frame attrs ':stipple 'face-stipple)
1191 (face-attr-match-1 face frame attrs ':bold 'face-bold-p)
1192 (face-attr-match-1 face frame attrs ':italic 'face-italic-p)
1193 (face-attr-match-1 face frame attrs ':underline 'face-underline-p)
1194))
1195
1196(defun face-attr-match-1 (face frame plist property function
1197 &optional defaultval)
1198 (while (and plist (not (eq (car plist) property)))
1199 (setq plist (cdr (cdr plist))))
1200 (eq (funcall function face frame)
1201 (if plist
1202 (nth 1 plist)
1203 (or defaultval
1204 (funcall function 'default frame)))))
1205
1206(defun face-spec-match-p (face spec &optional frame)
1207 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1208 (face-attr-match-p face (face-spec-choose spec frame) frame))
1209
1210(defun face-attr-construct (face &optional frame)
1211 "Return a defface-style attribute list for FACE, as it exists on FRAME."
1212 (let (result)
1213 (if (face-inverse-video-p face frame)
1214 (progn
1215 (setq result (cons ':inverse-video (cons t result)))
1216 (or (face-attr-match-1 face frame nil
1217 ':foreground 'face-background
1218 (cdr (assq 'foreground-color
1219 (frame-parameters frame))))
1220 (setq result (cons ':foreground
1221 (cons (face-foreground face frame) result))))
1222 (or (face-attr-match-1 face frame nil
1223 ':background 'face-foreground
1224 (cdr (assq 'background-color
1225 (frame-parameters frame))))
1226 (setq result (cons ':background
1227 (cons (face-background face frame) result)))))
1228 (if (face-foreground face frame)
1229 (setq result (cons ':foreground
1230 (cons (face-foreground face frame) result))))
1231 (if (face-background face frame)
1232 (setq result (cons ':background
1233 (cons (face-background face frame) result)))))
1234 (if (face-stipple face frame)
1235 (setq result (cons ':stipple
1236 (cons (face-stipple face frame) result))))
1237 (if (face-bold-p face frame)
1238 (setq result (cons ':bold
1239 (cons (face-bold-p face frame) result))))
1240 (if (face-italic-p face frame)
1241 (setq result (cons ':italic
1242 (cons (face-italic-p face frame) result))))
1243 (if (face-underline-p face frame)
1244 (setq result (cons ':underline
1245 (cons (face-underline-p face frame) result))))
1246 result))
1247
1248;; Choose the proper attributes for FRAME, out of SPEC.
1249(defun face-spec-choose (spec &optional frame)
1250 (or frame (setq frame (selected-frame)))
1251 (let ((tail spec)
1252 result)
1253 (while tail
d11fba25
RS
1254 (let* ((entry (car tail))
1255 (display (nth 0 entry))
1256 (attrs (nth 1 entry)))
1257 (setq tail (cdr tail))
d11fba25 1258 (when (face-spec-set-match-display display frame)
95c7d3d3
RS
1259 (setq result attrs tail nil))))
1260 result))
1261
1262(defun face-spec-set (face spec &optional frame)
1263 "Set FACE's face attributes according to the first matching entry in SPEC.
1264If optional FRAME is non-nil, set it for that frame only.
1265If it is nil, then apply SPEC to each frame individually.
1266See `defface' for information about SPEC."
1267 (if frame
1268 (let ((attrs (face-spec-choose spec frame)))
1269 (when attrs
1270 ;; If the font was set automatically, clear it out
1271 ;; to allow it to be set it again.
1272 (unless (face-font-explicit face frame)
1273 (set-face-font face nil frame))
d343b6f1 1274 (modify-face face '(nil) '(nil) nil nil nil nil nil frame)
d11fba25
RS
1275 (face-spec-set-1 face frame attrs ':foreground 'set-face-foreground)
1276 (face-spec-set-1 face frame attrs ':background 'set-face-background)
1277 (face-spec-set-1 face frame attrs ':stipple 'set-face-stipple)
1278 (face-spec-set-1 face frame attrs ':bold 'set-face-bold-p)
1279 (face-spec-set-1 face frame attrs ':italic 'set-face-italic-p)
1280 (face-spec-set-1 face frame attrs ':underline 'set-face-underline-p)
e8e4cda0 1281 (face-spec-set-1 face frame attrs ':inverse-video
95c7d3d3
RS
1282 'set-face-inverse-video-p)))
1283 (let ((frames (frame-list))
1284 frame)
1285 (while frames
1286 (setq frame (car frames)
1287 frames (cdr frames))
1288 (face-spec-set face (or (get face 'saved-face)
1289 (get face 'face-defface-spec))
1290 frame)
1291 (face-spec-set face spec frame)))))
d11fba25
RS
1292
1293(defun face-spec-set-1 (face frame plist property function)
1294 (while (and plist (not (eq (car plist) property)))
1295 (setq plist (cdr (cdr plist))))
1296 (if plist
1297 (funcall function face (nth 1 plist) frame)))
1298
1299(defun face-spec-set-match-display (display frame)
1300 "Non-nil iff DISPLAY matches FRAME.
1301DISPLAY is part of a spec such as can be used in `defface'.
1302If FRAME is nil, the current FRAME is used."
1303 (let* ((conjuncts display)
1304 conjunct req options
1305 ;; t means we have succeeded against all
1306 ;; the conjunts in DISPLAY that have been tested so far.
1307 (match t))
1308 (if (eq conjuncts t)
1309 (setq conjuncts nil))
1310 (while (and conjuncts match)
1311 (setq conjunct (car conjuncts)
1312 conjuncts (cdr conjuncts)
1313 req (car conjunct)
1314 options (cdr conjunct)
1315 match (cond ((eq req 'type)
1316 (memq window-system options))
1317 ((eq req 'class)
1318 (memq (frame-parameter frame 'display-type) options))
1319 ((eq req 'background)
1320 (memq (frame-parameter frame 'background-mode)
1321 options))
1322 (t
1323 (error "Unknown req `%S' with options `%S'"
1324 req options)))))
1325 match))
465fceed 1326\f
465fceed
ER
1327;; Like x-create-frame but also set up the faces.
1328
1329(defun x-create-frame-with-faces (&optional parameters)
6e4aafdc
KH
1330 ;; Read this frame's geometry resource, if it has an explicit name,
1331 ;; and put the specs into PARAMETERS.
1332 (let* ((name (or (cdr (assq 'name parameters))
313b841c 1333 (cdr (assq 'name default-frame-alist))))
6e4aafdc 1334 (x-resource-name name)
28ceec49 1335 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
6e4aafdc 1336 (if res-geometry
28ceec49 1337 (let ((parsed (x-parse-geometry res-geometry)))
6e4aafdc
KH
1338 ;; If the resource specifies a position,
1339 ;; call the position and size "user-specified".
1340 (if (or (assq 'top parsed) (assq 'left parsed))
28ceec49
SM
1341 (setq parsed (append '((user-position . t) (user-size . t))
1342 parsed)))
313b841c
KH
1343 ;; Put the geometry parameters at the end.
1344 ;; Copy default-frame-alist so that they go after it.
28ceec49 1345 (setq parameters (append parameters default-frame-alist parsed)))))
ef436392
KH
1346 (let (frame)
1347 (if (null global-face-data)
d11fba25
RS
1348 (progn
1349 (setq frame (x-create-frame parameters))
1350 (frame-set-background-mode frame))
ef436392 1351 (let* ((visibility-spec (assq 'visibility parameters))
d11fba25 1352 success faces rest)
ef436392
KH
1353 (setq frame (x-create-frame (cons '(visibility . nil) parameters)))
1354 (unwind-protect
1355 (progn
d11fba25
RS
1356 ;; Copy the face alist, copying the face vectors
1357 ;; and emptying out their attributes.
1358 (setq faces
1359 (mapcar '(lambda (elt)
1360 (cons (car elt)
1361 (vector 'face
1362 (face-name (cdr elt))
1363 (face-id (cdr elt))
1bcb155c
RS
1364 nil
1365 nil nil nil nil
1366 nil nil nil nil)))
d11fba25 1367 global-face-data))
ef436392
KH
1368 (set-frame-face-alist frame faces)
1369
d11fba25
RS
1370 ;; Handle the reverse-video frame parameter
1371 ;; and X resource. x-create-frame does not handle this one.
ef436392
KH
1372 (if (cdr (or (assq 'reverse parameters)
1373 (assq 'reverse default-frame-alist)
1374 (let ((resource (x-get-resource "reverseVideo"
1375 "ReverseVideo")))
1376 (if resource
1377 (cons nil (member (downcase resource)
1378 '("on" "true")))))))
1379 (let* ((params (frame-parameters frame))
1380 (bg (cdr (assq 'foreground-color params)))
1381 (fg (cdr (assq 'background-color params))))
1382 (modify-frame-parameters frame
1383 (list (cons 'foreground-color fg)
1384 (cons 'background-color bg)))
1385 (if (equal bg (cdr (assq 'border-color params)))
1386 (modify-frame-parameters frame
1387 (list (cons 'border-color fg))))
1388 (if (equal bg (cdr (assq 'mouse-color params)))
1389 (modify-frame-parameters frame
1390 (list (cons 'mouse-color fg))))
1391 (if (equal bg (cdr (assq 'cursor-color params)))
1392 (modify-frame-parameters frame
1393 (list (cons 'cursor-color fg))))))
d11fba25 1394
f0201260
RS
1395 (frame-set-background-mode frame)
1396
b1eb5e6a 1397 (face-set-after-frame-default frame)
d11fba25
RS
1398
1399 ;; Make the frame visible, if desired.
ef436392
KH
1400 (if (null visibility-spec)
1401 (make-frame-visible frame)
1402 (modify-frame-parameters frame (list visibility-spec)))
1403 (setq success t))
1404 (or success
1405 (delete-frame frame)))))
ef436392 1406 frame))
e09c52a8 1407
b1eb5e6a
RS
1408;; Update a frame's faces after the frame font changes.
1409;; This is called from modify-frame-parameters
1410;; as well as from elsewhere in this file.
1411(defun face-set-after-frame-default (frame)
1412 (let ((rest (frame-face-alist frame)))
1413 (while rest
1414 ;; Set up each face, first from the defface information,
1415 ;; then the global face data, and then the X resources.
1416 (let* ((face (car (car rest)))
1417 (spec (or (get face 'saved-face)
1418 (get face 'face-defface-spec)))
1419 (global (cdr (assq face global-face-data)))
1420 (local (cdr (car rest))))
87b6ab4c 1421 (when spec
b1eb5e6a
RS
1422 (face-spec-set face spec frame))
1423 (face-fill-in face global frame)
1424 (make-face-x-resource-internal local frame))
1425 (setq rest (cdr rest)))))
1426
d11fba25
RS
1427(defcustom frame-background-mode nil
1428 "*The brightness of the background.
1429Set this to the symbol dark if your background color is dark, light if
1430your background is light, or nil (default) if you want Emacs to
1431examine the brightness for you."
1432 :group 'faces
ba7eadda
RS
1433 :set #'(lambda (var value)
1434 (set var value)
1435 (mapcar 'frame-set-background-mode (frame-list)))
1436 :initialize 'custom-initialize-changed
d11fba25
RS
1437 :type '(choice (choice-item dark)
1438 (choice-item light)
1439 (choice-item :tag "default" nil)))
1440
1441(defun frame-set-background-mode (frame)
1442 "Set up the `background-mode' and `display-type' frame parameters for FRAME."
1443 (let ((bg-resource (x-get-resource ".backgroundMode"
1444 "BackgroundMode"))
1445 (params (frame-parameters frame))
1446 (bg-mode))
1447 (setq bg-mode
1448 (cond (frame-background-mode)
1449 (bg-resource (intern (downcase bg-resource)))
1450 ((< (apply '+ (x-color-values
1451 (cdr (assq 'background-color params))
1452 frame))
1453 ;; Just looking at the screen,
1454 ;; colors whose values add up to .6 of the white total
1455 ;; still look dark to me.
1456 (* (apply '+ (x-color-values "white" frame)) .6))
1457 'dark)
1458 (t 'light)))
1459 (modify-frame-parameters frame
1460 (list (cons 'background-mode bg-mode)
1461 (cons 'display-type
1462 (cond ((x-display-color-p frame)
1463 'color)
1464 ((x-display-grayscale-p frame)
1465 'grayscale)
1466 (t 'mono)))))))
1467
9d52c8d3 1468;; Update a frame's faces when we change its default font.
b1eb5e6a 1469(defun frame-update-faces (frame) nil)
9d52c8d3 1470
f16c38ae
RS
1471;; Update the colors of FACE, after FRAME's own colors have been changed.
1472;; This applies only to faces with global color specifications
1473;; that are not simple constants.
1474(defun frame-update-face-colors (frame)
0bea75b9 1475 (frame-set-background-mode frame)
f16c38ae
RS
1476 (let ((faces global-face-data))
1477 (while faces
1478 (condition-case nil
1479 (let* ((data (cdr (car faces)))
1480 (face (car (car faces)))
1481 (foreground (face-foreground data))
1482 (background (face-background data)))
1483 ;; If the global spec is a specific color,
1484 ;; which doesn't depend on the frame's attributes,
1485 ;; we don't need to recalculate it now.
1486 (or (listp foreground)
1487 (setq foreground nil))
1488 (or (listp background)
1489 (setq background nil))
1490 ;; If we are going to frob this face at all,
1491 ;; reinitialize it first.
1492 (if (or foreground background)
1493 (progn (set-face-foreground face nil frame)
1494 (set-face-background face nil frame)))
1495 (if foreground
1496 (face-try-color-list 'set-face-foreground
1497 face foreground frame))
1498 (if background
1499 (face-try-color-list 'set-face-background
1500 face background frame)))
1501 (error nil))
1502 (setq faces (cdr faces)))))
1503
19ae9866
RS
1504;; Fill in the face FACE from frame-independent face data DATA.
1505;; DATA should be the non-frame-specific ("global") face vector
1506;; for the face. FACE should be a face name or face object.
1507;; FRAME is the frame to act on; it must be an actual frame, not nil or t.
1508(defun face-fill-in (face data frame)
1509 (condition-case nil
1510 (let ((foreground (face-foreground data))
1511 (background (face-background data))
ca58b3ec
KH
1512 (font (face-font data))
1513 (stipple (face-stipple data)))
e8e4cda0
RS
1514 (if (face-underline-p data)
1515 (set-face-underline-p face (face-underline-p data) frame))
19ae9866
RS
1516 (if foreground
1517 (face-try-color-list 'set-face-foreground
1518 face foreground frame))
1519 (if background
1520 (face-try-color-list 'set-face-background
1521 face background frame))
1522 (if (listp font)
1523 (let ((bold (memq 'bold font))
1524 (italic (memq 'italic font)))
1525 (cond ((and bold italic)
1526 (make-face-bold-italic face frame))
1527 (bold
1528 (make-face-bold face frame))
1529 (italic
1530 (make-face-italic face frame))))
1531 (if font
ca58b3ec
KH
1532 (set-face-font face font frame)))
1533 (if stipple
1534 (set-face-stipple face stipple frame)))
19ae9866 1535 (error nil)))
e09c52a8 1536
4099a32d
RS
1537;; Assuming COLOR is a valid color name,
1538;; return t if it can be displayed on FRAME.
1539(defun face-color-supported-p (frame color background-p)
055ff5a6
RS
1540 (and window-system
1541 (or (x-display-color-p frame)
1542 ;; A black-and-white display can implement these.
1543 (member color '("black" "white"))
1544 ;; A black-and-white display can fake gray for background.
1545 (and background-p
1546 (face-color-gray-p color frame))
1547 ;; A grayscale display can implement colors that are gray (more or less).
1548 (and (x-display-grayscale-p frame)
1549 (face-color-gray-p color frame)))))
4099a32d 1550
19ae9866
RS
1551;; Use FUNCTION to store a color in FACE on FRAME.
1552;; COLORS is either a single color or a list of colors.
1553;; If it is a list, try the colors one by one until one of them
1554;; succeeds. We signal an error only if all the colors failed.
1555;; t as COLORS or as an element of COLORS means to invert the face.
1556;; That can't fail, so any subsequent elements after the t are ignored.
1557(defun face-try-color-list (function face colors frame)
1558 (if (stringp colors)
4099a32d
RS
1559 (if (face-color-supported-p frame colors
1560 (eq function 'set-face-background))
1561 (funcall function face colors frame))
19ae9866 1562 (if (eq colors t)
e8e4cda0 1563 (set-face-inverse-video-p face t frame)
19ae9866
RS
1564 (let (done)
1565 (while (and colors (not done))
de52827f 1566 (if (or (memq (car colors) '(t underline))
4099a32d
RS
1567 (face-color-supported-p frame (car colors)
1568 (eq function 'set-face-background)))
1569 (if (cdr colors)
1570 ;; If there are more colors to try, catch errors
1571 ;; and set `done' if we succeed.
1572 (condition-case nil
1573 (progn
1574 (cond ((eq (car colors) t)
e8e4cda0 1575 (set-face-inverse-video-p face t frame))
4099a32d
RS
1576 ((eq (car colors) 'underline)
1577 (set-face-underline-p face t frame))
1578 (t
1579 (funcall function face (car colors) frame)))
1580 (setq done t))
1581 (error nil))
1582 ;; If this is the last color, let the error get out if it fails.
1583 ;; If it succeeds, we will exit anyway after this iteration.
1584 (cond ((eq (car colors) t)
e8e4cda0 1585 (set-face-inverse-video-p face t frame))
4099a32d
RS
1586 ((eq (car colors) 'underline)
1587 (set-face-underline-p face t frame))
1588 (t
1589 (funcall function face (car colors) frame)))))
19ae9866 1590 (setq colors (cdr colors)))))))
e09c52a8 1591
55893d25
RS
1592;;; Make the standard faces.
1593;;; The C code knows the default and modeline faces as faces 0 and 1,
1594;;; so they must be the first two faces made.
1595(make-face 'default)
1596(make-face 'modeline)
1597(make-face 'highlight)
1598
1599;; These aren't really special in any way, but they're nice to have around.
1600
1601(make-face 'bold)
1602(make-face 'italic)
1603(make-face 'bold-italic)
1604(make-face 'region)
1605(make-face 'secondary-selection)
1606(make-face 'underline)
1607
1608(setq region-face (face-id 'region))
1609
113ab303
KH
1610(defgroup basic-faces nil
1611 "The standard faces of Emacs."
1612 :prefix "huh"
1613 :group 'faces)
1614
55893d25
RS
1615;; Specify how these faces look, and their documentation.
1616(let ((all '((bold "Use bold font." ((t (:bold t))))
1617 (bold-italic "Use bold italic font." ((t (:bold t :italic t))))
1618 (italic "Use italic font." ((t (:italic t))))
1619 (underline "Underline text." ((t (:underline t))))
1620 (default "Used for text not covered by other faces." ((t nil)))
1621 (highlight "Highlight text in some way."
1c1e0fe5
RS
1622 ((((class color) (background light))
1623 (:background "darkseagreen2"))
1624 (((class color) (background dark))
1625 (:background "darkolivegreen"))
55893d25
RS
1626 (t (:inverse-video t))))
1627 (modeline "Used for displaying the modeline."
1628 ((t (:inverse-video t))))
1629 (region "Used for displaying the region."
1c1e0fe5
RS
1630 ((((class color) (background dark))
1631 (:background "blue"))
1632 (t (:background "gray"))))
55893d25
RS
1633 (secondary-selection
1634 "Used for displaying the secondary selection."
1c1e0fe5
RS
1635 ((((class color) (background light))
1636 (:background "paleturquoise"))
1637 (((class color) (background dark))
1638 (:background "darkslateblue"))
55893d25
RS
1639 (t (:inverse-video t))))))
1640 entry symbol doc spec)
1641 (while all
1642 (setq entry (car all)
1643 all (cdr all)
1644 symbol (nth 0 entry)
1645 doc (nth 1 entry)
1646 spec (nth 2 entry))
113ab303 1647 (custom-add-to-group 'basic-faces symbol 'custom-face)
55893d25
RS
1648 (put symbol 'face-documentation doc)
1649 (put symbol 'face-defface-spec spec)))
465fceed 1650
f0138172
JB
1651(provide 'faces)
1652
465fceed 1653;;; faces.el ends here