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