1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 ;; 2002, 2003, 2004, 2005, 2006, 2007 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, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
32 ;; Warning suppression -- can't require x-win in batch:
33 (autoload 'xw-defined-colors
"x-win"))
35 (defvar help-xref-stack-item
)
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 (defgroup font-selection nil
42 "Influencing face font selection."
46 (defcustom face-font-selection-order
47 '(:width
:height
:weight
:slant
)
48 "*A list specifying how face font selection chooses fonts.
49 Each of the four symbols `:width', `:height', `:weight', and `:slant'
50 must appear once in the list, and the list must not contain any other
51 elements. Font selection first tries to find a best matching font
52 for those face attributes that appear before in the list. For
53 example, if `:slant' appears before `:height', font selection first
54 tries to find a font with a suitable slant, even if this results in
55 a font height that isn't optimal."
56 :tag
"Font selection order"
57 :type
'(list symbol symbol symbol symbol
)
58 :group
'font-selection
59 :set
#'(lambda (symbol value
)
60 (set-default symbol value
)
61 (internal-set-font-selection-order value
)))
64 ;; This is defined originally in xfaces.c.
65 (defcustom face-font-family-alternatives
67 ("helv" "helvetica" "arial" "fixed"))
68 "*Alist of alternative font family names.
69 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
70 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
72 :tag
"Alternative font families to try"
73 :type
'(repeat (repeat string
))
74 :group
'font-selection
75 :set
#'(lambda (symbol value
)
76 (set-default symbol value
)
77 (internal-set-alternative-font-family-alist value
)))
80 ;; This is defined originally in xfaces.c.
81 (defcustom face-font-registry-alternatives
82 (if (eq system-type
'windows-nt
)
83 '(("iso8859-1" "ms-oemlatin")
84 ("gb2312.1980" "gb2312")
85 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
86 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
87 ("muletibetan-2" "muletibetan-0"))
88 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk*")
89 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
90 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
91 ("muletibetan-2" "muletibetan-0")))
92 "*Alist of alternative font registry names.
93 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
94 If fonts of registry REGISTRY can be loaded, font selection
95 tries to find a best matching font among all fonts of registry
96 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
97 :tag
"Alternative font registries to try"
98 :type
'(repeat (repeat string
))
100 :group
'font-selection
101 :set
#'(lambda (symbol value
)
102 (set-default symbol value
)
103 (internal-set-alternative-font-registry-alist value
)))
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
108 ;;; Creation, copying.
109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
113 "Return a list of all defined face names."
114 (mapcar #'car face-new-frame-defaults
))
117 ;;; ### If not frame-local initialize by what X resources?
119 (defun make-face (face &optional no-init-from-resources
)
120 "Define a new face with name FACE, a symbol.
121 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
122 variants of FACE from X resources. (X resources recognized are found
123 in the global variable `face-x-resources'.) If FACE is already known
124 as a face, leave it unmodified. Value is FACE."
125 (interactive "SMake face: ")
127 ;; Make frame-local faces (this also makes the global one).
128 (dolist (frame (frame-list))
129 (internal-make-lisp-face face frame
))
130 ;; Add the face to the face menu.
131 (when (fboundp 'facemenu-add-new-face
)
132 (facemenu-add-new-face face
))
133 ;; Define frame-local faces for all frames from X resources.
134 (unless no-init-from-resources
135 (make-face-x-resource-internal face
)))
139 (defun make-empty-face (face)
140 "Define a new, empty face with name FACE.
141 If the face already exists, it is left unmodified. Value is FACE."
142 (interactive "SMake empty face: ")
143 (make-face face
'no-init-from-resources
))
146 (defun copy-face (old-face new-face
&optional frame new-frame
)
147 "Define a face just like OLD-FACE, with name NEW-FACE.
149 If NEW-FACE already exists as a face, it is modified to be like
150 OLD-FACE. If it doesn't already exist, it is created.
152 If the optional argument FRAME is given as a frame, NEW-FACE is
153 changed on FRAME only.
154 If FRAME is t, the frame-independent default specification for OLD-FACE
155 is copied to NEW-FACE.
156 If FRAME is nil, copying is done for the frame-independent defaults
157 and for each existing frame.
159 If the optional fourth argument NEW-FRAME is given,
160 copy the information from face OLD-FACE on frame FRAME
161 to NEW-FACE on frame NEW-FRAME. In this case, FRAME may not be nil."
162 (let ((inhibit-quit t
))
166 (error "Copying face %s from all frames to one frame"
168 (make-empty-face new-face
)
169 (dolist (frame (frame-list))
170 (copy-face old-face new-face frame
))
171 (copy-face old-face new-face t
))
172 (make-empty-face new-face
)
173 (internal-copy-lisp-face old-face new-face frame new-frame
))
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179 ;;; Obsolete functions
180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 ;; The functions in this section are defined because Lisp packages use
183 ;; them, despite the prefix `internal-' suggesting that they are
184 ;; private to the face implementation.
186 (defun internal-find-face (name &optional frame
)
187 "Retrieve the face named NAME.
188 Return nil if there is no such face.
189 If NAME is already a face, it is simply returned.
190 The optional argument FRAME is ignored."
192 (make-obsolete 'internal-find-face
'facep
"21.1")
195 (defun internal-get-face (name &optional frame
)
196 "Retrieve the face named NAME; error if there is none.
197 If NAME is already a face, it is simply returned.
198 The optional argument FRAME is ignored."
201 (make-obsolete 'internal-get-face
"see `facep' and `check-face'." "21.1")
204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
205 ;;; Predicates, type checks.
206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
209 "Return non-nil if FACE is a face name or internal face object.
210 Return nil otherwise. A face name can be a string or a symbol.
211 An internal face object is a vector of the kind used internally
212 to record face data."
213 (internal-lisp-face-p face
))
216 (defun check-face (face)
217 "Signal an error if FACE doesn't name a face.
220 (error "Not a face: %s" face
))
224 ;; The ID returned is not to be confused with the internally used IDs
225 ;; of realized faces. The ID assigned to Lisp faces is used to
226 ;; support faces in display table entries.
228 (defun face-id (face &optional frame
)
229 "Return the internal ID of face with name FACE.
230 If FACE is a face-alias, return the ID of the target face.
231 The optional argument FRAME is ignored, since the internal face ID
232 of a face name is the same for all frames."
235 (face-id (get face
'face-alias
))))
237 (defun face-equal (face1 face2
&optional frame
)
238 "Non-nil if faces FACE1 and FACE2 are equal.
239 Faces are considered equal if all their attributes are equal.
240 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
241 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
242 If FRAME is omitted or nil, use the selected frame."
243 (internal-lisp-face-equal-p face1 face2 frame
))
246 (defun face-differs-from-default-p (face &optional frame
)
247 "Return non-nil if FACE displays differently from the default face.
248 If the optional argument FRAME is given, report on face FACE in that frame.
249 If FRAME is t, report on the defaults for face FACE (for new frames).
250 If FRAME is omitted or nil, use the selected frame."
252 '(:family
:width
:height
:weight
:slant
:foreground
253 :background
:underline
:overline
:strike-through
254 :box
:inverse-video
))
256 (while (and attrs
(not differs
))
257 (let* ((attr (pop attrs
))
258 (attr-val (face-attribute face attr frame t
)))
260 (not (eq attr-val
'unspecified
))
261 (display-supports-face-attributes-p (list attr attr-val
)
263 (setq differs attr
))))
267 (defun face-nontrivial-p (face &optional frame
)
268 "True if face FACE has some non-nil attribute.
269 If the optional argument FRAME is given, report on face FACE in that frame.
270 If FRAME is t, report on the defaults for face FACE (for new frames).
271 If FRAME is omitted or nil, use the selected frame."
272 (not (internal-lisp-face-empty-p face frame
)))
276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
277 ;;; Setting face attributes from X resources.
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
280 (defcustom face-x-resources
281 '((:family
(".attributeFamily" .
"Face.AttributeFamily"))
282 (:width
(".attributeWidth" .
"Face.AttributeWidth"))
283 (:height
(".attributeHeight" .
"Face.AttributeHeight"))
284 (:weight
(".attributeWeight" .
"Face.AttributeWeight"))
285 (:slant
(".attributeSlant" .
"Face.AttributeSlant"))
286 (:foreground
(".attributeForeground" .
"Face.AttributeForeground"))
287 (:background
(".attributeBackground" .
"Face.AttributeBackground"))
288 (:overline
(".attributeOverline" .
"Face.AttributeOverline"))
289 (:strike-through
(".attributeStrikeThrough" .
"Face.AttributeStrikeThrough"))
290 (:box
(".attributeBox" .
"Face.AttributeBox"))
291 (:underline
(".attributeUnderline" .
"Face.AttributeUnderline"))
292 (:inverse-video
(".attributeInverse" .
"Face.AttributeInverse"))
294 (".attributeStipple" .
"Face.AttributeStipple")
295 (".attributeBackgroundPixmap" .
"Face.AttributeBackgroundPixmap"))
296 (:bold
(".attributeBold" .
"Face.AttributeBold"))
297 (:italic
(".attributeItalic" .
"Face.AttributeItalic"))
298 (:font
(".attributeFont" .
"Face.AttributeFont"))
299 (:inherit
(".attributeInherit" .
"Face.AttributeInherit")))
300 "*List of X resources and classes for face attributes.
301 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
302 the name of a face attribute, and each ENTRY is a cons of the form
303 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
304 X resource class for the attribute."
305 :type
'(repeat (cons symbol
(repeat (cons string string
))))
309 (defun set-face-attribute-from-resource (face attribute resource class frame
)
310 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
311 Value is the attribute value specified by the resource, or nil
312 if not present. This function displays a message if the resource
313 specifies an invalid attribute."
314 (let* ((face-name (face-name face
))
315 (value (internal-face-x-get-resource (concat face-name resource
)
319 (internal-set-lisp-face-attribute-from-resource
320 face attribute
(downcase value
) frame
)
322 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
323 face-name frame attribute value
))))
327 (defun set-face-attributes-from-resources (face frame
)
328 "Set attributes of FACE from X resources for FRAME."
329 (when (memq (framep frame
) '(x w32 mac
))
330 (dolist (definition face-x-resources
)
331 (let ((attribute (car definition
)))
332 (dolist (entry (cdr definition
))
333 (set-face-attribute-from-resource face attribute
(car entry
)
334 (cdr entry
) frame
))))))
337 (defun make-face-x-resource-internal (face &optional frame
)
338 "Fill frame-local FACE on FRAME from X resources.
339 FRAME nil or not specified means do it for all frames."
341 (dolist (frame (frame-list))
342 (set-face-attributes-from-resources face frame
))
343 (set-face-attributes-from-resources face frame
)))
347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
348 ;;; Retrieving face attributes.
349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
351 (defun face-name (face)
352 "Return the name of face FACE."
353 (symbol-name (check-face face
)))
356 (defun face-attribute (face attribute
&optional frame inherit
)
357 "Return the value of FACE's ATTRIBUTE on FRAME.
358 If the optional argument FRAME is given, report on face FACE in that frame.
359 If FRAME is t, report on the defaults for face FACE (for new frames).
360 If FRAME is omitted or nil, use the selected frame.
362 If INHERIT is nil, only attributes directly defined by FACE are considered,
363 so the return value may be `unspecified', or a relative value.
364 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
365 faces specified by its `:inherit' attribute; however the return value
366 may still be `unspecified' or relative.
367 If INHERIT is a face or a list of faces, then the result is further merged
368 with that face (or faces), until it becomes specified and absolute.
370 To ensure that the return value is always specified and absolute, use a
371 value of `default' for INHERIT; this will resolve any unspecified or
372 relative values by merging with the `default' face (which is always
373 completely specified)."
374 (let ((value (internal-get-lisp-face-attribute face attribute frame
)))
375 (when (and inherit
(face-attribute-relative-p attribute value
))
376 ;; VALUE is relative, so merge with inherited faces
377 (let ((inh-from (face-attribute face
:inherit frame
)))
378 (unless (or (null inh-from
) (eq inh-from
'unspecified
))
381 (face-attribute-merged-with attribute value inh-from frame
))
382 ;; The `inherit' attribute may point to non existent faces.
386 (face-attribute-relative-p attribute value
))
387 ;; We should merge with INHERIT as well
388 (setq value
(face-attribute-merged-with attribute value inherit frame
)))
391 (defun face-attribute-merged-with (attribute value faces
&optional frame
)
392 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
393 FACES may be either a single face or a list of faces.
394 \[This is an internal function.]"
395 (cond ((not (face-attribute-relative-p attribute value
))
400 (face-attribute-merged-with
402 (face-attribute-merged-with attribute value
(car faces
) frame
)
406 (merge-face-attribute attribute
408 (face-attribute faces attribute frame t
)))))
411 (defmacro face-attribute-specified-or
(value &rest body
)
412 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
413 (let ((temp (make-symbol "value")))
414 `(let ((,temp
,value
))
415 (if (not (eq ,temp
'unspecified
))
419 (defun face-foreground (face &optional frame inherit
)
420 "Return the foreground color name of FACE, or nil if unspecified.
421 If the optional argument FRAME is given, report on face FACE in that frame.
422 If FRAME is t, report on the defaults for face FACE (for new frames).
423 If FRAME is omitted or nil, use the selected frame.
425 If INHERIT is nil, only a foreground color directly defined by FACE is
426 considered, so the return value may be nil.
427 If INHERIT is t, and FACE doesn't define a foreground color, then any
428 foreground color that FACE inherits through its `:inherit' attribute
429 is considered as well; however the return value may still be nil.
430 If INHERIT is a face or a list of faces, then it is used to try to
431 resolve an unspecified foreground color.
433 To ensure that a valid color is always returned, use a value of
434 `default' for INHERIT; this will resolve any unspecified values by
435 merging with the `default' face (which is always completely specified)."
436 (face-attribute-specified-or (face-attribute face
:foreground frame inherit
)
439 (defun face-background (face &optional frame inherit
)
440 "Return the background color name of FACE, or nil if unspecified.
441 If the optional argument FRAME is given, report on face FACE in that frame.
442 If FRAME is t, report on the defaults for face FACE (for new frames).
443 If FRAME is omitted or nil, use the selected frame.
445 If INHERIT is nil, only a background color directly defined by FACE is
446 considered, so the return value may be nil.
447 If INHERIT is t, and FACE doesn't define a background color, then any
448 background color that FACE inherits through its `:inherit' attribute
449 is considered as well; however the return value may still be nil.
450 If INHERIT is a face or a list of faces, then it is used to try to
451 resolve an unspecified background color.
453 To ensure that a valid color is always returned, use a value of
454 `default' for INHERIT; this will resolve any unspecified values by
455 merging with the `default' face (which is always completely specified)."
456 (face-attribute-specified-or (face-attribute face
:background frame inherit
)
459 (defun face-stipple (face &optional frame inherit
)
460 "Return the stipple pixmap name of FACE, or nil if unspecified.
461 If the optional argument FRAME is given, report on face FACE in that frame.
462 If FRAME is t, report on the defaults for face FACE (for new frames).
463 If FRAME is omitted or nil, use the selected frame.
465 If INHERIT is nil, only a stipple directly defined by FACE is
466 considered, so the return value may be nil.
467 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
468 that FACE inherits through its `:inherit' attribute is considered as
469 well; however the return value may still be nil.
470 If INHERIT is a face or a list of faces, then it is used to try to
471 resolve an unspecified stipple.
473 To ensure that a valid stipple or nil is always returned, use a value of
474 `default' for INHERIT; this will resolve any unspecified values by merging
475 with the `default' face (which is always completely specified)."
476 (face-attribute-specified-or (face-attribute face
:stipple frame inherit
)
480 (defalias 'face-background-pixmap
'face-stipple
)
483 (defun face-underline-p (face &optional frame
)
484 "Return non-nil if FACE is underlined.
485 If the optional argument FRAME is given, report on face FACE in that frame.
486 If FRAME is t, report on the defaults for face FACE (for new frames).
487 If FRAME is omitted or nil, use the selected frame."
488 (eq (face-attribute face
:underline frame
) t
))
491 (defun face-inverse-video-p (face &optional frame
)
492 "Return non-nil if FACE is in inverse video on FRAME.
493 If the optional argument FRAME is given, report on face FACE in that frame.
494 If FRAME is t, report on the defaults for face FACE (for new frames).
495 If FRAME is omitted or nil, use the selected frame."
496 (eq (face-attribute face
:inverse-video frame
) t
))
499 (defun face-bold-p (face &optional frame
)
500 "Return non-nil if the font of FACE is bold on FRAME.
501 If the optional argument FRAME is given, report on face FACE in that frame.
502 If FRAME is t, report on the defaults for face FACE (for new frames).
503 If FRAME is omitted or nil, use the selected frame.
504 Use `face-attribute' for finer control."
505 (let ((bold (face-attribute face
:weight frame
)))
506 (memq bold
'(semi-bold bold extra-bold ultra-bold
))))
509 (defun face-italic-p (face &optional frame
)
510 "Return non-nil if the font of FACE is italic on FRAME.
511 If the optional argument FRAME is given, report on face FACE in that frame.
512 If FRAME is t, report on the defaults for face FACE (for new frames).
513 If FRAME is omitted or nil, use the selected frame.
514 Use `face-attribute' for finer control."
515 (let ((italic (face-attribute face
:slant frame
)))
516 (memq italic
'(italic oblique
))))
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
521 ;;; Face documentation.
522 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
524 (defun face-documentation (face)
525 "Get the documentation string for FACE.
526 If FACE is a face-alias, get the documentation for the target face."
527 (let ((alias (get face
'face-alias
))
531 (setq doc
(get alias
'face-documentation
))
532 (format "%s is an alias for the face `%s'.%s" face alias
533 (if doc
(format "\n%s" doc
)
535 (get face
'face-documentation
))))
538 (defun set-face-documentation (face string
)
539 "Set the documentation string for FACE to STRING."
540 ;; Perhaps the text should go in DOC.
541 (put face
'face-documentation
(purecopy string
)))
544 (defalias 'face-doc-string
'face-documentation
)
545 (defalias 'set-face-doc-string
'set-face-documentation
)
549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
550 ;; Setting face attributes.
551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
554 (defvar inhibit-face-set-after-frame-default nil
555 "If non-nil, that tells `face-set-after-frame-default' to do nothing.")
557 (defun set-face-attribute (face frame
&rest args
)
558 "Set attributes of FACE on FRAME from ARGS.
560 FRAME nil means change attributes on all frames. FRAME t means change
561 the default for new frames (this is done automatically each time an
562 attribute is changed on all frames).
564 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
565 face attribute name. All attributes can be set to `unspecified';
566 this fact is not further mentioned below.
568 The following attributes are recognized:
572 VALUE must be a string specifying the font family, e.g. ``courier'',
573 or a fontset alias name. If a font family is specified, wild-cards `*'
578 VALUE specifies the relative proportionate width of the font to use.
579 It must be one of the symbols `ultra-condensed', `extra-condensed',
580 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
581 `extra-expanded', or `ultra-expanded'.
585 VALUE must be either an integer specifying the height of the font to use
586 in 1/10 pt, a floating point number specifying the amount by which to
587 scale any underlying face, or a function, which is called with the old
588 height (from the underlying face), and should return the new height.
592 VALUE specifies the weight of the font to use. It must be one of the
593 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
594 `semi-light', `light', `extra-light', `ultra-light'.
598 VALUE specifies the slant of the font to use. It must be one of the
599 symbols `italic', `oblique', `normal', `reverse-italic', or
602 `:foreground', `:background'
604 VALUE must be a color name, a string.
608 VALUE specifies whether characters in FACE should be underlined. If
609 VALUE is t, underline with foreground color of the face. If VALUE is
610 a string, underline with that color. If VALUE is nil, explicitly
615 VALUE specifies whether characters in FACE should be overlined. If
616 VALUE is t, overline with foreground color of the face. If VALUE is a
617 string, overline with that color. If VALUE is nil, explicitly don't
622 VALUE specifies whether characters in FACE should be drawn with a line
623 striking through them. If VALUE is t, use the foreground color of the
624 face. If VALUE is a string, strike-through with that color. If VALUE
625 is nil, explicitly don't strike through.
629 VALUE specifies whether characters in FACE should have a box drawn
630 around them. If VALUE is nil, explicitly don't draw boxes. If
631 VALUE is t, draw a box with lines of width 1 in the foreground color
632 of the face. If VALUE is a string, the string must be a color name,
633 and the box is drawn in that color with a line width of 1. Otherwise,
634 VALUE must be a property list of the form `(:line-width WIDTH
635 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
636 the property list, a default value will be used for the value, as
637 specified below. WIDTH specifies the width of the lines to draw; it
638 defaults to 1. If WIDTH is negative, the absolute value is the width
639 of the lines, and draw top/bottom lines inside the characters area,
640 not around it. COLOR is the name of the color to draw in, default is
641 the foreground color of the face for simple boxes, and the background
642 color of the face for 3D boxes. STYLE specifies whether a 3D box
643 should be draw. If STYLE is `released-button', draw a box looking
644 like a released 3D button. If STYLE is `pressed-button' draw a box
645 that appears like a pressed button. If STYLE is nil, the default if
646 the property list doesn't contain a style specification, draw a 2D
651 VALUE specifies whether characters in FACE should be displayed in
652 inverse video. VALUE must be one of t or nil.
656 If VALUE is a string, it must be the name of a file of pixmap data.
657 The directories listed in the `x-bitmap-file-path' variable are
658 searched. Alternatively, VALUE may be a list of the form (WIDTH
659 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
660 is a string containing the raw bits of the bitmap. VALUE nil means
661 explicitly don't use a stipple pattern.
663 For convenience, attributes `:family', `:width', `:height', `:weight',
664 and `:slant' may also be set in one step from an X font name:
668 Set font-related face attributes from VALUE. VALUE must be a valid
669 XLFD font name. If it is a font name pattern, the first matching font
672 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
673 be used to specify that a bold or italic font should be used. VALUE
674 must be t or nil in that case. A value of `unspecified' is not allowed.
678 VALUE is the name of a face from which to inherit attributes, or a list
679 of face names. Attributes from inherited faces are merged into the face
680 like an underlying face would be, with higher priority than underlying faces."
681 (let ((where (if (null frame
) 0 frame
)))
682 (setq args
(purecopy args
))
683 ;; If we set the new-frame defaults, this face is modified outside Custom.
684 (if (memq where
'(0 t
))
685 (put (or (get face
'face-alias
) face
) 'face-modified t
))
687 ;; Don't recursively set the attributes from the frame's font param
688 ;; when we update the frame's font param fro the attributes.
689 (let ((inhibit-face-set-after-frame-default t
))
690 (internal-set-lisp-face-attribute face
(car args
)
691 (purecopy (cadr args
))
693 (setq args
(cdr (cdr args
))))))
696 (defun make-face-bold (face &optional frame noerror
)
697 "Make the font of FACE be bold, if possible.
698 FRAME nil or not specified means change face on all frames.
699 Argument NOERROR is ignored and retained for compatibility.
700 Use `set-face-attribute' for finer control of the font weight."
701 (interactive (list (read-face-name "Make which face bold")))
702 (set-face-attribute face frame
:weight
'bold
))
705 (defun make-face-unbold (face &optional frame noerror
)
706 "Make the font of FACE be non-bold, if possible.
707 FRAME nil or not specified means change face on all frames.
708 Argument NOERROR is ignored and retained for compatibility."
709 (interactive (list (read-face-name "Make which face non-bold")))
710 (set-face-attribute face frame
:weight
'normal
))
713 (defun make-face-italic (face &optional frame noerror
)
714 "Make the font of FACE be italic, if possible.
715 FRAME nil or not specified means change face on all frames.
716 Argument NOERROR is ignored and retained for compatibility.
717 Use `set-face-attribute' for finer control of the font slant."
718 (interactive (list (read-face-name "Make which face italic")))
719 (set-face-attribute face frame
:slant
'italic
))
722 (defun make-face-unitalic (face &optional frame noerror
)
723 "Make the font of FACE be non-italic, if possible.
724 FRAME nil or not specified means change face on all frames.
725 Argument NOERROR is ignored and retained for compatibility."
726 (interactive (list (read-face-name "Make which face non-italic")))
727 (set-face-attribute face frame
:slant
'normal
))
730 (defun make-face-bold-italic (face &optional frame noerror
)
731 "Make the font of FACE be bold and italic, if possible.
732 FRAME nil or not specified means change face on all frames.
733 Argument NOERROR is ignored and retained for compatibility.
734 Use `set-face-attribute' for finer control of font weight and slant."
735 (interactive (list (read-face-name "Make which face bold-italic")))
736 (set-face-attribute face frame
:weight
'bold
:slant
'italic
))
739 (defun set-face-font (face font
&optional frame
)
740 "Change font-related attributes of FACE to those of FONT (a string).
741 FRAME nil or not specified means change face on all frames.
742 This sets the attributes `:family', `:width', `:height', `:weight',
743 and `:slant'. When called interactively, prompt for the face and font."
744 (interactive (read-face-and-attribute :font
))
745 (set-face-attribute face frame
:font font
))
748 ;; Implementation note: Emulating gray background colors with a
749 ;; stipple pattern is now part of the face realization process, and is
750 ;; done in C depending on the frame on which the face is realized.
752 (defun set-face-background (face color
&optional frame
)
753 "Change the background color of face FACE to COLOR (a string).
754 FRAME nil or not specified means change face on all frames.
755 COLOR can be a system-defined color name (see `list-colors-display')
756 or a hex spec of the form #RRGGBB.
757 When called interactively, prompts for the face and color."
758 (interactive (read-face-and-attribute :background
))
759 (set-face-attribute face frame
:background
(or color
'unspecified
)))
762 (defun set-face-foreground (face color
&optional frame
)
763 "Change the foreground color of face FACE to COLOR (a string).
764 FRAME nil or not specified means change face on all frames.
765 COLOR can be a system-defined color name (see `list-colors-display')
766 or a hex spec of the form #RRGGBB.
767 When called interactively, prompts for the face and color."
768 (interactive (read-face-and-attribute :foreground
))
769 (set-face-attribute face frame
:foreground
(or color
'unspecified
)))
772 (defun set-face-stipple (face stipple
&optional frame
)
773 "Change the stipple pixmap of face FACE to STIPPLE.
774 FRAME nil or not specified means change face on all frames.
775 STIPPLE should be a string, the name of a file of pixmap data.
776 The directories listed in the `x-bitmap-file-path' variable are searched.
778 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
779 where WIDTH and HEIGHT are the size in pixels,
780 and DATA is a string, containing the raw bits of the bitmap."
781 (interactive (read-face-and-attribute :stipple
))
782 (set-face-attribute face frame
:stipple
(or stipple
'unspecified
)))
785 (defun set-face-underline-p (face underline
&optional frame
)
786 "Specify whether face FACE is underlined.
787 UNDERLINE nil means FACE explicitly doesn't underline.
788 UNDERLINE non-nil means FACE explicitly does underlining
789 with the same of the foreground color.
790 If UNDERLINE is a string, underline with the color named UNDERLINE.
791 FRAME nil or not specified means change face on all frames.
792 Use `set-face-attribute' to ``unspecify'' underlining."
794 (let ((list (read-face-and-attribute :underline
)))
795 (list (car list
) (eq (car (cdr list
)) t
))))
796 (set-face-attribute face frame
:underline underline
))
798 (define-obsolete-function-alias 'set-face-underline
799 'set-face-underline-p
"22.1")
802 (defun set-face-inverse-video-p (face inverse-video-p
&optional frame
)
803 "Specify whether face FACE is in inverse video.
804 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
805 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
806 FRAME nil or not specified means change face on all frames.
807 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
809 (let ((list (read-face-and-attribute :inverse-video
)))
810 (list (car list
) (eq (car (cdr list
)) t
))))
811 (set-face-attribute face frame
:inverse-video inverse-video-p
))
814 (defun set-face-bold-p (face bold-p
&optional frame
)
815 "Specify whether face FACE is bold.
816 BOLD-P non-nil means FACE should explicitly display bold.
817 BOLD-P nil means FACE should explicitly display non-bold.
818 FRAME nil or not specified means change face on all frames.
819 Use `set-face-attribute' or `modify-face' for finer control."
821 (make-face-unbold face frame
)
822 (make-face-bold face frame
)))
825 (defun set-face-italic-p (face italic-p
&optional frame
)
826 "Specify whether face FACE is italic.
827 ITALIC-P non-nil means FACE should explicitly display italic.
828 ITALIC-P nil means FACE should explicitly display non-italic.
829 FRAME nil or not specified means change face on all frames.
830 Use `set-face-attribute' or `modify-face' for finer control."
832 (make-face-unitalic face frame
)
833 (make-face-italic face frame
)))
836 (defalias 'set-face-background-pixmap
'set-face-stipple
)
839 (defun invert-face (face &optional frame
)
840 "Swap the foreground and background colors of FACE.
841 If FRAME is omitted or nil, it means change face on all frames.
842 If FACE specifies neither foreground nor background color,
843 set its foreground and background to the background and foreground
844 of the default face. Value is FACE."
845 (interactive (list (read-face-name "Invert face")))
846 (let ((fg (face-attribute face
:foreground frame
))
847 (bg (face-attribute face
:background frame
)))
848 (if (not (and (eq fg
'unspecified
) (eq bg
'unspecified
)))
849 (set-face-attribute face frame
:foreground bg
:background fg
)
850 (set-face-attribute face frame
852 (face-attribute 'default
:background frame
)
854 (face-attribute 'default
:foreground frame
))))
858 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
859 ;;; Interactively modifying faces.
860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
862 (defun read-face-name (prompt &optional string-describing-default multiple
)
863 "Read a face, defaulting to the face or faces on the char after point.
864 If it has the property `read-face-name', that overrides the `face' property.
865 PROMPT should be a string that describes what the caller will do with the face;
866 it should not end in a space.
867 STRING-DESCRIBING-DEFAULT should describe what default the caller will use if
868 the user just types RET; you can omit it.
869 If MULTIPLE is non-nil, return a list of faces (possibly only one).
870 Otherwise, return a single face."
871 (let ((faceprop (or (get-char-property (point) 'read-face-name
)
872 (get-char-property (point) 'face
)))
876 ;; Try to get a face name from the buffer.
877 (if (memq (intern-soft (thing-at-point 'symbol
)) (face-list))
878 (setq faces
(list (intern-soft (thing-at-point 'symbol
)))))
879 ;; Add the named faces that the `face' property uses.
880 (if (and (listp faceprop
)
881 ;; Don't treat an attribute spec as a list of faces.
882 (not (keywordp (car faceprop
)))
883 (not (memq (car faceprop
) '(foreground-color background-color
))))
887 (if (symbolp faceprop
)
888 (push faceprop faces
)))
891 ;; Build up the completion tables.
892 (mapatoms (lambda (s)
894 (if (get s
'face-alias
)
895 (push (symbol-name s
) aliasfaces
)
896 (push (symbol-name s
) nonaliasfaces
)))))
898 ;; If we only want one, and the default is more than one,
899 ;; discard the unwanted ones now.
902 (setq faces
(list (car faces
)))))
906 (completing-read-multiple
907 (if (or faces string-describing-default
)
908 (format "%s (default %s): " prompt
909 (if faces
(mapconcat 'symbol-name faces
",")
910 string-describing-default
))
911 (format "%s: " prompt
))
912 (complete-in-turn nonaliasfaces aliasfaces
)
914 (if faces
(mapconcat 'symbol-name faces
","))))
915 ;; Canonicalize the output.
917 (cond ((or (equal input
"") (equal input
'("")))
920 (mapcar 'intern
(split-string input
", *" t
)))
922 (mapcar 'intern input
))
924 ;; Return either a list of faces or just one face.
930 (defun face-valid-attribute-values (attribute &optional frame
)
931 "Return valid values for face attribute ATTRIBUTE.
932 The optional argument FRAME is used to determine available fonts
933 and colors. If it is nil or not specified, the selected frame is
934 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
935 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
940 (if (window-system frame
)
941 (mapcar #'(lambda (x) (cons (car x
) (car x
)))
942 (x-font-family-list))
943 ;; Only one font on TTYs.
944 (list (cons "default" "default"))))
945 ((:width
:weight
:slant
:inverse-video
)
946 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
947 (internal-lisp-face-attribute-values attribute
)))
948 ((:underline
:overline
:strike-through
:box
)
949 (if (window-system frame
)
950 (nconc (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
951 (internal-lisp-face-attribute-values attribute
))
952 (mapcar #'(lambda (c) (cons c c
))
953 (defined-colors frame
)))
954 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
955 (internal-lisp-face-attribute-values attribute
))))
956 ((:foreground
:background
)
957 (mapcar #'(lambda (c) (cons c c
))
958 (defined-colors frame
)))
962 (and (memq (window-system frame
) '(x w32 mac
))
965 (mapcar (lambda (dir)
966 (and (file-readable-p dir
)
967 (file-directory-p dir
)
968 (directory-files dir
)))
969 x-bitmap-file-path
)))))
971 (cons '("none" . nil
)
972 (mapcar #'(lambda (c) (cons (symbol-name c
) c
))
975 (error "Internal error")))))
976 (if (and (listp valid
) (not (memq attribute
'(:inherit
))))
977 (nconc (list (cons "unspecified" 'unspecified
)) valid
)
981 (defvar face-attribute-name-alist
982 '((:family .
"font family")
983 (:width .
"character set width")
984 (:height .
"height in 1/10 pt")
987 (:underline .
"underline")
988 (:overline .
"overline")
989 (:strike-through .
"strike-through")
991 (:inverse-video .
"inverse-video display")
992 (:foreground .
"foreground color")
993 (:background .
"background color")
994 (:stipple .
"background stipple")
995 (:inherit .
"inheritance"))
996 "An alist of descriptive names for face attributes.
997 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
998 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
999 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1002 (defun face-descriptive-attribute-name (attribute)
1003 "Return a descriptive name for ATTRIBUTE."
1004 (cdr (assq attribute face-attribute-name-alist
)))
1007 (defun face-read-string (face default name
&optional completion-alist
)
1008 "Interactively read a face attribute string value.
1009 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1010 default string to return if no new value is entered. NAME is a
1011 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1012 alist of valid values, if non-nil.
1014 Entering nothing accepts the default string DEFAULT.
1015 Value is the new attribute value."
1016 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1017 ;; each word in a string separately).
1018 (setq name
(concat (upcase (substring name
0 1)) (substring name
1)))
1019 (let* ((completion-ignore-case t
)
1020 (value (completing-read
1022 (format "%s for face `%s' (default %s): "
1024 (format "%s for face `%s': " name face
))
1025 completion-alist nil nil nil nil default
)))
1026 (if (equal value
"") default value
)))
1029 (defun face-read-integer (face default name
)
1030 "Interactively read an integer face attribute value.
1031 FACE is the face whose attribute is read. DEFAULT is the default
1032 value to return if no new value is entered. NAME is a descriptive
1033 name of the attribute for prompting. Value is the new attribute value."
1035 (face-read-string face
1036 (format "%s" default
)
1038 (list (cons "unspecified" 'unspecified
)))))
1039 (cond ((equal new-value
"unspecified")
1041 ((member new-value
'("unspecified-fg" "unspecified-bg"))
1044 (string-to-number new-value
)))))
1047 (defun read-face-attribute (face attribute
&optional frame
)
1048 "Interactively read a new value for FACE's ATTRIBUTE.
1049 Optional argument FRAME nil or unspecified means read an attribute value
1050 of a global face. Value is the new attribute value."
1051 (let* ((old-value (face-attribute face attribute frame
))
1052 (attribute-name (face-descriptive-attribute-name attribute
))
1053 (valid (face-valid-attribute-values attribute frame
))
1055 ;; Represent complex attribute values as strings by printing them
1056 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1057 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1059 (when (and (or (eq attribute
:stipple
)
1060 (eq attribute
:box
))
1061 (or (consp old-value
)
1062 (vectorp old-value
)))
1063 (setq old-value
(prin1-to-string old-value
)))
1064 (cond ((listp valid
)
1066 (or (car (rassoc old-value valid
))
1067 (format "%s" old-value
))))
1069 (face-read-string face default attribute-name valid
))
1070 (if (equal new-value default
)
1071 ;; Nothing changed, so don't bother with all the stuff
1072 ;; below. In particular, this avoids a non-tty color
1073 ;; from being canonicalized for a tty when the user
1074 ;; just uses the default.
1075 (setq new-value old-value
)
1076 ;; Terminal frames can support colors that don't appear
1077 ;; explicitly in VALID, using color approximation code
1078 ;; in tty-colors.el.
1079 (when (and (memq attribute
'(:foreground
:background
))
1080 (not (memq (window-system frame
) '(x w32 mac
)))
1081 (not (member new-value
1083 "unspecified-fg" "unspecified-bg"))))
1084 (setq new-value
(car (tty-color-desc new-value frame
))))
1085 (when (assoc new-value valid
)
1086 (setq new-value
(cdr (assoc new-value valid
)))))))
1087 ((eq valid
'integerp
)
1088 (setq new-value
(face-read-integer face old-value attribute-name
)))
1089 (t (error "Internal error")))
1090 ;; Convert stipple and box value text we read back to a list or
1091 ;; vector if it looks like one. This makes the assumption that a
1092 ;; pixmap file name won't start with an open-paren.
1093 (when (and (or (eq attribute
:stipple
)
1094 (eq attribute
:box
))
1096 (string-match "^[[(]" new-value
))
1097 (setq new-value
(read new-value
)))
1101 (defun read-face-font (face &optional frame
)
1102 "Read the name of a font for FACE on FRAME.
1103 If optional argument FRAME is nil or omitted, use the selected frame."
1104 (let ((completion-ignore-case t
))
1105 (completing-read (format "Set font attributes of face `%s' from font: " face
)
1106 (x-list-fonts "*" nil frame
))))
1109 (defun read-all-face-attributes (face &optional frame
)
1110 "Interactively read all attributes for FACE.
1111 If optional argument FRAME is nil or omitted, use the selected frame.
1112 Value is a property list of attribute names and new values."
1114 (dolist (attribute face-attribute-name-alist result
)
1115 (setq result
(cons (car attribute
)
1116 (cons (read-face-attribute face
(car attribute
) frame
)
1119 (defun modify-face (&optional face foreground background stipple
1120 bold-p italic-p underline inverse-p frame
)
1121 "Modify attributes of faces interactively.
1122 If optional argument FRAME is nil or omitted, modify the face used
1123 for newly created frame, i.e. the global face.
1124 For non-interactive use, `set-face-attribute' is preferred.
1125 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1126 and the face and its settings are obtained by querying the user."
1129 (set-face-attribute face frame
1130 :foreground
(or foreground
'unspecified
)
1131 :background
(or background
'unspecified
)
1135 :underline underline
1136 :inverse-video inverse-p
)
1137 (setq face
(read-face-name "Modify face"))
1138 (apply #'set-face-attribute face frame
1139 (read-all-face-attributes face frame
))))
1141 (defun read-face-and-attribute (attribute &optional frame
)
1142 "Read face name and face attribute value.
1143 ATTRIBUTE is the attribute whose new value is read.
1144 FRAME nil or unspecified means read attribute value of global face.
1145 Value is a list (FACE NEW-VALUE) where FACE is the face read
1146 \(a symbol), and NEW-VALUE is value read."
1147 (cond ((eq attribute
:font
)
1148 (let* ((prompt "Set font-related attributes of face")
1149 (face (read-face-name prompt
))
1150 (font (read-face-font face frame
)))
1153 (let* ((attribute-name (face-descriptive-attribute-name attribute
))
1154 (prompt (format "Set %s of face" attribute-name
))
1155 (face (read-face-name prompt
))
1156 (new-value (read-face-attribute face attribute frame
)))
1157 (list face new-value
)))))
1161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1165 (defvar list-faces-sample-text
1166 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1167 "*Text string to display as the sample text for `list-faces-display'.")
1170 ;; The name list-faces would be more consistent, but let's avoid a
1171 ;; conflict with Lucid, which uses that name differently.
1173 (defvar help-xref-stack
)
1174 (defun list-faces-display (&optional regexp
)
1175 "List all faces, using the same sample text in each.
1176 The sample text is a string that comes from the variable
1177 `list-faces-sample-text'.
1179 If REGEXP is non-nil, list only those faces with names matching
1180 this regular expression. When called interactively with a prefix
1181 arg, prompt for a regular expression."
1182 (interactive (list (and current-prefix-arg
1183 (read-string "List faces matching regexp: "))))
1184 (let ((all-faces (zerop (length regexp
)))
1185 (frame (selected-frame))
1188 disp-frame window face-name
)
1189 ;; We filter and take the max length in one pass
1193 (let ((s (symbol-name f
)))
1194 (when (or all-faces
(string-match regexp s
))
1195 (setq max-length
(max (length s
) max-length
))
1197 (sort (face-list) #'string-lessp
))))
1199 (error "No faces matching \"%s\"" regexp
))
1200 (setq max-length
(1+ max-length
)
1201 line-format
(format "%%-%ds" max-length
))
1202 (with-help-window "*Faces*"
1204 (set-buffer standard-output
)
1205 (setq truncate-lines t
)
1207 (substitute-command-keys
1210 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1211 "\\[help-follow] on a face name to customize it\n"
1212 "or on its sample text for a description of the face.\n\n")))
1213 (setq help-xref-stack nil
)
1214 (dolist (face faces
)
1215 (setq face-name
(symbol-name face
))
1216 (insert (format line-format face-name
))
1217 ;; Hyperlink to a customization buffer for the face. Using
1218 ;; the help xref mechanism may not be the best way.
1221 (search-backward face-name
)
1222 (setq help-xref-stack-item
`(list-faces-display ,regexp
))
1223 (help-xref-button 0 'help-customize-face face
)))
1225 (line-beg (line-beginning-position)))
1226 (insert list-faces-sample-text
)
1227 ;; Hyperlink to a help buffer for the face.
1230 (search-backward list-faces-sample-text
)
1231 (help-xref-button 0 'help-face face
)))
1233 (put-text-property beg
(1- (point)) 'face face
)
1234 ;; Make all face commands default to the proper face
1235 ;; anywhere in the line.
1236 (put-text-property line-beg
(1- (point)) 'read-face-name face
)
1237 ;; If the sample text has multiple lines, line up all of them.
1241 (insert-char ?\s max-length
)
1243 (goto-char (point-min))))
1244 ;; If the *Faces* buffer appears in a different frame,
1245 ;; copy all the face definitions from FRAME,
1246 ;; so that the display will reflect the frame that was selected.
1247 (setq window
(get-buffer-window (get-buffer "*Faces*") t
))
1248 (setq disp-frame
(if window
(window-frame window
)
1249 (car (frame-list))))
1250 (or (eq frame disp-frame
)
1251 (let ((faces (face-list)))
1253 (copy-face (car faces
) (car faces
) frame disp-frame
)
1254 (setq faces
(cdr faces
)))))))
1257 (defun describe-face (face &optional frame
)
1258 "Display the properties of face FACE on FRAME.
1259 Interactively, FACE defaults to the faces of the character after point
1260 and FRAME defaults to the selected frame.
1262 If the optional argument FRAME is given, report on face FACE in that frame.
1263 If FRAME is t, report on the defaults for face FACE (for new frames).
1264 If FRAME is omitted or nil, use the selected frame."
1265 (interactive (list (read-face-name "Describe face" "= `default' face" t
)))
1266 (let* ((attrs '((:family .
"Family")
1268 (:height .
"Height")
1269 (:weight .
"Weight")
1271 (:foreground .
"Foreground")
1272 (:background .
"Background")
1273 (:underline .
"Underline")
1274 (:overline .
"Overline")
1275 (:strike-through .
"Strike-through")
1277 (:inverse-video .
"Inverse")
1278 (:stipple .
"Stipple")
1279 (:font .
"Font or fontset")
1280 (:inherit .
"Inherit")))
1281 (max-width (apply #'max
(mapcar #'(lambda (x) (length (cdr x
)))
1283 (help-setup-xref (list #'describe-face face
) (interactive-p))
1285 (setq face
'default
))
1286 (if (not (listp face
))
1287 (setq face
(list face
)))
1288 (with-help-window (help-buffer)
1290 (set-buffer standard-output
)
1292 (if (stringp f
) (setq f
(intern f
)))
1293 (insert "Face: " (symbol-name f
))
1295 (insert " undefined face.\n")
1296 (let ((customize-label "customize this face")
1298 (insert (concat " (" (propertize "sample" 'font-lock-face f
) ")"))
1299 (princ (concat " (" customize-label
")\n"))
1300 (insert "Documentation: "
1301 (or (face-documentation f
)
1302 "Not documented as a face.")
1304 (with-current-buffer standard-output
1307 (concat "\\(" customize-label
"\\)") nil t
)
1308 (help-xref-button 1 'help-customize-face f
)))
1309 ;; The next 4 sexps are copied from describe-function-1
1311 (setq file-name
(symbol-file f
'defface
))
1312 (setq file-name
(describe-simplify-lib-file-name file-name
))
1314 (princ "Defined in `")
1317 ;; Make a hyperlink to the library.
1319 (re-search-backward "`\\([^`']+\\)'" nil t
)
1320 (help-xref-button 1 'help-face-def f file-name
))
1325 (let ((attr (face-attribute f
(car a
) frame
)))
1326 (insert (make-string (- max-width
(length (cdr a
))) ?\s
)
1327 (cdr a
) ": " (format "%s" attr
))
1328 (if (and (eq (car a
) :inherit
)
1329 (not (eq attr
'unspecified
)))
1330 ;; Make a hyperlink to the parent face.
1332 (re-search-backward ": \\([^:]+\\)" nil t
)
1333 (help-xref-button 1 'help-face attr
)))
1338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1339 ;;; Face specifications (defface).
1340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1342 ;; Parameter FRAME Is kept for call compatibility to with previous
1343 ;; face implementation.
1345 (defun face-attr-construct (face &optional frame
)
1346 "Return a `defface'-style attribute list for FACE on FRAME.
1347 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1348 face attributes of FACE where ATTRIBUTE is the attribute name and
1349 VALUE is the specified value of that attribute."
1351 (dolist (entry face-attribute-name-alist result
)
1352 (let* ((attribute (car entry
))
1353 (value (face-attribute face attribute
)))
1354 (unless (eq value
'unspecified
)
1355 (setq result
(nconc (list attribute value
) result
)))))))
1358 (defun face-spec-set-match-display (display frame
)
1359 "Non-nil if DISPLAY matches FRAME.
1360 DISPLAY is part of a spec such as can be used in `defface'.
1361 If FRAME is nil, the current FRAME is used."
1362 (let* ((conjuncts display
)
1363 conjunct req options
1364 ;; t means we have succeeded against all the conjuncts in
1365 ;; DISPLAY that have been tested so far.
1367 (if (eq conjuncts t
)
1368 (setq conjuncts nil
))
1369 (while (and conjuncts match
)
1370 (setq conjunct
(car conjuncts
)
1371 conjuncts
(cdr conjuncts
)
1373 options
(cdr conjunct
)
1374 match
(cond ((eq req
'type
)
1375 (or (memq (window-system frame
) options
)
1376 ;; FIXME: This should be revisited to use
1377 ;; display-graphic-p, provided that the
1378 ;; color selection depends on the number
1379 ;; of supported colors, and all defface's
1380 ;; are changed to look at number of colors
1381 ;; instead of (type graphic) etc.
1382 (and (null (window-system frame
))
1383 (memq 'tty options
))
1384 (and (memq 'motif options
)
1386 (and (memq 'gtk options
)
1388 (and (memq 'lucid options
)
1389 (featurep 'x-toolkit
)
1390 (not (featurep 'motif
))
1391 (not (featurep 'gtk
)))
1392 (and (memq 'x-toolkit options
)
1393 (featurep 'x-toolkit
))))
1394 ((eq req
'min-colors
)
1395 (>= (display-color-cells frame
) (car options
)))
1397 (memq (frame-parameter frame
'display-type
) options
))
1398 ((eq req
'background
)
1399 (memq (frame-parameter frame
'background-mode
)
1402 (display-supports-face-attributes-p options frame
))
1403 (t (error "Unknown req `%S' with options `%S'"
1408 (defun face-spec-choose (spec &optional frame
)
1409 "Choose the proper attributes for FRAME, out of SPEC.
1410 If SPEC is nil, return nil."
1412 (setq frame
(selected-frame)))
1416 (let* ((entry (pop tail
))
1417 (display (car entry
))
1420 ;; Get the attributes as actually specified by this alternative.
1422 (if (null (cdr attrs
)) ;; was (listp (car attrs))
1423 ;; Old-style entry, the attribute list is the
1428 ;; If the condition is `default', that sets the default
1429 ;; for following conditions.
1430 (if (eq display
'default
)
1431 (setq defaults thisval
)
1432 ;; Otherwise, if it matches, use it.
1433 (when (face-spec-set-match-display display frame
)
1434 (setq result thisval
)
1436 (if defaults
(append result defaults
) result
)))
1439 (defun face-spec-reset-face (face &optional frame
)
1440 "Reset all attributes of FACE on FRAME to unspecified."
1441 (let ((attrs face-attribute-name-alist
))
1443 (let ((attr-and-name (car attrs
)))
1444 (set-face-attribute face frame
(car attr-and-name
) 'unspecified
))
1445 (setq attrs
(cdr attrs
)))))
1448 (defun face-spec-set (face spec
&optional for-defface
)
1449 "Set FACE's face spec, which controls its appearance, to SPEC>
1450 If FOR-DEFFACE is t, set the base spec, the one that `defface'
1451 and Custom set. (In that case, the caller must put it in the
1452 appropriate property, because that depends on the caller.)
1453 If FOR-DEFFACE is nil, set the overriding spec (and store it
1454 in the `face-override-spec' property of FACE).
1456 The appearance of FACE is controlled by the base spec,
1457 by any custom theme specs on top of that, and by the
1458 the overriding spec on top of all the rest.
1460 FOR-DEFFACE can also be a frame, in which case we set the
1461 frame-specific attributes of FACE for that frame based on SPEC.
1462 That usage is deprecated.
1464 See `defface' for information about the format and meaning of SPEC."
1465 (if (framep for-defface
)
1466 ;; Handle the deprecated case where third arg is a frame.
1467 (face-spec-set-2 face for-defface spec
)
1469 ;; When we reset the face based on its custom spec, then it is
1470 ;; unmodified as far as Custom is concerned.
1471 (put (or (get face
'face-alias
) face
) 'face-modified nil
)
1472 ;; When we change a face based on a spec from outside custom,
1473 ;; record it for future frames.
1474 (put (or (get face
'face-alias
) face
) 'face-override-spec spec
))
1475 ;;; RMS 29 dec 2007: Perhaps this code should be reinstated.
1476 ;;; That depends on whether the overriding spec
1477 ;;; or the default face attributes
1478 ;;; should take priority.
1479 ;;; ;; Clear all the new-frame default attributes for this face.
1480 ;;; ;; face-spec-reset-face won't do it right.
1481 ;;; (let ((facevec (cdr (assq face face-new-frame-defaults))))
1482 ;;; (dotimes (i (length facevec))
1484 ;;; (aset facevec i 'unspecified))))
1485 ;; Reset each frame according to the rules implied by all its specs.
1486 (dolist (frame (frame-list))
1487 (face-spec-recalc face frame
))))
1489 (defun face-spec-recalc (face frame
)
1490 "Reset the face attributes of FACE on FRAME according to its specs.
1491 This applies the defface/custom spec first, then the custom theme specs,
1492 then the override spec."
1493 (face-spec-reset-face face frame
)
1494 (let ((face-sym (or (get face
'face-alias
) face
)))
1495 (face-spec-set-2 face frame
1496 (face-user-default-spec face
))
1497 (let ((theme-faces (reverse (get face-sym
'theme-face
))))
1498 (dolist (spec theme-faces
)
1499 (face-spec-set-2 face frame
(cadr spec
))))
1500 (face-spec-set-2 face frame
(get face-sym
'face-override-spec
))))
1502 (defun face-spec-set-2 (face frame spec
)
1503 "Set the face attributes of FACE on FRAME according to SPEC."
1504 (let* ((attrs (face-spec-choose spec frame
)))
1506 (let ((attribute (car attrs
))
1507 (value (car (cdr attrs
))))
1508 ;; Support some old-style attribute names and values.
1510 (:bold
(setq attribute
:weight value
(if value
'bold
'normal
)))
1511 (:italic
(setq attribute
:slant value
(if value
'italic
'normal
)))
1512 ((:foreground
:background
)
1513 ;; Compatibility with 20.x. Some bogus face specs seem to
1514 ;; exist containing things like `:foreground nil'.
1515 (if (null value
) (setq value
'unspecified
)))
1516 (t (unless (assq attribute face-x-resources
)
1517 (setq attribute nil
))))
1519 (set-face-attribute face frame attribute value
)))
1520 (setq attrs
(cdr (cdr attrs
))))))
1522 (defun face-attr-match-p (face attrs
&optional frame
)
1523 "Return t if attributes of FACE match values in plist ATTRS.
1524 Optional parameter FRAME is the frame whose definition of FACE
1525 is used. If nil or omitted, use the selected frame."
1527 (setq frame
(selected-frame)))
1528 (let ((list face-attribute-name-alist
)
1530 (while (and match
(not (null list
)))
1531 (let* ((attr (car (car list
)))
1533 (if (plist-member attrs attr
)
1534 (plist-get attrs attr
)
1536 (value-now (face-attribute face attr frame
)))
1537 (setq match
(equal specified-value value-now
))
1538 (setq list
(cdr list
))))
1541 (defun face-spec-match-p (face spec
&optional frame
)
1542 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1543 (face-attr-match-p face
(face-spec-choose spec frame
) frame
))
1545 (defsubst face-default-spec
(face)
1546 "Return the default face-spec for FACE, ignoring any user customization.
1547 If there is no default for FACE, return nil."
1548 (get face
'face-defface-spec
))
1550 (defsubst face-user-default-spec
(face)
1551 "Return the user's customized face-spec for FACE, or the default if none.
1552 If there is neither a user setting nor a default for FACE, return nil."
1553 (or (get face
'customized-face
)
1554 (get face
'saved-face
)
1555 (face-default-spec face
)))
1558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1559 ;;; Frame-type independent color support.
1560 ;;; We keep the old x-* names as aliases for back-compatibility.
1561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1563 (defun defined-colors (&optional frame
)
1564 "Return a list of colors supported for a particular frame.
1565 The argument FRAME specifies which frame to try.
1566 The value may be different for frames on different display types.
1567 If FRAME doesn't support colors, the value is nil.
1568 If FRAME is nil, that stands for the selected frame."
1569 (if (memq (framep (or frame
(selected-frame))) '(x w32 mac
))
1570 (xw-defined-colors frame
)
1571 (mapcar 'car
(tty-color-alist frame
))))
1572 (defalias 'x-defined-colors
'defined-colors
)
1574 (defun color-defined-p (color &optional frame
)
1575 "Return non-nil if color COLOR is supported on frame FRAME.
1576 If FRAME is omitted or nil, use the selected frame.
1577 If COLOR is the symbol `unspecified' or one of the strings
1578 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1579 (if (member color
'(unspecified "unspecified-bg" "unspecified-fg"))
1581 (if (member (framep (or frame
(selected-frame))) '(x w32 mac
))
1582 (xw-color-defined-p color frame
)
1583 (numberp (tty-color-translate color frame
)))))
1584 (defalias 'x-color-defined-p
'color-defined-p
)
1586 (defun color-values (color &optional frame
)
1587 "Return a description of the color named COLOR on frame FRAME.
1588 The value is a list of integer RGB values--(RED GREEN BLUE).
1589 These values appear to range from 0 to 65280 or 65535, depending
1590 on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
1591 If FRAME is omitted or nil, use the selected frame.
1592 If FRAME cannot display COLOR, the value is nil.
1593 If COLOR is the symbol `unspecified' or one of the strings
1594 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1595 (if (member color
'(unspecified "unspecified-fg" "unspecified-bg"))
1597 (if (memq (framep (or frame
(selected-frame))) '(x w32 mac
))
1598 (xw-color-values color frame
)
1599 (tty-color-values color frame
))))
1600 (defalias 'x-color-values
'color-values
)
1602 (defun display-color-p (&optional display
)
1603 "Return t if DISPLAY supports color.
1604 The optional argument DISPLAY specifies which display to ask about.
1605 DISPLAY should be either a frame or a display name (a string).
1606 If omitted or nil, that stands for the selected frame's display."
1607 (if (memq (framep-on-display display
) '(x w32 mac
))
1608 (xw-display-color-p display
)
1609 (tty-display-color-p display
)))
1610 (defalias 'x-display-color-p
'display-color-p
)
1612 (defun display-grayscale-p (&optional display
)
1613 "Return non-nil if frames on DISPLAY can display shades of gray."
1614 (let ((frame-type (framep-on-display display
)))
1616 ((memq frame-type
'(x w32 mac
))
1617 (x-display-grayscale-p display
))
1619 (> (tty-color-gray-shades display
) 2)))))
1621 (defun read-color (&optional prompt convert-to-RGB-p allow-empty-name-p msg-p
)
1622 "Read a color name or RGB hex value: #RRRRGGGGBBBB.
1623 Completion is available for color names, but not for RGB hex strings.
1624 If the user inputs an RGB hex string, it must have the form
1625 #XXXXXXXXXXXX or XXXXXXXXXXXX, where each X is a hex digit. The
1626 number of Xs must be a multiple of 3, with the same number of Xs for
1627 each of red, green, and blue. The order is red, green, blue.
1629 In addition to standard color names and RGB hex values, the following
1630 are available as color candidates. In each case, the corresponding
1633 * `foreground at point' - foreground under the cursor
1634 * `background at point' - background under the cursor
1636 Checks input to be sure it represents a valid color. If not, raises
1637 an error (but see exception for empty input with non-nil
1638 ALLOW-EMPTY-NAME-P).
1640 Optional arg PROMPT is the prompt; if nil, uses a default prompt.
1642 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, converts
1643 an input color name to an RGB hex string. Returns the RGB hex string.
1645 Optional arg ALLOW-EMPTY-NAME-P controls what happens if the user
1646 enters an empty color name (that is, just hits `RET'). If non-nil,
1647 then returns an empty color name, \"\". If nil, then raises an error.
1648 Programs must test for \"\" if ALLOW-EMPTY-NAME-P is non-nil. They
1649 can then perform an appropriate action in case of empty input.
1651 Interactively, or with optional arg MSG-P non-nil, echoes the color in
1653 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1654 (let* ((completion-ignore-case t
)
1655 (colors (append '("foreground at point" "background at point")
1657 (color (completing-read (or prompt
"Color (name or #R+G+B+): ")
1660 (cond ((string= "foreground at point" color
)
1661 (setq color
(foreground-color-at-point)))
1662 ((string= "background at point" color
)
1663 (setq color
(background-color-at-point))))
1667 (string-match "^#?\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color
))
1668 (if (and allow-empty-name-p
(string= "" color
))
1670 (when (and hex-string
(not (eq (aref color
0) ?
#)))
1671 (setq color
(concat "#" color
))) ; No #; add it.
1673 (when (or (string= "" color
) (not (test-completion color colors
)))
1674 (error "No such color: %S" color
))
1675 (when convert-to-RGB-p
1676 (let ((components (x-color-values color
)))
1677 (unless components
(error "No such color: %S" color
))
1678 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color
)
1679 (setq color
(format "#%04X%04X%04X"
1680 (logand 65535 (nth 0 components
))
1681 (logand 65535 (nth 1 components
))
1682 (logand 65535 (nth 2 components
))))))))
1683 (when msg-p
(message "Color: `%s'" color
))
1686 ;; Commented out because I decided it is better to include the
1687 ;; duplicates in read-color's completion list.
1689 ;; (defun defined-colors-without-duplicates ()
1690 ;; "Return the list of defined colors, without the no-space versions.
1691 ;; For each color name, we keep the variant that DOES have spaces."
1692 ;; (let ((result (copy-sequence (defined-colors)))
1695 ;; (dolist (this result)
1696 ;; (if (string-match " " this)
1697 ;; (push (replace-regexp-in-string " " ""
1699 ;; to-be-rejected)))
1700 ;; (dolist (elt to-be-rejected)
1701 ;; (let ((as-found (car (member-ignore-case elt result))))
1702 ;; (setq result (delete as-found result)))))
1705 (defun face-at-point ()
1706 "Return the face of the character after point.
1707 If it has more than one face, return the first one.
1708 Return nil if it has no specified face."
1709 (let* ((faceprop (or (get-char-property (point) 'read-face-name
)
1710 (get-char-property (point) 'face
)
1712 (face (cond ((symbolp faceprop
) faceprop
)
1713 ;; List of faces (don't treat an attribute spec).
1714 ;; Just use the first face.
1715 ((and (consp faceprop
) (not (keywordp (car faceprop
)))
1716 (not (memq (car faceprop
)
1717 '(foreground-color background-color
))))
1719 (t nil
)))) ; Invalid face value.
1720 (if (facep face
) face nil
)))
1722 (defun foreground-color-at-point ()
1723 "Return the foreground color of the character after point."
1724 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1725 ;; Need also pick up any face properties that are not associated with named faces.
1726 (let ((face (or (face-at-point)
1727 (get-char-property (point) 'read-face-name
)
1728 (get-char-property (point) 'face
))))
1729 (cond ((and face
(symbolp face
))
1730 (let ((value (face-foreground face nil
'default
)))
1731 (if (member value
'("unspecified-fg" "unspecified-bg"))
1735 (cond ((memq 'foreground-color face
) (cdr (memq 'foreground-color face
)))
1736 ((memq ':foreground face
) (cadr (memq ':foreground face
)))))
1737 (t nil
)))) ; Invalid face value.
1739 (defun background-color-at-point ()
1740 "Return the background color of the character after point."
1741 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1742 ;; Need also pick up any face properties that are not associated with named faces.
1743 (let ((face (or (face-at-point)
1744 (get-char-property (point) 'read-face-name
)
1745 (get-char-property (point) 'face
))))
1746 (cond ((and face
(symbolp face
))
1747 (let ((value (face-background face nil
'default
)))
1748 (if (member value
'("unspecified-fg" "unspecified-bg"))
1752 (cond ((memq 'background-color face
) (cdr (memq 'background-color face
)))
1753 ((memq ':background face
) (cadr (memq ':background face
)))))
1754 (t nil
)))) ; Invalid face value.
1756 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1757 ;;; Background mode.
1758 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1760 (defcustom frame-background-mode nil
1761 "*The brightness of the background.
1762 Set this to the symbol `dark' if your background color is dark,
1763 `light' if your background is light, or nil (automatic by default)
1764 if you want Emacs to examine the brightness for you. Don't set this
1765 variable with `setq'; this won't have the expected effect."
1767 :set
#'(lambda (var value
)
1768 (set-default var value
)
1769 (mapc 'frame-set-background-mode
(frame-list)))
1770 :initialize
'custom-initialize-changed
1771 :type
'(choice (const dark
)
1773 (const :tag
"automatic" nil
)))
1776 (defun frame-set-background-mode (frame)
1777 "Set up display-dependent faces on FRAME.
1778 Display-dependent faces are those which have different definitions
1779 according to the `background-mode' and `display-type' frame parameters."
1781 (and (window-system frame
)
1782 (x-get-resource "backgroundMode" "BackgroundMode")))
1783 (bg-color (frame-parameter frame
'background-color
))
1784 (terminal-bg-mode (terminal-parameter frame
'background-mode
))
1785 (tty-type (tty-type frame
))
1787 (cond (frame-background-mode)
1789 (intern (downcase bg-resource
)))
1791 ((and (null (window-system frame
))
1792 ;; Unspecified frame background color can only
1794 (member bg-color
'(nil unspecified
"unspecified-bg")))
1795 ;; There is no way to determine the background mode
1796 ;; automatically, so we make a guess based on the
1799 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1803 ((equal bg-color
"unspecified-fg") ; inverted colors
1805 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1809 ((>= (apply '+ (color-values bg-color frame
))
1810 ;; Just looking at the screen, colors whose
1811 ;; values add up to .6 of the white total
1812 ;; still look dark to me.
1813 (* (apply '+ (color-values "white" frame
)) .6))
1817 (cond ((null (window-system frame
))
1818 (if (tty-display-color-p frame
) 'color
'mono
))
1819 ((display-color-p frame
)
1821 ((x-display-grayscale-p frame
)
1825 (frame-parameter frame
'background-mode
))
1827 (frame-parameter frame
'display-type
)))
1829 (unless (and (eq bg-mode old-bg-mode
) (eq display-type old-display-type
))
1830 (let ((locally-modified-faces nil
))
1831 ;; Before modifying the frame parameters, we collect a list of
1832 ;; faces that don't match what their face-spec says they should
1833 ;; look like; we then avoid changing these faces below.
1834 ;; These are the faces whose attributes were modified on FRAME.
1835 ;; We use a negative list on the assumption that most faces will
1836 ;; be unmodified, so we can avoid consing in the common case.
1837 (dolist (face (face-list))
1838 (and (not (get face
'face-override-spec
))
1839 (not (face-spec-match-p face
1840 (face-user-default-spec face
)
1842 (push face locally-modified-faces
)))
1843 ;; Now change to the new frame parameters
1844 (modify-frame-parameters frame
1845 (list (cons 'background-mode bg-mode
)
1846 (cons 'display-type display-type
)))
1847 ;; For all named faces, choose face specs matching the new frame
1848 ;; parameters, unless they have been locally modified.
1849 (dolist (face (face-list))
1850 (unless (memq face locally-modified-faces
)
1851 (face-spec-recalc face frame
)))))))
1854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1856 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1858 (defun x-handle-named-frame-geometry (parameters)
1859 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1860 Value is the new parameter list."
1861 (let* ((name (or (cdr (assq 'name parameters
))
1862 (cdr (assq 'name default-frame-alist
))))
1863 (x-resource-name name
)
1864 (res-geometry (if name
(x-get-resource "geometry" "Geometry"))))
1866 (let ((parsed (x-parse-geometry res-geometry
)))
1867 ;; If the resource specifies a position, call the position
1868 ;; and size "user-specified".
1869 (when (or (assq 'top parsed
)
1870 (assq 'left parsed
))
1871 (setq parsed
(append '((user-position . t
) (user-size . t
)) parsed
)))
1872 ;; Put the geometry parameters at the end. Copy
1873 ;; default-frame-alist so that they go after it.
1874 (setq parameters
(append parameters default-frame-alist parsed
))))
1878 (defun x-handle-reverse-video (frame parameters
)
1879 "Handle the reverse-video frame parameter and X resource.
1880 `x-create-frame' does not handle this one."
1881 (when (cdr (or (assq 'reverse parameters
)
1882 (assq 'reverse default-frame-alist
)
1883 (let ((resource (x-get-resource "reverseVideo"
1886 (cons nil
(member (downcase resource
)
1887 '("on" "true")))))))
1888 (let* ((params (frame-parameters frame
))
1889 (bg (cdr (assq 'foreground-color params
)))
1890 (fg (cdr (assq 'background-color params
))))
1891 (modify-frame-parameters frame
1892 (list (cons 'foreground-color fg
)
1893 (cons 'background-color bg
)))
1894 (if (equal bg
(cdr (assq 'border-color params
)))
1895 (modify-frame-parameters frame
1896 (list (cons 'border-color fg
))))
1897 (if (equal bg
(cdr (assq 'mouse-color params
)))
1898 (modify-frame-parameters frame
1899 (list (cons 'mouse-color fg
))))
1900 (if (equal bg
(cdr (assq 'cursor-color params
)))
1901 (modify-frame-parameters frame
1902 (list (cons 'cursor-color fg
)))))))
1905 (defun x-create-frame-with-faces (&optional parameters
)
1906 "Create a frame from optional frame parameters PARAMETERS.
1907 Parameters not specified by PARAMETERS are taken from
1908 `default-frame-alist'. If PARAMETERS specify a frame name,
1909 handle X geometry resources for that name. If either PARAMETERS
1910 or `default-frame-alist' contains a `reverse' parameter, or
1911 the X resource ``reverseVideo'' is present, handle that.
1912 Value is the new frame created."
1913 (setq parameters
(x-handle-named-frame-geometry parameters
))
1914 (let ((visibility-spec (assq 'visibility parameters
))
1915 (frame (x-create-frame `((visibility . nil
) .
,parameters
)))
1919 (x-setup-function-keys frame
)
1920 (x-handle-reverse-video frame parameters
)
1921 (frame-set-background-mode frame
)
1922 (face-set-after-frame-default frame
)
1923 ;; Make sure the tool-bar is ready to be enabled. The
1924 ;; `tool-bar-lines' frame parameter will not take effect
1925 ;; without this call.
1926 (tool-bar-setup frame
)
1927 (if (null visibility-spec
)
1928 (make-frame-visible frame
)
1929 (modify-frame-parameters frame
(list visibility-spec
)))
1932 (delete-frame frame
)))
1935 (defun face-set-after-frame-default (frame)
1936 "Set frame-local faces of FRAME from face specs and resources.
1937 Initialize colors of certain faces from frame parameters."
1938 (unless inhibit-face-set-after-frame-default
1939 (if (face-attribute 'default
:font t
)
1940 (set-face-attribute 'default frame
:font
1941 (face-attribute 'default
:font t
))
1942 (set-face-attribute 'default frame
:family
1943 (face-attribute 'default
:family t
))
1944 (set-face-attribute 'default frame
:height
1945 (face-attribute 'default
:height t
))
1946 (set-face-attribute 'default frame
:slant
1947 (face-attribute 'default
:slant t
))
1948 (set-face-attribute 'default frame
:weight
1949 (face-attribute 'default
:weight t
))
1950 (set-face-attribute 'default frame
:width
1951 (face-attribute 'default
:width t
))))
1952 ;; Find attributes that should be initialized from frame parameters.
1953 (let ((face-params '((foreground-color default
:foreground
)
1954 (background-color default
:background
)
1955 (border-color border
:background
)
1956 (cursor-color cursor
:background
)
1957 (scroll-bar-foreground scroll-bar
:foreground
)
1958 (scroll-bar-background scroll-bar
:background
)
1959 (mouse-color mouse
:background
)))
1961 (dolist (param face-params
)
1962 (let* ((value (frame-parameter frame
(nth 0 param
)))
1963 (face (nth 1 param
))
1964 (attr (nth 2 param
))
1965 (default-value (face-attribute face attr t
)))
1966 ;; Compile a list of face attributes to set, but don't set
1967 ;; them yet. The call to make-face-x-resource-internal,
1968 ;; below, can change frame parameters, and the final set of
1969 ;; frame parameters should be the ones acquired at this step.
1970 (if (eq default-value
'unspecified
)
1971 ;; The face spec does not specify a new-frame value for
1972 ;; this attribute. Check if the existing frame parameter
1975 (push (list face frame attr value
) apply-params
))
1976 ;; The face spec specifies a value for this attribute, to be
1977 ;; applied to the face on all new frames.
1978 (push (list face frame attr default-value
) apply-params
))))
1979 ;; Initialize faces from face specs and X resources. The
1980 ;; condition-case prevents invalid specs from causing frame
1981 ;; creation to fail.
1982 (dolist (face (delq 'default
(face-list)))
1985 (face-spec-recalc face frame
)
1986 (if (memq (window-system frame
) '(x w32 mac
))
1987 (make-face-x-resource-internal face frame
))
1988 (internal-merge-in-global-face face frame
))
1990 ;; Apply the attributes specified by frame parameters. This
1991 ;; rewrites parameters changed by make-face-x-resource-internal
1992 (dolist (param apply-params
)
1993 (apply 'set-face-attribute param
))))
1995 (defun tty-handle-reverse-video (frame parameters
)
1996 "Handle the reverse-video frame parameter for terminal frames."
1997 (when (cdr (or (assq 'reverse parameters
)
1998 (assq 'reverse default-frame-alist
)))
1999 (let* ((params (frame-parameters frame
))
2000 (bg (cdr (assq 'foreground-color params
)))
2001 (fg (cdr (assq 'background-color params
))))
2002 (modify-frame-parameters frame
2003 (list (cons 'foreground-color fg
)
2004 (cons 'background-color bg
)))
2005 (if (equal bg
(cdr (assq 'mouse-color params
)))
2006 (modify-frame-parameters frame
2007 (list (cons 'mouse-color fg
))))
2008 (if (equal bg
(cdr (assq 'cursor-color params
)))
2009 (modify-frame-parameters frame
2010 (list (cons 'cursor-color fg
)))))))
2013 (defun tty-create-frame-with-faces (&optional parameters
)
2014 "Create a frame from optional frame parameters PARAMETERS.
2015 Parameters not specified by PARAMETERS are taken from
2016 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
2017 contains a `reverse' parameter, handle that. Value is the new frame
2019 (let ((frame (make-terminal-frame parameters
))
2022 (with-selected-frame frame
2023 (tty-handle-reverse-video frame
(frame-parameters frame
))
2025 (unless (terminal-parameter frame
'terminal-initted
)
2026 (set-terminal-parameter frame
'terminal-initted t
)
2027 (set-locale-environment nil frame
)
2028 (tty-run-terminal-initialization frame
))
2029 (frame-set-background-mode frame
)
2030 (face-set-after-frame-default frame
)
2033 (delete-frame frame
)))
2036 (defun tty-find-type (pred type
)
2037 "Return the longest prefix of TYPE to which PRED returns non-nil.
2038 TYPE should be a tty type name such as \"xterm-16color\".
2040 The function tries only those prefixes that are followed by a
2041 dash or underscore in the original type name, like \"xterm\" in
2045 (not (funcall pred type
)))
2046 ;; Strip off last hyphen and what follows, then try again
2048 (if (setq hyphend
(string-match "[-_][^-_]+$" type
))
2049 (substring type
0 hyphend
)
2053 (defun tty-run-terminal-initialization (frame &optional type
)
2054 "Run the special initialization code for the terminal type of FRAME.
2055 The optional TYPE parameter may be used to override the autodetected
2056 terminal type to a different value."
2057 (setq type
(or type
(tty-type frame
)))
2058 ;; Load library for our terminal type.
2059 ;; User init file can set term-file-prefix to nil to prevent this.
2060 (with-selected-frame frame
2061 (unless (null term-file-prefix
)
2062 (let* (term-init-func)
2063 ;; First, load the terminal initialization file, if it is
2064 ;; available and it hasn't been loaded already.
2065 (tty-find-type #'(lambda (type)
2066 (let ((file (locate-library (concat term-file-prefix type
))))
2068 (or (assoc file load-history
)
2071 ;; Next, try to find a matching initialization function, and call it.
2072 (tty-find-type #'(lambda (type)
2073 (fboundp (setq term-init-func
2074 (intern (concat "terminal-init-" type
)))))
2076 (when (fboundp term-init-func
)
2077 (funcall term-init-func
))
2078 (set-terminal-parameter frame
'terminal-initted term-init-func
)))))
2080 ;; Called from C function init_display to initialize faces of the
2081 ;; dumped terminal frame on startup.
2083 (defun tty-set-up-initial-frame-faces ()
2084 (let ((frame (selected-frame)))
2085 (frame-set-background-mode frame
)
2086 (face-set-after-frame-default frame
)))
2091 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2092 ;;; Compatiblity with 20.2
2093 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2095 ;; Update a frame's faces when we change its default font.
2097 (defalias 'frame-update-faces
'ignore
"")
2098 (make-obsolete 'frame-update-faces
"no longer necessary." "21.1")
2100 ;; Update the colors of FACE, after FRAME's own colors have been
2103 (define-obsolete-function-alias 'frame-update-face-colors
2104 'frame-set-background-mode
"21.1")
2107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2111 (defgroup basic-faces nil
2112 "The standard faces of Emacs."
2117 "Basic default face."
2118 :group
'basic-faces
)
2123 :group
'basic-faces
)
2126 '((((supports :slant italic
))
2128 (((supports :underline t
))
2131 ;; default to italic, even it doesn't appear to be supported,
2132 ;; because in some cases the display engine will do it's own
2133 ;; workaround (to `dim' on ttys)
2135 "Basic italic face."
2136 :group
'basic-faces
)
2138 (defface bold-italic
2139 '((t :weight bold
:slant italic
))
2140 "Basic bold-italic face."
2141 :group
'basic-faces
)
2144 '((((supports :underline t
))
2146 (((supports :weight bold
))
2149 "Basic underlined face."
2150 :group
'basic-faces
)
2152 (defface fixed-pitch
2153 '((t :family
"courier"))
2154 "The basic fixed-pitch face."
2155 :group
'basic-faces
)
2157 (defface variable-pitch
2158 '((t :family
"helv"))
2159 "The basic variable-pitch face."
2160 :group
'basic-faces
)
2163 '((((class color grayscale
) (min-colors 88) (background light
))
2164 :foreground
"grey50")
2165 (((class color grayscale
) (min-colors 88) (background dark
))
2166 :foreground
"grey70")
2167 (((class color
) (min-colors 8) (background light
))
2168 :foreground
"green")
2169 (((class color
) (min-colors 8) (background dark
))
2170 :foreground
"yellow"))
2171 "Basic face for shadowed text."
2176 '((((class color
) (min-colors 88) (background light
))
2177 :foreground
"blue1" :underline t
)
2178 (((class color
) (background light
))
2179 :foreground
"blue" :underline t
)
2180 (((class color
) (min-colors 88) (background dark
))
2181 :foreground
"cyan1" :underline t
)
2182 (((class color
) (background dark
))
2183 :foreground
"cyan" :underline t
)
2184 (t :inherit underline
))
2185 "Basic face for unvisited links."
2189 (defface link-visited
2190 '((default :inherit link
)
2191 (((class color
) (background light
)) :foreground
"magenta4")
2192 (((class color
) (background dark
)) :foreground
"violet"))
2193 "Basic face for visited links."
2198 '((((class color
) (min-colors 88) (background light
))
2199 :background
"darkseagreen2")
2200 (((class color
) (min-colors 88) (background dark
))
2201 :background
"darkolivegreen")
2202 (((class color
) (min-colors 16) (background light
))
2203 :background
"darkseagreen2")
2204 (((class color
) (min-colors 16) (background dark
))
2205 :background
"darkolivegreen")
2206 (((class color
) (min-colors 8))
2207 :background
"green" :foreground
"black")
2208 (t :inverse-video t
))
2209 "Basic face for highlighting."
2210 :group
'basic-faces
)
2213 '((((class color
) (min-colors 88) (background dark
))
2214 :background
"blue3")
2215 (((class color
) (min-colors 88) (background light
))
2216 :background
"lightgoldenrod2")
2217 (((class color
) (min-colors 16) (background dark
))
2218 :background
"blue3")
2219 (((class color
) (min-colors 16) (background light
))
2220 :background
"lightgoldenrod2")
2221 (((class color
) (min-colors 8))
2222 :background
"blue" :foreground
"white")
2223 (((type tty
) (class mono
))
2225 (t :background
"gray"))
2226 "Basic face for highlighting the region."
2228 :group
'basic-faces
)
2230 (defface secondary-selection
2231 '((((class color
) (min-colors 88) (background light
))
2232 :background
"yellow1")
2233 (((class color
) (min-colors 88) (background dark
))
2234 :background
"SkyBlue4")
2235 (((class color
) (min-colors 16) (background light
))
2236 :background
"yellow")
2237 (((class color
) (min-colors 16) (background dark
))
2238 :background
"SkyBlue4")
2239 (((class color
) (min-colors 8))
2240 :background
"cyan" :foreground
"black")
2241 (t :inverse-video t
))
2242 "Basic face for displaying the secondary selection."
2243 :group
'basic-faces
)
2245 (defface trailing-whitespace
2246 '((((class color
) (background light
))
2248 (((class color
) (background dark
))
2250 (t :inverse-video t
))
2251 "Basic face for highlighting trailing whitespace."
2253 :group
'whitespace-faces
; like `show-trailing-whitespace'
2254 :group
'basic-faces
)
2256 (defface escape-glyph
2257 '((((background dark
)) :foreground
"cyan")
2258 ;; See the comment in minibuffer-prompt for
2259 ;; the reason not to use blue on MS-DOS.
2260 (((type pc
)) :foreground
"magenta")
2261 ;; red4 is too dark, but some say blue is too loud.
2262 ;; brown seems to work ok. -- rms.
2263 (t :foreground
"brown"))
2264 "Face for characters displayed as sequences using `^' or `\\'."
2268 (defface nobreak-space
2269 '((((class color
) (min-colors 88)) :inherit escape-glyph
:underline t
)
2270 (((class color
) (min-colors 8)) :background
"magenta")
2271 (t :inverse-video t
))
2272 "Face for displaying nobreak space."
2276 (defgroup mode-line-faces nil
2277 "Faces used in the mode line."
2283 '((((class color
) (min-colors 88))
2284 :box
(:line-width -
1 :style released-button
)
2285 :background
"grey75" :foreground
"black")
2288 "Basic mode line face for selected window."
2290 :group
'mode-line-faces
2291 :group
'basic-faces
)
2293 (defface mode-line-inactive
2296 (((class color
) (min-colors 88) (background light
))
2298 :box
(:line-width -
1 :color
"grey75" :style nil
)
2299 :foreground
"grey20" :background
"grey90")
2300 (((class color
) (min-colors 88) (background dark
) )
2302 :box
(:line-width -
1 :color
"grey40" :style nil
)
2303 :foreground
"grey80" :background
"grey30"))
2304 "Basic mode line face for non-selected windows."
2306 :group
'mode-line-faces
2307 :group
'basic-faces
)
2309 (defface mode-line-highlight
2310 '((((class color
) (min-colors 88))
2311 :box
(:line-width
2 :color
"grey40" :style released-button
))
2313 :inherit highlight
))
2314 "Basic mode line face for highlighting."
2316 :group
'mode-line-faces
2317 :group
'basic-faces
)
2319 (defface mode-line-buffer-id
2320 '((t (:weight bold
)))
2321 "Face used for buffer identification parts of the mode line."
2323 :group
'mode-line-faces
2324 :group
'basic-faces
)
2326 ;; Make `modeline' an alias for `mode-line', for compatibility.
2327 (put 'modeline
'face-alias
'mode-line
)
2328 (put 'modeline-inactive
'face-alias
'mode-line-inactive
)
2329 (put 'modeline-highlight
'face-alias
'mode-line-highlight
)
2330 (put 'modeline-buffer-id
'face-alias
'mode-line-buffer-id
)
2332 (defface header-line
2336 ;; This used to be `:inverse-video t', but that doesn't look very
2337 ;; good when combined with inverse-video mode-lines and multiple
2338 ;; windows. Underlining looks better, and is more consistent with
2339 ;; the window-system face variants, which deemphasize the
2340 ;; header-line in relation to the mode-line face. If a terminal
2341 ;; can't underline, then the header-line will end up without any
2342 ;; highlighting; this may be too confusing in general, although it
2343 ;; happens to look good with the only current use of header-lines,
2344 ;; the info browser. XXX
2345 :inverse-video nil
;Override the value inherited from mode-line.
2347 (((class color grayscale
) (background light
))
2348 :background
"grey90" :foreground
"grey20"
2350 (((class color grayscale
) (background dark
))
2351 :background
"grey20" :foreground
"grey90"
2353 (((class mono
) (background light
))
2354 :background
"white" :foreground
"black"
2358 (((class mono
) (background dark
))
2359 :background
"black" :foreground
"white"
2363 "Basic header-line face."
2365 :group
'basic-faces
)
2367 (defface vertical-border
2368 '((((type tty
)) :inherit mode-line-inactive
))
2369 "Face used for vertical window dividers on ttys."
2371 :group
'basic-faces
)
2373 (defface minibuffer-prompt
2374 '((((background dark
)) :foreground
"cyan")
2375 ;; Don't use blue because many users of the MS-DOS port customize
2376 ;; their foreground color to be blue.
2377 (((type pc
)) :foreground
"magenta")
2378 (t :foreground
"medium blue"))
2379 "Face for minibuffer prompts.
2380 By default, Emacs automatically adds this face to the value of
2381 `minibuffer-prompt-properties', which is a list of text properties
2382 used to display the prompt text."
2384 :group
'basic-faces
)
2386 (setq minibuffer-prompt-properties
2387 (append minibuffer-prompt-properties
(list 'face
'minibuffer-prompt
)))
2390 '((((class color
) (background light
))
2391 :background
"grey95")
2392 (((class color
) (background dark
))
2393 :background
"grey10")
2395 :background
"gray"))
2396 "Basic face for the fringes to the left and right of windows under X."
2399 :group
'basic-faces
)
2401 (defface scroll-bar
'((t nil
))
2402 "Basic face for the scroll bar colors under X."
2405 :group
'basic-faces
)
2407 (defface border
'((t nil
))
2408 "Basic face for the frame border under X."
2411 :group
'basic-faces
)
2413 (defface cursor
'((t nil
))
2414 "Basic face for the cursor color under X.
2415 Note: Other faces cannot inherit from the cursor face."
2418 :group
'basic-faces
)
2420 (put 'cursor
'face-no-inherit t
)
2422 (defface mouse
'((t nil
))
2423 "Basic face for the mouse color under X."
2426 :group
'basic-faces
)
2430 :box
(:line-width
1 :style released-button
)
2431 :foreground
"black")
2432 (((type x w32 mac
) (class color
))
2433 :background
"grey75")
2434 (((type x
) (class mono
))
2435 :background
"grey"))
2436 "Basic tool-bar face."
2438 :group
'basic-faces
)
2447 "Basic face for the font and colors of the menu bar and popup menus."
2450 :group
'basic-faces
)
2453 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2454 ;;; Manipulating font names.
2455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2457 ;; This is here for compatibilty with Emacs 20.2. For example,
2458 ;; international/fontset.el uses x-resolve-font-name. The following
2459 ;; functions are not used in the face implementation itself.
2461 (defvar x-font-regexp nil
)
2462 (defvar x-font-regexp-head nil
)
2463 (defvar x-font-regexp-weight nil
)
2464 (defvar x-font-regexp-slant nil
)
2466 (defconst x-font-regexp-weight-subnum
1)
2467 (defconst x-font-regexp-slant-subnum
2)
2468 (defconst x-font-regexp-swidth-subnum
3)
2469 (defconst x-font-regexp-adstyle-subnum
4)
2471 ;;; Regexps matching font names in "Host Portable Character Representation."
2476 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2477 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2478 (weight\? "\\([^-]*\\)") ; 1
2479 (slant "\\([ior]\\)") ; 2
2480 ; (slant\? "\\([ior?*]?\\)") ; 2
2481 (slant\? "\\([^-]?\\)") ; 2
2482 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2483 (swidth "\\([^-]*\\)") ; 3
2484 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2485 (adstyle "\\([^-]*\\)") ; 4
2486 (pixelsize "[0-9]+")
2487 (pointsize "[0-9][0-9]+")
2488 (resx "[0-9][0-9]+")
2489 (resy "[0-9][0-9]+")
2496 (concat "\\`\\*?[-?*]"
2497 foundry - family - weight
\? - slant
\? - swidth - adstyle -
2498 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2499 registry - encoding
"\\*?\\'"
2501 (setq x-font-regexp-head
2502 (concat "\\`[-?*]" foundry - family - weight
\? - slant
\?
2503 "\\([-*?]\\|\\'\\)"))
2504 (setq x-font-regexp-slant
(concat - slant -
))
2505 (setq x-font-regexp-weight
(concat - weight -
))
2509 (defun x-resolve-font-name (pattern &optional face frame
)
2510 "Return a font name matching PATTERN.
2511 All wildcards in PATTERN are instantiated.
2512 If PATTERN is nil, return the name of the frame's base font, which never
2514 Given optional arguments FACE and FRAME, return a font which is
2515 also the same size as FACE on FRAME, or fail."
2517 (setq face
(face-name face
)))
2521 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2522 (let ((fonts (x-list-fonts pattern face frame
1)))
2525 (if (string-match "\\*" pattern
)
2526 (if (null (face-font face
))
2527 (error "No matching fonts are the same height as the frame default font")
2528 (error "No matching fonts are the same height as face `%s'" face
))
2529 (if (null (face-font face
))
2530 (error "Height of font `%s' doesn't match the frame default font"
2532 (error "Height of font `%s' doesn't match face `%s'"
2534 (error "No fonts match `%s'" pattern
)))
2536 (cdr (assq 'font
(frame-parameters (selected-frame))))))
2539 (defun x-frob-font-weight (font which
)
2540 (let ((case-fold-search t
))
2541 (cond ((string-match x-font-regexp font
)
2542 (concat (substring font
0
2543 (match-beginning x-font-regexp-weight-subnum
))
2545 (substring font
(match-end x-font-regexp-weight-subnum
)
2546 (match-beginning x-font-regexp-adstyle-subnum
))
2547 ;; Replace the ADD_STYLE_NAME field with *
2548 ;; because the info in it may not be the same
2549 ;; for related fonts.
2551 (substring font
(match-end x-font-regexp-adstyle-subnum
))))
2552 ((string-match x-font-regexp-head font
)
2553 (concat (substring font
0 (match-beginning 1)) which
2554 (substring font
(match-end 1))))
2555 ((string-match x-font-regexp-weight font
)
2556 (concat (substring font
0 (match-beginning 1)) which
2557 (substring font
(match-end 1)))))))
2558 (make-obsolete 'x-frob-font-weight
'make-face-...
"21.1")
2560 (defun x-frob-font-slant (font which
)
2561 (let ((case-fold-search t
))
2562 (cond ((string-match x-font-regexp font
)
2563 (concat (substring font
0
2564 (match-beginning x-font-regexp-slant-subnum
))
2566 (substring font
(match-end x-font-regexp-slant-subnum
)
2567 (match-beginning x-font-regexp-adstyle-subnum
))
2568 ;; Replace the ADD_STYLE_NAME field with *
2569 ;; because the info in it may not be the same
2570 ;; for related fonts.
2572 (substring font
(match-end x-font-regexp-adstyle-subnum
))))
2573 ((string-match x-font-regexp-head font
)
2574 (concat (substring font
0 (match-beginning 2)) which
2575 (substring font
(match-end 2))))
2576 ((string-match x-font-regexp-slant font
)
2577 (concat (substring font
0 (match-beginning 1)) which
2578 (substring font
(match-end 1)))))))
2579 (make-obsolete 'x-frob-font-slant
'make-face-...
"21.1")
2581 ;; These aliases are here so that we don't get warnings about obsolete
2582 ;; functions from the byte compiler.
2583 (defalias 'internal-frob-font-weight
'x-frob-font-weight
)
2584 (defalias 'internal-frob-font-slant
'x-frob-font-slant
)
2586 (defun x-make-font-bold (font)
2587 "Given an X font specification, make a bold version of it.
2588 If that can't be done, return nil."
2589 (internal-frob-font-weight font
"bold"))
2590 (make-obsolete 'x-make-font-bold
'make-face-bold
"21.1")
2592 (defun x-make-font-demibold (font)
2593 "Given an X font specification, make a demibold version of it.
2594 If that can't be done, return nil."
2595 (internal-frob-font-weight font
"demibold"))
2596 (make-obsolete 'x-make-font-demibold
'make-face-bold
"21.1")
2598 (defun x-make-font-unbold (font)
2599 "Given an X font specification, make a non-bold version of it.
2600 If that can't be done, return nil."
2601 (internal-frob-font-weight font
"medium"))
2602 (make-obsolete 'x-make-font-unbold
'make-face-unbold
"21.1")
2604 (defun x-make-font-italic (font)
2605 "Given an X font specification, make an italic version of it.
2606 If that can't be done, return nil."
2607 (internal-frob-font-slant font
"i"))
2608 (make-obsolete 'x-make-font-italic
'make-face-italic
"21.1")
2610 (defun x-make-font-oblique (font) ; you say tomayto...
2611 "Given an X font specification, make an oblique version of it.
2612 If that can't be done, return nil."
2613 (internal-frob-font-slant font
"o"))
2614 (make-obsolete 'x-make-font-oblique
'make-face-italic
"21.1")
2616 (defun x-make-font-unitalic (font)
2617 "Given an X font specification, make a non-italic version of it.
2618 If that can't be done, return nil."
2619 (internal-frob-font-slant font
"r"))
2620 (make-obsolete 'x-make-font-unitalic
'make-face-unitalic
"21.1")
2622 (defun x-make-font-bold-italic (font)
2623 "Given an X font specification, make a bold and italic version of it.
2624 If that can't be done, return nil."
2625 (and (setq font
(internal-frob-font-weight font
"bold"))
2626 (internal-frob-font-slant font
"i")))
2627 (make-obsolete 'x-make-font-bold-italic
'make-face-bold-italic
"21.1")
2631 ;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
2632 ;;; faces.el ends here