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