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