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