1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 ;; 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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/>.
31 (declare-function xw-defined-colors "term/x-win" (&optional frame))
33 (defvar help-xref-stack-item)
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 (defgroup font-selection nil
40 "Influencing face font selection."
44 (defcustom face-font-selection-order
45 '(:width :height :weight :slant)
46 "*A list specifying how face font selection chooses fonts.
47 Each of the four symbols `:width', `:height', `:weight', and `:slant'
48 must appear once in the list, and the list must not contain any other
49 elements. Font selection first tries to find a best matching font
50 for those face attributes that appear before in the list. For
51 example, if `:slant' appears before `:height', font selection first
52 tries to find a font with a suitable slant, even if this results in
53 a font height that isn't optimal."
54 :tag "Font selection order"
55 :type '(list symbol symbol symbol symbol)
56 :group 'font-selection
57 :set #'(lambda (symbol value)
58 (set-default symbol value)
59 (internal-set-font-selection-order value)))
62 ;; This is defined originally in xfaces.c.
63 (defcustom face-font-family-alternatives
65 ("helv" "helvetica" "arial" "fixed"))
66 "*Alist of alternative font family names.
67 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
68 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
70 :tag "Alternative font families to try"
71 :type '(repeat (repeat string))
72 :group 'font-selection
73 :set #'(lambda (symbol value)
74 (set-default symbol value)
75 (internal-set-alternative-font-family-alist value)))
78 ;; This is defined originally in xfaces.c.
79 (defcustom face-font-registry-alternatives
80 (if (eq system-type 'windows-nt)
81 '(("iso8859-1" "ms-oemlatin")
82 ("gb2312.1980" "gb2312" "gbk" "gb18030")
83 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
84 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
85 ("muletibetan-2" "muletibetan-0"))
86 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
87 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
88 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
89 ("muletibetan-2" "muletibetan-0")))
90 "*Alist of alternative font registry names.
91 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
92 If fonts of registry REGISTRY can be loaded, font selection
93 tries to find a best matching font among all fonts of registry
94 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
95 :tag "Alternative font registries to try"
96 :type '(repeat (repeat string))
98 :group 'font-selection
99 :set #'(lambda (symbol value)
100 (set-default symbol value)
101 (internal-set-alternative-font-registry-alist value)))
104 (defconst font-weight-table
106 (ultra-light 20 ultralight)
107 (extra-light 40 extralight)
109 (semi-light 75 semilight demilight book)
110 (normal 100 medium regular)
111 (semi-bold 180 semibold demibold demi)
113 (extra-bold 205 extrabold)
114 (ultra-bold 210 ultrabold black))
115 "Alist of font weight symbols vs the corresponding numeric values.
116 Each element has the form:
117 \(SYMBOLIC-VALUE NUMERIC-VALUE ALISE-SYMBOL ...)
120 (defconst font-slant-table
121 '((reverse-oblique 0 ro)
122 (reverse-italic 10 ri)
126 "Alist of font slant symbols vs the corresponding numeric values.
127 See `font-weight-table' for the detailed format.")
129 (defconst font-width-table
130 '((ultra-condensed 50 ultracondensed)
131 (extra-condensed 63 extracondensed)
132 (condensed 75 compressed narrow)
133 (semi-condensed 87 semicondensed semicondensed)
134 (normal 100 medium regular)
135 (semi-expanded 113 semiexpanded demiexpanded)
137 (extra-expanded 150 extraexpanded)
138 (ultra-expanded 200 ultraexpanded wide))
139 "Alist of font width symbols vs the corresponding numeric values.
140 See `font-weight-table' for the detailed format.")
142 (internal-set-font-style-table
143 font-weight-table font-slant-table font-width-table)
145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
146 ;;; Creation, copying.
147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
151 "Return a list of all defined face names."
152 (mapcar #'car face-new-frame-defaults))
155 ;;; ### If not frame-local initialize by what X resources?
157 (defun make-face (face &optional no-init-from-resources)
158 "Define a new face with name FACE, a symbol.
159 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
160 variants of FACE from X resources. (X resources recognized are found
161 in the global variable `face-x-resources'.) If FACE is already known
162 as a face, leave it unmodified. Value is FACE."
163 (interactive "SMake face: ")
165 ;; Make frame-local faces (this also makes the global one).
166 (dolist (frame (frame-list))
167 (internal-make-lisp-face face frame))
168 ;; Add the face to the face menu.
169 (when (fboundp 'facemenu-add-new-face)
170 (facemenu-add-new-face face))
171 ;; Define frame-local faces for all frames from X resources.
172 (unless no-init-from-resources
173 (make-face-x-resource-internal face)))
177 (defun make-empty-face (face)
178 "Define a new, empty face with name FACE.
179 If the face already exists, it is left unmodified. Value is FACE."
180 (interactive "SMake empty face: ")
181 (make-face face 'no-init-from-resources))
184 (defun copy-face (old-face new-face &optional frame new-frame)
185 "Define a face just like OLD-FACE, with name NEW-FACE.
187 If NEW-FACE already exists as a face, it is modified to be like
188 OLD-FACE. If it doesn't already exist, it is created.
190 If the optional argument FRAME is given as a frame, NEW-FACE is
191 changed on FRAME only.
192 If FRAME is t, the frame-independent default specification for OLD-FACE
193 is copied to NEW-FACE.
194 If FRAME is nil, copying is done for the frame-independent defaults
195 and for each existing frame.
197 If the optional fourth argument NEW-FRAME is given,
198 copy the information from face OLD-FACE on frame FRAME
199 to NEW-FACE on frame NEW-FRAME. In this case, FRAME may not be nil."
200 (let ((inhibit-quit t))
204 (error "Copying face %s from all frames to one frame"
206 (make-empty-face new-face)
207 (dolist (frame (frame-list))
208 (copy-face old-face new-face frame))
209 (copy-face old-face new-face t))
210 (make-empty-face new-face)
211 (internal-copy-lisp-face old-face new-face frame new-frame))
216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
217 ;;; Obsolete functions
218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220 ;; The functions in this section are defined because Lisp packages use
221 ;; them, despite the prefix `internal-' suggesting that they are
222 ;; private to the face implementation.
224 (defun internal-find-face (name &optional frame)
225 "Retrieve the face named NAME.
226 Return nil if there is no such face.
227 If NAME is already a face, it is simply returned.
228 The optional argument FRAME is ignored."
230 (make-obsolete 'internal-find-face 'facep "21.1")
233 (defun internal-get-face (name &optional frame)
234 "Retrieve the face named NAME; error if there is none.
235 If NAME is already a face, it is simply returned.
236 The optional argument FRAME is ignored."
239 (make-obsolete 'internal-get-face "see `facep' and `check-face'." "21.1")
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243 ;;; Predicates, type checks.
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
247 "Return non-nil if FACE is a face name; nil otherwise.
248 A face name can be a string or a symbol."
249 (internal-lisp-face-p face))
252 (defun check-face (face)
253 "Signal an error if FACE doesn't name a face.
256 (error "Not a face: %s" face))
260 ;; The ID returned is not to be confused with the internally used IDs
261 ;; of realized faces. The ID assigned to Lisp faces is used to
262 ;; support faces in display table entries.
264 (defun face-id (face &optional frame)
265 "Return the internal ID of face with name FACE.
266 If FACE is a face-alias, return the ID of the target face.
267 The optional argument FRAME is ignored, since the internal face ID
268 of a face name is the same for all frames."
271 (face-id (get face 'face-alias))))
273 (defun face-equal (face1 face2 &optional frame)
274 "Non-nil if faces FACE1 and FACE2 are equal.
275 Faces are considered equal if all their attributes are equal.
276 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
277 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
278 If FRAME is omitted or nil, use the selected frame."
279 (internal-lisp-face-equal-p face1 face2 frame))
282 (defun face-differs-from-default-p (face &optional frame)
283 "Return non-nil if FACE displays differently from the default face.
284 If the optional argument FRAME is given, report on face FACE in that frame.
285 If FRAME is t, report on the defaults for face FACE (for new frames).
286 If FRAME is omitted or nil, use the selected frame."
288 (delq :inherit (mapcar 'car face-attribute-name-alist)))
290 (while (and attrs (not differs))
291 (let* ((attr (pop attrs))
292 (attr-val (face-attribute face attr frame t)))
294 (not (eq attr-val 'unspecified))
295 (display-supports-face-attributes-p (list attr attr-val)
297 (setq differs attr))))
301 (defun face-nontrivial-p (face &optional frame)
302 "True if face FACE has some non-nil attribute.
303 If the optional argument FRAME is given, report on face FACE in that frame.
304 If FRAME is t, report on the defaults for face FACE (for new frames).
305 If FRAME is omitted or nil, use the selected frame."
306 (not (internal-lisp-face-empty-p face frame)))
310 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
311 ;;; Setting face attributes from X resources.
312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
314 (defcustom face-x-resources
315 '((:family (".attributeFamily" . "Face.AttributeFamily"))
316 (:width (".attributeWidth" . "Face.AttributeWidth"))
317 (:height (".attributeHeight" . "Face.AttributeHeight"))
318 (:weight (".attributeWeight" . "Face.AttributeWeight"))
319 (:slant (".attributeSlant" . "Face.AttributeSlant"))
320 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
321 (:background (".attributeBackground" . "Face.AttributeBackground"))
322 (:overline (".attributeOverline" . "Face.AttributeOverline"))
323 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
324 (:box (".attributeBox" . "Face.AttributeBox"))
325 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
326 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
328 (".attributeStipple" . "Face.AttributeStipple")
329 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
330 (:bold (".attributeBold" . "Face.AttributeBold"))
331 (:italic (".attributeItalic" . "Face.AttributeItalic"))
332 (:font (".attributeFont" . "Face.AttributeFont"))
333 (:inherit (".attributeInherit" . "Face.AttributeInherit")))
334 "*List of X resources and classes for face attributes.
335 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
336 the name of a face attribute, and each ENTRY is a cons of the form
337 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
338 X resource class for the attribute."
339 :type '(repeat (cons symbol (repeat (cons string string))))
343 (defun set-face-attribute-from-resource (face attribute resource class frame)
344 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
345 Value is the attribute value specified by the resource, or nil
346 if not present. This function displays a message if the resource
347 specifies an invalid attribute."
348 (let* ((face-name (face-name face))
349 (value (internal-face-x-get-resource (concat face-name resource)
353 (internal-set-lisp-face-attribute-from-resource
354 face attribute (downcase value) frame)
356 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
357 face-name frame attribute value))))
361 (defun set-face-attributes-from-resources (face frame)
362 "Set attributes of FACE from X resources for FRAME."
363 (when (memq (framep frame) '(x w32 mac))
364 (dolist (definition face-x-resources)
365 (let ((attribute (car definition)))
366 (dolist (entry (cdr definition))
367 (set-face-attribute-from-resource face attribute (car entry)
368 (cdr entry) frame))))))
371 (defun make-face-x-resource-internal (face &optional frame)
372 "Fill frame-local FACE on FRAME from X resources.
373 FRAME nil or not specified means do it for all frames."
375 (dolist (frame (frame-list))
376 (set-face-attributes-from-resources face frame))
377 (set-face-attributes-from-resources face frame)))
381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
382 ;;; Retrieving face attributes.
383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
385 (defun face-name (face)
386 "Return the name of face FACE."
387 (symbol-name (check-face face)))
390 (defun face-all-attributes (face &optional frame)
391 "Return an alist stating the attributes of FACE.
392 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
393 Normally the value describes the default attributes,
394 but if you specify FRAME, the value describes the attributes
396 (mapcar (lambda (pair)
397 (let ((attr (car pair)))
398 (cons attr (face-attribute face attr (or frame t)))))
399 face-attribute-name-alist))
401 (defun face-attribute (face attribute &optional frame inherit)
402 "Return the value of FACE's ATTRIBUTE on FRAME.
403 If the optional argument FRAME is given, report on face FACE in that frame.
404 If FRAME is t, report on the defaults for face FACE (for new frames).
405 If FRAME is omitted or nil, use the selected frame.
407 If INHERIT is nil, only attributes directly defined by FACE are considered,
408 so the return value may be `unspecified', or a relative value.
409 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
410 faces specified by its `:inherit' attribute; however the return value
411 may still be `unspecified' or relative.
412 If INHERIT is a face or a list of faces, then the result is further merged
413 with that face (or faces), until it becomes specified and absolute.
415 To ensure that the return value is always specified and absolute, use a
416 value of `default' for INHERIT; this will resolve any unspecified or
417 relative values by merging with the `default' face (which is always
418 completely specified)."
419 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
420 (when (and inherit (face-attribute-relative-p attribute value))
421 ;; VALUE is relative, so merge with inherited faces
422 (let ((inh-from (face-attribute face :inherit frame)))
423 (unless (or (null inh-from) (eq inh-from 'unspecified))
426 (face-attribute-merged-with attribute value inh-from frame))
427 ;; The `inherit' attribute may point to non existent faces.
431 (face-attribute-relative-p attribute value))
432 ;; We should merge with INHERIT as well
433 (setq value (face-attribute-merged-with attribute value inherit frame)))
436 (defun face-attribute-merged-with (attribute value faces &optional frame)
437 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
438 FACES may be either a single face or a list of faces.
439 \[This is an internal function.]"
440 (cond ((not (face-attribute-relative-p attribute value))
445 (face-attribute-merged-with
447 (face-attribute-merged-with attribute value (car faces) frame)
451 (merge-face-attribute attribute
453 (face-attribute faces attribute frame t)))))
456 (defmacro face-attribute-specified-or (value &rest body)
457 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
458 (let ((temp (make-symbol "value")))
459 `(let ((,temp ,value))
460 (if (not (eq ,temp 'unspecified))
464 (defun face-foreground (face &optional frame inherit)
465 "Return the foreground color name of FACE, or nil if unspecified.
466 If the optional argument FRAME is given, report on face FACE in that frame.
467 If FRAME is t, report on the defaults for face FACE (for new frames).
468 If FRAME is omitted or nil, use the selected frame.
470 If INHERIT is nil, only a foreground color directly defined by FACE is
471 considered, so the return value may be nil.
472 If INHERIT is t, and FACE doesn't define a foreground color, then any
473 foreground color that FACE inherits through its `:inherit' attribute
474 is considered as well; however the return value may still be nil.
475 If INHERIT is a face or a list of faces, then it is used to try to
476 resolve an unspecified foreground color.
478 To ensure that a valid color is always returned, use a value of
479 `default' for INHERIT; this will resolve any unspecified values by
480 merging with the `default' face (which is always completely specified)."
481 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
484 (defun face-background (face &optional frame inherit)
485 "Return the background color name of FACE, or nil if unspecified.
486 If the optional argument FRAME is given, report on face FACE in that frame.
487 If FRAME is t, report on the defaults for face FACE (for new frames).
488 If FRAME is omitted or nil, use the selected frame.
490 If INHERIT is nil, only a background color directly defined by FACE is
491 considered, so the return value may be nil.
492 If INHERIT is t, and FACE doesn't define a background color, then any
493 background color that FACE inherits through its `:inherit' attribute
494 is considered as well; however the return value may still be nil.
495 If INHERIT is a face or a list of faces, then it is used to try to
496 resolve an unspecified background color.
498 To ensure that a valid color is always returned, use a value of
499 `default' for INHERIT; this will resolve any unspecified values by
500 merging with the `default' face (which is always completely specified)."
501 (face-attribute-specified-or (face-attribute face :background frame inherit)
504 (defun face-stipple (face &optional frame inherit)
505 "Return the stipple pixmap name of FACE, or nil if unspecified.
506 If the optional argument FRAME is given, report on face FACE in that frame.
507 If FRAME is t, report on the defaults for face FACE (for new frames).
508 If FRAME is omitted or nil, use the selected frame.
510 If INHERIT is nil, only a stipple directly defined by FACE is
511 considered, so the return value may be nil.
512 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
513 that FACE inherits through its `:inherit' attribute is considered as
514 well; however the return value may still be nil.
515 If INHERIT is a face or a list of faces, then it is used to try to
516 resolve an unspecified stipple.
518 To ensure that a valid stipple or nil is always returned, use a value of
519 `default' for INHERIT; this will resolve any unspecified values by merging
520 with the `default' face (which is always completely specified)."
521 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
525 (defalias 'face-background-pixmap 'face-stipple)
528 (defun face-underline-p (face &optional frame)
529 "Return non-nil if FACE is underlined.
530 If the optional argument FRAME is given, report on face FACE in that frame.
531 If FRAME is t, report on the defaults for face FACE (for new frames).
532 If FRAME is omitted or nil, use the selected frame."
533 (eq (face-attribute face :underline frame) t))
536 (defun face-inverse-video-p (face &optional frame)
537 "Return non-nil if FACE is in inverse video on FRAME.
538 If the optional argument FRAME is given, report on face FACE in that frame.
539 If FRAME is t, report on the defaults for face FACE (for new frames).
540 If FRAME is omitted or nil, use the selected frame."
541 (eq (face-attribute face :inverse-video frame) t))
544 (defun face-bold-p (face &optional frame)
545 "Return non-nil if the font of FACE is bold on FRAME.
546 If the optional argument FRAME is given, report on face FACE in that frame.
547 If FRAME is t, report on the defaults for face FACE (for new frames).
548 If FRAME is omitted or nil, use the selected frame.
549 Use `face-attribute' for finer control."
550 (let ((bold (face-attribute face :weight frame)))
551 (memq bold '(semi-bold bold extra-bold ultra-bold))))
554 (defun face-italic-p (face &optional frame)
555 "Return non-nil if the font of FACE is italic on FRAME.
556 If the optional argument FRAME is given, report on face FACE in that frame.
557 If FRAME is t, report on the defaults for face FACE (for new frames).
558 If FRAME is omitted or nil, use the selected frame.
559 Use `face-attribute' for finer control."
560 (let ((italic (face-attribute face :slant frame)))
561 (memq italic '(italic oblique))))
565 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
566 ;;; Face documentation.
567 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
569 (defun face-documentation (face)
570 "Get the documentation string for FACE.
571 If FACE is a face-alias, get the documentation for the target face."
572 (let ((alias (get face 'face-alias))
576 (setq doc (get alias 'face-documentation))
577 (format "%s is an alias for the face `%s'.%s" face alias
578 (if doc (format "\n%s" doc)
580 (get face 'face-documentation))))
583 (defun set-face-documentation (face string)
584 "Set the documentation string for FACE to STRING."
585 ;; Perhaps the text should go in DOC.
586 (put face 'face-documentation (purecopy string)))
589 (defalias 'face-doc-string 'face-documentation)
590 (defalias 'set-face-doc-string 'set-face-documentation)
594 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
595 ;; Setting face attributes.
596 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
599 (defvar inhibit-face-set-after-frame-default nil
600 "If non-nil, that tells `face-set-after-frame-default' to do nothing.")
602 (defun set-face-attribute (face frame &rest args)
603 "Set attributes of FACE on FRAME from ARGS.
605 FRAME nil means change attributes on all frames. FRAME t means change
606 the default for new frames (this is done automatically each time an
607 attribute is changed on all frames).
609 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
610 face attribute name. All attributes can be set to `unspecified';
611 this fact is not further mentioned below.
613 The following attributes are recognized:
617 VALUE must be a string specifying the font family, e.g. ``courier'',
618 or a fontset alias name. If a font family is specified, wild-cards `*'
623 VALUE specifies the relative proportionate width of the font to use.
624 It must be one of the symbols `ultra-condensed', `extra-condensed',
625 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
626 `extra-expanded', or `ultra-expanded'.
630 VALUE must be either an integer specifying the height of the font to use
631 in 1/10 pt, a floating point number specifying the amount by which to
632 scale any underlying face, or a function, which is called with the old
633 height (from the underlying face), and should return the new height.
637 VALUE specifies the weight of the font to use. It must be one of the
638 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
639 `semi-light', `light', `extra-light', `ultra-light'.
643 VALUE specifies the slant of the font to use. It must be one of the
644 symbols `italic', `oblique', `normal', `reverse-italic', or
647 `:foreground', `:background'
649 VALUE must be a color name, a string.
653 VALUE specifies whether characters in FACE should be underlined. If
654 VALUE is t, underline with foreground color of the face. If VALUE is
655 a string, underline with that color. If VALUE is nil, explicitly
660 VALUE specifies whether characters in FACE should be overlined. If
661 VALUE is t, overline with foreground color of the face. If VALUE is a
662 string, overline with that color. If VALUE is nil, explicitly don't
667 VALUE specifies whether characters in FACE should be drawn with a line
668 striking through them. If VALUE is t, use the foreground color of the
669 face. If VALUE is a string, strike-through with that color. If VALUE
670 is nil, explicitly don't strike through.
674 VALUE specifies whether characters in FACE should have a box drawn
675 around them. If VALUE is nil, explicitly don't draw boxes. If
676 VALUE is t, draw a box with lines of width 1 in the foreground color
677 of the face. If VALUE is a string, the string must be a color name,
678 and the box is drawn in that color with a line width of 1. Otherwise,
679 VALUE must be a property list of the form `(:line-width WIDTH
680 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
681 the property list, a default value will be used for the value, as
682 specified below. WIDTH specifies the width of the lines to draw; it
683 defaults to 1. If WIDTH is negative, the absolute value is the width
684 of the lines, and draw top/bottom lines inside the characters area,
685 not around it. COLOR is the name of the color to draw in, default is
686 the foreground color of the face for simple boxes, and the background
687 color of the face for 3D boxes. STYLE specifies whether a 3D box
688 should be draw. If STYLE is `released-button', draw a box looking
689 like a released 3D button. If STYLE is `pressed-button' draw a box
690 that appears like a pressed button. If STYLE is nil, the default if
691 the property list doesn't contain a style specification, draw a 2D
696 VALUE specifies whether characters in FACE should be displayed in
697 inverse video. VALUE must be one of t or nil.
701 If VALUE is a string, it must be the name of a file of pixmap data.
702 The directories listed in the `x-bitmap-file-path' variable are
703 searched. Alternatively, VALUE may be a list of the form (WIDTH
704 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
705 is a string containing the raw bits of the bitmap. VALUE nil means
706 explicitly don't use a stipple pattern.
708 For convenience, attributes `:family', `:width', `:height', `:weight',
709 and `:slant' may also be set in one step from an X font name:
713 Set font-related face attributes from VALUE. VALUE must be a valid
714 XLFD font name. If it is a font name pattern, the first matching font
717 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
718 be used to specify that a bold or italic font should be used. VALUE
719 must be t or nil in that case. A value of `unspecified' is not allowed.
723 VALUE is the name of a face from which to inherit attributes, or a list
724 of face names. Attributes from inherited faces are merged into the face
725 like an underlying face would be, with higher priority than underlying faces."
726 (let ((where (if (null frame) 0 frame)))
727 (setq args (purecopy args))
728 ;; If we set the new-frame defaults, this face is modified outside Custom.
729 (if (memq where '(0 t))
730 (put (or (get face 'face-alias) face) 'face-modified t))
732 ;; Don't recursively set the attributes from the frame's font param
733 ;; when we update the frame's font param fro the attributes.
734 (let ((inhibit-face-set-after-frame-default t))
735 (internal-set-lisp-face-attribute face (car args)
736 (purecopy (cadr args))
738 (setq args (cdr (cdr args))))))
741 (defun make-face-bold (face &optional frame noerror)
742 "Make the font of FACE be bold, if possible.
743 FRAME nil or not specified means change face on all frames.
744 Argument NOERROR is ignored and retained for compatibility.
745 Use `set-face-attribute' for finer control of the font weight."
746 (interactive (list (read-face-name "Make which face bold")))
747 (set-face-attribute face frame :weight 'bold))
750 (defun make-face-unbold (face &optional frame noerror)
751 "Make the font of FACE be non-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 (interactive (list (read-face-name "Make which face non-bold")))
755 (set-face-attribute face frame :weight 'normal))
758 (defun make-face-italic (face &optional frame noerror)
759 "Make the font of FACE be italic, if possible.
760 FRAME nil or not specified means change face on all frames.
761 Argument NOERROR is ignored and retained for compatibility.
762 Use `set-face-attribute' for finer control of the font slant."
763 (interactive (list (read-face-name "Make which face italic")))
764 (set-face-attribute face frame :slant 'italic))
767 (defun make-face-unitalic (face &optional frame noerror)
768 "Make the font of FACE be non-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 (interactive (list (read-face-name "Make which face non-italic")))
772 (set-face-attribute face frame :slant 'normal))
775 (defun make-face-bold-italic (face &optional frame noerror)
776 "Make the font of FACE be bold and italic, if possible.
777 FRAME nil or not specified means change face on all frames.
778 Argument NOERROR is ignored and retained for compatibility.
779 Use `set-face-attribute' for finer control of font weight and slant."
780 (interactive (list (read-face-name "Make which face bold-italic")))
781 (set-face-attribute face frame :weight 'bold :slant 'italic))
784 (defun set-face-font (face font &optional frame)
785 "Change font-related attributes of FACE to those of FONT (a string).
786 FRAME nil or not specified means change face on all frames.
787 This sets the attributes `:family', `:width', `:height', `:weight',
788 and `:slant'. When called interactively, prompt for the face and font."
789 (interactive (read-face-and-attribute :font))
790 (set-face-attribute face frame :font font))
793 ;; Implementation note: Emulating gray background colors with a
794 ;; stipple pattern is now part of the face realization process, and is
795 ;; done in C depending on the frame on which the face is realized.
797 (defun set-face-background (face color &optional frame)
798 "Change the background color of face FACE to COLOR (a string).
799 FRAME nil or not specified means change face on all frames.
800 COLOR can be a system-defined color name (see `list-colors-display')
801 or a hex spec of the form #RRGGBB.
802 When called interactively, prompts for the face and color."
803 (interactive (read-face-and-attribute :background))
804 (set-face-attribute face frame :background (or color 'unspecified)))
807 (defun set-face-foreground (face color &optional frame)
808 "Change the foreground 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 :foreground))
814 (set-face-attribute face frame :foreground (or color 'unspecified)))
817 (defun set-face-stipple (face stipple &optional frame)
818 "Change the stipple pixmap of face FACE to STIPPLE.
819 FRAME nil or not specified means change face on all frames.
820 STIPPLE should be a string, the name of a file of pixmap data.
821 The directories listed in the `x-bitmap-file-path' variable are searched.
823 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
824 where WIDTH and HEIGHT are the size in pixels,
825 and DATA is a string, containing the raw bits of the bitmap."
826 (interactive (read-face-and-attribute :stipple))
827 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
830 (defun set-face-underline-p (face underline &optional frame)
831 "Specify whether face FACE is underlined.
832 UNDERLINE nil means FACE explicitly doesn't underline.
833 UNDERLINE non-nil means FACE explicitly does underlining
834 with the same of the foreground color.
835 If UNDERLINE is a string, underline with the color named UNDERLINE.
836 FRAME nil or not specified means change face on all frames.
837 Use `set-face-attribute' to ``unspecify'' underlining."
839 (let ((list (read-face-and-attribute :underline)))
840 (list (car list) (eq (car (cdr list)) t))))
841 (set-face-attribute face frame :underline underline))
843 (define-obsolete-function-alias 'set-face-underline
844 'set-face-underline-p "22.1")
847 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
848 "Specify whether face FACE is in inverse video.
849 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
850 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
851 FRAME nil or not specified means change face on all frames.
852 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
854 (let ((list (read-face-and-attribute :inverse-video)))
855 (list (car list) (eq (car (cdr list)) t))))
856 (set-face-attribute face frame :inverse-video inverse-video-p))
859 (defun set-face-bold-p (face bold-p &optional frame)
860 "Specify whether face FACE is bold.
861 BOLD-P non-nil means FACE should explicitly display bold.
862 BOLD-P nil means FACE should explicitly display non-bold.
863 FRAME nil or not specified means change face on all frames.
864 Use `set-face-attribute' or `modify-face' for finer control."
866 (make-face-unbold face frame)
867 (make-face-bold face frame)))
870 (defun set-face-italic-p (face italic-p &optional frame)
871 "Specify whether face FACE is italic.
872 ITALIC-P non-nil means FACE should explicitly display italic.
873 ITALIC-P nil means FACE should explicitly display non-italic.
874 FRAME nil or not specified means change face on all frames.
875 Use `set-face-attribute' or `modify-face' for finer control."
877 (make-face-unitalic face frame)
878 (make-face-italic face frame)))
881 (defalias 'set-face-background-pixmap 'set-face-stipple)
884 (defun invert-face (face &optional frame)
885 "Swap the foreground and background colors of FACE.
886 If FRAME is omitted or nil, it means change face on all frames.
887 If FACE specifies neither foreground nor background color,
888 set its foreground and background to the background and foreground
889 of the default face. Value is FACE."
890 (interactive (list (read-face-name "Invert face")))
891 (let ((fg (face-attribute face :foreground frame))
892 (bg (face-attribute face :background frame)))
893 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
894 (set-face-attribute face frame :foreground bg :background fg)
895 (set-face-attribute face frame
897 (face-attribute 'default :background frame)
899 (face-attribute 'default :foreground frame))))
903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
904 ;;; Interactively modifying faces.
905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
907 (defun read-face-name (prompt &optional string-describing-default multiple)
908 "Read a face, defaulting to the face or faces on the char after point.
909 If it has the property `read-face-name', that overrides the `face' property.
910 PROMPT should be a string that describes what the caller will do with the face;
911 it should not end in a space.
912 STRING-DESCRIBING-DEFAULT should describe what default the caller will use if
913 the user just types RET; you can omit it.
914 If MULTIPLE is non-nil, return a list of faces (possibly only one).
915 Otherwise, return a single face."
916 (let ((faceprop (or (get-char-property (point) 'read-face-name)
917 (get-char-property (point) 'face)))
921 ;; Try to get a face name from the buffer.
922 (if (memq (intern-soft (thing-at-point 'symbol)) (face-list))
923 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
924 ;; Add the named faces that the `face' property uses.
925 (if (and (listp faceprop)
926 ;; Don't treat an attribute spec as a list of faces.
927 (not (keywordp (car faceprop)))
928 (not (memq (car faceprop) '(foreground-color background-color))))
932 (if (symbolp faceprop)
933 (push faceprop faces)))
936 ;; Build up the completion tables.
937 (mapatoms (lambda (s)
939 (if (get s 'face-alias)
940 (push (symbol-name s) aliasfaces)
941 (push (symbol-name s) nonaliasfaces)))))
943 ;; If we only want one, and the default is more than one,
944 ;; discard the unwanted ones now.
947 (setq faces (list (car faces)))))
951 (completing-read-multiple
952 (if (or faces string-describing-default)
953 (format "%s (default %s): " prompt
954 (if faces (mapconcat 'symbol-name faces ",")
955 string-describing-default))
956 (format "%s: " prompt))
957 (completion-table-in-turn nonaliasfaces aliasfaces)
959 (if faces (mapconcat 'symbol-name faces ","))))
960 ;; Canonicalize the output.
962 (cond ((or (equal input "") (equal input '("")))
965 (mapcar 'intern (split-string input ", *" t)))
967 (mapcar 'intern input))
969 ;; Return either a list of faces or just one face.
975 (defun face-valid-attribute-values (attribute &optional frame)
976 "Return valid values for face attribute ATTRIBUTE.
977 The optional argument FRAME is used to determine available fonts
978 and colors. If it is nil or not specified, the selected frame is
979 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
980 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
985 (if (window-system frame)
986 (mapcar #'(lambda (x) (cons (car x) (car x)))
988 ;; Only one font on TTYs.
989 (list (cons "default" "default"))))
991 (mapcar #'(lambda (x) (cons (symbol-name (car x)) (car x)))
994 (mapcar #'(lambda (x) (cons (symbol-name (car x)) (car x)))
997 (mapcar #'(lambda (x) (cons (symbol-name (car x)) (car x)))
1000 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1001 (internal-lisp-face-attribute-values attribute)))
1002 ((:underline :overline :strike-through :box)
1003 (if (window-system frame)
1004 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
1005 (internal-lisp-face-attribute-values attribute))
1006 (mapcar #'(lambda (c) (cons c c))
1007 (defined-colors frame)))
1008 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1009 (internal-lisp-face-attribute-values attribute))))
1010 ((:foreground :background)
1011 (mapcar #'(lambda (c) (cons c c))
1012 (defined-colors frame)))
1016 (and (memq (window-system frame) '(x w32 mac))
1019 (mapcar (lambda (dir)
1020 (and (file-readable-p dir)
1021 (file-directory-p dir)
1022 (directory-files dir)))
1023 x-bitmap-file-path)))))
1025 (cons '("none" . nil)
1026 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1029 (error "Internal error")))))
1030 (if (and (listp valid) (not (memq attribute '(:inherit))))
1031 (nconc (list (cons "unspecified" 'unspecified)) valid)
1035 (defvar face-attribute-name-alist
1036 '((:family . "font family")
1037 (:width . "character set width")
1038 (:height . "height in 1/10 pt")
1039 (:weight . "weight")
1041 (:underline . "underline")
1042 (:overline . "overline")
1043 (:strike-through . "strike-through")
1045 (:inverse-video . "inverse-video display")
1046 (:foreground . "foreground color")
1047 (:background . "background color")
1048 (:stipple . "background stipple")
1049 (:inherit . "inheritance"))
1050 "An alist of descriptive names for face attributes.
1051 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1052 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1053 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1056 (defun face-descriptive-attribute-name (attribute)
1057 "Return a descriptive name for ATTRIBUTE."
1058 (cdr (assq attribute face-attribute-name-alist)))
1061 (defun face-read-string (face default name &optional completion-alist)
1062 "Interactively read a face attribute string value.
1063 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1064 default string to return if no new value is entered. NAME is a
1065 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1066 alist of valid values, if non-nil.
1068 Entering nothing accepts the default string DEFAULT.
1069 Value is the new attribute value."
1070 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1071 ;; each word in a string separately).
1072 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1073 (let* ((completion-ignore-case t)
1074 (value (completing-read
1076 (format "%s for face `%s' (default %s): "
1078 (format "%s for face `%s': " name face))
1079 completion-alist nil nil nil nil default)))
1080 (if (equal value "") default value)))
1083 (defun face-read-integer (face default name)
1084 "Interactively read an integer face attribute value.
1085 FACE is the face whose attribute is read. DEFAULT is the default
1086 value to return if no new value is entered. NAME is a descriptive
1087 name of the attribute for prompting. Value is the new attribute value."
1089 (face-read-string face
1090 (format "%s" default)
1092 (list (cons "unspecified" 'unspecified)))))
1093 (cond ((equal new-value "unspecified")
1095 ((member new-value '("unspecified-fg" "unspecified-bg"))
1098 (string-to-number new-value)))))
1101 (defun read-face-attribute (face attribute &optional frame)
1102 "Interactively read a new value for FACE's ATTRIBUTE.
1103 Optional argument FRAME nil or unspecified means read an attribute value
1104 of a global face. Value is the new attribute value."
1105 (let* ((old-value (face-attribute face attribute frame))
1106 (attribute-name (face-descriptive-attribute-name attribute))
1107 (valid (face-valid-attribute-values attribute frame))
1109 ;; Represent complex attribute values as strings by printing them
1110 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1111 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1113 (when (and (or (eq attribute :stipple)
1114 (eq attribute :box))
1115 (or (consp old-value)
1116 (vectorp old-value)))
1117 (setq old-value (prin1-to-string old-value)))
1118 (cond ((listp valid)
1120 (or (car (rassoc old-value valid))
1121 (format "%s" old-value))))
1123 (face-read-string face default attribute-name valid))
1124 (if (equal new-value default)
1125 ;; Nothing changed, so don't bother with all the stuff
1126 ;; below. In particular, this avoids a non-tty color
1127 ;; from being canonicalized for a tty when the user
1128 ;; just uses the default.
1129 (setq new-value old-value)
1130 ;; Terminal frames can support colors that don't appear
1131 ;; explicitly in VALID, using color approximation code
1132 ;; in tty-colors.el.
1133 (when (and (memq attribute '(:foreground :background))
1134 (not (memq (window-system frame) '(x w32 mac)))
1135 (not (member new-value
1137 "unspecified-fg" "unspecified-bg"))))
1138 (setq new-value (car (tty-color-desc new-value frame))))
1139 (when (assoc new-value valid)
1140 (setq new-value (cdr (assoc new-value valid)))))))
1141 ((eq valid 'integerp)
1142 (setq new-value (face-read-integer face old-value attribute-name)))
1143 (t (error "Internal error")))
1144 ;; Convert stipple and box value text we read back to a list or
1145 ;; vector if it looks like one. This makes the assumption that a
1146 ;; pixmap file name won't start with an open-paren.
1147 (when (and (or (eq attribute :stipple)
1148 (eq attribute :box))
1150 (string-match "^[[(]" new-value))
1151 (setq new-value (read new-value)))
1155 (defun read-face-font (face &optional frame)
1156 "Read the name of a font for FACE on FRAME.
1157 If optional argument FRAME is nil or omitted, use the selected frame."
1158 (let ((completion-ignore-case t))
1159 (completing-read (format "Set font attributes of face `%s' from font: " face)
1160 (append (fontset-list) (x-list-fonts "*" nil frame)))))
1163 (defun read-all-face-attributes (face &optional frame)
1164 "Interactively read all attributes for FACE.
1165 If optional argument FRAME is nil or omitted, use the selected frame.
1166 Value is a property list of attribute names and new values."
1168 (dolist (attribute face-attribute-name-alist result)
1169 (setq result (cons (car attribute)
1170 (cons (read-face-attribute face (car attribute) frame)
1173 (defun modify-face (&optional face foreground background stipple
1174 bold-p italic-p underline inverse-p frame)
1175 "Modify attributes of faces interactively.
1176 If optional argument FRAME is nil or omitted, modify the face used
1177 for newly created frame, i.e. the global face.
1178 For non-interactive use, `set-face-attribute' is preferred.
1179 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1180 and the face and its settings are obtained by querying the user."
1183 (set-face-attribute face frame
1184 :foreground (or foreground 'unspecified)
1185 :background (or background 'unspecified)
1189 :underline underline
1190 :inverse-video inverse-p)
1191 (setq face (read-face-name "Modify face"))
1192 (apply #'set-face-attribute face frame
1193 (read-all-face-attributes face frame))))
1195 (defun read-face-and-attribute (attribute &optional frame)
1196 "Read face name and face attribute value.
1197 ATTRIBUTE is the attribute whose new value is read.
1198 FRAME nil or unspecified means read attribute value of global face.
1199 Value is a list (FACE NEW-VALUE) where FACE is the face read
1200 \(a symbol), and NEW-VALUE is value read."
1201 (cond ((eq attribute :font)
1202 (let* ((prompt "Set font-related attributes of face")
1203 (face (read-face-name prompt))
1204 (font (read-face-font face frame)))
1207 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1208 (prompt (format "Set %s of face" attribute-name))
1209 (face (read-face-name prompt))
1210 (new-value (read-face-attribute face attribute frame)))
1211 (list face new-value)))))
1215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1219 (defvar list-faces-sample-text
1220 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1221 "*Text string to display as the sample text for `list-faces-display'.")
1224 ;; The name list-faces would be more consistent, but let's avoid a
1225 ;; conflict with Lucid, which uses that name differently.
1227 (defvar help-xref-stack)
1228 (defun list-faces-display (&optional regexp)
1229 "List all faces, using the same sample text in each.
1230 The sample text is a string that comes from the variable
1231 `list-faces-sample-text'.
1233 If REGEXP is non-nil, list only those faces with names matching
1234 this regular expression. When called interactively with a prefix
1235 arg, prompt for a regular expression."
1236 (interactive (list (and current-prefix-arg
1237 (read-string "List faces matching regexp: "))))
1238 (let ((all-faces (zerop (length regexp)))
1239 (frame (selected-frame))
1242 disp-frame window face-name)
1243 ;; We filter and take the max length in one pass
1247 (let ((s (symbol-name f)))
1248 (when (or all-faces (string-match regexp s))
1249 (setq max-length (max (length s) max-length))
1251 (sort (face-list) #'string-lessp))))
1253 (error "No faces matching \"%s\"" regexp))
1254 (setq max-length (1+ max-length)
1255 line-format (format "%%-%ds" max-length))
1256 (with-help-window "*Faces*"
1258 (set-buffer standard-output)
1259 (setq truncate-lines t)
1261 (substitute-command-keys
1264 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1265 "\\[help-follow] on a face name to customize it\n"
1266 "or on its sample text for a description of the face.\n\n")))
1267 (setq help-xref-stack nil)
1268 (dolist (face faces)
1269 (setq face-name (symbol-name face))
1270 (insert (format line-format face-name))
1271 ;; Hyperlink to a customization buffer for the face. Using
1272 ;; the help xref mechanism may not be the best way.
1275 (search-backward face-name)
1276 (setq help-xref-stack-item `(list-faces-display ,regexp))
1277 (help-xref-button 0 'help-customize-face face)))
1279 (line-beg (line-beginning-position)))
1280 (insert list-faces-sample-text)
1281 ;; Hyperlink to a help buffer for the face.
1284 (search-backward list-faces-sample-text)
1285 (help-xref-button 0 'help-face face)))
1287 (put-text-property beg (1- (point)) 'face face)
1288 ;; Make all face commands default to the proper face
1289 ;; anywhere in the line.
1290 (put-text-property line-beg (1- (point)) 'read-face-name face)
1291 ;; If the sample text has multiple lines, line up all of them.
1295 (insert-char ?\s max-length)
1297 (goto-char (point-min))))
1298 ;; If the *Faces* buffer appears in a different frame,
1299 ;; copy all the face definitions from FRAME,
1300 ;; so that the display will reflect the frame that was selected.
1301 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1302 (setq disp-frame (if window (window-frame window)
1303 (car (frame-list))))
1304 (or (eq frame disp-frame)
1305 (let ((faces (face-list)))
1307 (copy-face (car faces) (car faces) frame disp-frame)
1308 (setq faces (cdr faces)))))))
1311 (defun describe-face (face &optional frame)
1312 "Display the properties of face FACE on FRAME.
1313 Interactively, FACE defaults to the faces of the character after point
1314 and FRAME defaults to the selected frame.
1316 If the optional argument FRAME is given, report on face FACE in that frame.
1317 If FRAME is t, report on the defaults for face FACE (for new frames).
1318 If FRAME is omitted or nil, use the selected frame."
1319 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1320 (let* ((attrs '((:family . "Family")
1322 (:height . "Height")
1323 (:weight . "Weight")
1325 (:foreground . "Foreground")
1326 (:background . "Background")
1327 (:underline . "Underline")
1328 (:overline . "Overline")
1329 (:strike-through . "Strike-through")
1331 (:inverse-video . "Inverse")
1332 (:stipple . "Stipple")
1334 (:fontset . "Fontset")
1335 (:inherit . "Inherit")))
1336 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1338 (help-setup-xref (list #'describe-face face) (interactive-p))
1340 (setq face 'default))
1341 (if (not (listp face))
1342 (setq face (list face)))
1343 (with-help-window (help-buffer)
1345 (set-buffer standard-output)
1347 (if (stringp f) (setq f (intern f)))
1348 (insert "Face: " (symbol-name f))
1350 (insert " undefined face.\n")
1351 (let ((customize-label "customize this face")
1353 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1354 (princ (concat " (" customize-label ")\n"))
1355 (insert "Documentation: "
1356 (or (face-documentation f)
1357 "Not documented as a face.")
1359 (with-current-buffer standard-output
1362 (concat "\\(" customize-label "\\)") nil t)
1363 (help-xref-button 1 'help-customize-face f)))
1364 ;; The next 4 sexps are copied from describe-function-1
1366 (setq file-name (symbol-file f 'defface))
1367 (setq file-name (describe-simplify-lib-file-name file-name))
1369 (princ "Defined in `")
1372 ;; Make a hyperlink to the library.
1374 (re-search-backward "`\\([^`']+\\)'" nil t)
1375 (help-xref-button 1 'help-face-def f file-name))
1380 (let ((attr (face-attribute f (car a) frame)))
1381 (insert (make-string (- max-width (length (cdr a))) ?\s)
1382 (cdr a) ": " (format "%s" attr))
1383 (if (and (eq (car a) :inherit)
1384 (not (eq attr 'unspecified)))
1385 ;; Make a hyperlink to the parent face.
1387 (re-search-backward ": \\([^:]+\\)" nil t)
1388 (help-xref-button 1 'help-face attr)))
1393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1394 ;;; Face specifications (defface).
1395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1397 ;; Parameter FRAME Is kept for call compatibility to with previous
1398 ;; face implementation.
1400 (defun face-attr-construct (face &optional frame)
1401 "Return a `defface'-style attribute list for FACE on FRAME.
1402 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1403 face attributes of FACE where ATTRIBUTE is the attribute name and
1404 VALUE is the specified value of that attribute."
1406 (dolist (entry face-attribute-name-alist result)
1407 (let* ((attribute (car entry))
1408 (value (face-attribute face attribute)))
1409 (unless (eq value 'unspecified)
1410 (setq result (nconc (list attribute value) result)))))))
1413 (defun face-spec-set-match-display (display frame)
1414 "Non-nil if DISPLAY matches FRAME.
1415 DISPLAY is part of a spec such as can be used in `defface'.
1416 If FRAME is nil, the current FRAME is used."
1417 (let* ((conjuncts display)
1418 conjunct req options
1419 ;; t means we have succeeded against all the conjuncts in
1420 ;; DISPLAY that have been tested so far.
1422 (if (eq conjuncts t)
1423 (setq conjuncts nil))
1424 (while (and conjuncts match)
1425 (setq conjunct (car conjuncts)
1426 conjuncts (cdr conjuncts)
1428 options (cdr conjunct)
1429 match (cond ((eq req 'type)
1430 (or (memq (window-system frame) options)
1431 ;; FIXME: This should be revisited to use
1432 ;; display-graphic-p, provided that the
1433 ;; color selection depends on the number
1434 ;; of supported colors, and all defface's
1435 ;; are changed to look at number of colors
1436 ;; instead of (type graphic) etc.
1437 (and (null (window-system frame))
1438 (memq 'tty options))
1439 (and (memq 'motif options)
1441 (and (memq 'gtk options)
1443 (and (memq 'lucid options)
1444 (featurep 'x-toolkit)
1445 (not (featurep 'motif))
1446 (not (featurep 'gtk)))
1447 (and (memq 'x-toolkit options)
1448 (featurep 'x-toolkit))))
1449 ((eq req 'min-colors)
1450 (>= (display-color-cells frame) (car options)))
1452 (memq (frame-parameter frame 'display-type) options))
1453 ((eq req 'background)
1454 (memq (frame-parameter frame 'background-mode)
1457 (display-supports-face-attributes-p options frame))
1458 (t (error "Unknown req `%S' with options `%S'"
1463 (defun face-spec-choose (spec &optional frame)
1464 "Choose the proper attributes for FRAME, out of SPEC.
1465 If SPEC is nil, return nil."
1467 (setq frame (selected-frame)))
1471 (let* ((entry (pop tail))
1472 (display (car entry))
1475 ;; Get the attributes as actually specified by this alternative.
1477 (if (null (cdr attrs)) ;; was (listp (car attrs))
1478 ;; Old-style entry, the attribute list is the
1483 ;; If the condition is `default', that sets the default
1484 ;; for following conditions.
1485 (if (eq display 'default)
1486 (setq defaults thisval)
1487 ;; Otherwise, if it matches, use it.
1488 (when (face-spec-set-match-display display frame)
1489 (setq result thisval)
1491 (if defaults (append result defaults) result)))
1494 (defun face-spec-reset-face (face &optional frame)
1495 "Reset all attributes of FACE on FRAME to unspecified."
1496 (let ((attrs face-attribute-name-alist))
1498 (let ((attr-and-name (car attrs)))
1499 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1500 (setq attrs (cdr attrs)))))
1503 (defun face-spec-set (face spec &optional for-defface)
1504 "Set FACE's face spec, which controls its appearance, to SPEC.
1505 If FOR-DEFFACE is t, set the base spec, the one that `defface'
1506 and Custom set. (In that case, the caller must put it in the
1507 appropriate property, because that depends on the caller.)
1508 If FOR-DEFFACE is nil, set the overriding spec (and store it
1509 in the `face-override-spec' property of FACE).
1511 The appearance of FACE is controlled by the base spec,
1512 by any custom theme specs on top of that, and by the
1513 overriding spec on top of all the rest.
1515 FOR-DEFFACE can also be a frame, in which case we set the
1516 frame-specific attributes of FACE for that frame based on SPEC.
1517 That usage is deprecated.
1519 See `defface' for information about the format and meaning of SPEC."
1520 (if (framep for-defface)
1521 ;; Handle the deprecated case where third arg is a frame.
1522 (face-spec-set-2 face for-defface spec)
1524 ;; When we reset the face based on its custom spec, then it is
1525 ;; unmodified as far as Custom is concerned.
1526 (put (or (get face 'face-alias) face) 'face-modified nil)
1527 ;; When we change a face based on a spec from outside custom,
1528 ;; record it for future frames.
1529 (put (or (get face 'face-alias) face) 'face-override-spec spec))
1530 ;;; RMS 29 dec 2007: Perhaps this code should be reinstated.
1531 ;;; That depends on whether the overriding spec
1532 ;;; or the default face attributes
1533 ;;; should take priority.
1534 ;;; ;; Clear all the new-frame default attributes for this face.
1535 ;;; ;; face-spec-reset-face won't do it right.
1536 ;;; (let ((facevec (cdr (assq face face-new-frame-defaults))))
1537 ;;; (dotimes (i (length facevec))
1539 ;;; (aset facevec i 'unspecified))))
1540 ;; Reset each frame according to the rules implied by all its specs.
1541 (dolist (frame (frame-list))
1542 (face-spec-recalc face frame))))
1544 (defun face-spec-recalc (face frame)
1545 "Reset the face attributes of FACE on FRAME according to its specs.
1546 This applies the defface/custom spec first, then the custom theme specs,
1547 then the override spec."
1548 (face-spec-reset-face face frame)
1549 (let ((face-sym (or (get face 'face-alias) face)))
1550 (face-spec-set-2 face frame
1551 (face-user-default-spec face))
1552 (let ((theme-faces (reverse (get face-sym 'theme-face))))
1553 (dolist (spec theme-faces)
1554 (face-spec-set-2 face frame (cadr spec))))
1555 (face-spec-set-2 face frame (get face-sym 'face-override-spec))))
1557 (defun face-spec-set-2 (face frame spec)
1558 "Set the face attributes of FACE on FRAME according to SPEC."
1559 (let* ((attrs (face-spec-choose spec frame)))
1561 (let ((attribute (car attrs))
1562 (value (car (cdr attrs))))
1563 ;; Support some old-style attribute names and values.
1565 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1566 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1567 ((:foreground :background)
1568 ;; Compatibility with 20.x. Some bogus face specs seem to
1569 ;; exist containing things like `:foreground nil'.
1570 (if (null value) (setq value 'unspecified)))
1571 (t (unless (assq attribute face-x-resources)
1572 (setq attribute nil))))
1574 (set-face-attribute face frame attribute value)))
1575 (setq attrs (cdr (cdr attrs))))))
1577 (defun face-attr-match-p (face attrs &optional frame)
1578 "Return t if attributes of FACE match values in plist ATTRS.
1579 Optional parameter FRAME is the frame whose definition of FACE
1580 is used. If nil or omitted, use the selected frame."
1582 (setq frame (selected-frame)))
1583 (let ((list face-attribute-name-alist)
1585 (while (and match (not (null list)))
1586 (let* ((attr (car (car list)))
1588 (if (plist-member attrs attr)
1589 (plist-get attrs attr)
1591 (value-now (face-attribute face attr frame)))
1592 (setq match (equal specified-value value-now))
1593 (setq list (cdr list))))
1596 (defun face-spec-match-p (face spec &optional frame)
1597 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1598 (face-attr-match-p face (face-spec-choose spec frame) frame))
1600 (defsubst face-default-spec (face)
1601 "Return the default face-spec for FACE, ignoring any user customization.
1602 If there is no default for FACE, return nil."
1603 (get face 'face-defface-spec))
1605 (defsubst face-user-default-spec (face)
1606 "Return the user's customized face-spec for FACE, or the default if none.
1607 If there is neither a user setting nor a default for FACE, return nil."
1608 (or (get face 'customized-face)
1609 (get face 'saved-face)
1610 (face-default-spec face)))
1613 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1614 ;;; Frame-type independent color support.
1615 ;;; We keep the old x-* names as aliases for back-compatibility.
1616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1618 (defun defined-colors (&optional frame)
1619 "Return a list of colors supported for a particular frame.
1620 The argument FRAME specifies which frame to try.
1621 The value may be different for frames on different display types.
1622 If FRAME doesn't support colors, the value is nil.
1623 If FRAME is nil, that stands for the selected frame."
1624 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1625 (xw-defined-colors frame)
1626 (mapcar 'car (tty-color-alist frame))))
1627 (defalias 'x-defined-colors 'defined-colors)
1629 (defun color-defined-p (color &optional frame)
1630 "Return non-nil if color COLOR is supported on frame FRAME.
1631 If FRAME is omitted or nil, use the selected frame.
1632 If COLOR is the symbol `unspecified' or one of the strings
1633 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1634 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1636 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1637 (xw-color-defined-p color frame)
1638 (numberp (tty-color-translate color frame)))))
1639 (defalias 'x-color-defined-p 'color-defined-p)
1641 (defun color-values (color &optional frame)
1642 "Return a description of the color named COLOR on frame FRAME.
1643 The value is a list of integer RGB values--(RED GREEN BLUE).
1644 These values appear to range from 0 to 65280 or 65535, depending
1645 on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
1646 If FRAME is omitted or nil, use the selected frame.
1647 If FRAME cannot display COLOR, the value is nil.
1648 If COLOR is the symbol `unspecified' or one of the strings
1649 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1650 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1652 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1653 (xw-color-values color frame)
1654 (tty-color-values color frame))))
1655 (defalias 'x-color-values 'color-values)
1657 (defun display-color-p (&optional display)
1658 "Return t if DISPLAY supports color.
1659 The optional argument DISPLAY specifies which display to ask about.
1660 DISPLAY should be either a frame or a display name (a string).
1661 If omitted or nil, that stands for the selected frame's display."
1662 (if (memq (framep-on-display display) '(x w32 mac))
1663 (xw-display-color-p display)
1664 (tty-display-color-p display)))
1665 (defalias 'x-display-color-p 'display-color-p)
1667 (defun display-grayscale-p (&optional display)
1668 "Return non-nil if frames on DISPLAY can display shades of gray."
1669 (let ((frame-type (framep-on-display display)))
1671 ((memq frame-type '(x w32 mac))
1672 (x-display-grayscale-p display))
1674 (> (tty-color-gray-shades display) 2)))))
1676 (defun read-color (&optional prompt convert-to-RGB-p allow-empty-name-p msg-p)
1677 "Read a color name or RGB hex value: #RRRRGGGGBBBB.
1678 Completion is available for color names, but not for RGB hex strings.
1679 If the user inputs an RGB hex string, it must have the form
1680 #XXXXXXXXXXXX or XXXXXXXXXXXX, where each X is a hex digit. The
1681 number of Xs must be a multiple of 3, with the same number of Xs for
1682 each of red, green, and blue. The order is red, green, blue.
1684 In addition to standard color names and RGB hex values, the following
1685 are available as color candidates. In each case, the corresponding
1688 * `foreground at point' - foreground under the cursor
1689 * `background at point' - background under the cursor
1691 Checks input to be sure it represents a valid color. If not, raises
1692 an error (but see exception for empty input with non-nil
1693 ALLOW-EMPTY-NAME-P).
1695 Optional arg PROMPT is the prompt; if nil, uses a default prompt.
1697 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, converts
1698 an input color name to an RGB hex string. Returns the RGB hex string.
1700 Optional arg ALLOW-EMPTY-NAME-P controls what happens if the user
1701 enters an empty color name (that is, just hits `RET'). If non-nil,
1702 then returns an empty color name, \"\". If nil, then raises an error.
1703 Programs must test for \"\" if ALLOW-EMPTY-NAME-P is non-nil. They
1704 can then perform an appropriate action in case of empty input.
1706 Interactively, or with optional arg MSG-P non-nil, echoes the color in
1708 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1709 (let* ((completion-ignore-case t)
1710 (colors (append '("foreground at point" "background at point")
1712 (color (completing-read (or prompt "Color (name or #R+G+B+): ")
1715 (cond ((string= "foreground at point" color)
1716 (setq color (foreground-color-at-point)))
1717 ((string= "background at point" color)
1718 (setq color (background-color-at-point))))
1722 (string-match "^#?\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color))
1723 (if (and allow-empty-name-p (string= "" color))
1725 (when (and hex-string (not (eq (aref color 0) ?#)))
1726 (setq color (concat "#" color))) ; No #; add it.
1728 (when (or (string= "" color) (not (test-completion color colors)))
1729 (error "No such color: %S" color))
1730 (when convert-to-RGB-p
1731 (let ((components (x-color-values color)))
1732 (unless components (error "No such color: %S" color))
1733 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1734 (setq color (format "#%04X%04X%04X"
1735 (logand 65535 (nth 0 components))
1736 (logand 65535 (nth 1 components))
1737 (logand 65535 (nth 2 components))))))))
1738 (when msg-p (message "Color: `%s'" color))
1741 ;; Commented out because I decided it is better to include the
1742 ;; duplicates in read-color's completion list.
1744 ;; (defun defined-colors-without-duplicates ()
1745 ;; "Return the list of defined colors, without the no-space versions.
1746 ;; For each color name, we keep the variant that DOES have spaces."
1747 ;; (let ((result (copy-sequence (defined-colors)))
1750 ;; (dolist (this result)
1751 ;; (if (string-match " " this)
1752 ;; (push (replace-regexp-in-string " " ""
1754 ;; to-be-rejected)))
1755 ;; (dolist (elt to-be-rejected)
1756 ;; (let ((as-found (car (member-ignore-case elt result))))
1757 ;; (setq result (delete as-found result)))))
1760 (defun face-at-point ()
1761 "Return the face of the character after point.
1762 If it has more than one face, return the first one.
1763 Return nil if it has no specified face."
1764 (let* ((faceprop (or (get-char-property (point) 'read-face-name)
1765 (get-char-property (point) 'face)
1767 (face (cond ((symbolp faceprop) faceprop)
1768 ;; List of faces (don't treat an attribute spec).
1769 ;; Just use the first face.
1770 ((and (consp faceprop) (not (keywordp (car faceprop)))
1771 (not (memq (car faceprop)
1772 '(foreground-color background-color))))
1774 (t nil)))) ; Invalid face value.
1775 (if (facep face) face nil)))
1777 (defun foreground-color-at-point ()
1778 "Return the foreground color of the character after point."
1779 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1780 ;; Need also pick up any face properties that are not associated with named faces.
1781 (let ((face (or (face-at-point)
1782 (get-char-property (point) 'read-face-name)
1783 (get-char-property (point) 'face))))
1784 (cond ((and face (symbolp face))
1785 (let ((value (face-foreground face nil 'default)))
1786 (if (member value '("unspecified-fg" "unspecified-bg"))
1790 (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face)))
1791 ((memq ':foreground face) (cadr (memq ':foreground face)))))
1792 (t nil)))) ; Invalid face value.
1794 (defun background-color-at-point ()
1795 "Return the background color of the character after point."
1796 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1797 ;; Need also pick up any face properties that are not associated with named faces.
1798 (let ((face (or (face-at-point)
1799 (get-char-property (point) 'read-face-name)
1800 (get-char-property (point) 'face))))
1801 (cond ((and face (symbolp face))
1802 (let ((value (face-background face nil 'default)))
1803 (if (member value '("unspecified-fg" "unspecified-bg"))
1807 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1808 ((memq ':background face) (cadr (memq ':background face)))))
1809 (t nil)))) ; Invalid face value.
1811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1812 ;;; Background mode.
1813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1815 (defcustom frame-background-mode nil
1816 "*The brightness of the background.
1817 Set this to the symbol `dark' if your background color is dark,
1818 `light' if your background is light, or nil (automatic by default)
1819 if you want Emacs to examine the brightness for you. Don't set this
1820 variable with `setq'; this won't have the expected effect."
1822 :set #'(lambda (var value)
1823 (set-default var value)
1824 (mapc 'frame-set-background-mode (frame-list)))
1825 :initialize 'custom-initialize-changed
1826 :type '(choice (const dark)
1828 (const :tag "automatic" nil)))
1831 (defun frame-set-background-mode (frame)
1832 "Set up display-dependent faces on FRAME.
1833 Display-dependent faces are those which have different definitions
1834 according to the `background-mode' and `display-type' frame parameters."
1836 (and (window-system frame)
1837 (x-get-resource "backgroundMode" "BackgroundMode")))
1838 (bg-color (frame-parameter frame 'background-color))
1839 (terminal-bg-mode (terminal-parameter frame 'background-mode))
1840 (tty-type (tty-type frame))
1842 (cond (frame-background-mode)
1844 (intern (downcase bg-resource)))
1846 ((and (null (window-system frame))
1847 ;; Unspecified frame background color can only
1849 (member bg-color '(nil unspecified "unspecified-bg")))
1850 ;; There is no way to determine the background mode
1851 ;; automatically, so we make a guess based on the
1854 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1858 ((equal bg-color "unspecified-fg") ; inverted colors
1860 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1864 ((>= (apply '+ (color-values bg-color frame))
1865 ;; Just looking at the screen, colors whose
1866 ;; values add up to .6 of the white total
1867 ;; still look dark to me.
1868 (* (apply '+ (color-values "white" frame)) .6))
1872 (cond ((null (window-system frame))
1873 (if (tty-display-color-p frame) 'color 'mono))
1874 ((display-color-p frame)
1876 ((x-display-grayscale-p frame)
1880 (frame-parameter frame 'background-mode))
1882 (frame-parameter frame 'display-type)))
1884 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1885 (let ((locally-modified-faces nil))
1886 ;; Before modifying the frame parameters, we collect a list of
1887 ;; faces that don't match what their face-spec says they should
1888 ;; look like; we then avoid changing these faces below.
1889 ;; These are the faces whose attributes were modified on FRAME.
1890 ;; We use a negative list on the assumption that most faces will
1891 ;; be unmodified, so we can avoid consing in the common case.
1892 (dolist (face (face-list))
1893 (and (not (get face 'face-override-spec))
1894 (not (face-spec-match-p face
1895 (face-user-default-spec face)
1897 (push face locally-modified-faces)))
1898 ;; Now change to the new frame parameters
1899 (modify-frame-parameters frame
1900 (list (cons 'background-mode bg-mode)
1901 (cons 'display-type display-type)))
1902 ;; For all named faces, choose face specs matching the new frame
1903 ;; parameters, unless they have been locally modified.
1904 (dolist (face (face-list))
1905 (unless (memq face locally-modified-faces)
1906 (face-spec-recalc face frame)))))))
1909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1911 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1913 (defun x-handle-named-frame-geometry (parameters)
1914 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1915 Value is the new parameter list."
1916 (let* ((name (or (cdr (assq 'name parameters))
1917 (cdr (assq 'name default-frame-alist))))
1918 (x-resource-name name)
1919 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1921 (let ((parsed (x-parse-geometry res-geometry)))
1922 ;; If the resource specifies a position, call the position
1923 ;; and size "user-specified".
1924 (when (or (assq 'top parsed)
1925 (assq 'left parsed))
1926 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1927 ;; Put the geometry parameters at the end. Copy
1928 ;; default-frame-alist so that they go after it.
1929 (setq parameters (append parameters default-frame-alist parsed))))
1933 (defun x-handle-reverse-video (frame parameters)
1934 "Handle the reverse-video frame parameter and X resource.
1935 `x-create-frame' does not handle this one."
1936 (when (cdr (or (assq 'reverse parameters)
1937 (assq 'reverse default-frame-alist)
1938 (let ((resource (x-get-resource "reverseVideo"
1941 (cons nil (member (downcase resource)
1942 '("on" "true")))))))
1943 (let* ((params (frame-parameters frame))
1944 (bg (cdr (assq 'foreground-color params)))
1945 (fg (cdr (assq 'background-color params))))
1946 (modify-frame-parameters frame
1947 (list (cons 'foreground-color fg)
1948 (cons 'background-color bg)))
1949 (if (equal bg (cdr (assq 'border-color params)))
1950 (modify-frame-parameters frame
1951 (list (cons 'border-color fg))))
1952 (if (equal bg (cdr (assq 'mouse-color params)))
1953 (modify-frame-parameters frame
1954 (list (cons 'mouse-color fg))))
1955 (if (equal bg (cdr (assq 'cursor-color params)))
1956 (modify-frame-parameters frame
1957 (list (cons 'cursor-color fg)))))))
1960 (defun x-create-frame-with-faces (&optional parameters)
1961 "Create a frame from optional frame parameters PARAMETERS.
1962 Parameters not specified by PARAMETERS are taken from
1963 `default-frame-alist'. If PARAMETERS specify a frame name,
1964 handle X geometry resources for that name. If either PARAMETERS
1965 or `default-frame-alist' contains a `reverse' parameter, or
1966 the X resource ``reverseVideo'' is present, handle that.
1967 Value is the new frame created."
1968 (setq parameters (x-handle-named-frame-geometry parameters))
1969 (let ((visibility-spec (assq 'visibility parameters))
1970 (frame (x-create-frame `((visibility . nil) . ,parameters)))
1974 (x-setup-function-keys frame)
1975 (x-handle-reverse-video frame parameters)
1976 (frame-set-background-mode frame)
1977 (face-set-after-frame-default frame)
1978 ;; Make sure the tool-bar is ready to be enabled. The
1979 ;; `tool-bar-lines' frame parameter will not take effect
1980 ;; without this call.
1981 (tool-bar-setup frame)
1982 (if (null visibility-spec)
1983 (make-frame-visible frame)
1984 (modify-frame-parameters frame (list visibility-spec)))
1987 (delete-frame frame)))
1990 (defun face-set-after-frame-default (frame)
1991 "Set frame-local faces of FRAME from face specs and resources.
1992 Initialize colors of certain faces from frame parameters."
1993 (unless inhibit-face-set-after-frame-default
1994 (if (face-attribute 'default :font t)
1995 (set-face-attribute 'default frame :font
1996 (face-attribute 'default :font t))
1997 (set-face-attribute 'default frame :family
1998 (face-attribute 'default :family t))
1999 (set-face-attribute 'default frame :height
2000 (face-attribute 'default :height t))
2001 (set-face-attribute 'default frame :slant
2002 (face-attribute 'default :slant t))
2003 (set-face-attribute 'default frame :weight
2004 (face-attribute 'default :weight t))
2005 (set-face-attribute 'default frame :width
2006 (face-attribute 'default :width t))))
2007 ;; Find attributes that should be initialized from frame parameters.
2008 (let ((face-params '((foreground-color default :foreground)
2009 (background-color default :background)
2010 (border-color border :background)
2011 (cursor-color cursor :background)
2012 (scroll-bar-foreground scroll-bar :foreground)
2013 (scroll-bar-background scroll-bar :background)
2014 (mouse-color mouse :background)))
2016 (dolist (param face-params)
2017 (let* ((value (frame-parameter frame (nth 0 param)))
2018 (face (nth 1 param))
2019 (attr (nth 2 param))
2020 (default-value (face-attribute face attr t)))
2021 ;; Compile a list of face attributes to set, but don't set
2022 ;; them yet. The call to make-face-x-resource-internal,
2023 ;; below, can change frame parameters, and the final set of
2024 ;; frame parameters should be the ones acquired at this step.
2025 (if (eq default-value 'unspecified)
2026 ;; The face spec does not specify a new-frame value for
2027 ;; this attribute. Check if the existing frame parameter
2030 (push (list face frame attr value) apply-params))
2031 ;; The face spec specifies a value for this attribute, to be
2032 ;; applied to the face on all new frames.
2033 (push (list face frame attr default-value) apply-params))))
2034 ;; Initialize faces from face specs and X resources. The
2035 ;; condition-case prevents invalid specs from causing frame
2036 ;; creation to fail.
2037 (dolist (face (delq 'default (face-list)))
2040 (face-spec-recalc face frame)
2041 (if (memq (window-system frame) '(x w32 mac))
2042 (make-face-x-resource-internal face frame))
2043 (internal-merge-in-global-face face frame))
2045 ;; Apply the attributes specified by frame parameters. This
2046 ;; rewrites parameters changed by make-face-x-resource-internal
2047 (dolist (param apply-params)
2048 (apply 'set-face-attribute param))))
2050 (defun tty-handle-reverse-video (frame parameters)
2051 "Handle the reverse-video frame parameter for terminal frames."
2052 (when (cdr (or (assq 'reverse parameters)
2053 (assq 'reverse default-frame-alist)))
2054 (let* ((params (frame-parameters frame))
2055 (bg (cdr (assq 'foreground-color params)))
2056 (fg (cdr (assq 'background-color params))))
2057 (modify-frame-parameters frame
2058 (list (cons 'foreground-color fg)
2059 (cons 'background-color bg)))
2060 (if (equal bg (cdr (assq 'mouse-color params)))
2061 (modify-frame-parameters frame
2062 (list (cons 'mouse-color fg))))
2063 (if (equal bg (cdr (assq 'cursor-color params)))
2064 (modify-frame-parameters frame
2065 (list (cons 'cursor-color fg)))))))
2068 (defun tty-create-frame-with-faces (&optional parameters)
2069 "Create a frame from optional frame parameters PARAMETERS.
2070 Parameters not specified by PARAMETERS are taken from
2071 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
2072 contains a `reverse' parameter, handle that. Value is the new frame
2074 (let ((frame (make-terminal-frame parameters))
2077 (with-selected-frame frame
2078 (tty-handle-reverse-video frame (frame-parameters frame))
2080 (unless (terminal-parameter frame 'terminal-initted)
2081 (set-terminal-parameter frame 'terminal-initted t)
2082 (set-locale-environment nil frame)
2083 (tty-run-terminal-initialization frame))
2084 (frame-set-background-mode frame)
2085 (face-set-after-frame-default frame)
2088 (delete-frame frame)))
2091 (defun tty-find-type (pred type)
2092 "Return the longest prefix of TYPE to which PRED returns non-nil.
2093 TYPE should be a tty type name such as \"xterm-16color\".
2095 The function tries only those prefixes that are followed by a
2096 dash or underscore in the original type name, like \"xterm\" in
2100 (not (funcall pred type)))
2101 ;; Strip off last hyphen and what follows, then try again
2103 (if (setq hyphend (string-match "[-_][^-_]+$" type))
2104 (substring type 0 hyphend)
2108 (defun tty-run-terminal-initialization (frame &optional type)
2109 "Run the special initialization code for the terminal type of FRAME.
2110 The optional TYPE parameter may be used to override the autodetected
2111 terminal type to a different value."
2112 (setq type (or type (tty-type frame)))
2113 ;; Load library for our terminal type.
2114 ;; User init file can set term-file-prefix to nil to prevent this.
2115 (with-selected-frame frame
2116 (unless (null term-file-prefix)
2117 (let* (term-init-func)
2118 ;; First, load the terminal initialization file, if it is
2119 ;; available and it hasn't been loaded already.
2120 (tty-find-type #'(lambda (type)
2121 (let ((file (locate-library (concat term-file-prefix type))))
2123 (or (assoc file load-history)
2126 ;; Next, try to find a matching initialization function, and call it.
2127 (tty-find-type #'(lambda (type)
2128 (fboundp (setq term-init-func
2129 (intern (concat "terminal-init-" type)))))
2131 (when (fboundp term-init-func)
2132 (funcall term-init-func))
2133 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
2135 ;; Called from C function init_display to initialize faces of the
2136 ;; dumped terminal frame on startup.
2138 (defun tty-set-up-initial-frame-faces ()
2139 (let ((frame (selected-frame)))
2140 (frame-set-background-mode frame)
2141 (face-set-after-frame-default frame)))
2146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2147 ;;; Compatiblity with 20.2
2148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2150 ;; Update a frame's faces when we change its default font.
2152 (defalias 'frame-update-faces 'ignore "")
2153 (make-obsolete 'frame-update-faces "no longer necessary." "21.1")
2155 ;; Update the colors of FACE, after FRAME's own colors have been
2158 (define-obsolete-function-alias 'frame-update-face-colors
2159 'frame-set-background-mode "21.1")
2162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2166 (defgroup basic-faces nil
2167 "The standard faces of Emacs."
2171 '((t nil)) ; If this were nil, face-defface-spec would not be set.
2172 "Basic default face."
2173 :group 'basic-faces)
2178 :group 'basic-faces)
2181 '((((supports :slant italic))
2183 (((supports :underline t))
2186 ;; default to italic, even it doesn't appear to be supported,
2187 ;; because in some cases the display engine will do it's own
2188 ;; workaround (to `dim' on ttys)
2190 "Basic italic face."
2191 :group 'basic-faces)
2193 (defface bold-italic
2194 '((t :weight bold :slant italic))
2195 "Basic bold-italic face."
2196 :group 'basic-faces)
2199 '((((supports :underline t))
2201 (((supports :weight bold))
2204 "Basic underlined face."
2205 :group 'basic-faces)
2207 (defface fixed-pitch
2208 '((t :family "courier"))
2209 "The basic fixed-pitch face."
2210 :group 'basic-faces)
2212 (defface variable-pitch
2213 '((t :family "helv"))
2214 "The basic variable-pitch face."
2215 :group 'basic-faces)
2218 '((((class color grayscale) (min-colors 88) (background light))
2219 :foreground "grey50")
2220 (((class color grayscale) (min-colors 88) (background dark))
2221 :foreground "grey70")
2222 (((class color) (min-colors 8) (background light))
2223 :foreground "green")
2224 (((class color) (min-colors 8) (background dark))
2225 :foreground "yellow"))
2226 "Basic face for shadowed text."
2231 '((((class color) (min-colors 88) (background light))
2232 :foreground "blue1" :underline t)
2233 (((class color) (background light))
2234 :foreground "blue" :underline t)
2235 (((class color) (min-colors 88) (background dark))
2236 :foreground "cyan1" :underline t)
2237 (((class color) (background dark))
2238 :foreground "cyan" :underline t)
2239 (t :inherit underline))
2240 "Basic face for unvisited links."
2244 (defface link-visited
2245 '((default :inherit link)
2246 (((class color) (background light)) :foreground "magenta4")
2247 (((class color) (background dark)) :foreground "violet"))
2248 "Basic face for visited links."
2253 '((((class color) (min-colors 88) (background light))
2254 :background "darkseagreen2")
2255 (((class color) (min-colors 88) (background dark))
2256 :background "darkolivegreen")
2257 (((class color) (min-colors 16) (background light))
2258 :background "darkseagreen2")
2259 (((class color) (min-colors 16) (background dark))
2260 :background "darkolivegreen")
2261 (((class color) (min-colors 8))
2262 :background "green" :foreground "black")
2263 (t :inverse-video t))
2264 "Basic face for highlighting."
2265 :group 'basic-faces)
2268 '((((class color) (min-colors 88) (background dark))
2269 :background "blue3")
2270 (((class color) (min-colors 88) (background light))
2271 :background "lightgoldenrod2")
2272 (((class color) (min-colors 16) (background dark))
2273 :background "blue3")
2274 (((class color) (min-colors 16) (background light))
2275 :background "lightgoldenrod2")
2276 (((class color) (min-colors 8))
2277 :background "blue" :foreground "white")
2278 (((type tty) (class mono))
2280 (t :background "gray"))
2281 "Basic face for highlighting the region."
2283 :group 'basic-faces)
2285 (defface secondary-selection
2286 '((((class color) (min-colors 88) (background light))
2287 :background "yellow1")
2288 (((class color) (min-colors 88) (background dark))
2289 :background "SkyBlue4")
2290 (((class color) (min-colors 16) (background light))
2291 :background "yellow")
2292 (((class color) (min-colors 16) (background dark))
2293 :background "SkyBlue4")
2294 (((class color) (min-colors 8))
2295 :background "cyan" :foreground "black")
2296 (t :inverse-video t))
2297 "Basic face for displaying the secondary selection."
2298 :group 'basic-faces)
2300 (defface trailing-whitespace
2301 '((((class color) (background light))
2303 (((class color) (background dark))
2305 (t :inverse-video t))
2306 "Basic face for highlighting trailing whitespace."
2308 :group 'whitespace-faces ; like `show-trailing-whitespace'
2309 :group 'basic-faces)
2311 (defface escape-glyph
2312 '((((background dark)) :foreground "cyan")
2313 ;; See the comment in minibuffer-prompt for
2314 ;; the reason not to use blue on MS-DOS.
2315 (((type pc)) :foreground "magenta")
2316 ;; red4 is too dark, but some say blue is too loud.
2317 ;; brown seems to work ok. -- rms.
2318 (t :foreground "brown"))
2319 "Face for characters displayed as sequences using `^' or `\\'."
2323 (defface nobreak-space
2324 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2325 (((class color) (min-colors 8)) :background "magenta")
2326 (t :inverse-video t))
2327 "Face for displaying nobreak space."
2331 (defgroup mode-line-faces nil
2332 "Faces used in the mode line."
2338 '((((class color) (min-colors 88))
2339 :box (:line-width -1 :style released-button)
2340 :background "grey75" :foreground "black")
2343 "Basic mode line face for selected window."
2345 :group 'mode-line-faces
2346 :group 'basic-faces)
2348 (defface mode-line-inactive
2351 (((class color) (min-colors 88) (background light))
2353 :box (:line-width -1 :color "grey75" :style nil)
2354 :foreground "grey20" :background "grey90")
2355 (((class color) (min-colors 88) (background dark) )
2357 :box (:line-width -1 :color "grey40" :style nil)
2358 :foreground "grey80" :background "grey30"))
2359 "Basic mode line face for non-selected windows."
2361 :group 'mode-line-faces
2362 :group 'basic-faces)
2364 (defface mode-line-highlight
2365 '((((class color) (min-colors 88))
2366 :box (:line-width 2 :color "grey40" :style released-button))
2368 :inherit highlight))
2369 "Basic mode line face for highlighting."
2371 :group 'mode-line-faces
2372 :group 'basic-faces)
2374 (defface mode-line-emphasis
2375 '((t (:weight bold)))
2376 "Face used to emphasize certain mode line features.
2377 Use the face `mode-line-highlight' for features that can be selected."
2379 :group 'mode-line-faces
2380 :group 'basic-faces)
2382 (defface mode-line-buffer-id
2383 '((t (:weight bold)))
2384 "Face used for buffer identification parts of the mode line."
2386 :group 'mode-line-faces
2387 :group 'basic-faces)
2389 ;; Make `modeline' an alias for `mode-line', for compatibility.
2390 (put 'modeline 'face-alias 'mode-line)
2391 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
2392 (put 'modeline-highlight 'face-alias 'mode-line-highlight)
2393 (put 'modeline-buffer-id 'face-alias 'mode-line-buffer-id)
2395 (defface header-line
2399 ;; This used to be `:inverse-video t', but that doesn't look very
2400 ;; good when combined with inverse-video mode-lines and multiple
2401 ;; windows. Underlining looks better, and is more consistent with
2402 ;; the window-system face variants, which deemphasize the
2403 ;; header-line in relation to the mode-line face. If a terminal
2404 ;; can't underline, then the header-line will end up without any
2405 ;; highlighting; this may be too confusing in general, although it
2406 ;; happens to look good with the only current use of header-lines,
2407 ;; the info browser. XXX
2408 :inverse-video nil ;Override the value inherited from mode-line.
2410 (((class color grayscale) (background light))
2411 :background "grey90" :foreground "grey20"
2413 (((class color grayscale) (background dark))
2414 :background "grey20" :foreground "grey90"
2416 (((class mono) (background light))
2417 :background "white" :foreground "black"
2421 (((class mono) (background dark))
2422 :background "black" :foreground "white"
2426 "Basic header-line face."
2428 :group 'basic-faces)
2430 (defface vertical-border
2431 '((((type tty)) :inherit mode-line-inactive))
2432 "Face used for vertical window dividers on ttys."
2434 :group 'basic-faces)
2436 (defface minibuffer-prompt
2437 '((((background dark)) :foreground "cyan")
2438 ;; Don't use blue because many users of the MS-DOS port customize
2439 ;; their foreground color to be blue.
2440 (((type pc)) :foreground "magenta")
2441 (t :foreground "medium blue"))
2442 "Face for minibuffer prompts.
2443 By default, Emacs automatically adds this face to the value of
2444 `minibuffer-prompt-properties', which is a list of text properties
2445 used to display the prompt text."
2447 :group 'basic-faces)
2449 (setq minibuffer-prompt-properties
2450 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2453 '((((class color) (background light))
2454 :background "grey95")
2455 (((class color) (background dark))
2456 :background "grey10")
2458 :background "gray"))
2459 "Basic face for the fringes to the left and right of windows under X."
2462 :group 'basic-faces)
2464 (defface scroll-bar '((t nil))
2465 "Basic face for the scroll bar colors under X."
2468 :group 'basic-faces)
2470 (defface border '((t nil))
2471 "Basic face for the frame border under X."
2474 :group 'basic-faces)
2476 (defface cursor '((t nil))
2477 "Basic face for the cursor color under X.
2478 Note: Other faces cannot inherit from the cursor face."
2481 :group 'basic-faces)
2483 (put 'cursor 'face-no-inherit t)
2485 (defface mouse '((t nil))
2486 "Basic face for the mouse color under X."
2489 :group 'basic-faces)
2493 :box (:line-width 1 :style released-button)
2494 :foreground "black")
2495 (((type x w32 mac) (class color))
2496 :background "grey75")
2497 (((type x) (class mono))
2498 :background "grey"))
2499 "Basic tool-bar face."
2501 :group 'basic-faces)
2510 "Basic face for the font and colors of the menu bar and popup menus."
2513 :group 'basic-faces)
2516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2517 ;;; Manipulating font names.
2518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2520 ;; This is here for compatibilty with Emacs 20.2. For example,
2521 ;; international/fontset.el uses x-resolve-font-name. The following
2522 ;; functions are not used in the face implementation itself.
2524 (defvar x-font-regexp nil)
2525 (defvar x-font-regexp-head nil)
2526 (defvar x-font-regexp-weight nil)
2527 (defvar x-font-regexp-slant nil)
2529 (defconst x-font-regexp-weight-subnum 1)
2530 (defconst x-font-regexp-slant-subnum 2)
2531 (defconst x-font-regexp-swidth-subnum 3)
2532 (defconst x-font-regexp-adstyle-subnum 4)
2534 ;;; Regexps matching font names in "Host Portable Character Representation."
2539 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2540 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2541 (weight\? "\\([^-]*\\)") ; 1
2542 (slant "\\([ior]\\)") ; 2
2543 ; (slant\? "\\([ior?*]?\\)") ; 2
2544 (slant\? "\\([^-]?\\)") ; 2
2545 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2546 (swidth "\\([^-]*\\)") ; 3
2547 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2548 (adstyle "\\([^-]*\\)") ; 4
2549 (pixelsize "[0-9]+")
2550 (pointsize "[0-9][0-9]+")
2551 (resx "[0-9][0-9]+")
2552 (resy "[0-9][0-9]+")
2559 (concat "\\`\\*?[-?*]"
2560 foundry - family - weight\? - slant\? - swidth - adstyle -
2561 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2562 registry - encoding "\\*?\\'"
2564 (setq x-font-regexp-head
2565 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2566 "\\([-*?]\\|\\'\\)"))
2567 (setq x-font-regexp-slant (concat - slant -))
2568 (setq x-font-regexp-weight (concat - weight -))
2572 (defun x-resolve-font-name (pattern &optional face frame)
2573 "Return a font name matching PATTERN.
2574 All wildcards in PATTERN are instantiated.
2575 If PATTERN is nil, return the name of the frame's base font, which never
2577 Given optional arguments FACE and FRAME, return a font which is
2578 also the same size as FACE on FRAME, or fail."
2580 (setq face (face-name face)))
2584 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2585 (let ((fonts (x-list-fonts pattern face frame 1)))
2588 (if (string-match "\\*" pattern)
2589 (if (null (face-font face))
2590 (error "No matching fonts are the same height as the frame default font")
2591 (error "No matching fonts are the same height as face `%s'" face))
2592 (if (null (face-font face))
2593 (error "Height of font `%s' doesn't match the frame default font"
2595 (error "Height of font `%s' doesn't match face `%s'"
2597 (error "No fonts match `%s'" pattern)))
2599 (cdr (assq 'font (frame-parameters (selected-frame))))))
2602 (defun x-frob-font-weight (font which)
2603 (let ((case-fold-search t))
2604 (cond ((string-match x-font-regexp font)
2605 (concat (substring font 0
2606 (match-beginning x-font-regexp-weight-subnum))
2608 (substring font (match-end x-font-regexp-weight-subnum)
2609 (match-beginning x-font-regexp-adstyle-subnum))
2610 ;; Replace the ADD_STYLE_NAME field with *
2611 ;; because the info in it may not be the same
2612 ;; for related fonts.
2614 (substring font (match-end x-font-regexp-adstyle-subnum))))
2615 ((string-match x-font-regexp-head font)
2616 (concat (substring font 0 (match-beginning 1)) which
2617 (substring font (match-end 1))))
2618 ((string-match x-font-regexp-weight font)
2619 (concat (substring font 0 (match-beginning 1)) which
2620 (substring font (match-end 1)))))))
2621 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
2623 (defun x-frob-font-slant (font which)
2624 (let ((case-fold-search t))
2625 (cond ((string-match x-font-regexp font)
2626 (concat (substring font 0
2627 (match-beginning x-font-regexp-slant-subnum))
2629 (substring font (match-end x-font-regexp-slant-subnum)
2630 (match-beginning x-font-regexp-adstyle-subnum))
2631 ;; Replace the ADD_STYLE_NAME field with *
2632 ;; because the info in it may not be the same
2633 ;; for related fonts.
2635 (substring font (match-end x-font-regexp-adstyle-subnum))))
2636 ((string-match x-font-regexp-head font)
2637 (concat (substring font 0 (match-beginning 2)) which
2638 (substring font (match-end 2))))
2639 ((string-match x-font-regexp-slant font)
2640 (concat (substring font 0 (match-beginning 1)) which
2641 (substring font (match-end 1)))))))
2642 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
2644 ;; These aliases are here so that we don't get warnings about obsolete
2645 ;; functions from the byte compiler.
2646 (defalias 'internal-frob-font-weight 'x-frob-font-weight)
2647 (defalias 'internal-frob-font-slant 'x-frob-font-slant)
2649 (defun x-make-font-bold (font)
2650 "Given an X font specification, make a bold version of it.
2651 If that can't be done, return nil."
2652 (internal-frob-font-weight font "bold"))
2653 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
2655 (defun x-make-font-demibold (font)
2656 "Given an X font specification, make a demibold version of it.
2657 If that can't be done, return nil."
2658 (internal-frob-font-weight font "demibold"))
2659 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
2661 (defun x-make-font-unbold (font)
2662 "Given an X font specification, make a non-bold version of it.
2663 If that can't be done, return nil."
2664 (internal-frob-font-weight font "medium"))
2665 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
2667 (defun x-make-font-italic (font)
2668 "Given an X font specification, make an italic version of it.
2669 If that can't be done, return nil."
2670 (internal-frob-font-slant font "i"))
2671 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
2673 (defun x-make-font-oblique (font) ; you say tomayto...
2674 "Given an X font specification, make an oblique version of it.
2675 If that can't be done, return nil."
2676 (internal-frob-font-slant font "o"))
2677 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
2679 (defun x-make-font-unitalic (font)
2680 "Given an X font specification, make a non-italic version of it.
2681 If that can't be done, return nil."
2682 (internal-frob-font-slant font "r"))
2683 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
2685 (defun x-make-font-bold-italic (font)
2686 "Given an X font specification, make a bold and italic version of it.
2687 If that can't be done, return nil."
2688 (and (setq font (internal-frob-font-weight font "bold"))
2689 (internal-frob-font-slant font "i")))
2690 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2694 ;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
2695 ;;; faces.el ends here