Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / faces.el
CommitLineData
5f5c8ee5 1;;; faces.el --- Lisp faces
465fceed 2
73b0cd50 3;; Copyright (C) 1992-1996, 1998-2011
3446bfc8 4;; Free Software Foundation, Inc.
465fceed 5
6228c05b 6;; Maintainer: FSF
30764597 7;; Keywords: internal
bd78fa1d 8;; Package: emacs
6228c05b 9
465fceed
ER
10;; This file is part of GNU Emacs.
11
eb3fa2cf 12;; GNU Emacs is free software: you can redistribute it and/or modify
465fceed 13;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
465fceed
ER
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
eb3fa2cf 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
465fceed
ER
24
25;;; Commentary:
26
465fceed
ER
27;;; Code:
28
39b3b754 29(eval-when-compile
f31b1257
DN
30 (require 'cl))
31
c8ccffb1 32(declare-function xw-defined-colors "term/common-win" (&optional frame))
5f5c8ee5 33
b782a458 34(defvar help-xref-stack-item)
2aef0850
JL
35
36(defvar face-name-history nil
37 "History list for some commands that read face names.
38Maximum length of the history list is determined by the value
39of `history-length', which see.")
40
5f5c8ee5
GM
41\f
42;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43;;; Font selection.
44;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
46(defgroup font-selection nil
47 "Influencing face font selection."
48 :group 'faces)
49
50
51(defcustom face-font-selection-order
52 '(:width :height :weight :slant)
9201cc28 53 "A list specifying how face font selection chooses fonts.
5f5c8ee5
GM
54Each of the four symbols `:width', `:height', `:weight', and `:slant'
55must appear once in the list, and the list must not contain any other
7c626e9d 56elements. Font selection first tries to find a best matching font
b73f65b6 57for those face attributes that appear before in the list. For
5f5c8ee5
GM
58example, if `:slant' appears before `:height', font selection first
59tries to find a font with a suitable slant, even if this results in
60a font height that isn't optimal."
239ad97f 61 :tag "Font selection order"
94354bdd 62 :type '(list symbol symbol symbol symbol)
5f5c8ee5
GM
63 :group 'font-selection
64 :set #'(lambda (symbol value)
65 (set-default symbol value)
66 (internal-set-font-selection-order value)))
67
18f1dcb4 68
ed008205 69;; In the absence of Fontconfig support, Monospace and Sans Serif are
80073c33
CY
70;; unavailable, and we fall back on the courier and helv families,
71;; which are generally available.
5f5c8ee5 72(defcustom face-font-family-alternatives
1e8780b1 73 (mapcar (lambda (arg) (mapcar 'purecopy arg))
d5f57335 74 '(("Monospace" "courier" "fixed")
f37a389e 75 ("courier" "CMU Typewriter Text" "fixed")
ed008205 76 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
1e8780b1 77 ("helv" "helvetica" "arial" "fixed")))
9201cc28 78 "Alist of alternative font family names.
86886bce 79Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
5f5c8ee5
GM
80If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
81ALTERNATIVE2 etc."
239ad97f 82 :tag "Alternative font families to try"
94354bdd 83 :type '(repeat (repeat string))
5f5c8ee5
GM
84 :group 'font-selection
85 :set #'(lambda (symbol value)
86 (set-default symbol value)
87 (internal-set-alternative-font-family-alist value)))
88
89
18f1dcb4
GM
90;; This is defined originally in xfaces.c.
91(defcustom face-font-registry-alternatives
1e8780b1 92 (mapcar (lambda (arg) (mapcar 'purecopy arg))
c97db4e4 93 (if (eq system-type 'windows-nt)
990d68dd 94 '(("iso8859-1" "ms-oemlatin")
e38c812e 95 ("gb2312.1980" "gb2312" "gbk" "gb18030")
c97db4e4
AI
96 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
97 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
98 ("muletibetan-2" "muletibetan-0"))
e38c812e 99 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
c97db4e4
AI
100 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
101 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
1e8780b1 102 ("muletibetan-2" "muletibetan-0"))))
9201cc28 103 "Alist of alternative font registry names.
86886bce 104Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
8ac2d32f
KH
105If fonts of registry REGISTRY can be loaded, font selection
106tries to find a best matching font among all fonts of registry
107REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
239ad97f 108 :tag "Alternative font registries to try"
18f1dcb4 109 :type '(repeat (repeat string))
f676894c 110 :version "21.1"
18f1dcb4
GM
111 :group 'font-selection
112 :set #'(lambda (symbol value)
113 (set-default symbol value)
114 (internal-set-alternative-font-registry-alist value)))
115
bdda3754 116\f
5f5c8ee5
GM
117;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118;;; Creation, copying.
119;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120
121
122(defun face-list ()
123 "Return a list of all defined face names."
124 (mapcar #'car face-new-frame-defaults))
125
126
127;;; ### If not frame-local initialize by what X resources?
128
129(defun make-face (face &optional no-init-from-resources)
130 "Define a new face with name FACE, a symbol.
131NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
132variants of FACE from X resources. (X resources recognized are found
133in the global variable `face-x-resources'.) If FACE is already known
134as a face, leave it unmodified. Value is FACE."
2aef0850
JL
135 (interactive (list (read-from-minibuffer
136 "Make face: " nil nil t 'face-name-history)))
5f5c8ee5
GM
137 (unless (facep face)
138 ;; Make frame-local faces (this also makes the global one).
139 (dolist (frame (frame-list))
140 (internal-make-lisp-face face frame))
141 ;; Add the face to the face menu.
142 (when (fboundp 'facemenu-add-new-face)
143 (facemenu-add-new-face face))
144 ;; Define frame-local faces for all frames from X resources.
145 (unless no-init-from-resources
146 (make-face-x-resource-internal face)))
147 face)
148
149
150(defun make-empty-face (face)
151 "Define a new, empty face with name FACE.
152If the face already exists, it is left unmodified. Value is FACE."
2aef0850
JL
153 (interactive (list (read-from-minibuffer
154 "Make empty face: " nil nil t 'face-name-history)))
5f5c8ee5
GM
155 (make-face face 'no-init-from-resources))
156
157
158(defun copy-face (old-face new-face &optional frame new-frame)
159 "Define a face just like OLD-FACE, with name NEW-FACE.
160
161If NEW-FACE already exists as a face, it is modified to be like
162OLD-FACE. If it doesn't already exist, it is created.
163
1c521fb0 164If the optional argument FRAME is given as a frame, NEW-FACE is
5f5c8ee5
GM
165changed on FRAME only.
166If FRAME is t, the frame-independent default specification for OLD-FACE
167is copied to NEW-FACE.
168If FRAME is nil, copying is done for the frame-independent defaults
169and for each existing frame.
170
171If the optional fourth argument NEW-FRAME is given,
172copy the information from face OLD-FACE on frame FRAME
341a1bfb 173to NEW-FACE on frame NEW-FRAME. In this case, FRAME may not be nil."
5f5c8ee5
GM
174 (let ((inhibit-quit t))
175 (if (null frame)
176 (progn
341a1bfb
RS
177 (when new-frame
178 (error "Copying face %s from all frames to one frame"
179 old-face))
180 (make-empty-face new-face)
5f5c8ee5
GM
181 (dolist (frame (frame-list))
182 (copy-face old-face new-face frame))
183 (copy-face old-face new-face t))
341a1bfb 184 (make-empty-face new-face)
5f5c8ee5
GM
185 (internal-copy-lisp-face old-face new-face frame new-frame))
186 new-face))
187
5f5c8ee5
GM
188\f
189;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
190;;; Predicates, type checks.
191;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
192
193(defun facep (face)
20d29b0b
RS
194 "Return non-nil if FACE is a face name; nil otherwise.
195A face name can be a string or a symbol."
5f5c8ee5
GM
196 (internal-lisp-face-p face))
197
198
199(defun check-face (face)
200 "Signal an error if FACE doesn't name a face.
201Value is FACE."
202 (unless (facep face)
203 (error "Not a face: %s" face))
204 face)
205
206
207;; The ID returned is not to be confused with the internally used IDs
208;; of realized faces. The ID assigned to Lisp faces is used to
209;; support faces in display table entries.
210
211(defun face-id (face &optional frame)
2df447f2 212 "Return the internal ID of face with name FACE.
b2d5aa46 213If FACE is a face-alias, return the ID of the target face.
9ae89a1a
RS
214The optional argument FRAME is ignored, since the internal face ID
215of a face name is the same for all frames."
5f5c8ee5 216 (check-face face)
b2d5aa46
JB
217 (or (get face 'face)
218 (face-id (get face 'face-alias))))
5f5c8ee5
GM
219
220(defun face-equal (face1 face2 &optional frame)
221 "Non-nil if faces FACE1 and FACE2 are equal.
222Faces are considered equal if all their attributes are equal.
a09be93a
JB
223If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
224If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
5f5c8ee5
GM
225If FRAME is omitted or nil, use the selected frame."
226 (internal-lisp-face-equal-p face1 face2 frame))
227
228
229(defun face-differs-from-default-p (face &optional frame)
7e07a66d 230 "Return non-nil if FACE displays differently from the default face.
5f5c8ee5
GM
231If the optional argument FRAME is given, report on face FACE in that frame.
232If FRAME is t, report on the defaults for face FACE (for new frames).
7e07a66d 233If FRAME is omitted or nil, use the selected frame."
1151d617 234 (let ((attrs
833547aa 235 (delq :inherit (mapcar 'car face-attribute-name-alist)))
1151d617
MB
236 (differs nil))
237 (while (and attrs (not differs))
238 (let* ((attr (pop attrs))
239 (attr-val (face-attribute face attr frame t)))
240 (when (and
241 (not (eq attr-val 'unspecified))
242 (display-supports-face-attributes-p (list attr attr-val)
243 frame))
244 (setq differs attr))))
245 differs))
5f5c8ee5
GM
246
247
248(defun face-nontrivial-p (face &optional frame)
249 "True if face FACE has some non-nil attribute.
250If the optional argument FRAME is given, report on face FACE in that frame.
251If FRAME is t, report on the defaults for face FACE (for new frames).
252If FRAME is omitted or nil, use the selected frame."
253 (not (internal-lisp-face-empty-p face frame)))
254
255
256\f
257;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
258;;; Setting face attributes from X resources.
259;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260
261(defcustom face-x-resources
1e8780b1
DN
262 (mapcar
263 (lambda (arg)
264 ;; FIXME; can we purecopy some of the conses too?
265 (cons (car arg)
266 (cons (purecopy (car (cdr arg))) (purecopy (cdr (cdr arg))))))
5f5c8ee5 267 '((:family (".attributeFamily" . "Face.AttributeFamily"))
fcea6e23 268 (:foundry (".attributeFoundry" . "Face.AttributeFoundry"))
5f5c8ee5
GM
269 (:width (".attributeWidth" . "Face.AttributeWidth"))
270 (:height (".attributeHeight" . "Face.AttributeHeight"))
271 (:weight (".attributeWeight" . "Face.AttributeWeight"))
272 (:slant (".attributeSlant" . "Face.AttributeSlant"))
273 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
274 (:background (".attributeBackground" . "Face.AttributeBackground"))
275 (:overline (".attributeOverline" . "Face.AttributeOverline"))
276 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
277 (:box (".attributeBox" . "Face.AttributeBox"))
278 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
279 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
280 (:stipple
281 (".attributeStipple" . "Face.AttributeStipple")
282 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
5f5c8ee5
GM
283 (:bold (".attributeBold" . "Face.AttributeBold"))
284 (:italic (".attributeItalic" . "Face.AttributeItalic"))
a0e5a5a4 285 (:font (".attributeFont" . "Face.AttributeFont"))
1e8780b1 286 (:inherit (".attributeInherit" . "Face.AttributeInherit"))))
9201cc28 287 "List of X resources and classes for face attributes.
5f5c8ee5
GM
288Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
289the name of a face attribute, and each ENTRY is a cons of the form
2cb95d1b 290\(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
5f5c8ee5 291X resource class for the attribute."
b5325e78 292 :type '(repeat (cons symbol (repeat (cons string string))))
5f5c8ee5
GM
293 :group 'faces)
294
295
aa360da1
GM
296(declare-function internal-face-x-get-resource "xfaces.c"
297 (resource class frame))
298
299(declare-function internal-set-lisp-face-attribute-from-resource "xfaces.c"
300 (face attr value &optional frame))
301
5f5c8ee5
GM
302(defun set-face-attribute-from-resource (face attribute resource class frame)
303 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
304Value is the attribute value specified by the resource, or nil
305if not present. This function displays a message if the resource
306specifies an invalid attribute."
307 (let* ((face-name (face-name face))
308 (value (internal-face-x-get-resource (concat face-name resource)
309 class frame)))
310 (when value
311 (condition-case ()
312 (internal-set-lisp-face-attribute-from-resource
313 face attribute (downcase value) frame)
314 (error
315 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
316 face-name frame attribute value))))
317 value))
318
319
320(defun set-face-attributes-from-resources (face frame)
321 "Set attributes of FACE from X resources for FRAME."
e51fe00a 322 (when (memq (framep frame) '(x w32))
5f5c8ee5
GM
323 (dolist (definition face-x-resources)
324 (let ((attribute (car definition)))
325 (dolist (entry (cdr definition))
326 (set-face-attribute-from-resource face attribute (car entry)
327 (cdr entry) frame))))))
00f51890
SS
328
329
5f5c8ee5
GM
330(defun make-face-x-resource-internal (face &optional frame)
331 "Fill frame-local FACE on FRAME from X resources.
332FRAME nil or not specified means do it for all frames."
333 (if (null frame)
334 (dolist (frame (frame-list))
335 (set-face-attributes-from-resources face frame))
336 (set-face-attributes-from-resources face frame)))
337
338
339\f
340;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
341;;; Retrieving face attributes.
342;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
343
feaad827 344(defun face-name (face)
465fceed 345 "Return the name of face FACE."
5f5c8ee5
GM
346 (symbol-name (check-face face)))
347
348
833547aa
RS
349(defun face-all-attributes (face &optional frame)
350 "Return an alist stating the attributes of FACE.
351Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
37766706 352If FRAME is omitted or nil the value describes the default attributes,
833547aa
RS
353but if you specify FRAME, the value describes the attributes
354of FACE on FRAME."
606c9f59
RS
355 (mapcar (lambda (pair)
356 (let ((attr (car pair)))
357 (cons attr (face-attribute face attr (or frame t)))))
833547aa
RS
358 face-attribute-name-alist))
359
c7f814cb 360(defun face-attribute (face attribute &optional frame inherit)
5f5c8ee5
GM
361 "Return the value of FACE's ATTRIBUTE on FRAME.
362If the optional argument FRAME is given, report on face FACE in that frame.
363If FRAME is t, report on the defaults for face FACE (for new frames).
c7f814cb 364If FRAME is omitted or nil, use the selected frame.
5f5c8ee5 365
c7f814cb
MB
366If INHERIT is nil, only attributes directly defined by FACE are considered,
367 so the return value may be `unspecified', or a relative value.
368If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
369 faces specified by its `:inherit' attribute; however the return value
370 may still be `unspecified' or relative.
371If INHERIT is a face or a list of faces, then the result is further merged
372 with that face (or faces), until it becomes specified and absolute.
373
374To ensure that the return value is always specified and absolute, use a
375value of `default' for INHERIT; this will resolve any unspecified or
376relative values by merging with the `default' face (which is always
377completely specified)."
378 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
379 (when (and inherit (face-attribute-relative-p attribute value))
380 ;; VALUE is relative, so merge with inherited faces
381 (let ((inh-from (face-attribute face :inherit frame)))
382 (unless (or (null inh-from) (eq inh-from 'unspecified))
621e71ee
SM
383 (condition-case nil
384 (setq value
385 (face-attribute-merged-with attribute value inh-from frame))
386 ;; The `inherit' attribute may point to non existent faces.
387 (error nil)))))
c7f814cb
MB
388 (when (and inherit
389 (not (eq inherit t))
390 (face-attribute-relative-p attribute value))
b6b90dfc 391 ;; We should merge with INHERIT as well
c7f814cb
MB
392 (setq value (face-attribute-merged-with attribute value inherit frame)))
393 value))
5f5c8ee5 394
c7f814cb
MB
395(defun face-attribute-merged-with (attribute value faces &optional frame)
396 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
397FACES may be either a single face or a list of faces.
522fb950 398\[This is an internal function.]"
c7f814cb
MB
399 (cond ((not (face-attribute-relative-p attribute value))
400 value)
401 ((null faces)
402 value)
403 ((consp faces)
404 (face-attribute-merged-with
405 attribute
406 (face-attribute-merged-with attribute value (car faces) frame)
407 (cdr faces)
408 frame))
409 (t
410 (merge-face-attribute attribute
411 value
412 (face-attribute faces attribute frame t)))))
413
414
415(defmacro face-attribute-specified-or (value &rest body)
416 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
417 (let ((temp (make-symbol "value")))
418 `(let ((,temp ,value))
419 (if (not (eq ,temp 'unspecified))
420 ,temp
421 ,@body))))
422
423(defun face-foreground (face &optional frame inherit)
5f5c8ee5
GM
424 "Return the foreground color name of FACE, or nil if unspecified.
425If the optional argument FRAME is given, report on face FACE in that frame.
426If FRAME is t, report on the defaults for face FACE (for new frames).
c7f814cb 427If FRAME is omitted or nil, use the selected frame.
5f5c8ee5 428
c7f814cb
MB
429If INHERIT is nil, only a foreground color directly defined by FACE is
430 considered, so the return value may be nil.
431If INHERIT is t, and FACE doesn't define a foreground color, then any
432 foreground color that FACE inherits through its `:inherit' attribute
433 is considered as well; however the return value may still be nil.
434If INHERIT is a face or a list of faces, then it is used to try to
435 resolve an unspecified foreground color.
436
437To ensure that a valid color is always returned, use a value of
438`default' for INHERIT; this will resolve any unspecified values by
439merging with the `default' face (which is always completely specified)."
440 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
441 nil))
442
443(defun face-background (face &optional frame inherit)
5f5c8ee5
GM
444 "Return the background color name of FACE, or nil if unspecified.
445If the optional argument FRAME is given, report on face FACE in that frame.
446If FRAME is t, report on the defaults for face FACE (for new frames).
c7f814cb 447If FRAME is omitted or nil, use the selected frame.
5f5c8ee5 448
c7f814cb
MB
449If INHERIT is nil, only a background color directly defined by FACE is
450 considered, so the return value may be nil.
451If INHERIT is t, and FACE doesn't define a background color, then any
452 background color that FACE inherits through its `:inherit' attribute
453 is considered as well; however the return value may still be nil.
454If INHERIT is a face or a list of faces, then it is used to try to
455 resolve an unspecified background color.
456
457To ensure that a valid color is always returned, use a value of
458`default' for INHERIT; this will resolve any unspecified values by
459merging with the `default' face (which is always completely specified)."
460 (face-attribute-specified-or (face-attribute face :background frame inherit)
461 nil))
462
463(defun face-stipple (face &optional frame inherit)
5f5c8ee5
GM
464 "Return the stipple pixmap name of FACE, or nil if unspecified.
465If the optional argument FRAME is given, report on face FACE in that frame.
466If FRAME is t, report on the defaults for face FACE (for new frames).
c7f814cb
MB
467If FRAME is omitted or nil, use the selected frame.
468
469If INHERIT is nil, only a stipple directly defined by FACE is
470 considered, so the return value may be nil.
471If INHERIT is t, and FACE doesn't define a stipple, then any stipple
472 that FACE inherits through its `:inherit' attribute is considered as
473 well; however the return value may still be nil.
474If INHERIT is a face or a list of faces, then it is used to try to
475 resolve an unspecified stipple.
476
477To ensure that a valid stipple or nil is always returned, use a value of
478`default' for INHERIT; this will resolve any unspecified values by merging
479with the `default' face (which is always completely specified)."
480 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
481 nil))
5f5c8ee5
GM
482
483
484(defalias 'face-background-pixmap 'face-stipple)
485
486
487(defun face-underline-p (face &optional frame)
488 "Return non-nil if FACE is underlined.
489If the optional argument FRAME is given, report on face FACE in that frame.
490If FRAME is t, report on the defaults for face FACE (for new frames).
491If FRAME is omitted or nil, use the selected frame."
492 (eq (face-attribute face :underline frame) t))
493
494
495(defun face-inverse-video-p (face &optional frame)
496 "Return non-nil if FACE is in inverse video on FRAME.
497If the optional argument FRAME is given, report on face FACE in that frame.
498If FRAME is t, report on the defaults for face FACE (for new frames).
499If FRAME is omitted or nil, use the selected frame."
500 (eq (face-attribute face :inverse-video frame) t))
501
502
503(defun face-bold-p (face &optional frame)
504 "Return non-nil if the font of FACE is bold on FRAME.
505If the optional argument FRAME is given, report on face FACE in that frame.
506If FRAME is t, report on the defaults for face FACE (for new frames).
507If FRAME is omitted or nil, use the selected frame.
508Use `face-attribute' for finer control."
509 (let ((bold (face-attribute face :weight frame)))
da2c7b8c 510 (memq bold '(semi-bold bold extra-bold ultra-bold))))
5f5c8ee5
GM
511
512
513(defun face-italic-p (face &optional frame)
514 "Return non-nil if the font of FACE is italic on FRAME.
515If the optional argument FRAME is given, report on face FACE in that frame.
516If FRAME is t, report on the defaults for face FACE (for new frames).
517If FRAME is omitted or nil, use the selected frame.
518Use `face-attribute' for finer control."
519 (let ((italic (face-attribute face :slant frame)))
a48f6020 520 (memq italic '(italic oblique))))
00f51890 521
5f5c8ee5 522
5f5c8ee5
GM
523\f
524;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
525;;; Face documentation.
526;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
527
528(defun face-documentation (face)
9a558a07
GM
529 "Get the documentation string for FACE.
530If FACE is a face-alias, get the documentation for the target face."
531 (let ((alias (get face 'face-alias))
532 doc)
533 (if alias
534 (progn
535 (setq doc (get alias 'face-documentation))
3446bfc8 536 (format "%s is an alias for the face `%s'.%s" face alias
9a558a07
GM
537 (if doc (format "\n%s" doc)
538 "")))
539 (get face 'face-documentation))))
5f5c8ee5
GM
540
541
542(defun set-face-documentation (face string)
543 "Set the documentation string for FACE to STRING."
291cfb96 544 ;; Perhaps the text should go in DOC.
49435801 545 (put face 'face-documentation (purecopy string)))
5f5c8ee5
GM
546
547
548(defalias 'face-doc-string 'face-documentation)
549(defalias 'set-face-doc-string 'set-face-documentation)
550
551
552\f
553;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
554;; Setting face attributes.
555;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
556
557
558(defun set-face-attribute (face frame &rest args)
559 "Set attributes of FACE on FRAME from ARGS.
560
561FRAME nil means change attributes on all frames. FRAME t means change
562the default for new frames (this is done automatically each time an
563attribute is changed on all frames).
564
565ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
c6f3804c 566face attribute name. All attributes can be set to `unspecified';
5f5c8ee5
GM
567this fact is not further mentioned below.
568
569The following attributes are recognized:
570
571`:family'
572
bfffdd07 573VALUE must be a string specifying the font family, e.g. ``monospace'',
5f5c8ee5
GM
574or a fontset alias name. If a font family is specified, wild-cards `*'
575and `?' are allowed.
576
fcea6e23
KH
577`:foundry'
578
579VALUE must be a string specifying the font foundry,
580e.g. ``adobe''. If a font foundry is specified, wild-cards `*'
581and `?' are allowed.
582
5f5c8ee5
GM
583`:width'
584
585VALUE specifies the relative proportionate width of the font to use.
586It must be one of the symbols `ultra-condensed', `extra-condensed',
587`condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
588`extra-expanded', or `ultra-expanded'.
589
590`:height'
591
19feb949
MB
592VALUE must be either an integer specifying the height of the font to use
593in 1/10 pt, a floating point number specifying the amount by which to
594scale any underlying face, or a function, which is called with the old
595height (from the underlying face), and should return the new height.
5f5c8ee5
GM
596
597`:weight'
598
599VALUE specifies the weight of the font to use. It must be one of the
600symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
601`semi-light', `light', `extra-light', `ultra-light'.
602
603`:slant'
604
605VALUE specifies the slant of the font to use. It must be one of the
606symbols `italic', `oblique', `normal', `reverse-italic', or
607`reverse-oblique'.
608
609`:foreground', `:background'
610
611VALUE must be a color name, a string.
612
613`:underline'
614
615VALUE specifies whether characters in FACE should be underlined. If
616VALUE is t, underline with foreground color of the face. If VALUE is
617a string, underline with that color. If VALUE is nil, explicitly
618don't underline.
619
620`:overline'
621
622VALUE specifies whether characters in FACE should be overlined. If
623VALUE is t, overline with foreground color of the face. If VALUE is a
624string, overline with that color. If VALUE is nil, explicitly don't
625overline.
626
627`:strike-through'
628
629VALUE specifies whether characters in FACE should be drawn with a line
630striking through them. If VALUE is t, use the foreground color of the
631face. If VALUE is a string, strike-through with that color. If VALUE
632is nil, explicitly don't strike through.
633
634`:box'
635
636VALUE specifies whether characters in FACE should have a box drawn
637around them. If VALUE is nil, explicitly don't draw boxes. If
638VALUE is t, draw a box with lines of width 1 in the foreground color
639of the face. If VALUE is a string, the string must be a color name,
640and the box is drawn in that color with a line width of 1. Otherwise,
641VALUE must be a property list of the form `(:line-width WIDTH
642:color COLOR :style STYLE)'. If a keyword/value pair is missing from
643the property list, a default value will be used for the value, as
644specified below. WIDTH specifies the width of the lines to draw; it
0f937ebd
KH
645defaults to 1. If WIDTH is negative, the absolute value is the width
646of the lines, and draw top/bottom lines inside the characters area,
647not around it. COLOR is the name of the color to draw in, default is
5f5c8ee5
GM
648the foreground color of the face for simple boxes, and the background
649color of the face for 3D boxes. STYLE specifies whether a 3D box
650should be draw. If STYLE is `released-button', draw a box looking
651like a released 3D button. If STYLE is `pressed-button' draw a box
652that appears like a pressed button. If STYLE is nil, the default if
653the property list doesn't contain a style specification, draw a 2D
654box.
655
656`:inverse-video'
657
658VALUE specifies whether characters in FACE should be displayed in
70d0c3b0 659inverse video. VALUE must be one of t or nil.
5f5c8ee5
GM
660
661`:stipple'
662
663If VALUE is a string, it must be the name of a file of pixmap data.
664The directories listed in the `x-bitmap-file-path' variable are
665searched. Alternatively, VALUE may be a list of the form (WIDTH
666HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
667is a string containing the raw bits of the bitmap. VALUE nil means
668explicitly don't use a stipple pattern.
669
fcea6e23
KH
670For convenience, attributes `:family', `:foundry', `:width',
671`:height', `:weight', and `:slant' may also be set in one step
672from an X font name:
5f5c8ee5
GM
673
674`:font'
675
676Set font-related face attributes from VALUE. VALUE must be a valid
677XLFD font name. If it is a font name pattern, the first matching font
678will be used.
679
680For compatibility with Emacs 20, keywords `:bold' and `:italic' can
681be used to specify that a bold or italic font should be used. VALUE
19feb949
MB
682must be t or nil in that case. A value of `unspecified' is not allowed.
683
684`:inherit'
685
686VALUE is the name of a face from which to inherit attributes, or a list
687of face names. Attributes from inherited faces are merged into the face
688like an underlying face would be, with higher priority than underlying faces."
61ab9392
CY
689 (setq args (purecopy args))
690 (let ((where (if (null frame) 0 frame))
691 (spec args)
692 family foundry)
680da3f8
RS
693 ;; If we set the new-frame defaults, this face is modified outside Custom.
694 (if (memq where '(0 t))
9a558a07 695 (put (or (get face 'face-alias) face) 'face-modified t))
61ab9392
CY
696 ;; If family and/or foundry are specified, set it first. Certain
697 ;; face attributes, e.g. :weight semi-condensed, are not supported
698 ;; in every font. See bug#1127.
699 (while spec
700 (cond ((eq (car spec) :family)
701 (setq family (cadr spec)))
702 ((eq (car spec) :foundry)
703 (setq foundry (cadr spec))))
704 (setq spec (cddr spec)))
705 (when (or family foundry)
706 (when (and (stringp family)
707 (string-match "\\([^-]*\\)-\\([^-]*\\)" family))
708 (unless foundry
3a92c095
KH
709 (setq foundry (match-string 1 family)))
710 (setq family (match-string 2 family)))
c917476d 711 (when (or (stringp family) (eq family 'unspecified))
61ab9392
CY
712 (internal-set-lisp-face-attribute face :family (purecopy family)
713 where))
c917476d 714 (when (or (stringp foundry) (eq foundry 'unspecified))
61ab9392
CY
715 (internal-set-lisp-face-attribute face :foundry (purecopy foundry)
716 where)))
70a267c9 717 (while args
61ab9392 718 (unless (memq (car args) '(:family :foundry))
96c1a800
CY
719 (internal-set-lisp-face-attribute face (car args)
720 (purecopy (cadr args))
721 where))
61ab9392 722 (setq args (cddr args)))))
5f5c8ee5 723
39cac3e7 724(defun make-face-bold (face &optional frame noerror)
5f5c8ee5
GM
725 "Make the font of FACE be bold, if possible.
726FRAME nil or not specified means change face on all frames.
39cac3e7 727Argument NOERROR is ignored and retained for compatibility.
5f5c8ee5 728Use `set-face-attribute' for finer control of the font weight."
95125512 729 (interactive (list (read-face-name "Make which face bold")))
5f5c8ee5
GM
730 (set-face-attribute face frame :weight 'bold))
731
732
39cac3e7 733(defun make-face-unbold (face &optional frame noerror)
5f5c8ee5 734 "Make the font of FACE be non-bold, if possible.
39cac3e7
GM
735FRAME nil or not specified means change face on all frames.
736Argument NOERROR is ignored and retained for compatibility."
95125512 737 (interactive (list (read-face-name "Make which face non-bold")))
5f5c8ee5
GM
738 (set-face-attribute face frame :weight 'normal))
739
00f51890 740
39cac3e7 741(defun make-face-italic (face &optional frame noerror)
5f5c8ee5
GM
742 "Make the font of FACE be italic, if possible.
743FRAME nil or not specified means change face on all frames.
39cac3e7 744Argument NOERROR is ignored and retained for compatibility.
5f5c8ee5 745Use `set-face-attribute' for finer control of the font slant."
95125512 746 (interactive (list (read-face-name "Make which face italic")))
5f5c8ee5
GM
747 (set-face-attribute face frame :slant 'italic))
748
749
39cac3e7 750(defun make-face-unitalic (face &optional frame noerror)
5f5c8ee5 751 "Make the font of FACE be non-italic, if possible.
70d0c3b0
DL
752FRAME nil or not specified means change face on all frames.
753Argument NOERROR is ignored and retained for compatibility."
95125512 754 (interactive (list (read-face-name "Make which face non-italic")))
5f5c8ee5
GM
755 (set-face-attribute face frame :slant 'normal))
756
00f51890 757
39cac3e7 758(defun make-face-bold-italic (face &optional frame noerror)
5f5c8ee5
GM
759 "Make the font of FACE be bold and italic, if possible.
760FRAME nil or not specified means change face on all frames.
39cac3e7 761Argument NOERROR is ignored and retained for compatibility.
5f5c8ee5 762Use `set-face-attribute' for finer control of font weight and slant."
95125512 763 (interactive (list (read-face-name "Make which face bold-italic")))
5f5c8ee5
GM
764 (set-face-attribute face frame :weight 'bold :slant 'italic))
765
766
767(defun set-face-font (face font &optional frame)
768 "Change font-related attributes of FACE to those of FONT (a string).
769FRAME nil or not specified means change face on all frames.
fcea6e23
KH
770This sets the attributes `:family', `:foundry', `:width',
771`:height', `:weight', and `:slant'. When called interactively,
772prompt for the face and font."
5f5c8ee5
GM
773 (interactive (read-face-and-attribute :font))
774 (set-face-attribute face frame :font font))
775
776
777;; Implementation note: Emulating gray background colors with a
778;; stipple pattern is now part of the face realization process, and is
779;; done in C depending on the frame on which the face is realized.
780
781(defun set-face-background (face color &optional frame)
782 "Change the background color of face FACE to COLOR (a string).
783FRAME nil or not specified means change face on all frames.
72e6f142
RS
784COLOR can be a system-defined color name (see `list-colors-display')
785or a hex spec of the form #RRGGBB.
786When called interactively, prompts for the face and color."
5f5c8ee5 787 (interactive (read-face-and-attribute :background))
78ad1cd5 788 (set-face-attribute face frame :background (or color 'unspecified)))
5f5c8ee5
GM
789
790
791(defun set-face-foreground (face color &optional frame)
792 "Change the foreground color of face FACE to COLOR (a string).
793FRAME nil or not specified means change face on all frames.
72e6f142
RS
794COLOR can be a system-defined color name (see `list-colors-display')
795or a hex spec of the form #RRGGBB.
796When called interactively, prompts for the face and color."
5f5c8ee5 797 (interactive (read-face-and-attribute :foreground))
78ad1cd5 798 (set-face-attribute face frame :foreground (or color 'unspecified)))
5f5c8ee5
GM
799
800
801(defun set-face-stipple (face stipple &optional frame)
802 "Change the stipple pixmap of face FACE to STIPPLE.
803FRAME nil or not specified means change face on all frames.
70d0c3b0 804STIPPLE should be a string, the name of a file of pixmap data.
5f5c8ee5
GM
805The directories listed in the `x-bitmap-file-path' variable are searched.
806
807Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
808where WIDTH and HEIGHT are the size in pixels,
809and DATA is a string, containing the raw bits of the bitmap."
810 (interactive (read-face-and-attribute :stipple))
78ad1cd5 811 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
5f5c8ee5
GM
812
813
a61afeac 814(defun set-face-underline-p (face underline &optional frame)
5f5c8ee5
GM
815 "Specify whether face FACE is underlined.
816UNDERLINE nil means FACE explicitly doesn't underline.
817UNDERLINE non-nil means FACE explicitly does underlining
818with the same of the foreground color.
819If UNDERLINE is a string, underline with the color named UNDERLINE.
820FRAME nil or not specified means change face on all frames.
5f5c8ee5
GM
821Use `set-face-attribute' to ``unspecify'' underlining."
822 (interactive
823 (let ((list (read-face-and-attribute :underline)))
824 (list (car list) (eq (car (cdr list)) t))))
a61afeac 825 (set-face-attribute face frame :underline underline))
5f5c8ee5 826
9b82fc01
JL
827(define-obsolete-function-alias 'set-face-underline
828 'set-face-underline-p "22.1")
829
5f5c8ee5
GM
830
831(defun set-face-inverse-video-p (face inverse-video-p &optional frame)
832 "Specify whether face FACE is in inverse video.
833INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
834INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
835FRAME nil or not specified means change face on all frames.
836Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
837 (interactive
838 (let ((list (read-face-and-attribute :inverse-video)))
839 (list (car list) (eq (car (cdr list)) t))))
840 (set-face-attribute face frame :inverse-video inverse-video-p))
841
842
843(defun set-face-bold-p (face bold-p &optional frame)
844 "Specify whether face FACE is bold.
845BOLD-P non-nil means FACE should explicitly display bold.
846BOLD-P nil means FACE should explicitly display non-bold.
847FRAME nil or not specified means change face on all frames.
848Use `set-face-attribute' or `modify-face' for finer control."
849 (if (null bold-p)
850 (make-face-unbold face frame)
851 (make-face-bold face frame)))
852
853
854(defun set-face-italic-p (face italic-p &optional frame)
855 "Specify whether face FACE is italic.
856ITALIC-P non-nil means FACE should explicitly display italic.
857ITALIC-P nil means FACE should explicitly display non-italic.
858FRAME nil or not specified means change face on all frames.
859Use `set-face-attribute' or `modify-face' for finer control."
860 (if (null italic-p)
861 (make-face-unitalic face frame)
862 (make-face-italic face frame)))
863
864
865(defalias 'set-face-background-pixmap 'set-face-stipple)
866
867
868(defun invert-face (face &optional frame)
869 "Swap the foreground and background colors of FACE.
e458cb49 870If FRAME is omitted or nil, it means change face on all frames.
5f5c8ee5
GM
871If FACE specifies neither foreground nor background color,
872set its foreground and background to the background and foreground
873of the default face. Value is FACE."
95125512 874 (interactive (list (read-face-name "Invert face")))
5f5c8ee5
GM
875 (let ((fg (face-attribute face :foreground frame))
876 (bg (face-attribute face :background frame)))
e458cb49 877 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
5f5c8ee5
GM
878 (set-face-attribute face frame :foreground bg :background fg)
879 (set-face-attribute face frame
880 :foreground
881 (face-attribute 'default :background frame)
882 :background
883 (face-attribute 'default :foreground frame))))
884 face)
885
886\f
887;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
888;;; Interactively modifying faces.
889;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
890
c91e692b 891(defun read-face-name (prompt &optional default multiple)
a482f364 892 "Read a face, defaulting to the face or faces on the char after point.
c7b93b44 893If it has the property `read-face-name', that overrides the `face' property.
3748d13d
RS
894PROMPT should be a string that describes what the caller will do with the face;
895it should not end in a space.
c91e692b
JL
896The optional argument DEFAULT provides the value to display in the
897minibuffer prompt that is returned if the user just types RET
898unless DEFAULT is a string (in which case nil is returned).
a482f364
RS
899If MULTIPLE is non-nil, return a list of faces (possibly only one).
900Otherwise, return a single face."
901 (let ((faceprop (or (get-char-property (point) 'read-face-name)
902 (get-char-property (point) 'face)))
e3b5b35b
SM
903 (aliasfaces nil)
904 (nonaliasfaces nil)
a482f364 905 faces)
224d108e
JL
906 ;; Try to get a face name from the buffer.
907 (if (memq (intern-soft (thing-at-point 'symbol)) (face-list))
908 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
909 ;; Add the named faces that the `face' property uses.
1bd59f82
RS
910 (if (and (listp faceprop)
911 ;; Don't treat an attribute spec as a list of faces.
912 (not (keywordp (car faceprop)))
913 (not (memq (car faceprop) '(foreground-color background-color))))
a482f364
RS
914 (dolist (f faceprop)
915 (if (symbolp f)
916 (push f faces)))
917 (if (symbolp faceprop)
1bd59f82 918 (push faceprop faces)))
81435dc4 919 (delete-dups faces)
a482f364 920
e3b5b35b
SM
921 ;; Build up the completion tables.
922 (mapatoms (lambda (s)
923 (if (custom-facep s)
924 (if (get s 'face-alias)
925 (push (symbol-name s) aliasfaces)
926 (push (symbol-name s) nonaliasfaces)))))
927
a482f364
RS
928 ;; If we only want one, and the default is more than one,
929 ;; discard the unwanted ones now.
930 (unless multiple
931 (if faces
932 (setq faces (list (car faces)))))
224d108e 933 (require 'crm)
a482f364
RS
934 (let* ((input
935 ;; Read the input.
224d108e 936 (completing-read-multiple
c91e692b
JL
937 (if (or faces default)
938 (format "%s (default `%s'): " prompt
224d108e 939 (if faces (mapconcat 'symbol-name faces ",")
c91e692b 940 default))
3b4ef34b 941 (format "%s: " prompt))
45555ebe 942 (completion-table-in-turn nonaliasfaces aliasfaces)
2aef0850 943 nil t nil 'face-name-history
224d108e 944 (if faces (mapconcat 'symbol-name faces ","))))
a482f364
RS
945 ;; Canonicalize the output.
946 (output
224d108e 947 (cond ((or (equal input "") (equal input '("")))
c91e692b 948 (or faces (unless (stringp default) default)))
224d108e
JL
949 ((stringp input)
950 (mapcar 'intern (split-string input ", *" t)))
951 ((listp input)
952 (mapcar 'intern input))
953 (input))))
a482f364
RS
954 ;; Return either a list of faces or just one face.
955 (if multiple
956 output
957 (car output)))))
958
aa360da1
GM
959;; Not defined without X, but behind window-system test.
960(defvar x-bitmap-file-path)
a482f364 961
5f5c8ee5
GM
962(defun face-valid-attribute-values (attribute &optional frame)
963 "Return valid values for face attribute ATTRIBUTE.
964The optional argument FRAME is used to determine available fonts
c6f3804c
JB
965and colors. If it is nil or not specified, the selected frame is used.
966Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
967of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
5f5c8ee5 968an integer value."
00f51890
SS
969 (let ((valid
970 (case attribute
971 (:family
428a555e 972 (if (window-system frame)
95ac8fbd 973 (mapcar (lambda (x) (cons x x))
6e783e91 974 (font-family-list))
00f51890
SS
975 ;; Only one font on TTYs.
976 (list (cons "default" "default"))))
fcea6e23
KH
977 (:foundry
978 (list nil))
6e783e91 979 (:width
e83eedbf 980 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
6e783e91
KH
981 font-width-table))
982 (:weight
e83eedbf 983 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
6e783e91
KH
984 font-weight-table))
985 (:slant
e83eedbf 986 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
6e783e91
KH
987 font-slant-table))
988 (:inverse-video
989 (mapcar #'(lambda (x) (cons (symbol-name x) x))
990 (internal-lisp-face-attribute-values attribute)))
00f51890 991 ((:underline :overline :strike-through :box)
428a555e 992 (if (window-system frame)
00f51890
SS
993 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
994 (internal-lisp-face-attribute-values attribute))
995 (mapcar #'(lambda (c) (cons c c))
b533d0ae 996 (defined-colors frame)))
00f51890
SS
997 (mapcar #'(lambda (x) (cons (symbol-name x) x))
998 (internal-lisp-face-attribute-values attribute))))
999 ((:foreground :background)
1000 (mapcar #'(lambda (c) (cons c c))
1001 (defined-colors frame)))
1002 ((:height)
1003 'integerp)
1004 (:stipple
0db2e6af 1005 (and (memq (window-system frame) '(x ns)) ; No stipple on w32
00f51890
SS
1006 (mapcar #'list
1007 (apply #'nconc
1008 (mapcar (lambda (dir)
1009 (and (file-readable-p dir)
1010 (file-directory-p dir)
1011 (directory-files dir)))
1012 x-bitmap-file-path)))))
1013 (:inherit
1014 (cons '("none" . nil)
1015 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1016 (face-list))))
1017 (t
1018 (error "Internal error")))))
19feb949 1019 (if (and (listp valid) (not (memq attribute '(:inherit))))
fbd5f1cc
GM
1020 (nconc (list (cons "unspecified" 'unspecified)) valid)
1021 valid)))
5f5c8ee5
GM
1022
1023
2f7f4bee 1024(defconst face-attribute-name-alist
5f5c8ee5 1025 '((:family . "font family")
fcea6e23 1026 (:foundry . "font foundry")
5f5c8ee5
GM
1027 (:width . "character set width")
1028 (:height . "height in 1/10 pt")
1029 (:weight . "weight")
1030 (:slant . "slant")
1031 (:underline . "underline")
1032 (:overline . "overline")
1033 (:strike-through . "strike-through")
1034 (:box . "box")
1035 (:inverse-video . "inverse-video display")
1036 (:foreground . "foreground color")
1037 (:background . "background color")
19feb949
MB
1038 (:stipple . "background stipple")
1039 (:inherit . "inheritance"))
5f5c8ee5
GM
1040 "An alist of descriptive names for face attributes.
1041Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1042ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1043DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1044
1045
1046(defun face-descriptive-attribute-name (attribute)
1047 "Return a descriptive name for ATTRIBUTE."
1048 (cdr (assq attribute face-attribute-name-alist)))
1049
1050
1051(defun face-read-string (face default name &optional completion-alist)
1052 "Interactively read a face attribute string value.
19feb949
MB
1053FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1054default string to return if no new value is entered. NAME is a
1055descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1056alist of valid values, if non-nil.
5f5c8ee5 1057
19feb949 1058Entering nothing accepts the default string DEFAULT.
5f5c8ee5 1059Value is the new attribute value."
19feb949
MB
1060 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1061 ;; each word in a string separately).
1062 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
5f5c8ee5
GM
1063 (let* ((completion-ignore-case t)
1064 (value (completing-read
1065 (if default
19feb949
MB
1066 (format "%s for face `%s' (default %s): "
1067 name face default)
1068 (format "%s for face `%s': " name face))
d69ab4ba 1069 completion-alist nil nil nil nil default)))
fbd5f1cc 1070 (if (equal value "") default value)))
5f5c8ee5
GM
1071
1072
1073(defun face-read-integer (face default name)
1074 "Interactively read an integer face attribute value.
1075FACE is the face whose attribute is read. DEFAULT is the default
1076value to return if no new value is entered. NAME is a descriptive
1077name of the attribute for prompting. Value is the new attribute value."
fbd5f1cc
GM
1078 (let ((new-value
1079 (face-read-string face
19feb949 1080 (format "%s" default)
fbd5f1cc
GM
1081 name
1082 (list (cons "unspecified" 'unspecified)))))
19feb949
MB
1083 (cond ((equal new-value "unspecified")
1084 'unspecified)
1085 ((member new-value '("unspecified-fg" "unspecified-bg"))
1086 new-value)
1087 (t
027a4b6b 1088 (string-to-number new-value)))))
5f5c8ee5
GM
1089
1090
1091(defun read-face-attribute (face attribute &optional frame)
1092 "Interactively read a new value for FACE's ATTRIBUTE.
1093Optional argument FRAME nil or unspecified means read an attribute value
1094of a global face. Value is the new attribute value."
1095 (let* ((old-value (face-attribute face attribute frame))
1096 (attribute-name (face-descriptive-attribute-name attribute))
1097 (valid (face-valid-attribute-values attribute frame))
1098 new-value)
1099 ;; Represent complex attribute values as strings by printing them
1100 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1101 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1102 ;; SHADOW)'.
1103 (when (and (or (eq attribute :stipple)
1104 (eq attribute :box))
1105 (or (consp old-value)
1106 (vectorp old-value)))
1107 (setq old-value (prin1-to-string old-value)))
1108 (cond ((listp valid)
19feb949
MB
1109 (let ((default
1110 (or (car (rassoc old-value valid))
1111 (format "%s" old-value))))
1112 (setq new-value
1113 (face-read-string face default attribute-name valid))
1114 (if (equal new-value default)
1115 ;; Nothing changed, so don't bother with all the stuff
1116 ;; below. In particular, this avoids a non-tty color
1117 ;; from being canonicalized for a tty when the user
1118 ;; just uses the default.
1119 (setq new-value old-value)
1120 ;; Terminal frames can support colors that don't appear
1121 ;; explicitly in VALID, using color approximation code
1122 ;; in tty-colors.el.
f9056dd9 1123 (when (and (memq attribute '(:foreground :background))
9e2a2647 1124 (not (memq (window-system frame) '(x w32 ns)))
f9056dd9
MB
1125 (not (member new-value
1126 '("unspecified"
1127 "unspecified-fg" "unspecified-bg"))))
4385f1b0 1128 (setq new-value (car (tty-color-desc new-value frame))))
f9056dd9
MB
1129 (when (assoc new-value valid)
1130 (setq new-value (cdr (assoc new-value valid)))))))
5f5c8ee5
GM
1131 ((eq valid 'integerp)
1132 (setq new-value (face-read-integer face old-value attribute-name)))
1133 (t (error "Internal error")))
1134 ;; Convert stipple and box value text we read back to a list or
1135 ;; vector if it looks like one. This makes the assumption that a
1136 ;; pixmap file name won't start with an open-paren.
1137 (when (and (or (eq attribute :stipple)
1138 (eq attribute :box))
1139 (stringp new-value)
1140 (string-match "^[[(]" new-value))
1141 (setq new-value (read new-value)))
1142 new-value))
1143
aa360da1
GM
1144(declare-function fontset-list "fontset.c" ())
1145(declare-function x-list-fonts "xfaces.c"
1146 (pattern &optional face frame maximum width))
5f5c8ee5
GM
1147
1148(defun read-face-font (face &optional frame)
1149 "Read the name of a font for FACE on FRAME.
522fb950 1150If optional argument FRAME is nil or omitted, use the selected frame."
5f5c8ee5 1151 (let ((completion-ignore-case t))
48ec9939 1152 (completing-read (format "Set font attributes of face `%s' from font: " face)
6b61353c 1153 (append (fontset-list) (x-list-fonts "*" nil frame)))))
5f5c8ee5
GM
1154
1155
1156(defun read-all-face-attributes (face &optional frame)
1157 "Interactively read all attributes for FACE.
522fb950 1158If optional argument FRAME is nil or omitted, use the selected frame.
5f5c8ee5
GM
1159Value is a property list of attribute names and new values."
1160 (let (result)
1161 (dolist (attribute face-attribute-name-alist result)
1162 (setq result (cons (car attribute)
1163 (cons (read-face-attribute face (car attribute) frame)
1164 result))))))
1165
7cd512f2 1166(defun modify-face (&optional face foreground background stipple
a61afeac 1167 bold-p italic-p underline inverse-p frame)
5f5c8ee5
GM
1168 "Modify attributes of faces interactively.
1169If optional argument FRAME is nil or omitted, modify the face used
7cd512f2
SM
1170for newly created frame, i.e. the global face.
1171For non-interactive use, `set-face-attribute' is preferred.
522fb950 1172When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
7cd512f2 1173and the face and its settings are obtained by querying the user."
5f5c8ee5 1174 (interactive)
7cd512f2
SM
1175 (if face
1176 (set-face-attribute face frame
1177 :foreground (or foreground 'unspecified)
1178 :background (or background 'unspecified)
1179 :stipple stipple
1180 :bold bold-p
1181 :italic italic-p
a61afeac 1182 :underline underline
7cd512f2
SM
1183 :inverse-video inverse-p)
1184 (setq face (read-face-name "Modify face"))
5f5c8ee5
GM
1185 (apply #'set-face-attribute face frame
1186 (read-all-face-attributes face frame))))
1187
5f5c8ee5
GM
1188(defun read-face-and-attribute (attribute &optional frame)
1189 "Read face name and face attribute value.
1190ATTRIBUTE is the attribute whose new value is read.
1191FRAME nil or unspecified means read attribute value of global face.
1192Value is a list (FACE NEW-VALUE) where FACE is the face read
7cd512f2 1193\(a symbol), and NEW-VALUE is value read."
5f5c8ee5 1194 (cond ((eq attribute :font)
48ec9939 1195 (let* ((prompt "Set font-related attributes of face")
5f5c8ee5
GM
1196 (face (read-face-name prompt))
1197 (font (read-face-font face frame)))
1198 (list face font)))
1199 (t
1200 (let* ((attribute-name (face-descriptive-attribute-name attribute))
19feb949 1201 (prompt (format "Set %s of face" attribute-name))
5f5c8ee5
GM
1202 (face (read-face-name prompt))
1203 (new-value (read-face-attribute face attribute frame)))
1204 (list face new-value)))))
1205
1206
1207\f
1208;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1209;;; Listing faces.
1210;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1211
2f7f4bee 1212(defconst list-faces-sample-text
5f5c8ee5
GM
1213 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1214 "*Text string to display as the sample text for `list-faces-display'.")
1215
1216
1217;; The name list-faces would be more consistent, but let's avoid a
1218;; conflict with Lucid, which uses that name differently.
1219
645a1038 1220(defvar help-xref-stack)
e2c11e3b 1221(defun list-faces-display (&optional regexp)
5f5c8ee5
GM
1222 "List all faces, using the same sample text in each.
1223The sample text is a string that comes from the variable
e2c11e3b
RS
1224`list-faces-sample-text'.
1225
1226If REGEXP is non-nil, list only those faces with names matching
1227this regular expression. When called interactively with a prefix
1228arg, prompt for a regular expression."
1229 (interactive (list (and current-prefix-arg
2aef0850 1230 (read-regexp "List faces matching regexp"))))
011131fd 1231 (let ((all-faces (zerop (length regexp)))
5f5c8ee5 1232 (frame (selected-frame))
011131fd
JB
1233 (max-length 0)
1234 faces line-format
84fe35f0 1235 disp-frame window face-name)
011131fd
JB
1236 ;; We filter and take the max length in one pass
1237 (setq faces
1238 (delq nil
1239 (mapcar (lambda (f)
1240 (let ((s (symbol-name f)))
1241 (when (or all-faces (string-match regexp s))
1242 (setq max-length (max (length s) max-length))
1243 f)))
1244 (sort (face-list) #'string-lessp))))
1245 (unless faces
1246 (error "No faces matching \"%s\"" regexp))
1247 (setq max-length (1+ max-length)
1248 line-format (format "%%-%ds" max-length))
b766be6a 1249 (with-help-window "*Faces*"
7fdbcd83 1250 (with-current-buffer standard-output
5f5c8ee5 1251 (setq truncate-lines t)
84fe35f0
DL
1252 (insert
1253 (substitute-command-keys
1254 (concat
1255 "Use "
53c80cf6 1256 (if (display-mouse-p) "\\[help-follow-mouse] or ")
32e33f60 1257 "\\[help-follow] on a face name to customize it\n"
46057f5f 1258 "or on its sample text for a description of the face.\n\n")))
84fe35f0 1259 (setq help-xref-stack nil)
e2c11e3b 1260 (dolist (face faces)
84fe35f0 1261 (setq face-name (symbol-name face))
011131fd 1262 (insert (format line-format face-name))
84fe35f0
DL
1263 ;; Hyperlink to a customization buffer for the face. Using
1264 ;; the help xref mechanism may not be the best way.
1265 (save-excursion
1266 (save-match-data
1267 (search-backward face-name)
35a0a8aa 1268 (setq help-xref-stack-item `(list-faces-display ,regexp))
a482f364
RS
1269 (help-xref-button 0 'help-customize-face face)))
1270 (let ((beg (point))
1271 (line-beg (line-beginning-position)))
5f5c8ee5 1272 (insert list-faces-sample-text)
84fe35f0
DL
1273 ;; Hyperlink to a help buffer for the face.
1274 (save-excursion
1275 (save-match-data
1276 (search-backward list-faces-sample-text)
8940232b 1277 (help-xref-button 0 'help-face face)))
5f5c8ee5
GM
1278 (insert "\n")
1279 (put-text-property beg (1- (point)) 'face face)
a482f364
RS
1280 ;; Make all face commands default to the proper face
1281 ;; anywhere in the line.
1282 (put-text-property line-beg (1- (point)) 'read-face-name face)
5f5c8ee5
GM
1283 ;; If the sample text has multiple lines, line up all of them.
1284 (goto-char beg)
1285 (forward-line 1)
1286 (while (not (eobp))
011131fd 1287 (insert-char ?\s max-length)
5f5c8ee5 1288 (forward-line 1))))
b766be6a 1289 (goto-char (point-min))))
5f5c8ee5
GM
1290 ;; If the *Faces* buffer appears in a different frame,
1291 ;; copy all the face definitions from FRAME,
1292 ;; so that the display will reflect the frame that was selected.
1293 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1294 (setq disp-frame (if window (window-frame window)
1295 (car (frame-list))))
1296 (or (eq frame disp-frame)
1297 (let ((faces (face-list)))
1298 (while faces
1299 (copy-face (car faces) (car faces) frame disp-frame)
1300 (setq faces (cdr faces)))))))
1301
e2c11e3b 1302
5f5c8ee5
GM
1303(defun describe-face (face &optional frame)
1304 "Display the properties of face FACE on FRAME.
6afa5404 1305Interactively, FACE defaults to the faces of the character after point
a482f364
RS
1306and FRAME defaults to the selected frame.
1307
5f5c8ee5
GM
1308If the optional argument FRAME is given, report on face FACE in that frame.
1309If FRAME is t, report on the defaults for face FACE (for new frames).
1310If FRAME is omitted or nil, use the selected frame."
c91e692b 1311 (interactive (list (read-face-name "Describe face" 'default t)))
5f5c8ee5 1312 (let* ((attrs '((:family . "Family")
fcea6e23 1313 (:foundry . "Foundry")
5f5c8ee5
GM
1314 (:width . "Width")
1315 (:height . "Height")
1316 (:weight . "Weight")
1317 (:slant . "Slant")
1318 (:foreground . "Foreground")
1319 (:background . "Background")
1320 (:underline . "Underline")
1321 (:overline . "Overline")
1322 (:strike-through . "Strike-through")
1323 (:box . "Box")
1324 (:inverse-video . "Inverse")
b32631c8 1325 (:stipple . "Stipple")
0540dc5e
KH
1326 (:font . "Font")
1327 (:fontset . "Fontset")
25ac7b52 1328 (:inherit . "Inherit")))
5f5c8ee5
GM
1329 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1330 attrs))))
32226619
JB
1331 (help-setup-xref (list #'describe-face face)
1332 (called-interactively-p 'interactive))
a482f364
RS
1333 (unless face
1334 (setq face 'default))
1335 (if (not (listp face))
1336 (setq face (list face)))
b766be6a 1337 (with-help-window (help-buffer)
7fdbcd83 1338 (with-current-buffer standard-output
a482f364 1339 (dolist (f face)
faa3d27b 1340 (if (stringp f) (setq f (intern f)))
0d3b1f4e
CY
1341 ;; We may get called for anonymous faces (i.e., faces
1342 ;; expressed using prop-value plists). Those can't be
1343 ;; usefully customized, so ignore them.
1344 (when (symbolp f)
1345 (insert "Face: " (symbol-name f))
1346 (if (not (facep f))
1347 (insert " undefined face.\n")
1348 (let ((customize-label "customize this face")
1349 file-name)
1350 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1351 (princ (concat " (" customize-label ")\n"))
3446bfc8
GM
1352 ;; FIXME not sure how much of this belongs here, and
1353 ;; how much in `face-documentation'. The latter is
1354 ;; not used much, but needs to return nil for
1355 ;; undocumented faces.
1356 (let ((alias (get f 'face-alias))
1357 (face f)
1358 obsolete)
1359 (when alias
1360 (setq face alias)
1361 (insert
1362 (format "\n %s is an alias for the face `%s'.\n%s"
1363 f alias
1364 (if (setq obsolete (get f 'obsolete-face))
1365 (format " This face is obsolete%s; use `%s' instead.\n"
1366 (if (stringp obsolete)
1367 (format " since %s" obsolete)
1368 "")
1369 alias)
1370 ""))))
1371 (insert "\nDocumentation:\n"
1372 (or (face-documentation face)
1373 "Not documented as a face.")
1374 "\n\n"))
0d3b1f4e
CY
1375 (with-current-buffer standard-output
1376 (save-excursion
1377 (re-search-backward
1378 (concat "\\(" customize-label "\\)") nil t)
1379 (help-xref-button 1 'help-customize-face f)))
1380 (setq file-name (find-lisp-object-file-name f 'defface))
1381 (when file-name
1382 (princ "Defined in `")
1383 (princ (file-name-nondirectory file-name))
1384 (princ "'")
1385 ;; Make a hyperlink to the library.
1386 (save-excursion
1387 (re-search-backward "`\\([^`']+\\)'" nil t)
1388 (help-xref-button 1 'help-face-def f file-name))
1389 (princ ".")
1390 (terpri)
1391 (terpri))
1392 (dolist (a attrs)
1393 (let ((attr (face-attribute f (car a) frame)))
1394 (insert (make-string (- max-width (length (cdr a))) ?\s)
1395 (cdr a) ": " (format "%s" attr))
1396 (if (and (eq (car a) :inherit)
1397 (not (eq attr 'unspecified)))
1398 ;; Make a hyperlink to the parent face.
1399 (save-excursion
1400 (re-search-backward ": \\([^:]+\\)" nil t)
1401 (help-xref-button 1 'help-face attr)))
1402 (insert "\n")))))
1403 (terpri)))))))
8940232b 1404
5f5c8ee5
GM
1405\f
1406;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1407;;; Face specifications (defface).
1408;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1409
1410;; Parameter FRAME Is kept for call compatibility to with previous
1411;; face implementation.
1412
1413(defun face-attr-construct (face &optional frame)
522fb950 1414 "Return a `defface'-style attribute list for FACE on FRAME.
5f5c8ee5
GM
1415Value is a property list of pairs ATTRIBUTE VALUE for all specified
1416face attributes of FACE where ATTRIBUTE is the attribute name and
1417VALUE is the specified value of that attribute."
1418 (let (result)
1419 (dolist (entry face-attribute-name-alist result)
1420 (let* ((attribute (car entry))
1421 (value (face-attribute face attribute)))
1422 (unless (eq value 'unspecified)
1423 (setq result (nconc (list attribute value) result)))))))
00f51890 1424
5f5c8ee5
GM
1425
1426(defun face-spec-set-match-display (display frame)
1427 "Non-nil if DISPLAY matches FRAME.
1428DISPLAY is part of a spec such as can be used in `defface'.
1429If FRAME is nil, the current FRAME is used."
1430 (let* ((conjuncts display)
1431 conjunct req options
1432 ;; t means we have succeeded against all the conjuncts in
1433 ;; DISPLAY that have been tested so far.
1434 (match t))
1435 (if (eq conjuncts t)
1436 (setq conjuncts nil))
1437 (while (and conjuncts match)
1438 (setq conjunct (car conjuncts)
1439 conjuncts (cdr conjuncts)
1440 req (car conjunct)
1441 options (cdr conjunct)
1442 match (cond ((eq req 'type)
428a555e 1443 (or (memq (window-system frame) options)
1695ca2b
EZ
1444 ;; FIXME: This should be revisited to use
1445 ;; display-graphic-p, provided that the
1446 ;; color selection depends on the number
1447 ;; of supported colors, and all defface's
1448 ;; are changed to look at number of colors
1449 ;; instead of (type graphic) etc.
428a555e 1450 (and (null (window-system frame))
1695ca2b 1451 (memq 'tty options))
ee716db5
GM
1452 (and (memq 'motif options)
1453 (featurep 'motif))
9b44aa8b
JD
1454 (and (memq 'gtk options)
1455 (featurep 'gtk))
ee716db5
GM
1456 (and (memq 'lucid options)
1457 (featurep 'x-toolkit)
9b44aa8b
JD
1458 (not (featurep 'motif))
1459 (not (featurep 'gtk)))
ee716db5
GM
1460 (and (memq 'x-toolkit options)
1461 (featurep 'x-toolkit))))
6b61353c
KH
1462 ((eq req 'min-colors)
1463 (>= (display-color-cells frame) (car options)))
5f5c8ee5
GM
1464 ((eq req 'class)
1465 (memq (frame-parameter frame 'display-type) options))
1466 ((eq req 'background)
1467 (memq (frame-parameter frame 'background-mode)
1468 options))
16320ac7
MB
1469 ((eq req 'supports)
1470 (display-supports-face-attributes-p options frame))
70d0c3b0 1471 (t (error "Unknown req `%S' with options `%S'"
5f5c8ee5
GM
1472 req options)))))
1473 match))
1474
1475
1476(defun face-spec-choose (spec &optional frame)
96c2938f
MB
1477 "Choose the proper attributes for FRAME, out of SPEC.
1478If SPEC is nil, return nil."
5f5c8ee5
GM
1479 (unless frame
1480 (setq frame (selected-frame)))
1481 (let ((tail spec)
cf459bb7 1482 result defaults)
5f5c8ee5 1483 (while tail
073f69e6
MB
1484 (let* ((entry (pop tail))
1485 (display (car entry))
cf459bb7
RS
1486 (attrs (cdr entry))
1487 thisval)
1488 ;; Get the attributes as actually specified by this alternative.
1489 (setq thisval
1490 (if (null (cdr attrs)) ;; was (listp (car attrs))
1491 ;; Old-style entry, the attribute list is the
1492 ;; first element.
1493 (car attrs)
1494 attrs))
1495
1496 ;; If the condition is `default', that sets the default
1497 ;; for following conditions.
1498 (if (eq display 'default)
1499 (setq defaults thisval)
1500 ;; Otherwise, if it matches, use it.
1501 (when (face-spec-set-match-display display frame)
1502 (setq result thisval)
b6b90dfc 1503 (setq tail nil)))))
cf459bb7 1504 (if defaults (append result defaults) result)))
5f5c8ee5
GM
1505
1506
1507(defun face-spec-reset-face (face &optional frame)
1508 "Reset all attributes of FACE on FRAME to unspecified."
4983ddea
CY
1509 (let (reset-args)
1510 (dolist (attr-and-name face-attribute-name-alist)
1511 (push 'unspecified reset-args)
1512 (push (car attr-and-name) reset-args))
1513 (apply 'set-face-attribute face frame reset-args)))
5f5c8ee5 1514
24837f13 1515(defun face-spec-set (face spec &optional for-defface)
a1792b9b 1516 "Set FACE's face spec, which controls its appearance, to SPEC.
24837f13
RS
1517If FOR-DEFFACE is t, set the base spec, the one that `defface'
1518 and Custom set. (In that case, the caller must put it in the
1519 appropriate property, because that depends on the caller.)
1520If FOR-DEFFACE is nil, set the overriding spec (and store it
1521 in the `face-override-spec' property of FACE).
1522
1523The appearance of FACE is controlled by the base spec,
1524by any custom theme specs on top of that, and by the
a1792b9b 1525overriding spec on top of all the rest.
24837f13
RS
1526
1527FOR-DEFFACE can also be a frame, in which case we set the
1528frame-specific attributes of FACE for that frame based on SPEC.
1529That usage is deprecated.
1530
1531See `defface' for information about the format and meaning of SPEC."
1532 (if (framep for-defface)
1533 ;; Handle the deprecated case where third arg is a frame.
1534 (face-spec-set-2 face for-defface spec)
1535 (if for-defface
1536 ;; When we reset the face based on its custom spec, then it is
1537 ;; unmodified as far as Custom is concerned.
1538 (put (or (get face 'face-alias) face) 'face-modified nil)
1539 ;; When we change a face based on a spec from outside custom,
1540 ;; record it for future frames.
1541 (put (or (get face 'face-alias) face) 'face-override-spec spec))
24837f13 1542 ;; Reset each frame according to the rules implied by all its specs.
01d2eac8 1543 (dolist (frame (frame-list))
24837f13
RS
1544 (face-spec-recalc face frame))))
1545
1546(defun face-spec-recalc (face frame)
1547 "Reset the face attributes of FACE on FRAME according to its specs.
1548This applies the defface/custom spec first, then the custom theme specs,
1549then the override spec."
1550 (face-spec-reset-face face frame)
1551 (let ((face-sym (or (get face 'face-alias) face)))
7ecc4011
CY
1552 (or (get face 'customized-face)
1553 (get face 'saved-face)
1554 (face-spec-set-2 face frame (face-default-spec face)))
24837f13
RS
1555 (let ((theme-faces (reverse (get face-sym 'theme-face))))
1556 (dolist (spec theme-faces)
1557 (face-spec-set-2 face frame (cadr spec))))
1558 (face-spec-set-2 face frame (get face-sym 'face-override-spec))))
1559
1560(defun face-spec-set-2 (face frame spec)
1561 "Set the face attributes of FACE on FRAME according to SPEC."
4f77c25d
CY
1562 (let* ((spec (face-spec-choose spec frame))
1563 attrs)
1564 (while spec
1565 (when (assq (car spec) face-x-resources)
1566 (push (car spec) attrs)
1567 (push (cadr spec) attrs))
1568 (setq spec (cddr spec)))
1569 (apply 'set-face-attribute face frame (nreverse attrs))))
5f5c8ee5
GM
1570
1571(defun face-attr-match-p (face attrs &optional frame)
a9de7d29 1572 "Return t if attributes of FACE match values in plist ATTRS.
5f5c8ee5
GM
1573Optional parameter FRAME is the frame whose definition of FACE
1574is used. If nil or omitted, use the selected frame."
1575 (unless frame
1576 (setq frame (selected-frame)))
1577 (let ((list face-attribute-name-alist)
1578 (match t))
4983ddea
CY
1579 (while (and match list)
1580 (let* ((attr (caar list))
a9de7d29
MB
1581 (specified-value
1582 (if (plist-member attrs attr)
1583 (plist-get attrs attr)
1584 'unspecified))
5f5c8ee5 1585 (value-now (face-attribute face attr frame)))
a9de7d29 1586 (setq match (equal specified-value value-now))
5f5c8ee5
GM
1587 (setq list (cdr list))))
1588 match))
1589
4983ddea 1590(defsubst face-spec-match-p (face spec &optional frame)
5f5c8ee5
GM
1591 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1592 (face-attr-match-p face (face-spec-choose spec frame) frame))
1593
94fe8a31 1594(defsubst face-default-spec (face)
96c2938f
MB
1595 "Return the default face-spec for FACE, ignoring any user customization.
1596If there is no default for FACE, return nil."
1597 (get face 'face-defface-spec))
5f5c8ee5 1598
94fe8a31
MB
1599(defsubst face-user-default-spec (face)
1600 "Return the user's customized face-spec for FACE, or the default if none.
7cd512f2 1601If there is neither a user setting nor a default for FACE, return nil."
e44d251c
JL
1602 (or (get face 'customized-face)
1603 (get face 'saved-face)
94fe8a31
MB
1604 (face-default-spec face)))
1605
5f5c8ee5 1606\f
f795f633
EZ
1607;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1608;;; Frame-type independent color support.
1609;;; We keep the old x-* names as aliases for back-compatibility.
1610;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1611
1612(defun defined-colors (&optional frame)
1613 "Return a list of colors supported for a particular frame.
1614The argument FRAME specifies which frame to try.
1615The value may be different for frames on different display types.
43c58260
RS
1616If FRAME doesn't support colors, the value is nil.
1617If FRAME is nil, that stands for the selected frame."
9e2a2647 1618 (if (memq (framep (or frame (selected-frame))) '(x w32 ns))
f795f633 1619 (xw-defined-colors frame)
37462f4c 1620 (mapcar 'car (tty-color-alist frame))))
f795f633
EZ
1621(defalias 'x-defined-colors 'defined-colors)
1622
aa360da1
GM
1623(declare-function xw-color-defined-p "xfns.c" (color &optional frame))
1624
f795f633
EZ
1625(defun color-defined-p (color &optional frame)
1626 "Return non-nil if color COLOR is supported on frame FRAME.
1627If FRAME is omitted or nil, use the selected frame.
293b4814
EZ
1628If COLOR is the symbol `unspecified' or one of the strings
1629\"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1e221c16 1630 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
f795f633 1631 nil
9e2a2647 1632 (if (member (framep (or frame (selected-frame))) '(x w32 ns))
f795f633 1633 (xw-color-defined-p color frame)
37462f4c 1634 (numberp (tty-color-translate color frame)))))
f795f633
EZ
1635(defalias 'x-color-defined-p 'color-defined-p)
1636
aa360da1
GM
1637(declare-function xw-color-values "xfns.c" (color &optional frame))
1638
f795f633
EZ
1639(defun color-values (color &optional frame)
1640 "Return a description of the color named COLOR on frame FRAME.
22bbca61
JB
1641The value is a list of integer RGB values--(RED GREEN BLUE).
1642These values appear to range from 0 to 65280 or 65535, depending
1643on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
f795f633
EZ
1644If FRAME is omitted or nil, use the selected frame.
1645If FRAME cannot display COLOR, the value is nil.
293b4814
EZ
1646If COLOR is the symbol `unspecified' or one of the strings
1647\"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1e221c16 1648 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
f795f633 1649 nil
9e2a2647 1650 (if (memq (framep (or frame (selected-frame))) '(x w32 ns))
f795f633
EZ
1651 (xw-color-values color frame)
1652 (tty-color-values color frame))))
1653(defalias 'x-color-values 'color-values)
1654
aa360da1
GM
1655(declare-function xw-display-color-p "xfns.c" (&optional terminal))
1656
f795f633
EZ
1657(defun display-color-p (&optional display)
1658 "Return t if DISPLAY supports color.
1659The optional argument DISPLAY specifies which display to ask about.
1660DISPLAY should be either a frame or a display name (a string).
1661If omitted or nil, that stands for the selected frame's display."
9e2a2647 1662 (if (memq (framep-on-display display) '(x w32 ns))
d5179a01
EZ
1663 (xw-display-color-p display)
1664 (tty-display-color-p display)))
f795f633
EZ
1665(defalias 'x-display-color-p 'display-color-p)
1666
aa360da1
GM
1667(declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
1668
d5179a01
EZ
1669(defun display-grayscale-p (&optional display)
1670 "Return non-nil if frames on DISPLAY can display shades of gray."
1671 (let ((frame-type (framep-on-display display)))
1672 (cond
9e2a2647 1673 ((memq frame-type '(x w32 ns))
d5179a01
EZ
1674 (x-display-grayscale-p display))
1675 (t
1676 (> (tty-color-gray-shades display) 2)))))
1677
9317e499
CY
1678(defun read-color (&optional prompt convert-to-RGB allow-empty-name msg)
1679 "Read a color name or RGB triplet of the form \"#RRRRGGGGBBBB\".
1680Completion is available for color names, but not for RGB triplets.
1681
1682RGB triplets have the form #XXXXXXXXXXXX, where each X is a hex
1683digit. The number of Xs must be a multiple of 3, with the same
1684number of Xs for each of red, green, and blue. The order is red,
1685green, blue.
1686
1687In addition to standard color names and RGB hex values, the
1688following are available as color candidates. In each case, the
1689corresponding color is used.
26c07a69
RS
1690
1691 * `foreground at point' - foreground under the cursor
1692 * `background at point' - background under the cursor
1693
9317e499 1694Optional arg PROMPT is the prompt; if nil, use a default prompt.
26c07a69 1695
9317e499
CY
1696Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1697convert an input color name to an RGB hex string. Return the RGB
1698hex string.
26c07a69 1699
9317e499
CY
1700If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1701to enter an empty color name (the empty string).
26c07a69 1702
9317e499
CY
1703Interactively, or with optional arg MSG non-nil, print the
1704resulting color name in the echo area."
26c07a69
RS
1705 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1706 (let* ((completion-ignore-case t)
9317e499
CY
1707 (colors (or facemenu-color-alist
1708 (append '("foreground at point" "background at point")
1709 (if allow-empty-name '(""))
1710 (defined-colors))))
1711 (color (completing-read
1712 (or prompt "Color (name or #RGB triplet): ")
1713 ;; Completing function for reading colors, accepting
1714 ;; both color names and RGB triplets.
1715 (lambda (string pred flag)
1716 (cond
1717 ((null flag) ; Try completion.
1718 (or (try-completion string colors pred)
1719 (if (color-defined-p string)
1720 string)))
1721 ((eq flag t) ; List all completions.
1722 (or (all-completions string colors pred)
1723 (if (color-defined-p string)
1724 (list string))))
1725 ((eq flag 'lambda) ; Test completion.
1726 (or (memq string colors)
1727 (color-defined-p string)))))
1728 nil t))
1729 hex-string)
1730
1731 ;; Process named colors.
1732 (when (member color colors)
1733 (cond ((string-equal color "foreground at point")
1734 (setq color (foreground-color-at-point)))
1735 ((string-equal color "background at point")
1736 (setq color (background-color-at-point))))
1737 (when (and convert-to-RGB
1738 (not (string-equal color "")))
1739 (let ((components (x-color-values color)))
1740 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1741 (setq color (format "#%04X%04X%04X"
1742 (logand 65535 (nth 0 components))
1743 (logand 65535 (nth 1 components))
1744 (logand 65535 (nth 2 components))))))))
1745 (when msg (message "Color: `%s'" color))
1746 color))
1747
26c07a69
RS
1748
1749(defun face-at-point ()
1750 "Return the face of the character after point.
1751If it has more than one face, return the first one.
1752Return nil if it has no specified face."
1753 (let* ((faceprop (or (get-char-property (point) 'read-face-name)
1754 (get-char-property (point) 'face)
1755 'default))
1756 (face (cond ((symbolp faceprop) faceprop)
1757 ;; List of faces (don't treat an attribute spec).
1758 ;; Just use the first face.
1759 ((and (consp faceprop) (not (keywordp (car faceprop)))
1760 (not (memq (car faceprop)
1761 '(foreground-color background-color))))
1762 (car faceprop))
1763 (t nil)))) ; Invalid face value.
1764 (if (facep face) face nil)))
1765
1766(defun foreground-color-at-point ()
1767 "Return the foreground color of the character after point."
1768 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1769 ;; Need also pick up any face properties that are not associated with named faces.
1770 (let ((face (or (face-at-point)
1771 (get-char-property (point) 'read-face-name)
1772 (get-char-property (point) 'face))))
1773 (cond ((and face (symbolp face))
1774 (let ((value (face-foreground face nil 'default)))
1775 (if (member value '("unspecified-fg" "unspecified-bg"))
1776 nil
1777 value)))
1778 ((consp face)
1779 (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face)))
1780 ((memq ':foreground face) (cadr (memq ':foreground face)))))
1781 (t nil)))) ; Invalid face value.
1782
1783(defun background-color-at-point ()
1784 "Return the background color of the character after point."
1785 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1786 ;; Need also pick up any face properties that are not associated with named faces.
1787 (let ((face (or (face-at-point)
1788 (get-char-property (point) 'read-face-name)
1789 (get-char-property (point) 'face))))
1790 (cond ((and face (symbolp face))
1791 (let ((value (face-background face nil 'default)))
1792 (if (member value '("unspecified-fg" "unspecified-bg"))
1793 nil
1794 value)))
1795 ((consp face)
1796 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1797 ((memq ':background face) (cadr (memq ':background face)))))
1798 (t nil)))) ; Invalid face value.
f795f633 1799\f
5f5c8ee5
GM
1800;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1801;;; Background mode.
1802;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1803
1804(defcustom frame-background-mode nil
9201cc28 1805 "The brightness of the background.
e44d251c 1806Set this to the symbol `dark' if your background color is dark,
d4c6530f
JL
1807`light' if your background is light, or nil (automatic by default)
1808if you want Emacs to examine the brightness for you. Don't set this
1809variable with `setq'; this won't have the expected effect."
5f5c8ee5
GM
1810 :group 'faces
1811 :set #'(lambda (var value)
c20d5073 1812 (set-default var value)
b5325e78 1813 (mapc 'frame-set-background-mode (frame-list)))
5f5c8ee5 1814 :initialize 'custom-initialize-changed
d4c6530f
JL
1815 :type '(choice (const dark)
1816 (const light)
1817 (const :tag "automatic" nil)))
5f5c8ee5
GM
1818
1819
aa360da1
GM
1820(declare-function x-get-resource "frame.c"
1821 (attribute class &optional component subclass))
1822
2d0e0565
CY
1823(defvar inhibit-frame-set-background-mode nil)
1824
4983ddea 1825(defun frame-set-background-mode (frame &optional keep-face-specs)
d8abcd91
MB
1826 "Set up display-dependent faces on FRAME.
1827Display-dependent faces are those which have different definitions
4983ddea
CY
1828according to the `background-mode' and `display-type' frame parameters.
1829
1830If optional arg KEEP-FACE-SPECS is non-nil, don't recalculate
1831face specs for the new background mode."
2d0e0565
CY
1832 (unless inhibit-frame-set-background-mode
1833 (let* ((bg-resource
1834 (and (window-system frame)
1835 (x-get-resource "backgroundMode" "BackgroundMode")))
1836 (bg-color (frame-parameter frame 'background-color))
1837 (terminal-bg-mode (terminal-parameter frame 'background-mode))
1838 (tty-type (tty-type frame))
df93e513
JR
1839 (default-bg-mode
1840 (if (or (window-system frame)
1841 (and tty-type
1842 (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
1843 tty-type)))
1844 'light
1845 'dark))
1846 (non-default-bg-mode (if (eq default-bg-mode 'light) 'dark 'light))
2d0e0565
CY
1847 (bg-mode
1848 (cond (frame-background-mode)
1849 (bg-resource (intern (downcase bg-resource)))
1850 (terminal-bg-mode)
2d0e0565 1851 ((equal bg-color "unspecified-fg") ; inverted colors
df93e513
JR
1852 non-default-bg-mode)
1853 ((not (color-values bg-color frame))
1854 default-bg-mode)
2d0e0565
CY
1855 ((>= (apply '+ (color-values bg-color frame))
1856 ;; Just looking at the screen, colors whose
1857 ;; values add up to .6 of the white total
1858 ;; still look dark to me.
1859 (* (apply '+ (color-values "white" frame)) .6))
1860 'light)
1861 (t 'dark)))
1862 (display-type
1863 (cond ((null (window-system frame))
1864 (if (tty-display-color-p frame) 'color 'mono))
1865 ((display-color-p frame)
1866 'color)
1867 ((x-display-grayscale-p frame)
1868 'grayscale)
1869 (t 'mono)))
1870 (old-bg-mode
1871 (frame-parameter frame 'background-mode))
1872 (old-display-type
1873 (frame-parameter frame 'display-type)))
1874
1875 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1876 (let ((locally-modified-faces nil)
1877 ;; Prevent face-spec-recalc from calling this function
1878 ;; again, resulting in a loop (bug#911).
4983ddea
CY
1879 (inhibit-frame-set-background-mode t)
1880 (params (list (cons 'background-mode bg-mode)
1881 (cons 'display-type display-type))))
1882 (if keep-face-specs
1883 (modify-frame-parameters frame params)
1884 ;; If we are recomputing face specs, first collect a list
1885 ;; of faces that don't match their face-specs. These are
1886 ;; the faces modified on FRAME, and we avoid changing them
1887 ;; below. Use a negative list to avoid consing (we assume
1888 ;; most faces are unmodified).
1889 (dolist (face (face-list))
1890 (and (not (get face 'face-override-spec))
1891 (not (face-spec-match-p face
1892 (face-user-default-spec face)
1893 (selected-frame)))
1894 (push face locally-modified-faces)))
1895 ;; Now change to the new frame parameters
1896 (modify-frame-parameters frame params)
1897 ;; For all unmodified named faces, choose face specs
1898 ;; matching the new frame parameters.
1899 (dolist (face (face-list))
1900 (unless (memq face locally-modified-faces)
1901 (face-spec-recalc face frame)))))))))
5f5c8ee5 1902
5f5c8ee5
GM
1903\f
1904;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1905;;; Frame creation.
1906;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1907
aa360da1
GM
1908(declare-function x-parse-geometry "frame.c" (string))
1909
5f5c8ee5
GM
1910(defun x-handle-named-frame-geometry (parameters)
1911 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1912Value is the new parameter list."
e8a2b2da 1913 ;; Note that `x-resource-name' has a global meaning.
c1ef4455 1914 (let ((x-resource-name (cdr (assq 'name parameters))))
e8a2b2da
CY
1915 (when x-resource-name
1916 ;; Before checking X resources, we must have an X connection.
1917 (or (window-system)
1918 (x-display-list)
1919 (x-open-connection (or (cdr (assq 'display parameters))
1920 x-display-name)))
1921 (let (res-geometry parsed)
1922 (and (setq res-geometry (x-get-resource "geometry" "Geometry"))
1923 (setq parsed (x-parse-geometry res-geometry))
1924 (setq parameters
c1ef4455 1925 (append parameters parsed
e8a2b2da
CY
1926 ;; If the resource specifies a position,
1927 ;; take note of that.
1928 (if (or (assq 'top parsed) (assq 'left parsed))
1929 '((user-position . t) (user-size . t)))))))))
1930 parameters)
5f5c8ee5
GM
1931
1932
1933(defun x-handle-reverse-video (frame parameters)
1934 "Handle the reverse-video frame parameter and X resource.
1935`x-create-frame' does not handle this one."
1936 (when (cdr (or (assq 'reverse parameters)
5f5c8ee5
GM
1937 (let ((resource (x-get-resource "reverseVideo"
1938 "ReverseVideo")))
1939 (if resource
1940 (cons nil (member (downcase resource)
1941 '("on" "true")))))))
1942 (let* ((params (frame-parameters frame))
1943 (bg (cdr (assq 'foreground-color params)))
1944 (fg (cdr (assq 'background-color params))))
1945 (modify-frame-parameters frame
1946 (list (cons 'foreground-color fg)
1947 (cons 'background-color bg)))
1948 (if (equal bg (cdr (assq 'border-color params)))
1949 (modify-frame-parameters frame
1950 (list (cons 'border-color fg))))
1951 (if (equal bg (cdr (assq 'mouse-color params)))
1952 (modify-frame-parameters frame
1953 (list (cons 'mouse-color fg))))
1954 (if (equal bg (cdr (assq 'cursor-color params)))
1955 (modify-frame-parameters frame
1956 (list (cons 'cursor-color fg)))))))
1957
aa360da1 1958(declare-function x-create-frame "xfns.c" (parms))
c8ccffb1 1959(declare-function x-setup-function-keys "term/common-win" (frame))
5f5c8ee5
GM
1960
1961(defun x-create-frame-with-faces (&optional parameters)
c1ef4455
CY
1962 "Create and return a frame with frame parameters PARAMETERS.
1963If PARAMETERS specify a frame name, handle X geometry resources
1964for that name. If PARAMETERS includes a `reverse' parameter, or
1965the X resource ``reverseVideo'' is present, handle that."
5f5c8ee5 1966 (setq parameters (x-handle-named-frame-geometry parameters))
41e6403e
CY
1967 (let* ((params (copy-tree parameters))
1968 (visibility-spec (assq 'visibility parameters))
1969 (delayed-params '(foreground-color background-color font
1970 border-color cursor-color mouse-color
1971 visibility scroll-bar-foreground
1972 scroll-bar-background))
1973 frame success)
1974 (dolist (param delayed-params)
1975 (setq params (assq-delete-all param params)))
1976 (setq frame (x-create-frame `((visibility . nil) . ,params)))
5f5c8ee5
GM
1977 (unwind-protect
1978 (progn
2bb819d5 1979 (x-setup-function-keys frame)
5f5c8ee5 1980 (x-handle-reverse-video frame parameters)
4983ddea 1981 (frame-set-background-mode frame t)
fa7015f4 1982 (face-set-after-frame-default frame parameters)
095fe281 1983 (if (null visibility-spec)
5f5c8ee5
GM
1984 (make-frame-visible frame)
1985 (modify-frame-parameters frame (list visibility-spec)))
1986 (setq success t))
1987 (unless success
1988 (delete-frame frame)))
1989 frame))
1990
fa7015f4
CY
1991(defun face-set-after-frame-default (frame &optional parameters)
1992 "Initialize the frame-local faces of FRAME.
1993Calculate the face definitions using the face specs, custom theme
41e6403e 1994settings, X resources, and `face-new-frame-defaults'.
fa7015f4 1995Finally, apply any relevant face attributes found amongst the
c1ef4455 1996frame parameters in PARAMETERS."
4983ddea
CY
1997 (let ((window-system-p (memq (window-system frame) '(x w32))))
1998 (dolist (face (nreverse (face-list))) ;Why reverse? --Stef
1999 (condition-case ()
2000 (progn
2001 ;; Initialize faces from face spec and custom theme.
2002 (face-spec-recalc face frame)
2003 ;; X resouces for the default face are applied during
2004 ;; `x-create-frame'.
2005 (and (not (eq face 'default)) window-system-p
2006 (make-face-x-resource-internal face frame))
2007 ;; Apply attributes specified by face-new-frame-defaults
2008 (internal-merge-in-global-face face frame))
2009 ;; Don't let invalid specs prevent frame creation.
2010 (error nil))))
2011
fa7015f4 2012 ;; Apply attributes specified by frame parameters.
8db9c5ee 2013 (let ((face-params '((foreground-color default :foreground)
fa7015f4
CY
2014 (background-color default :background)
2015 (font default :font)
2016 (border-color border :background)
2017 (cursor-color cursor :background)
2018 (scroll-bar-foreground scroll-bar :foreground)
2019 (scroll-bar-background scroll-bar :background)
2020 (mouse-color mouse :background))))
8db9c5ee 2021 (dolist (param face-params)
fa7015f4 2022 (let* ((param-name (nth 0 param))
c1ef4455 2023 (value (cdr (assq param-name parameters))))
fa7015f4
CY
2024 (if value
2025 (set-face-attribute (nth 1 param) frame
2026 (nth 2 param) value))))))
5f5c8ee5 2027
53990c84
EZ
2028(defun tty-handle-reverse-video (frame parameters)
2029 "Handle the reverse-video frame parameter for terminal frames."
c1ef4455 2030 (when (cdr (assq 'reverse parameters))
53990c84
EZ
2031 (let* ((params (frame-parameters frame))
2032 (bg (cdr (assq 'foreground-color params)))
2033 (fg (cdr (assq 'background-color params))))
2034 (modify-frame-parameters frame
2035 (list (cons 'foreground-color fg)
2036 (cons 'background-color bg)))
2037 (if (equal bg (cdr (assq 'mouse-color params)))
2038 (modify-frame-parameters frame
2039 (list (cons 'mouse-color fg))))
2040 (if (equal bg (cdr (assq 'cursor-color params)))
2041 (modify-frame-parameters frame
2042 (list (cons 'cursor-color fg)))))))
2043
5f5c8ee5
GM
2044
2045(defun tty-create-frame-with-faces (&optional parameters)
c1ef4455
CY
2046 "Create and return a frame from optional frame parameters PARAMETERS.
2047If PARAMETERS contains a `reverse' parameter, handle that."
5f5c8ee5
GM
2048 (let ((frame (make-terminal-frame parameters))
2049 success)
2050 (unwind-protect
061e4e7f 2051 (with-selected-frame frame
53990c84 2052 (tty-handle-reverse-video frame (frame-parameters frame))
cd85984a 2053
8782c744
SM
2054 (unless (terminal-parameter frame 'terminal-initted)
2055 (set-terminal-parameter frame 'terminal-initted t)
2056 (set-locale-environment nil frame)
2057 (tty-run-terminal-initialization frame))
4983ddea 2058 (frame-set-background-mode frame t)
fa7015f4 2059 (face-set-after-frame-default frame parameters)
5f5c8ee5
GM
2060 (setq success t))
2061 (unless success
2062 (delete-frame frame)))
2063 frame))
465fceed 2064
b34c34da
KL
2065(defun tty-find-type (pred type)
2066 "Return the longest prefix of TYPE to which PRED returns non-nil.
2067TYPE should be a tty type name such as \"xterm-16color\".
2068
2069The function tries only those prefixes that are followed by a
2070dash or underscore in the original type name, like \"xterm\" in
2071the above example."
2072 (let (hyphend)
2073 (while (and type
2074 (not (funcall pred type)))
2075 ;; Strip off last hyphen and what follows, then try again
2076 (setq type
2077 (if (setq hyphend (string-match "[-_][^-_]+$" type))
2078 (substring type 0 hyphend)
2079 nil))))
2080 type)
2081
8cbd7bed
KL
2082(defun tty-run-terminal-initialization (frame &optional type)
2083 "Run the special initialization code for the terminal type of FRAME.
2084The optional TYPE parameter may be used to override the autodetected
2085terminal type to a different value."
2086 (setq type (or type (tty-type frame)))
cd85984a
KL
2087 ;; Load library for our terminal type.
2088 ;; User init file can set term-file-prefix to nil to prevent this.
2089 (with-selected-frame frame
8782c744 2090 (unless (null term-file-prefix)
b34c34da
KL
2091 (let* (term-init-func)
2092 ;; First, load the terminal initialization file, if it is
2093 ;; available and it hasn't been loaded already.
2094 (tty-find-type #'(lambda (type)
2095 (let ((file (locate-library (concat term-file-prefix type))))
2096 (and file
2097 (or (assoc file load-history)
2098 (load file t t)))))
8cbd7bed 2099 type)
b34c34da
KL
2100 ;; Next, try to find a matching initialization function, and call it.
2101 (tty-find-type #'(lambda (type)
2102 (fboundp (setq term-init-func
2103 (intern (concat "terminal-init-" type)))))
8cbd7bed 2104 type)
567c8878 2105 (when (fboundp term-init-func)
b34c34da
KL
2106 (funcall term-init-func))
2107 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
465fceed 2108
5f5c8ee5
GM
2109;; Called from C function init_display to initialize faces of the
2110;; dumped terminal frame on startup.
465fceed 2111
5f5c8ee5
GM
2112(defun tty-set-up-initial-frame-faces ()
2113 (let ((frame (selected-frame)))
4983ddea 2114 (frame-set-background-mode frame t)
5f5c8ee5 2115 (face-set-after-frame-default frame)))
00f51890 2116
465fceed 2117
bdda3754 2118\f
5f5c8ee5
GM
2119;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2120;;; Standard faces.
2121;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
465fceed 2122
5f5c8ee5
GM
2123(defgroup basic-faces nil
2124 "The standard faces of Emacs."
2125 :group 'faces)
ef436392 2126
bacbbe8f
CY
2127(defface default
2128 '((t nil)) ; If this were nil, face-defface-spec would not be set.
5f5c8ee5
GM
2129 "Basic default face."
2130 :group 'basic-faces)
465fceed 2131
51d44a36
JL
2132(defface bold
2133 '((t :weight bold))
2134 "Basic bold face."
2135 :group 'basic-faces)
2136
2137(defface italic
2138 '((((supports :slant italic))
2139 :slant italic)
2140 (((supports :underline t))
2141 :underline t)
2142 (t
2143 ;; default to italic, even it doesn't appear to be supported,
2144 ;; because in some cases the display engine will do it's own
2145 ;; workaround (to `dim' on ttys)
2146 :slant italic))
2147 "Basic italic face."
2148 :group 'basic-faces)
2149
2150(defface bold-italic
2151 '((t :weight bold :slant italic))
2152 "Basic bold-italic face."
2153 :group 'basic-faces)
2154
2155(defface underline
2156 '((((supports :underline t))
2157 :underline t)
2158 (((supports :weight bold))
2159 :weight bold)
2160 (t :underline t))
2161 "Basic underlined face."
2162 :group 'basic-faces)
2163
2164(defface fixed-pitch
d5f57335 2165 '((t :family "Monospace"))
51d44a36
JL
2166 "The basic fixed-pitch face."
2167 :group 'basic-faces)
2168
2169(defface variable-pitch
ed008205 2170 '((t :family "Sans Serif"))
51d44a36
JL
2171 "The basic variable-pitch face."
2172 :group 'basic-faces)
2173
2174(defface shadow
2175 '((((class color grayscale) (min-colors 88) (background light))
2176 :foreground "grey50")
2177 (((class color grayscale) (min-colors 88) (background dark))
2178 :foreground "grey70")
2179 (((class color) (min-colors 8) (background light))
2180 :foreground "green")
2181 (((class color) (min-colors 8) (background dark))
2182 :foreground "yellow"))
2183 "Basic face for shadowed text."
2184 :group 'basic-faces
2185 :version "22.1")
2186
59746720
JL
2187(defface link
2188 '((((class color) (min-colors 88) (background light))
2189 :foreground "blue1" :underline t)
2190 (((class color) (background light))
2191 :foreground "blue" :underline t)
2192 (((class color) (min-colors 88) (background dark))
2193 :foreground "cyan1" :underline t)
2194 (((class color) (background dark))
2195 :foreground "cyan" :underline t)
2196 (t :inherit underline))
2197 "Basic face for unvisited links."
2198 :group 'basic-faces
2199 :version "22.1")
2200
2201(defface link-visited
2202 '((default :inherit link)
2203 (((class color) (background light)) :foreground "magenta4")
2204 (((class color) (background dark)) :foreground "violet"))
2205 "Basic face for visited links."
2206 :group 'basic-faces
2207 :version "22.1")
2208
51d44a36
JL
2209(defface highlight
2210 '((((class color) (min-colors 88) (background light))
2211 :background "darkseagreen2")
2212 (((class color) (min-colors 88) (background dark))
2213 :background "darkolivegreen")
2214 (((class color) (min-colors 16) (background light))
2215 :background "darkseagreen2")
2216 (((class color) (min-colors 16) (background dark))
2217 :background "darkolivegreen")
2218 (((class color) (min-colors 8))
2219 :background "green" :foreground "black")
2220 (t :inverse-video t))
2221 "Basic face for highlighting."
2222 :group 'basic-faces)
2223
f3e848f4
AR
2224;; Region face: under NS, default to the system-defined selection
2225;; color (optimized for the fixed white background of other apps),
2226;; if background is light.
51d44a36
JL
2227(defface region
2228 '((((class color) (min-colors 88) (background dark))
2229 :background "blue3")
3a46642b
J
2230 (((class color) (min-colors 88) (background light) (type gtk))
2231 :foreground "gtk_selection_fg_color"
2232 :background "gtk_selection_bg_color")
f3e848f4
AR
2233 (((class color) (min-colors 88) (background light) (type ns))
2234 :background "ns_selection_color")
51d44a36
JL
2235 (((class color) (min-colors 88) (background light))
2236 :background "lightgoldenrod2")
2237 (((class color) (min-colors 16) (background dark))
2238 :background "blue3")
2239 (((class color) (min-colors 16) (background light))
2240 :background "lightgoldenrod2")
2241 (((class color) (min-colors 8))
2242 :background "blue" :foreground "white")
2243 (((type tty) (class mono))
2244 :inverse-video t)
2245 (t :background "gray"))
2246 "Basic face for highlighting the region."
2247 :version "21.1"
2248 :group 'basic-faces)
2249
2250(defface secondary-selection
2251 '((((class color) (min-colors 88) (background light))
2252 :background "yellow1")
2253 (((class color) (min-colors 88) (background dark))
2254 :background "SkyBlue4")
2255 (((class color) (min-colors 16) (background light))
2256 :background "yellow")
2257 (((class color) (min-colors 16) (background dark))
2258 :background "SkyBlue4")
2259 (((class color) (min-colors 8))
2260 :background "cyan" :foreground "black")
2261 (t :inverse-video t))
2262 "Basic face for displaying the secondary selection."
2263 :group 'basic-faces)
2264
2265(defface trailing-whitespace
2266 '((((class color) (background light))
2267 :background "red1")
2268 (((class color) (background dark))
2269 :background "red1")
2270 (t :inverse-video t))
2271 "Basic face for highlighting trailing whitespace."
2272 :version "21.1"
d4c6530f 2273 :group 'whitespace-faces ; like `show-trailing-whitespace'
51d44a36
JL
2274 :group 'basic-faces)
2275
2276(defface escape-glyph
2277 '((((background dark)) :foreground "cyan")
2278 ;; See the comment in minibuffer-prompt for
2279 ;; the reason not to use blue on MS-DOS.
2280 (((type pc)) :foreground "magenta")
2281 ;; red4 is too dark, but some say blue is too loud.
2282 ;; brown seems to work ok. -- rms.
2283 (t :foreground "brown"))
1a77c985 2284 "Face for characters displayed as sequences using `^' or `\\'."
51d44a36
JL
2285 :group 'basic-faces
2286 :version "22.1")
2287
2288(defface nobreak-space
2289 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2290 (((class color) (min-colors 8)) :background "magenta")
2291 (t :inverse-video t))
2292 "Face for displaying nobreak space."
2293 :group 'basic-faces
2294 :version "22.1")
72418504 2295
97bca259
JL
2296(defgroup mode-line-faces nil
2297 "Faces used in the mode line."
6d968826 2298 :group 'mode-line
97bca259
JL
2299 :group 'faces
2300 :version "22.1")
2301
3759f14b 2302(defface mode-line
11c2175c 2303 '((((class color) (min-colors 88))
b6b90dfc
SM
2304 :box (:line-width -1 :style released-button)
2305 :background "grey75" :foreground "black")
5f5c8ee5 2306 (t
b6b90dfc 2307 :inverse-video t))
c5752dcb 2308 "Basic mode line face for selected window."
a4391cf1 2309 :version "21.1"
97bca259 2310 :group 'mode-line-faces
5f5c8ee5 2311 :group 'basic-faces)
9f255bc3
GM
2312;; No need to define aliases of this form for new faces.
2313(define-obsolete-face-alias 'modeline 'mode-line "21.1")
465fceed 2314
c5752dcb 2315(defface mode-line-inactive
cf459bb7 2316 '((default
b6b90dfc 2317 :inherit mode-line)
11c2175c 2318 (((class color) (min-colors 88) (background light))
c5752dcb
KS
2319 :weight light
2320 :box (:line-width -1 :color "grey75" :style nil)
2321 :foreground "grey20" :background "grey90")
11c2175c 2322 (((class color) (min-colors 88) (background dark) )
53a2f6e1
MB
2323 :weight light
2324 :box (:line-width -1 :color "grey40" :style nil)
b6b90dfc 2325 :foreground "grey80" :background "grey30"))
c5752dcb 2326 "Basic mode line face for non-selected windows."
bf247b6e 2327 :version "22.1"
97bca259
JL
2328 :group 'mode-line-faces
2329 :group 'basic-faces)
9f255bc3 2330(define-obsolete-face-alias 'modeline-inactive 'mode-line-inactive "22.1")
97bca259
JL
2331
2332(defface mode-line-highlight
2333 '((((class color) (min-colors 88))
2334 :box (:line-width 2 :color "grey40" :style released-button))
2335 (t
2336 :inherit highlight))
2337 "Basic mode line face for highlighting."
2338 :version "22.1"
2339 :group 'mode-line-faces
2340 :group 'basic-faces)
9f255bc3 2341(define-obsolete-face-alias 'modeline-highlight 'mode-line-highlight "22.1")
97bca259 2342
313e2fc4
GM
2343(defface mode-line-emphasis
2344 '((t (:weight bold)))
2345 "Face used to emphasize certain mode line features.
2346Use the face `mode-line-highlight' for features that can be selected."
2347 :version "23.1"
2348 :group 'mode-line-faces
2349 :group 'basic-faces)
2350
97bca259
JL
2351(defface mode-line-buffer-id
2352 '((t (:weight bold)))
2353 "Face used for buffer identification parts of the mode line."
2354 :version "22.1"
2355 :group 'mode-line-faces
c5752dcb 2356 :group 'basic-faces)
9f255bc3 2357(define-obsolete-face-alias 'modeline-buffer-id 'mode-line-buffer-id "22.1")
d11fba25 2358
e5e7779f 2359(defface header-line
cf459bb7 2360 '((default
6b61353c
KH
2361 :inherit mode-line)
2362 (((type tty))
1cb4393e
MB
2363 ;; This used to be `:inverse-video t', but that doesn't look very
2364 ;; good when combined with inverse-video mode-lines and multiple
2365 ;; windows. Underlining looks better, and is more consistent with
2366 ;; the window-system face variants, which deemphasize the
2367 ;; header-line in relation to the mode-line face. If a terminal
2368 ;; can't underline, then the header-line will end up without any
2369 ;; highlighting; this may be too confusing in general, although it
2370 ;; happens to look good with the only current use of header-lines,
2371 ;; the info browser. XXX
6b61353c 2372 :inverse-video nil ;Override the value inherited from mode-line.
a7ac92b6 2373 :underline t)
98490598 2374 (((class color grayscale) (background light))
bdab1d43 2375 :background "grey90" :foreground "grey20"
6b61353c 2376 :box nil)
98490598 2377 (((class color grayscale) (background dark))
bdab1d43 2378 :background "grey20" :foreground "grey90"
6b61353c 2379 :box nil)
98490598 2380 (((class mono) (background light))
bdab1d43
MB
2381 :background "white" :foreground "black"
2382 :inverse-video nil
2383 :box nil
6b61353c 2384 :underline t)
98490598 2385 (((class mono) (background dark))
bdab1d43
MB
2386 :background "black" :foreground "white"
2387 :inverse-video nil
2388 :box nil
6b61353c 2389 :underline t))
e5e7779f 2390 "Basic header-line face."
a4391cf1 2391 :version "21.1"
5f5c8ee5 2392 :group 'basic-faces)
e8e4cda0 2393
51d44a36
JL
2394(defface vertical-border
2395 '((((type tty)) :inherit mode-line-inactive))
2396 "Face used for vertical window dividers on ttys."
2397 :version "22.1"
5f5c8ee5 2398 :group 'basic-faces)
d11fba25 2399
9ed779e8
JL
2400(defface minibuffer-prompt
2401 '((((background dark)) :foreground "cyan")
2402 ;; Don't use blue because many users of the MS-DOS port customize
2403 ;; their foreground color to be blue.
2404 (((type pc)) :foreground "magenta")
c57a1dc6 2405 (t :foreground "medium blue"))
9ed779e8
JL
2406 "Face for minibuffer prompts.
2407By default, Emacs automatically adds this face to the value of
2408`minibuffer-prompt-properties', which is a list of text properties
2409used to display the prompt text."
bf247b6e 2410 :version "22.1"
31cf46d3
RS
2411 :group 'basic-faces)
2412
2413(setq minibuffer-prompt-properties
2414 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2415
f1cae29e 2416(defface fringe
d6d59057 2417 '((((class color) (background light))
b6b90dfc
SM
2418 :background "grey95")
2419 (((class color) (background dark))
2420 :background "grey10")
2421 (t
2422 :background "gray"))
f1cae29e
GM
2423 "Basic face for the fringes to the left and right of windows under X."
2424 :version "21.1"
84fe35f0 2425 :group 'frames
f1cae29e
GM
2426 :group 'basic-faces)
2427
d390b4d2 2428(defface scroll-bar '((t nil))
f1cae29e
GM
2429 "Basic face for the scroll bar colors under X."
2430 :version "21.1"
84fe35f0 2431 :group 'frames
f1cae29e
GM
2432 :group 'basic-faces)
2433
d390b4d2 2434(defface border '((t nil))
f1cae29e
GM
2435 "Basic face for the frame border under X."
2436 :version "21.1"
84fe35f0 2437 :group 'frames
f1cae29e
GM
2438 :group 'basic-faces)
2439
4983ddea
CY
2440(defface cursor
2441 '((((background light)) :background "black")
2442 (((background dark)) :background "white"))
8d413c2b
KS
2443 "Basic face for the cursor color under X.
2444Note: Other faces cannot inherit from the cursor face."
f1cae29e 2445 :version "21.1"
84fe35f0 2446 :group 'cursor
f1cae29e
GM
2447 :group 'basic-faces)
2448
8d413c2b 2449(put 'cursor 'face-no-inherit t)
f1cae29e 2450
d390b4d2 2451(defface mouse '((t nil))
f1cae29e 2452 "Basic face for the mouse color under X."
e59176e2 2453 :version "21.1"
84fe35f0 2454 :group 'mouse
5f5c8ee5 2455 :group 'basic-faces)
bdda3754 2456
51d44a36
JL
2457(defface tool-bar
2458 '((default
2459 :box (:line-width 1 :style released-button)
2460 :foreground "black")
9e2a2647 2461 (((type x w32 ns) (class color))
51d44a36
JL
2462 :background "grey75")
2463 (((type x) (class mono))
2464 :background "grey"))
2465 "Basic tool-bar face."
2466 :version "21.1"
5f5c8ee5 2467 :group 'basic-faces)
bdda3754 2468
51d44a36
JL
2469(defface menu
2470 '((((type tty))
2471 :inverse-video t)
2472 (((type x-toolkit))
2473 )
16320ac7 2474 (t
51d44a36
JL
2475 :inverse-video t))
2476 "Basic face for the font and colors of the menu bar and popup menus."
a4391cf1 2477 :version "21.1"
51d44a36 2478 :group 'menu
a4391cf1 2479 :group 'basic-faces)
465fceed 2480
6c58c39c
CY
2481(defface help-argument-name '((((supports :slant italic)) :inherit italic))
2482 "Face to highlight argument names in *Help* buffers."
2483 :group 'help)
b2cca856 2484
b18fad6d
KH
2485(defface glyphless-char
2486 '((((type tty)) :inherit underline)
1cd64aae 2487 (((type pc)) :inherit escape-glyph)
b18fad6d 2488 (t :height 0.6))
b2cca856
KH
2489 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2490It is used for characters of no fonts too."
2491 :version "24.1"
2492 :group 'basic-faces)
465fceed 2493\f
5f5c8ee5
GM
2494;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2495;;; Manipulating font names.
2496;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2497
2498;; This is here for compatibilty with Emacs 20.2. For example,
07f27947
DL
2499;; international/fontset.el uses x-resolve-font-name. The following
2500;; functions are not used in the face implementation itself.
465fceed 2501
d7fa5aa2
RS
2502(defvar x-font-regexp nil)
2503(defvar x-font-regexp-head nil)
2504(defvar x-font-regexp-weight nil)
2505(defvar x-font-regexp-slant nil)
465fceed 2506
021ca129
KH
2507(defconst x-font-regexp-weight-subnum 1)
2508(defconst x-font-regexp-slant-subnum 2)
2509(defconst x-font-regexp-swidth-subnum 3)
2510(defconst x-font-regexp-adstyle-subnum 4)
2511
465fceed
ER
2512;;; Regexps matching font names in "Host Portable Character Representation."
2513;;;
2514(let ((- "[-?]")
2515 (foundry "[^-]+")
2516 (family "[^-]+")
2517 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2518; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2519 (weight\? "\\([^-]*\\)") ; 1
2520 (slant "\\([ior]\\)") ; 2
2521; (slant\? "\\([ior?*]?\\)") ; 2
2522 (slant\? "\\([^-]?\\)") ; 2
2523; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2524 (swidth "\\([^-]*\\)") ; 3
2525; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
c8787b81 2526 (adstyle "\\([^-]*\\)") ; 4
465fceed
ER
2527 (pixelsize "[0-9]+")
2528 (pointsize "[0-9][0-9]+")
2529 (resx "[0-9][0-9]+")
2530 (resy "[0-9][0-9]+")
2531 (spacing "[cmp?*]")
2532 (avgwidth "[0-9]+")
2533 (registry "[^-]+")
2534 (encoding "[^-]+")
2535 )
2536 (setq x-font-regexp
1e8780b1 2537 (purecopy (concat "\\`\\*?[-?*]"
465fceed 2538 foundry - family - weight\? - slant\? - swidth - adstyle -
e20d641f
RS
2539 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2540 registry - encoding "\\*?\\'"
1e8780b1 2541 )))
465fceed 2542 (setq x-font-regexp-head
1e8780b1
DN
2543 (purecopy (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2544 "\\([-*?]\\|\\'\\)")))
2545 (setq x-font-regexp-slant (purecopy (concat - slant -)))
2546 (setq x-font-regexp-weight (purecopy (concat - weight -)))
70d0c3b0 2547 nil)
465fceed 2548
5f5c8ee5 2549
281dc1c2
JB
2550(defun x-resolve-font-name (pattern &optional face frame)
2551 "Return a font name matching PATTERN.
ac4c2e6b 2552All wildcards in PATTERN are instantiated.
10d89673
JB
2553If PATTERN is nil, return the name of the frame's base font, which never
2554contains wildcards.
e17dbede
RS
2555Given optional arguments FACE and FRAME, return a font which is
2556also the same size as FACE on FRAME, or fail."
14e6867c
RS
2557 (or (symbolp face)
2558 (setq face (face-name face)))
2559 (and (eq frame t)
2560 (setq frame nil))
10d89673 2561 (if pattern
8db93e45 2562 ;; Note that x-list-fonts has code to handle a face with nil as its font.
abd89b80 2563 (let ((fonts (x-list-fonts pattern face frame 1)))
10d89673
JB
2564 (or fonts
2565 (if face
962a60aa
RS
2566 (if (string-match "\\*" pattern)
2567 (if (null (face-font face))
2568 (error "No matching fonts are the same height as the frame default font")
2569 (error "No matching fonts are the same height as face `%s'" face))
2570 (if (null (face-font face))
2571 (error "Height of font `%s' doesn't match the frame default font"
2572 pattern)
2573 (error "Height of font `%s' doesn't match face `%s'"
2574 pattern face)))
7cf6fac1 2575 (error "No fonts match `%s'" pattern)))
10d89673
JB
2576 (car fonts))
2577 (cdr (assq 'font (frame-parameters (selected-frame))))))
281dc1c2 2578
f0138172
JB
2579(provide 'faces)
2580
70d0c3b0 2581;;; faces.el ends here