1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992-1996, 1998-2014 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (defcustom term-file-prefix
(purecopy "term/")
29 "If non-nil, Emacs startup performs terminal-specific initialization.
30 It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
32 You may set this variable to nil in your init file if you do not wish
33 the terminal-initialization file to be loaded."
34 :type
'(choice (const :tag
"No terminal-specific initialization" nil
)
35 (string :tag
"Name of directory with term files"))
38 (declare-function xw-defined-colors
"term/common-win" (&optional frame
))
40 (defvar help-xref-stack-item
)
42 (defvar face-name-history nil
43 "History list for some commands that read face names.
44 Maximum length of the history list is determined by the value
45 of `history-length', which see.")
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 (defgroup font-selection nil
53 "Influencing face font selection."
57 (defcustom face-font-selection-order
58 '(:width
:height
:weight
:slant
)
59 "A list specifying how face font selection chooses fonts.
60 Each of the four symbols `:width', `:height', `:weight', and `:slant'
61 must appear once in the list, and the list must not contain any other
62 elements. Font selection first tries to find a best matching font
63 for those face attributes that appear before in the list. For
64 example, if `:slant' appears before `:height', font selection first
65 tries to find a font with a suitable slant, even if this results in
66 a font height that isn't optimal."
67 :tag
"Font selection order"
68 :type
'(list symbol symbol symbol symbol
)
69 :group
'font-selection
70 :set
#'(lambda (symbol value
)
71 (set-default symbol value
)
72 (internal-set-font-selection-order value
)))
75 ;; In the absence of Fontconfig support, Monospace and Sans Serif are
76 ;; unavailable, and we fall back on the courier and helv families,
77 ;; which are generally available.
78 (defcustom face-font-family-alternatives
79 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
80 '(("Monospace" "courier" "fixed")
81 ("courier" "CMU Typewriter Text" "fixed")
82 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
83 ("helv" "helvetica" "arial" "fixed")))
84 "Alist of alternative font family names.
85 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
86 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
88 :tag
"Alternative font families to try"
89 :type
'(repeat (repeat string
))
90 :group
'font-selection
91 :set
#'(lambda (symbol value
)
92 (set-default symbol value
)
93 (internal-set-alternative-font-family-alist value
)))
96 ;; This is defined originally in xfaces.c.
97 (defcustom face-font-registry-alternatives
98 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
100 '(("iso8859-1" "ms-oemlatin")
101 ("gb2312.1980" "gb2312" "gbk" "gb18030")
102 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
103 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
104 ("muletibetan-2" "muletibetan-0"))
105 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
106 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
107 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
108 ("muletibetan-2" "muletibetan-0"))))
109 "Alist of alternative font registry names.
110 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
111 If fonts of registry REGISTRY can be loaded, font selection
112 tries to find a best matching font among all fonts of registry
113 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
114 :tag
"Alternative font registries to try"
115 :type
'(repeat (repeat string
))
117 :group
'font-selection
118 :set
#'(lambda (symbol value
)
119 (set-default symbol value
)
120 (internal-set-alternative-font-registry-alist value
)))
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124 ;;; Creation, copying.
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 "Return a list of all defined faces."
130 (mapcar #'car face-new-frame-defaults
))
132 (defun make-face (face &optional no-init-from-resources
)
133 "Define a new face with name FACE, a symbol.
134 Do not call this directly from Lisp code; use `defface' instead.
136 If NO-INIT-FROM-RESOURCES is non-nil, don't initialize face
137 attributes from X resources. If FACE is already known as a face,
138 leave it unmodified. Return FACE."
139 (interactive (list (read-from-minibuffer
140 "Make face: " nil nil t
'face-name-history
)))
142 ;; Make frame-local faces (this also makes the global one).
143 (dolist (frame (frame-list))
144 (internal-make-lisp-face face frame
))
145 ;; Add the face to the face menu.
146 (when (fboundp 'facemenu-add-new-face
)
147 (facemenu-add-new-face face
))
148 ;; Define frame-local faces for all frames from X resources.
149 (unless no-init-from-resources
150 (make-face-x-resource-internal face
)))
153 (defun make-empty-face (face)
154 "Define a new, empty face with name FACE.
155 Do not call this directly from Lisp code; use `defface' instead."
156 (interactive (list (read-from-minibuffer
157 "Make empty face: " nil nil t
'face-name-history
)))
158 (make-face face
'no-init-from-resources
))
160 (defun copy-face (old-face new-face
&optional frame new-frame
)
161 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
162 This function does not copy face customization data, so NEW-FACE
163 will not be made customizable. Most Lisp code should not call
164 this function; use `defface' with :inherit instead.
166 If NEW-FACE already exists as a face, modify it to be like
167 OLD-FACE. If NEW-FACE doesn't already exist, create it.
169 If the optional argument FRAME is a frame, change NEW-FACE on
170 FRAME only. If FRAME is t, copy the frame-independent default
171 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
172 the defaults as well as the faces on each existing frame.
174 If the optional fourth argument NEW-FRAME is given, copy the
175 information from face OLD-FACE on frame FRAME to NEW-FACE on
176 frame NEW-FRAME. In this case, FRAME must not be nil."
177 (let ((inhibit-quit t
))
181 (error "Copying face %s from all frames to one frame"
183 (make-empty-face new-face
)
184 (dolist (frame (frame-list))
185 (copy-face old-face new-face frame
))
186 (copy-face old-face new-face t
))
187 (make-empty-face new-face
)
188 (internal-copy-lisp-face old-face new-face frame new-frame
))
192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
193 ;;; Predicates, type checks.
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197 "Return non-nil if FACE is a face name; nil otherwise.
198 A face name can be a string or a symbol."
199 (internal-lisp-face-p face
))
202 (defun check-face (face)
203 "Signal an error if FACE doesn't name a face.
206 (error "Not a face: %s" face
))
210 ;; The ID returned is not to be confused with the internally used IDs
211 ;; of realized faces. The ID assigned to Lisp faces is used to
212 ;; support faces in display table entries.
214 (defun face-id (face &optional _frame
)
215 "Return the internal ID of face with name FACE.
216 If FACE is a face-alias, return the ID of the target face.
217 The optional argument FRAME is ignored, since the internal face ID
218 of a face name is the same for all frames."
221 (face-id (get face
'face-alias
))))
223 (defun face-equal (face1 face2
&optional frame
)
224 "Non-nil if faces FACE1 and FACE2 are equal.
225 Faces are considered equal if all their attributes are equal.
226 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
227 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
228 If FRAME is omitted or nil, use the selected frame."
229 (internal-lisp-face-equal-p face1 face2 frame
))
232 (defun face-differs-from-default-p (face &optional frame
)
233 "Return non-nil if FACE displays differently from the default face.
234 If the optional argument FRAME is given, report on face FACE in that frame.
235 If FRAME is t, report on the defaults for face FACE (for new frames).
236 If FRAME is omitted or nil, use the selected frame."
238 (delq :inherit
(mapcar 'car face-attribute-name-alist
)))
240 (while (and attrs
(not differs
))
241 (let* ((attr (pop attrs
))
242 (attr-val (face-attribute face attr frame t
)))
244 (not (eq attr-val
'unspecified
))
245 (display-supports-face-attributes-p (list attr attr-val
)
247 (setq differs attr
))))
251 (defun face-nontrivial-p (face &optional frame
)
252 "True if face FACE has some non-nil attribute.
253 If the optional argument FRAME is given, report on face FACE in that frame.
254 If FRAME is t, report on the defaults for face FACE (for new frames).
255 If FRAME is omitted or nil, use the selected frame."
256 (not (internal-lisp-face-empty-p face frame
)))
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
261 ;;; Setting face attributes from X resources.
262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 (defcustom face-x-resources
267 ;; FIXME; can we purecopy some of the conses too?
269 (cons (purecopy (car (cdr arg
))) (purecopy (cdr (cdr arg
))))))
270 '((:family
(".attributeFamily" .
"Face.AttributeFamily"))
271 (:foundry
(".attributeFoundry" .
"Face.AttributeFoundry"))
272 (:width
(".attributeWidth" .
"Face.AttributeWidth"))
273 (:height
(".attributeHeight" .
"Face.AttributeHeight"))
274 (:weight
(".attributeWeight" .
"Face.AttributeWeight"))
275 (:slant
(".attributeSlant" .
"Face.AttributeSlant"))
276 (:foreground
(".attributeForeground" .
"Face.AttributeForeground"))
278 (".attributeDistantForeground" .
"Face.AttributeDistantForeground"))
279 (:background
(".attributeBackground" .
"Face.AttributeBackground"))
280 (:overline
(".attributeOverline" .
"Face.AttributeOverline"))
281 (:strike-through
(".attributeStrikeThrough" .
"Face.AttributeStrikeThrough"))
282 (:box
(".attributeBox" .
"Face.AttributeBox"))
283 (:underline
(".attributeUnderline" .
"Face.AttributeUnderline"))
284 (:inverse-video
(".attributeInverse" .
"Face.AttributeInverse"))
286 (".attributeStipple" .
"Face.AttributeStipple")
287 (".attributeBackgroundPixmap" .
"Face.AttributeBackgroundPixmap"))
288 (:bold
(".attributeBold" .
"Face.AttributeBold"))
289 (:italic
(".attributeItalic" .
"Face.AttributeItalic"))
290 (:font
(".attributeFont" .
"Face.AttributeFont"))
291 (:inherit
(".attributeInherit" .
"Face.AttributeInherit"))))
292 "List of X resources and classes for face attributes.
293 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
294 the name of a face attribute, and each ENTRY is a cons of the form
295 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
296 X resource class for the attribute."
297 :type
'(repeat (cons symbol
(repeat (cons string string
))))
301 (declare-function internal-face-x-get-resource
"xfaces.c"
302 (resource class
&optional frame
))
304 (declare-function internal-set-lisp-face-attribute-from-resource
"xfaces.c"
305 (face attr value
&optional frame
))
307 (defun set-face-attribute-from-resource (face attribute resource class frame
)
308 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
309 Value is the attribute value specified by the resource, or nil
310 if not present. This function displays a message if the resource
311 specifies an invalid attribute."
312 (let* ((face-name (face-name face
))
313 (value (internal-face-x-get-resource (concat face-name resource
)
317 (internal-set-lisp-face-attribute-from-resource
318 face attribute
(downcase value
) frame
)
320 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
321 face-name frame attribute value
))))
325 (defun set-face-attributes-from-resources (face frame
)
326 "Set attributes of FACE from X resources for FRAME."
327 (when (memq (framep frame
) '(x w32
))
328 (dolist (definition face-x-resources
)
329 (let ((attribute (car definition
)))
330 (dolist (entry (cdr definition
))
331 (set-face-attribute-from-resource face attribute
(car entry
)
332 (cdr entry
) frame
))))))
335 (defun make-face-x-resource-internal (face &optional frame
)
336 "Fill frame-local FACE on FRAME from X resources.
337 FRAME nil or not specified means do it for all frames.
339 If `inhibit-x-resources' is non-nil, this function does nothing."
340 (unless inhibit-x-resources
341 (dolist (frame (if (null frame
) (frame-list) (list frame
)))
342 ;; `x-create-frame' already took care of correctly handling
343 ;; the reverse video case-- do _not_ touch the default face
344 (unless (and (eq face
'default
)
345 (frame-parameter frame
'reverse
))
346 (set-face-attributes-from-resources face frame
)))))
350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
351 ;;; Retrieving face attributes.
352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
354 (defun face-name (face)
355 "Return the name of face FACE."
356 (symbol-name (check-face face
)))
359 (defun face-all-attributes (face &optional frame
)
360 "Return an alist stating the attributes of FACE.
361 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
362 If FRAME is omitted or nil the value describes the default attributes,
363 but if you specify FRAME, the value describes the attributes
365 (mapcar (lambda (pair)
366 (let ((attr (car pair
)))
367 (cons attr
(face-attribute face attr
(or frame t
)))))
368 face-attribute-name-alist
))
370 (defun face-attribute (face attribute
&optional frame inherit
)
371 "Return the value of FACE's ATTRIBUTE on FRAME.
372 If the optional argument FRAME is given, report on face FACE in that frame.
373 If FRAME is t, report on the defaults for face FACE (for new frames).
374 If FRAME is omitted or nil, use the selected frame.
376 If INHERIT is nil, only attributes directly defined by FACE are considered,
377 so the return value may be `unspecified', or a relative value.
378 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
379 faces specified by its `:inherit' attribute; however the return value
380 may still be `unspecified' or relative.
381 If INHERIT is a face or a list of faces, then the result is further merged
382 with that face (or faces), until it becomes specified and absolute.
384 To ensure that the return value is always specified and absolute, use a
385 value of `default' for INHERIT; this will resolve any unspecified or
386 relative values by merging with the `default' face (which is always
387 completely specified)."
388 (let ((value (internal-get-lisp-face-attribute face attribute frame
)))
389 (when (and inherit
(face-attribute-relative-p attribute value
))
390 ;; VALUE is relative, so merge with inherited faces
391 (let ((inh-from (face-attribute face
:inherit frame
)))
392 (unless (or (null inh-from
) (eq inh-from
'unspecified
))
395 (face-attribute-merged-with attribute value inh-from frame
))
396 ;; The `inherit' attribute may point to non existent faces.
400 (face-attribute-relative-p attribute value
))
401 ;; We should merge with INHERIT as well
402 (setq value
(face-attribute-merged-with attribute value inherit frame
)))
405 (defun face-attribute-merged-with (attribute value faces
&optional frame
)
406 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
407 FACES may be either a single face or a list of faces.
408 \[This is an internal function.]"
409 (cond ((not (face-attribute-relative-p attribute value
))
414 (face-attribute-merged-with
416 (face-attribute-merged-with attribute value
(car faces
) frame
)
420 (merge-face-attribute attribute
422 (face-attribute faces attribute frame t
)))))
425 (defmacro face-attribute-specified-or
(value &rest body
)
426 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
427 (let ((temp (make-symbol "value")))
428 `(let ((,temp
,value
))
429 (if (not (eq ,temp
'unspecified
))
433 (defun face-foreground (face &optional frame inherit
)
434 "Return the foreground color name of FACE, or nil if unspecified.
435 If the optional argument FRAME is given, report on face FACE in that frame.
436 If FRAME is t, report on the defaults for face FACE (for new frames).
437 If FRAME is omitted or nil, use the selected frame.
439 If INHERIT is nil, only a foreground color directly defined by FACE is
440 considered, so the return value may be nil.
441 If INHERIT is t, and FACE doesn't define a foreground color, then any
442 foreground color that FACE inherits through its `:inherit' attribute
443 is considered as well; however the return value may still be nil.
444 If INHERIT is a face or a list of faces, then it is used to try to
445 resolve an unspecified foreground color.
447 To ensure that a valid color is always returned, use a value of
448 `default' for INHERIT; this will resolve any unspecified values by
449 merging with the `default' face (which is always completely specified)."
450 (face-attribute-specified-or (face-attribute face
:foreground frame inherit
)
453 (defun face-background (face &optional frame inherit
)
454 "Return the background color name of FACE, or nil if unspecified.
455 If the optional argument FRAME is given, report on face FACE in that frame.
456 If FRAME is t, report on the defaults for face FACE (for new frames).
457 If FRAME is omitted or nil, use the selected frame.
459 If INHERIT is nil, only a background color directly defined by FACE is
460 considered, so the return value may be nil.
461 If INHERIT is t, and FACE doesn't define a background color, then any
462 background color that FACE inherits through its `:inherit' attribute
463 is considered as well; however the return value may still be nil.
464 If INHERIT is a face or a list of faces, then it is used to try to
465 resolve an unspecified background color.
467 To ensure that a valid color is always returned, use a value of
468 `default' for INHERIT; this will resolve any unspecified values by
469 merging with the `default' face (which is always completely specified)."
470 (face-attribute-specified-or (face-attribute face
:background frame inherit
)
473 (defun face-stipple (face &optional frame inherit
)
474 "Return the stipple pixmap name of FACE, or nil if unspecified.
475 If the optional argument FRAME is given, report on face FACE in that frame.
476 If FRAME is t, report on the defaults for face FACE (for new frames).
477 If FRAME is omitted or nil, use the selected frame.
479 If INHERIT is nil, only a stipple directly defined by FACE is
480 considered, so the return value may be nil.
481 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
482 that FACE inherits through its `:inherit' attribute is considered as
483 well; however the return value may still be nil.
484 If INHERIT is a face or a list of faces, then it is used to try to
485 resolve an unspecified stipple.
487 To ensure that a valid stipple or nil is always returned, use a value of
488 `default' for INHERIT; this will resolve any unspecified values by merging
489 with the `default' face (which is always completely specified)."
490 (face-attribute-specified-or (face-attribute face
:stipple frame inherit
)
494 (defalias 'face-background-pixmap
'face-stipple
)
497 (defun face-underline-p (face &optional frame inherit
)
498 "Return non-nil if FACE specifies a non-nil underlining.
499 If the optional argument FRAME is given, report on face FACE in that frame.
500 If FRAME is t, report on the defaults for face FACE (for new frames).
501 If FRAME is omitted or nil, use the selected frame.
502 Optional argument INHERIT is passed to `face-attribute'."
503 (face-attribute-specified-or
504 (face-attribute face
:underline frame inherit
) nil
))
507 (defun face-inverse-video-p (face &optional frame inherit
)
508 "Return non-nil if FACE specifies a non-nil inverse-video.
509 If the optional argument FRAME is given, report on face FACE in that frame.
510 If FRAME is t, report on the defaults for face FACE (for new frames).
511 If FRAME is omitted or nil, use the selected frame.
512 Optional argument INHERIT is passed to `face-attribute'."
513 (eq (face-attribute face
:inverse-video frame inherit
) t
))
516 (defun face-bold-p (face &optional frame inherit
)
517 "Return non-nil if the font of FACE is bold on FRAME.
518 If the optional argument FRAME is given, report on face FACE in that frame.
519 If FRAME is t, report on the defaults for face FACE (for new frames).
520 If FRAME is omitted or nil, use the selected frame.
521 Optional argument INHERIT is passed to `face-attribute'.
522 Use `face-attribute' for finer control."
523 (let ((bold (face-attribute face
:weight frame inherit
)))
524 (memq bold
'(semi-bold bold extra-bold ultra-bold
))))
527 (defun face-italic-p (face &optional frame inherit
)
528 "Return non-nil if the font of FACE is italic on FRAME.
529 If the optional argument FRAME is given, report on face FACE in that frame.
530 If FRAME is t, report on the defaults for face FACE (for new frames).
531 If FRAME is omitted or nil, use the selected frame.
532 Optional argument INHERIT is passed to `face-attribute'.
533 Use `face-attribute' for finer control."
534 (let ((italic (face-attribute face
:slant frame inherit
)))
535 (memq italic
'(italic oblique
))))
539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
540 ;;; Face documentation.
541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
543 (defun face-documentation (face)
544 "Get the documentation string for FACE.
545 If FACE is a face-alias, get the documentation for the target face."
546 (let ((alias (get face
'face-alias
)))
548 (let ((doc (get alias
'face-documentation
)))
549 (format "%s is an alias for the face `%s'.%s" face alias
550 (if doc
(format "\n%s" doc
)
552 (get face
'face-documentation
))))
555 (defun set-face-documentation (face string
)
556 "Set the documentation string for FACE to STRING."
557 ;; Perhaps the text should go in DOC.
558 (put face
'face-documentation
(purecopy string
)))
561 (defalias 'face-doc-string
'face-documentation
)
562 (defalias 'set-face-doc-string
'set-face-documentation
)
566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
567 ;; Setting face attributes.
568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
571 (defun set-face-attribute (face frame
&rest args
)
572 "Set attributes of FACE on FRAME from ARGS.
573 This function overrides the face attributes specified by FACE's
574 face spec. It is mostly intended for internal use only.
576 If FRAME is nil, set the attributes for all existing frames, as
577 well as the default for new frames. If FRAME is t, change the
578 default for new frames only.
580 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a
581 valid face attribute name. All attributes can be set to
582 `unspecified'; this fact is not further mentioned below.
584 The following attributes are recognized:
588 VALUE must be a string specifying the font family
589 \(e.g. \"Monospace\") or a fontset.
593 VALUE must be a string specifying the font foundry,
594 e.g. ``adobe''. If a font foundry is specified, wild-cards `*'
599 VALUE specifies the relative proportionate width of the font to use.
600 It must be one of the symbols `ultra-condensed', `extra-condensed',
601 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
602 `extra-expanded', or `ultra-expanded'.
606 VALUE specifies the relative or absolute height of the font. An
607 absolute height is an integer, and specifies font height in units
608 of 1/10 pt. A relative height is either a floating point number,
609 which specifies a scaling factor for the underlying face height;
610 or a function that takes a single argument (the underlying face
611 height) and returns the new height. Note that for the `default'
612 face, you must specify an absolute height (since there is nothing
613 for it to be relative to).
617 VALUE specifies the weight of the font to use. It must be one of the
618 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
619 `semi-light', `light', `extra-light', `ultra-light'.
623 VALUE specifies the slant of the font to use. It must be one of the
624 symbols `italic', `oblique', `normal', `reverse-italic', or
627 `:foreground', `:background'
629 VALUE must be a color name, a string.
633 VALUE specifies whether characters in FACE should be underlined.
634 If VALUE is t, underline with foreground color of the face.
635 If VALUE is a string, underline with that color.
636 If VALUE is nil, explicitly don't underline.
638 Otherwise, VALUE must be a property list of the form:
640 `(:color COLOR :style STYLE)'.
642 COLOR can be a either a color name string or `foreground-color'.
643 STYLE can be either `line' or `wave'.
644 If a keyword/value pair is missing from the property list, a
645 default value will be used for the value.
646 The default value of COLOR is the foreground color of the face.
647 The default value of STYLE is `line'.
651 VALUE specifies whether characters in FACE should be overlined. If
652 VALUE is t, overline with foreground color of the face. If VALUE is a
653 string, overline with that color. If VALUE is nil, explicitly don't
658 VALUE specifies whether characters in FACE should be drawn with a line
659 striking through them. If VALUE is t, use the foreground color of the
660 face. If VALUE is a string, strike-through with that color. If VALUE
661 is nil, explicitly don't strike through.
665 VALUE specifies whether characters in FACE should have a box drawn
666 around them. If VALUE is nil, explicitly don't draw boxes. If
667 VALUE is t, draw a box with lines of width 1 in the foreground color
668 of the face. If VALUE is a string, the string must be a color name,
669 and the box is drawn in that color with a line width of 1. Otherwise,
670 VALUE must be a property list of the form `(:line-width WIDTH
671 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
672 the property list, a default value will be used for the value, as
673 specified below. WIDTH specifies the width of the lines to draw; it
674 defaults to 1. If WIDTH is negative, the absolute value is the width
675 of the lines, and draw top/bottom lines inside the characters area,
676 not around it. COLOR is the name of the color to draw in, default is
677 the foreground color of the face for simple boxes, and the background
678 color of the face for 3D boxes. STYLE specifies whether a 3D box
679 should be draw. If STYLE is `released-button', draw a box looking
680 like a released 3D button. If STYLE is `pressed-button' draw a box
681 that appears like a pressed button. If STYLE is nil, the default if
682 the property list doesn't contain a style specification, draw a 2D
687 VALUE specifies whether characters in FACE should be displayed in
688 inverse video. VALUE must be one of t or nil.
692 If VALUE is a string, it must be the name of a file of pixmap data.
693 The directories listed in the `x-bitmap-file-path' variable are
694 searched. Alternatively, VALUE may be a list of the form (WIDTH
695 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
696 is a string containing the raw bits of the bitmap. VALUE nil means
697 explicitly don't use a stipple pattern.
699 For convenience, attributes `:family', `:foundry', `:width',
700 `:height', `:weight', and `:slant' may also be set in one step
705 Set font-related face attributes from VALUE. VALUE must be a
706 valid font name or font object. Setting this attribute will also
707 set the `:family', `:foundry', `:width', `:height', `:weight',
708 and `:slant' attributes.
712 VALUE is the name of a face from which to inherit attributes, or
713 a list of face names. Attributes from inherited faces are merged
714 into the face like an underlying face would be, with higher
715 priority than underlying faces.
717 For backward compatibility, the keywords `:bold' and `:italic'
718 can be used to specify weight and slant respectively. This usage
719 is considered obsolete. For these two keywords, the VALUE must
720 be either t or nil. A value of t for `:bold' is equivalent to
721 setting `:weight' to `bold', and a value of t for `:italic' is
722 equivalent to setting `:slant' to `italic'. But if `:weight' is
723 specified in the face spec, `:bold' is ignored, and if `:slant'
724 is specified, `:italic' is ignored."
725 (setq args
(purecopy args
))
726 (let ((where (if (null frame
) 0 frame
))
729 ;; If we set the new-frame defaults, this face is modified outside Custom.
730 (if (memq where
'(0 t
))
731 (put (or (get face
'face-alias
) face
) 'face-modified t
))
732 ;; If family and/or foundry are specified, set it first. Certain
733 ;; face attributes, e.g. :weight semi-condensed, are not supported
734 ;; in every font. See bug#1127.
736 (cond ((eq (car spec
) :family
)
737 (setq family
(cadr spec
)))
738 ((eq (car spec
) :foundry
)
739 (setq foundry
(cadr spec
))))
740 (setq spec
(cddr spec
)))
741 (when (or family foundry
)
742 (when (and (stringp family
)
743 (string-match "\\([^-]*\\)-\\([^-]*\\)" family
))
745 (setq foundry
(match-string 1 family
)))
746 (setq family
(match-string 2 family
)))
747 (when (or (stringp family
) (eq family
'unspecified
))
748 (internal-set-lisp-face-attribute face
:family
(purecopy family
)
750 (when (or (stringp foundry
) (eq foundry
'unspecified
))
751 (internal-set-lisp-face-attribute face
:foundry
(purecopy foundry
)
754 (unless (memq (car args
) '(:family
:foundry
))
755 (internal-set-lisp-face-attribute face
(car args
)
756 (purecopy (cadr args
))
758 (setq args
(cddr args
)))))
760 (defun make-face-bold (face &optional frame _noerror
)
761 "Make the font of FACE be bold, if possible.
762 FRAME nil or not specified means change face on all frames.
763 Argument NOERROR is ignored and retained for compatibility.
764 Use `set-face-attribute' for finer control of the font weight."
765 (interactive (list (read-face-name "Make which face bold"
767 (set-face-attribute face frame
:weight
'bold
))
770 (defun make-face-unbold (face &optional frame _noerror
)
771 "Make the font of FACE be non-bold, if possible.
772 FRAME nil or not specified means change face on all frames.
773 Argument NOERROR is ignored and retained for compatibility."
774 (interactive (list (read-face-name "Make which face non-bold"
776 (set-face-attribute face frame
:weight
'normal
))
779 (defun make-face-italic (face &optional frame _noerror
)
780 "Make the font of FACE be italic, if possible.
781 FRAME nil or not specified means change face on all frames.
782 Argument NOERROR is ignored and retained for compatibility.
783 Use `set-face-attribute' for finer control of the font slant."
784 (interactive (list (read-face-name "Make which face italic"
786 (set-face-attribute face frame
:slant
'italic
))
789 (defun make-face-unitalic (face &optional frame _noerror
)
790 "Make the font of FACE be non-italic, if possible.
791 FRAME nil or not specified means change face on all frames.
792 Argument NOERROR is ignored and retained for compatibility."
793 (interactive (list (read-face-name "Make which face non-italic"
795 (set-face-attribute face frame
:slant
'normal
))
798 (defun make-face-bold-italic (face &optional frame _noerror
)
799 "Make the font of FACE be bold and italic, if possible.
800 FRAME nil or not specified means change face on all frames.
801 Argument NOERROR is ignored and retained for compatibility.
802 Use `set-face-attribute' for finer control of font weight and slant."
803 (interactive (list (read-face-name "Make which face bold-italic"
805 (set-face-attribute face frame
:weight
'bold
:slant
'italic
))
808 (defun set-face-font (face font
&optional frame
)
809 "Change font-related attributes of FACE to those of FONT (a string).
810 FRAME nil or not specified means change face on all frames.
811 This sets the attributes `:family', `:foundry', `:width',
812 `:height', `:weight', and `:slant'. When called interactively,
813 prompt for the face and font."
814 (interactive (read-face-and-attribute :font
))
815 (set-face-attribute face frame
:font font
))
818 ;; Implementation note: Emulating gray background colors with a
819 ;; stipple pattern is now part of the face realization process, and is
820 ;; done in C depending on the frame on which the face is realized.
822 (defun set-face-background (face color
&optional frame
)
823 "Change the background color of face FACE to COLOR (a string).
824 FRAME nil or not specified means change face on all frames.
825 COLOR can be a system-defined color name (see `list-colors-display')
826 or a hex spec of the form #RRGGBB.
827 When called interactively, prompts for the face and color."
828 (interactive (read-face-and-attribute :background
))
829 (set-face-attribute face frame
:background
(or color
'unspecified
)))
832 (defun set-face-foreground (face color
&optional frame
)
833 "Change the foreground color of face FACE to COLOR (a string).
834 FRAME nil or not specified means change face on all frames.
835 COLOR can be a system-defined color name (see `list-colors-display')
836 or a hex spec of the form #RRGGBB.
837 When called interactively, prompts for the face and color."
838 (interactive (read-face-and-attribute :foreground
))
839 (set-face-attribute face frame
:foreground
(or color
'unspecified
)))
842 (defun set-face-stipple (face stipple
&optional frame
)
843 "Change the stipple pixmap of face FACE to STIPPLE.
844 FRAME nil or not specified means change face on all frames.
845 STIPPLE should be a string, the name of a file of pixmap data.
846 The directories listed in the `x-bitmap-file-path' variable are searched.
848 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
849 where WIDTH and HEIGHT are the size in pixels,
850 and DATA is a string, containing the raw bits of the bitmap."
851 (interactive (read-face-and-attribute :stipple
))
852 (set-face-attribute face frame
:stipple
(or stipple
'unspecified
)))
855 (defun set-face-underline (face underline
&optional frame
)
856 "Specify whether face FACE is underlined.
857 UNDERLINE nil means FACE explicitly doesn't underline.
858 UNDERLINE t means FACE underlines with its foreground color.
859 If UNDERLINE is a string, underline with that color.
861 UNDERLINE may also be a list of the form (:color COLOR :style STYLE),
862 where COLOR is a string or `foreground-color', and STYLE is either
863 `line' or `wave'. :color may be omitted, which means to use the
864 foreground color. :style may be omitted, which means to use a line.
866 FRAME nil or not specified means change face on all frames.
867 Use `set-face-attribute' to ``unspecify'' underlining."
868 (interactive (read-face-and-attribute :underline
))
869 (set-face-attribute face frame
:underline underline
))
871 (define-obsolete-function-alias 'set-face-underline-p
872 'set-face-underline
"24.3")
875 (defun set-face-inverse-video (face inverse-video-p
&optional frame
)
876 "Specify whether face FACE is in inverse video.
877 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
878 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
879 FRAME nil or not specified means change face on all frames.
880 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
882 (let ((list (read-face-and-attribute :inverse-video
)))
883 (list (car list
) (if (cadr list
) t
))))
884 (set-face-attribute face frame
:inverse-video inverse-video-p
))
886 (define-obsolete-function-alias 'set-face-inverse-video-p
887 'set-face-inverse-video
"24.4")
889 (defun set-face-bold (face bold-p
&optional frame
)
890 "Specify whether face FACE is bold.
891 BOLD-P non-nil means FACE should explicitly display bold.
892 BOLD-P nil means FACE should explicitly display non-bold.
893 FRAME nil or not specified means change face on all frames.
894 Use `set-face-attribute' or `modify-face' for finer control."
896 (make-face-unbold face frame
)
897 (make-face-bold face frame
)))
899 (define-obsolete-function-alias 'set-face-bold-p
'set-face-bold
"24.4")
902 (defun set-face-italic (face italic-p
&optional frame
)
903 "Specify whether face FACE is italic.
904 ITALIC-P non-nil means FACE should explicitly display italic.
905 ITALIC-P nil means FACE should explicitly display non-italic.
906 FRAME nil or not specified means change face on all frames.
907 Use `set-face-attribute' or `modify-face' for finer control."
909 (make-face-unitalic face frame
)
910 (make-face-italic face frame
)))
912 (define-obsolete-function-alias 'set-face-italic-p
'set-face-italic
"24.4")
915 (defalias 'set-face-background-pixmap
'set-face-stipple
)
918 (defun invert-face (face &optional frame
)
919 "Swap the foreground and background colors of FACE.
920 If FRAME is omitted or nil, it means change face on all frames.
921 If FACE specifies neither foreground nor background color,
922 set its foreground and background to the background and foreground
923 of the default face. Value is FACE."
924 (interactive (list (read-face-name "Invert face" (face-at-point t
))))
925 (let ((fg (face-attribute face
:foreground frame
))
926 (bg (face-attribute face
:background frame
)))
927 (if (not (and (eq fg
'unspecified
) (eq bg
'unspecified
)))
928 (set-face-attribute face frame
:foreground bg
:background fg
)
929 (set-face-attribute face frame
931 (face-attribute 'default
:background frame
)
933 (face-attribute 'default
:foreground frame
))))
937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
938 ;;; Interactively modifying faces.
939 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
941 (defvar crm-separator
) ; from crm.el
943 (defun read-face-name (prompt &optional default multiple
)
944 "Read one or more face names, prompting with PROMPT.
945 PROMPT should not end in a space or a colon.
947 Return DEFAULT if the user enters the empty string.
948 If DEFAULT is non-nil, it should be a single face or a list of face names
949 \(symbols or strings). In the latter case, return the `car' of DEFAULT
950 \(if MULTIPLE is nil, see below), or DEFAULT (if MULTIPLE is non-nil).
952 If MULTIPLE is non-nil, this function uses `completing-read-multiple'
953 to read multiple faces with \"[ \\t]*,[ \\t]*\" as the separator regexp
954 and it returns a list of face names. Otherwise, it reads and returns
956 (if (and default
(not (stringp default
)))
958 (cond ((symbolp default
)
959 (symbol-name default
))
961 (mapconcat (lambda (f) (if (symbolp f
) (symbol-name f
) f
))
963 ;; If we only want one, and the default is more than one,
964 ;; discard the unwanted ones.
965 (t (symbol-name (car default
))))))
966 (when (and default
(not multiple
))
968 ;; For compatibility with `completing-read-multiple' use `crm-separator'
969 ;; to define DEFAULT if MULTIPLE is nil.
970 (setq default
(car (split-string default crm-separator t
))))
972 (let ((prompt (if default
973 (format "%s (default `%s'): " prompt default
)
974 (format "%s: " prompt
)))
975 aliasfaces nonaliasfaces faces
)
976 ;; Build up the completion tables.
977 (mapatoms (lambda (s)
979 (if (get s
'face-alias
)
980 (push (symbol-name s
) aliasfaces
)
981 (push (symbol-name s
) nonaliasfaces
)))))
984 (dolist (face (completing-read-multiple
986 (completion-table-in-turn nonaliasfaces aliasfaces
)
987 nil t nil
'face-name-history default
))
988 ;; Ignore elements that are not faces
989 ;; (for example, because DEFAULT was "all faces")
990 (if (facep face
) (push (intern face
) faces
)))
992 (let ((face (completing-read
994 (completion-table-in-turn nonaliasfaces aliasfaces
)
995 nil t nil
'face-name-history default
)))
996 (if (facep face
) (intern face
))))))
998 ;; Not defined without X, but behind window-system test.
999 (defvar x-bitmap-file-path
)
1001 (defun face-valid-attribute-values (attribute &optional frame
)
1002 "Return valid values for face attribute ATTRIBUTE.
1003 The optional argument FRAME is used to determine available fonts
1004 and colors. If it is nil or not specified, the selected frame is used.
1005 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
1006 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1011 (if (window-system frame
)
1012 (mapcar (lambda (x) (cons x x
))
1014 ;; Only one font on TTYs.
1015 (list (cons "default" "default"))))
1019 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1022 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1025 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1028 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1029 (internal-lisp-face-attribute-values attribute
)))
1030 ((or `:underline
`:overline
`:strike-through
`:box
)
1031 (if (window-system frame
)
1032 (nconc (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1033 (internal-lisp-face-attribute-values attribute
))
1034 (mapcar #'(lambda (c) (cons c c
))
1035 (defined-colors frame
)))
1036 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1037 (internal-lisp-face-attribute-values attribute
))))
1038 ((or `:foreground
`:background
)
1039 (mapcar #'(lambda (c) (cons c c
))
1040 (defined-colors frame
)))
1044 (and (memq (window-system frame
) '(x ns
)) ; No stipple on w32
1047 (mapcar (lambda (dir)
1048 (and (file-readable-p dir
)
1049 (file-directory-p dir
)
1050 (directory-files dir
)))
1051 x-bitmap-file-path
)))))
1053 (cons '("none" . nil
)
1054 (mapcar #'(lambda (c) (cons (symbol-name c
) c
))
1057 (error "Internal error")))))
1058 (if (and (listp valid
) (not (memq attribute
'(:inherit
))))
1059 (nconc (list (cons "unspecified" 'unspecified
)) valid
)
1063 (defconst face-attribute-name-alist
1064 '((:family .
"font family")
1065 (:foundry .
"font foundry")
1066 (:width .
"character set width")
1067 (:height .
"height in 1/10 pt")
1068 (:weight .
"weight")
1070 (:underline .
"underline")
1071 (:overline .
"overline")
1072 (:strike-through .
"strike-through")
1074 (:inverse-video .
"inverse-video display")
1075 (:foreground .
"foreground color")
1076 (:background .
"background color")
1077 (:stipple .
"background stipple")
1078 (:inherit .
"inheritance"))
1079 "An alist of descriptive names for face attributes.
1080 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1081 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1082 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1085 (defun face-descriptive-attribute-name (attribute)
1086 "Return a descriptive name for ATTRIBUTE."
1087 (cdr (assq attribute face-attribute-name-alist
)))
1090 (defun face-read-string (face default name
&optional completion-alist
)
1091 "Interactively read a face attribute string value.
1092 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1093 default string to return if no new value is entered. NAME is a
1094 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1095 alist of valid values, if non-nil.
1097 Entering nothing accepts the default string DEFAULT.
1098 Value is the new attribute value."
1099 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1100 ;; each word in a string separately).
1101 (setq name
(concat (upcase (substring name
0 1)) (substring name
1)))
1102 (let* ((completion-ignore-case t
)
1103 (value (completing-read
1105 (format "%s for face `%s' (default %s): "
1107 (format "%s for face `%s': " name face
))
1108 completion-alist nil nil nil nil default
)))
1109 (if (equal value
"") default value
)))
1112 (defun face-read-integer (face default name
)
1113 "Interactively read an integer face attribute value.
1114 FACE is the face whose attribute is read. DEFAULT is the default
1115 value to return if no new value is entered. NAME is a descriptive
1116 name of the attribute for prompting. Value is the new attribute value."
1118 (face-read-string face
1119 (format "%s" default
)
1121 (list (cons "unspecified" 'unspecified
)))))
1122 (cond ((equal new-value
"unspecified")
1124 ((member new-value
'("unspecified-fg" "unspecified-bg"))
1127 (string-to-number new-value
)))))
1130 ;; FIXME this does allow you to enter the list forms of :box,
1131 ;; :stipple, or :underline, because face-valid-attribute-values does
1132 ;; not return those forms.
1133 (defun read-face-attribute (face attribute
&optional frame
)
1134 "Interactively read a new value for FACE's ATTRIBUTE.
1135 Optional argument FRAME nil or unspecified means read an attribute value
1136 of a global face. Value is the new attribute value."
1137 (let* ((old-value (face-attribute face attribute frame
))
1138 (attribute-name (face-descriptive-attribute-name attribute
))
1139 (valid (face-valid-attribute-values attribute frame
))
1141 ;; Represent complex attribute values as strings by printing them
1142 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1143 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1144 ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'.
1145 (and (memq attribute
'(:box
:stipple
:underline
))
1146 (or (consp old-value
)
1147 (vectorp old-value
))
1148 (setq old-value
(prin1-to-string old-value
)))
1149 (cond ((listp valid
)
1151 (or (car (rassoc old-value valid
))
1152 (format "%s" old-value
))))
1154 (face-read-string face default attribute-name valid
))
1155 (if (equal new-value default
)
1156 ;; Nothing changed, so don't bother with all the stuff
1157 ;; below. In particular, this avoids a non-tty color
1158 ;; from being canonicalized for a tty when the user
1159 ;; just uses the default.
1160 (setq new-value old-value
)
1161 ;; Terminal frames can support colors that don't appear
1162 ;; explicitly in VALID, using color approximation code
1163 ;; in tty-colors.el.
1164 (when (and (memq attribute
'(:foreground
:background
))
1165 (not (memq (window-system frame
) '(x w32 ns
)))
1166 (not (member new-value
1168 "unspecified-fg" "unspecified-bg"))))
1169 (setq new-value
(car (tty-color-desc new-value frame
))))
1170 (when (assoc new-value valid
)
1171 (setq new-value
(cdr (assoc new-value valid
)))))))
1172 ((eq valid
'integerp
)
1173 (setq new-value
(face-read-integer face old-value attribute-name
)))
1174 (t (error "Internal error")))
1175 ;; Convert stipple and box value text we read back to a list or
1176 ;; vector if it looks like one. This makes the assumption that a
1177 ;; pixmap file name won't start with an open-paren.
1178 (and (memq attribute
'(:stipple
:box
:underline
))
1180 (string-match-p "^[[(]" new-value
)
1181 (setq new-value
(read new-value
)))
1184 (declare-function fontset-list
"fontset.c" ())
1185 (declare-function x-list-fonts
"xfaces.c"
1186 (pattern &optional face frame maximum width
))
1188 (defun read-face-font (face &optional frame
)
1189 "Read the name of a font for FACE on FRAME.
1190 If optional argument FRAME is nil or omitted, use the selected frame."
1191 (let ((completion-ignore-case t
))
1192 (completing-read (format "Set font attributes of face `%s' from font: " face
)
1193 (append (fontset-list) (x-list-fonts "*" nil frame
)))))
1196 (defun read-all-face-attributes (face &optional frame
)
1197 "Interactively read all attributes for FACE.
1198 If optional argument FRAME is nil or omitted, use the selected frame.
1199 Value is a property list of attribute names and new values."
1201 (dolist (attribute face-attribute-name-alist result
)
1202 (setq result
(cons (car attribute
)
1203 (cons (read-face-attribute face
(car attribute
) frame
)
1206 (defun modify-face (&optional face foreground background stipple
1207 bold-p italic-p underline inverse-p frame
)
1208 "Modify attributes of faces interactively.
1209 If optional argument FRAME is nil or omitted, modify the face used
1210 for newly created frame, i.e. the global face.
1211 For non-interactive use, `set-face-attribute' is preferred.
1212 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1213 and the face and its settings are obtained by querying the user."
1216 (set-face-attribute face frame
1217 :foreground
(or foreground
'unspecified
)
1218 :background
(or background
'unspecified
)
1220 :weight
(if bold-p
'bold
'normal
)
1221 :slant
(if italic-p
'italic
'normal
)
1222 :underline underline
1223 :inverse-video inverse-p
)
1224 (setq face
(read-face-name "Modify face" (face-at-point t
)))
1225 (apply #'set-face-attribute face frame
1226 (read-all-face-attributes face frame
))))
1228 (defun read-face-and-attribute (attribute &optional frame
)
1229 "Read face name and face attribute value.
1230 ATTRIBUTE is the attribute whose new value is read.
1231 FRAME nil or unspecified means read attribute value of global face.
1232 Value is a list (FACE NEW-VALUE) where FACE is the face read
1233 \(a symbol), and NEW-VALUE is value read."
1234 (cond ((eq attribute
:font
)
1235 (let* ((prompt "Set font-related attributes of face")
1236 (face (read-face-name prompt
(face-at-point t
)))
1237 (font (read-face-font face frame
)))
1240 (let* ((attribute-name (face-descriptive-attribute-name attribute
))
1241 (prompt (format "Set %s of face" attribute-name
))
1242 (face (read-face-name prompt
(face-at-point t
)))
1243 (new-value (read-face-attribute face attribute frame
)))
1244 (list face new-value
)))))
1248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1252 (defconst list-faces-sample-text
1253 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1254 "Text string to display as the sample text for `list-faces-display'.")
1257 ;; The name list-faces would be more consistent, but let's avoid a
1258 ;; conflict with Lucid, which uses that name differently.
1260 (defvar help-xref-stack
)
1261 (defun list-faces-display (&optional regexp
)
1262 "List all faces, using the same sample text in each.
1263 The sample text is a string that comes from the variable
1264 `list-faces-sample-text'.
1266 If REGEXP is non-nil, list only those faces with names matching
1267 this regular expression. When called interactively with a prefix
1268 argument, prompt for a regular expression using `read-regexp'."
1269 (interactive (list (and current-prefix-arg
1270 (read-regexp "List faces matching regexp"))))
1271 (let ((all-faces (zerop (length regexp
)))
1272 (frame (selected-frame))
1275 disp-frame window face-name
)
1276 ;; We filter and take the max length in one pass
1280 (let ((s (symbol-name f
)))
1281 (when (or all-faces
(string-match-p regexp s
))
1282 (setq max-length
(max (length s
) max-length
))
1284 (sort (face-list) #'string-lessp
))))
1286 (error "No faces matching \"%s\"" regexp
))
1287 (setq max-length
(1+ max-length
)
1288 line-format
(format "%%-%ds" max-length
))
1289 (with-help-window "*Faces*"
1290 (with-current-buffer standard-output
1291 (setq truncate-lines t
)
1293 (substitute-command-keys
1295 "\\<help-mode-map>Use "
1296 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1297 "\\[help-follow] on a face name to customize it\n"
1298 "or on its sample text for a description of the face.\n\n")))
1299 (setq help-xref-stack nil
)
1300 (dolist (face faces
)
1301 (setq face-name
(symbol-name face
))
1302 (insert (format line-format face-name
))
1303 ;; Hyperlink to a customization buffer for the face. Using
1304 ;; the help xref mechanism may not be the best way.
1307 (search-backward face-name
)
1308 (setq help-xref-stack-item
`(list-faces-display ,regexp
))
1309 (help-xref-button 0 'help-customize-face face
)))
1311 (line-beg (line-beginning-position)))
1312 (insert list-faces-sample-text
)
1313 ;; Hyperlink to a help buffer for the face.
1316 (search-backward list-faces-sample-text
)
1317 (help-xref-button 0 'help-face face
)))
1319 (put-text-property beg
(1- (point)) 'face face
)
1320 ;; Make all face commands default to the proper face
1321 ;; anywhere in the line.
1322 (put-text-property line-beg
(1- (point)) 'read-face-name face
)
1323 ;; If the sample text has multiple lines, line up all of them.
1327 (insert-char ?\s max-length
)
1329 (goto-char (point-min))))
1330 ;; If the *Faces* buffer appears in a different frame,
1331 ;; copy all the face definitions from FRAME,
1332 ;; so that the display will reflect the frame that was selected.
1333 (setq window
(get-buffer-window (get-buffer "*Faces*") t
))
1334 (setq disp-frame
(if window
(window-frame window
)
1335 (car (frame-list))))
1336 (or (eq frame disp-frame
)
1337 (dolist (face (face-list))
1338 (copy-face face face frame disp-frame
)))))
1341 (defun describe-face (face &optional frame
)
1342 "Display the properties of face FACE on FRAME.
1343 Interactively, FACE defaults to the faces of the character after point
1344 and FRAME defaults to the selected frame.
1346 If the optional argument FRAME is given, report on face FACE in that frame.
1347 If FRAME is t, report on the defaults for face FACE (for new frames).
1348 If FRAME is omitted or nil, use the selected frame."
1349 (interactive (list (read-face-name "Describe face"
1350 (or (face-at-point t
) 'default
)
1352 (let* ((attrs '((:family .
"Family")
1353 (:foundry .
"Foundry")
1355 (:height .
"Height")
1356 (:weight .
"Weight")
1358 (:foreground .
"Foreground")
1359 (:distant-foreground .
"DistantForeground")
1360 (:background .
"Background")
1361 (:underline .
"Underline")
1362 (:overline .
"Overline")
1363 (:strike-through .
"Strike-through")
1365 (:inverse-video .
"Inverse")
1366 (:stipple .
"Stipple")
1368 (:fontset .
"Fontset")
1369 (:inherit .
"Inherit")))
1370 (max-width (apply #'max
(mapcar #'(lambda (x) (length (cdr x
)))
1372 (help-setup-xref (list #'describe-face face
)
1373 (called-interactively-p 'interactive
))
1375 (setq face
'default
))
1376 (if (not (listp face
))
1377 (setq face
(list face
)))
1378 (with-help-window (help-buffer)
1379 (with-current-buffer standard-output
1381 (if (stringp f
) (setq f
(intern f
)))
1382 ;; We may get called for anonymous faces (i.e., faces
1383 ;; expressed using prop-value plists). Those can't be
1384 ;; usefully customized, so ignore them.
1386 (insert "Face: " (symbol-name f
))
1388 (insert " undefined face.\n")
1389 (let ((customize-label "customize this face")
1391 (insert (concat " (" (propertize "sample" 'font-lock-face f
) ")"))
1392 (princ (concat " (" customize-label
")\n"))
1393 ;; FIXME not sure how much of this belongs here, and
1394 ;; how much in `face-documentation'. The latter is
1395 ;; not used much, but needs to return nil for
1396 ;; undocumented faces.
1397 (let ((alias (get f
'face-alias
))
1403 (format "\n %s is an alias for the face `%s'.\n%s"
1405 (if (setq obsolete
(get f
'obsolete-face
))
1406 (format " This face is obsolete%s; use `%s' instead.\n"
1407 (if (stringp obsolete
)
1408 (format " since %s" obsolete
)
1412 (insert "\nDocumentation:\n"
1413 (or (face-documentation face
)
1414 "Not documented as a face.")
1416 (with-current-buffer standard-output
1419 (concat "\\(" customize-label
"\\)") nil t
)
1420 (help-xref-button 1 'help-customize-face f
)))
1421 (setq file-name
(find-lisp-object-file-name f
'defface
))
1423 (princ "Defined in `")
1424 (princ (file-name-nondirectory file-name
))
1426 ;; Make a hyperlink to the library.
1428 (re-search-backward "`\\([^`']+\\)'" nil t
)
1429 (help-xref-button 1 'help-face-def f file-name
))
1434 (let ((attr (face-attribute f
(car a
) frame
)))
1435 (insert (make-string (- max-width
(length (cdr a
))) ?\s
)
1436 (cdr a
) ": " (format "%s" attr
))
1437 (if (and (eq (car a
) :inherit
)
1438 (not (eq attr
'unspecified
)))
1439 ;; Make a hyperlink to the parent face.
1441 (re-search-backward ": \\([^:]+\\)" nil t
)
1442 (help-xref-button 1 'help-face attr
)))
1447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1448 ;;; Face specifications (defface).
1449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1451 ;; Parameter FRAME Is kept for call compatibility to with previous
1452 ;; face implementation.
1454 (defun face-attr-construct (face &optional _frame
)
1455 "Return a `defface'-style attribute list for FACE.
1456 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1457 face attributes of FACE where ATTRIBUTE is the attribute name and
1458 VALUE is the specified value of that attribute.
1459 Argument FRAME is ignored and retained for compatibility."
1461 (dolist (entry face-attribute-name-alist result
)
1462 (let* ((attribute (car entry
))
1463 (value (face-attribute face attribute
)))
1464 (unless (eq value
'unspecified
)
1465 (setq result
(nconc (list attribute value
) result
)))))))
1468 (defun face-spec-set-match-display (display frame
)
1469 "Non-nil if DISPLAY matches FRAME.
1470 DISPLAY is part of a spec such as can be used in `defface'.
1471 If FRAME is nil, the current FRAME is used."
1472 (let* ((conjuncts display
)
1473 conjunct req options
1474 ;; t means we have succeeded against all the conjuncts in
1475 ;; DISPLAY that have been tested so far.
1477 (if (eq conjuncts t
)
1478 (setq conjuncts nil
))
1479 (while (and conjuncts match
)
1480 (setq conjunct
(car conjuncts
)
1481 conjuncts
(cdr conjuncts
)
1483 options
(cdr conjunct
)
1484 match
(cond ((eq req
'type
)
1485 (or (memq (window-system frame
) options
)
1486 (and (memq 'graphic options
)
1487 (memq (window-system frame
) '(x w32 ns
)))
1488 ;; FIXME: This should be revisited to use
1489 ;; display-graphic-p, provided that the
1490 ;; color selection depends on the number
1491 ;; of supported colors, and all defface's
1492 ;; are changed to look at number of colors
1493 ;; instead of (type graphic) etc.
1494 (if (null (window-system frame
))
1496 (or (and (memq 'motif options
)
1498 (and (memq 'gtk options
)
1500 (and (memq 'lucid options
)
1501 (featurep 'x-toolkit
)
1502 (not (featurep 'motif
))
1503 (not (featurep 'gtk
)))
1504 (and (memq 'x-toolkit options
)
1505 (featurep 'x-toolkit
))))))
1506 ((eq req
'min-colors
)
1507 (>= (display-color-cells frame
) (car options
)))
1509 (memq (frame-parameter frame
'display-type
) options
))
1510 ((eq req
'background
)
1511 (memq (frame-parameter frame
'background-mode
)
1514 (display-supports-face-attributes-p options frame
))
1515 (t (error "Unknown req `%S' with options `%S'"
1520 (defun face-spec-choose (spec &optional frame no-match-retval
)
1521 "Return the proper attributes for FRAME, out of SPEC.
1523 If no match is found or SPEC is nil, return nil, unless NO-MATCH-RETVAL
1524 is given, in which case return its value instead."
1526 (setq frame
(selected-frame)))
1528 result defaults match-found
)
1530 (let* ((entry (pop tail
))
1531 (display (car entry
))
1534 ;; Get the attributes as actually specified by this alternative.
1536 (if (null (cdr attrs
)) ;; was (listp (car attrs))
1537 ;; Old-style entry, the attribute list is the
1542 ;; If the condition is `default', that sets the default
1543 ;; for following conditions.
1544 (if (eq display
'default
)
1545 (setq defaults thisval
)
1546 ;; Otherwise, if it matches, use it.
1547 (when (face-spec-set-match-display display frame
)
1548 (setq result thisval
1551 ;; If defaults have been found, it's safe to just append those to the result
1552 ;; list (which at this point will be either nil or contain actual specs) and
1553 ;; return it to the caller. Since there will most definitely be something to
1554 ;; return in this case, there's no need to know/check if a match was found.
1556 (append result defaults
)
1562 (defun face-spec-reset-face (face &optional frame
)
1563 "Reset all attributes of FACE on FRAME to unspecified."
1564 (apply 'set-face-attribute face frame
1565 (if (eq face
'default
)
1566 ;; For the default face, avoid making any attribute
1567 ;; unspecified. Instead, set attributes to default values
1568 ;; (see also realize_default_face in xfaces.c).
1570 '(:underline nil
:overline nil
:strike-through nil
1571 :box nil
:inverse-video nil
:stipple nil
:inherit nil
)
1572 ;; `display-graphic-p' is unavailable when running
1573 ;; temacs, prior to loading frame.el.
1574 (when (fboundp 'display-graphic-p
)
1575 (unless (display-graphic-p frame
)
1576 `(:family
"default" :foundry
"default" :width normal
1577 :height
1 :weight normal
:slant normal
1578 :foreground
,(if (frame-parameter nil
'reverse
)
1581 :background
,(if (frame-parameter nil
'reverse
)
1583 "unspecified-bg")))))
1584 ;; For all other faces, unspecify all attributes.
1586 (mapcar (lambda (x) (list (car x
) 'unspecified
))
1587 face-attribute-name-alist
)))))
1589 (defun face-spec-set (face spec
&optional spec-type
)
1590 "Set the face spec SPEC for FACE.
1591 See `defface' for the format of SPEC.
1593 The appearance of each face is controlled by its specs (set via
1594 this function), and by the internal frame-specific face
1595 attributes (set via `set-face-attribute').
1597 This function also defines FACE as a valid face name if it is not
1598 already one, and (re)calculates its attributes on existing
1601 The argument SPEC-TYPE determines which spec to set:
1602 nil or `face-override-spec' means the override spec (which is
1603 usually what you want if calling this function outside of
1605 `customized-face' or `saved-face' means the customized spec or
1606 the saved custom spec;
1607 `face-defface-spec' means the default spec
1608 (usually set only via `defface');
1609 `reset' means to ignore SPEC, but clear the `customized-face'
1610 and `face-override-spec' specs;
1611 Any other value means not to set any spec, but to run the
1612 function for its other effects."
1613 (if (get face
'face-alias
)
1614 (setq face
(get face
'face-alias
)))
1615 ;; Save SPEC to the relevant symbol property.
1617 (setq spec-type
'face-override-spec
))
1618 (if (memq spec-type
'(face-defface-spec face-override-spec
1619 customized-face saved-face
))
1620 (put face spec-type spec
))
1621 (if (memq spec-type
'(reset saved-face
))
1622 (put face
'customized-face nil
))
1623 ;; Setting the face spec via Custom empties out any override spec,
1624 ;; similar to how setting a variable via Custom changes its values.
1625 (if (memq spec-type
'(customized-face saved-face reset
))
1626 (put face
'face-override-spec nil
))
1627 ;; If we reset the face based on its custom spec, it is unmodified
1628 ;; as far as Custom is concerned.
1629 (unless (eq face
'face-override-spec
)
1630 (put face
'face-modified nil
))
1631 ;; Initialize the face if it does not exist, then recalculate.
1632 (make-empty-face face
)
1633 (dolist (frame (frame-list))
1634 (face-spec-recalc face frame
)))
1636 (defun face-spec-recalc (face frame
)
1637 "Reset the face attributes of FACE on FRAME according to its specs.
1638 After the reset, the specs are applied from the following sources in this order:
1639 X resources (if applicable)
1641 (theme and user customization)
1642 or, if nonexistent or does not match the current frame,
1643 (defface default spec)
1645 defface override spec"
1646 (while (get face
'face-alias
)
1647 (setq face
(get face
'face-alias
)))
1648 (face-spec-reset-face face frame
)
1649 (make-face-x-resource-internal face frame
)
1650 ;; If FACE is customized or themed, set the custom spec from
1651 ;; `theme-face' records.
1652 (let ((theme-faces (get face
'theme-face
))
1654 spec theme-face-applied
)
1656 (dolist (elt (reverse theme-faces
))
1657 (setq spec
(face-spec-choose (cadr elt
) frame no-match-found
))
1658 (unless (eq spec no-match-found
)
1659 (face-spec-set-2 face frame spec
)
1660 (setq theme-face-applied t
))))
1661 ;; If there was a spec applicable to FRAME, that overrides the
1662 ;; defface spec entirely (rather than inheriting from it). If
1663 ;; there was no spec applicable to FRAME, apply the defface spec.
1664 (unless theme-face-applied
1665 (setq spec
(face-spec-choose (face-default-spec face
) frame
))
1666 (face-spec-set-2 face frame spec
))
1667 (setq spec
(face-spec-choose (get face
'face-override-spec
) frame
))
1668 (face-spec-set-2 face frame spec
)))
1670 (defun face-spec-set-2 (face frame spec
)
1671 "Set the face attributes of FACE on FRAME according to SPEC."
1674 (when (assq (car spec
) face-x-resources
)
1675 (push (car spec
) attrs
)
1676 (push (cadr spec
) attrs
))
1677 (setq spec
(cddr spec
)))
1678 (apply 'set-face-attribute face frame
(nreverse attrs
))))
1680 (defun face-attr-match-p (face attrs
&optional frame
)
1681 "Return t if attributes of FACE match values in plist ATTRS.
1682 Optional parameter FRAME is the frame whose definition of FACE
1683 is used. If nil or omitted, use the selected frame."
1685 (setq frame
(selected-frame)))
1686 (let* ((list face-attribute-name-alist
)
1688 (bold (and (plist-member attrs
:bold
)
1689 (not (plist-member attrs
:weight
))))
1690 (italic (and (plist-member attrs
:italic
)
1691 (not (plist-member attrs
:slant
))))
1692 (plist (if (or bold italic
)
1693 (copy-sequence attrs
)
1695 ;; Handle the Emacs 20 :bold and :italic properties.
1697 (plist-put plist
:weight
(if bold
'bold
'normal
)))
1699 (plist-put plist
:slant
(if italic
'italic
'normal
)))
1700 (while (and match list
)
1701 (let* ((attr (caar list
))
1703 (if (plist-member plist attr
)
1704 (plist-get plist attr
)
1706 (value-now (face-attribute face attr frame
)))
1707 (setq match
(equal specified-value value-now
))
1708 (setq list
(cdr list
))))
1711 (defsubst face-spec-match-p
(face spec
&optional frame
)
1712 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1713 (face-attr-match-p face
(face-spec-choose spec frame
) frame
))
1715 (defsubst face-default-spec
(face)
1716 "Return the default face-spec for FACE, ignoring any user customization.
1717 If there is no default for FACE, return nil."
1718 (get face
'face-defface-spec
))
1720 (defsubst face-user-default-spec
(face)
1721 "Return the user's customized face-spec for FACE, or the default if none.
1722 If there is neither a user setting nor a default for FACE, return nil."
1723 (or (get face
'customized-face
)
1724 (get face
'saved-face
)
1725 (face-default-spec face
)))
1728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1729 ;;; Frame-type independent color support.
1730 ;;; We keep the old x-* names as aliases for back-compatibility.
1731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1733 (defun defined-colors (&optional frame
)
1734 "Return a list of colors supported for a particular frame.
1735 The argument FRAME specifies which frame to try.
1736 The value may be different for frames on different display types.
1737 If FRAME doesn't support colors, the value is nil.
1738 If FRAME is nil, that stands for the selected frame."
1739 (if (memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1740 (xw-defined-colors frame
)
1741 (mapcar 'car
(tty-color-alist frame
))))
1742 (defalias 'x-defined-colors
'defined-colors
)
1744 (declare-function xw-color-defined-p
"xfns.c" (color &optional frame
))
1746 (defun color-defined-p (color &optional frame
)
1747 "Return non-nil if COLOR is supported on frame FRAME.
1748 COLOR should be a string naming a color (e.g. \"white\"), or a
1749 string specifying a color's RGB components (e.g. \"#ff12ec\"), or
1750 the symbol `unspecified'.
1752 This function returns nil if COLOR is the symbol `unspecified',
1753 or one of the strings \"unspecified-fg\" or \"unspecified-bg\".
1755 If FRAME is omitted or nil, use the selected frame."
1756 (unless (member color
'(unspecified "unspecified-bg" "unspecified-fg"))
1757 (if (member (framep (or frame
(selected-frame))) '(x w32 ns
))
1758 (xw-color-defined-p color frame
)
1759 (numberp (tty-color-translate color frame
)))))
1760 (defalias 'x-color-defined-p
'color-defined-p
)
1762 (declare-function xw-color-values
"xfns.c" (color &optional frame
))
1764 (defun color-values (color &optional frame
)
1765 "Return a description of the color named COLOR on frame FRAME.
1766 COLOR should be a string naming a color (e.g. \"white\"), or a
1767 string specifying a color's RGB components (e.g. \"#ff12ec\").
1769 Return a list of three integers, (RED GREEN BLUE), each between 0
1770 and either 65280 or 65535 (the maximum depends on the system).
1771 Use `color-name-to-rgb' if you want RGB floating-point values
1774 If FRAME is omitted or nil, use the selected frame.
1775 If FRAME cannot display COLOR, the value is nil.
1777 COLOR can also be the symbol `unspecified' or one of the strings
1778 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1779 return value is nil."
1781 ((member color
'(unspecified "unspecified-fg" "unspecified-bg"))
1783 ((memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1784 (xw-color-values color frame
))
1786 (tty-color-values color frame
))))
1788 (defalias 'x-color-values
'color-values
)
1790 (declare-function xw-display-color-p
"xfns.c" (&optional terminal
))
1792 (defun display-color-p (&optional display
)
1793 "Return t if DISPLAY supports color.
1794 The optional argument DISPLAY specifies which display to ask about.
1795 DISPLAY should be either a frame or a display name (a string).
1796 If omitted or nil, that stands for the selected frame's display."
1797 (if (memq (framep-on-display display
) '(x w32 ns
))
1798 (xw-display-color-p display
)
1799 (tty-display-color-p display
)))
1800 (defalias 'x-display-color-p
'display-color-p
)
1802 (declare-function x-display-grayscale-p
"xfns.c" (&optional terminal
))
1804 (defun display-grayscale-p (&optional display
)
1805 "Return non-nil if frames on DISPLAY can display shades of gray."
1806 (let ((frame-type (framep-on-display display
)))
1808 ((memq frame-type
'(x w32 ns
))
1809 (x-display-grayscale-p display
))
1811 (> (tty-color-gray-shades display
) 2)))))
1813 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg
)
1814 "Read a color name or RGB triplet.
1815 Completion is available for color names, but not for RGB triplets.
1817 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1818 components can have one to four digits, but all three components
1819 must have the same number of digits. Each digit is a hex value
1820 between 0 and F; either upper case or lower case for A through F
1823 In addition to standard color names and RGB hex values, the
1824 following are available as color candidates. In each case, the
1825 corresponding color is used.
1827 * `foreground at point' - foreground under the cursor
1828 * `background at point' - background under the cursor
1830 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1832 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1833 convert an input color name to an RGB hex string. Return the RGB
1836 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1837 to enter an empty color name (the empty string).
1839 Interactively, or with optional arg MSG non-nil, print the
1840 resulting color name in the echo area."
1841 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1842 (let* ((completion-ignore-case t
)
1843 (colors (or facemenu-color-alist
1844 (append '("foreground at point" "background at point")
1845 (if allow-empty-name
'(""))
1847 (color (completing-read
1848 (or prompt
"Color (name or #RGB triplet): ")
1849 ;; Completing function for reading colors, accepting
1850 ;; both color names and RGB triplets.
1851 (lambda (string pred flag
)
1853 ((null flag
) ; Try completion.
1854 (or (try-completion string colors pred
)
1855 (if (color-defined-p string
)
1857 ((eq flag t
) ; List all completions.
1858 (or (all-completions string colors pred
)
1859 (if (color-defined-p string
)
1861 ((eq flag
'lambda
) ; Test completion.
1862 (or (member string colors
)
1863 (color-defined-p string
)))))
1866 ;; Process named colors.
1867 (when (member color colors
)
1868 (cond ((string-equal color
"foreground at point")
1869 (setq color
(foreground-color-at-point)))
1870 ((string-equal color
"background at point")
1871 (setq color
(background-color-at-point))))
1872 (when (and convert-to-RGB
1873 (not (string-equal color
"")))
1874 (let ((components (x-color-values color
)))
1875 (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color
)
1876 (setq color
(format "#%04X%04X%04X"
1877 (logand 65535 (nth 0 components
))
1878 (logand 65535 (nth 1 components
))
1879 (logand 65535 (nth 2 components
))))))))
1880 (when msg
(message "Color: `%s'" color
))
1883 (defun face-at-point (&optional thing multiple
)
1884 "Return the face of the character after point.
1885 If it has more than one face, return the first one.
1886 If THING is non-nil try first to get a face name from the buffer.
1887 IF MULTIPLE is non-nil, return a list of all faces.
1888 Return nil if there is no face."
1891 ;; Try to get a face name from the buffer.
1892 (let ((face (intern-soft (thing-at-point 'symbol
))))
1894 (push face faces
))))
1895 ;; Add the named faces that the `read-face-name' or `face' property uses.
1896 (let ((faceprop (or (get-char-property (point) 'read-face-name
)
1897 (get-char-property (point) 'face
))))
1898 (cond ((facep faceprop
)
1899 (push faceprop faces
))
1900 ((and (listp faceprop
)
1901 ;; Don't treat an attribute spec as a list of faces.
1902 (not (keywordp (car faceprop
)))
1903 (not (memq (car faceprop
)
1904 '(foreground-color background-color
))))
1905 (dolist (face faceprop
)
1907 (push face faces
))))))
1908 (setq faces
(delete-dups (nreverse faces
)))
1909 (if multiple faces
(car faces
))))
1911 (defun foreground-color-at-point ()
1912 "Return the foreground color of the character after point."
1913 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1914 ;; Need also pick up any face properties that are not associated with named faces.
1915 (let ((face (or (face-at-point)
1916 (get-char-property (point) 'read-face-name
)
1917 (get-char-property (point) 'face
))))
1918 (cond ((and face
(symbolp face
))
1919 (let ((value (face-foreground face nil
'default
)))
1920 (if (member value
'("unspecified-fg" "unspecified-bg"))
1924 (cond ((memq 'foreground-color face
) (cdr (memq 'foreground-color face
)))
1925 ((memq ':foreground face
) (cadr (memq ':foreground face
)))))
1926 (t nil
)))) ; Invalid face value.
1928 (defun background-color-at-point ()
1929 "Return the background color of the character after point."
1930 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1931 ;; Need also pick up any face properties that are not associated with named faces.
1932 (let ((face (or (face-at-point)
1933 (get-char-property (point) 'read-face-name
)
1934 (get-char-property (point) 'face
))))
1935 (cond ((and face
(symbolp face
))
1936 (let ((value (face-background face nil
'default
)))
1937 (if (member value
'("unspecified-fg" "unspecified-bg"))
1941 (cond ((memq 'background-color face
) (cdr (memq 'background-color face
)))
1942 ((memq ':background face
) (cadr (memq ':background face
)))))
1943 (t nil
)))) ; Invalid face value.
1946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1948 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1950 (declare-function x-display-list
"xfns.c" ())
1951 (declare-function x-open-connection
"xfns.c"
1952 (display &optional xrm-string must-succeed
))
1953 (declare-function x-get-resource
"frame.c"
1954 (attribute class
&optional component subclass
))
1955 (declare-function x-parse-geometry
"frame.c" (string))
1956 (defvar x-display-name
)
1958 (defun x-handle-named-frame-geometry (parameters)
1959 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1960 Value is the new parameter list."
1961 ;; Note that `x-resource-name' has a global meaning.
1962 (let ((x-resource-name (cdr (assq 'name parameters
))))
1963 (when x-resource-name
1964 ;; Before checking X resources, we must have an X connection.
1967 (x-open-connection (or (cdr (assq 'display parameters
))
1969 (let (res-geometry parsed
)
1970 (and (setq res-geometry
(x-get-resource "geometry" "Geometry"))
1971 (setq parsed
(x-parse-geometry res-geometry
))
1973 (append parameters parsed
1974 ;; If the resource specifies a position,
1975 ;; take note of that.
1976 (if (or (assq 'top parsed
) (assq 'left parsed
))
1977 '((user-position . t
) (user-size . t
)))))))))
1981 (defun x-handle-reverse-video (frame parameters
)
1982 "Handle the reverse-video frame parameter and X resource.
1983 `x-create-frame' does not handle this one."
1984 (when (cdr (or (assq 'reverse parameters
)
1985 (let ((resource (x-get-resource "reverseVideo"
1988 (cons nil
(member (downcase resource
)
1989 '("on" "true")))))))
1990 (let* ((params (frame-parameters frame
))
1991 (bg (cdr (assq 'foreground-color params
)))
1992 (fg (cdr (assq 'background-color params
))))
1993 (modify-frame-parameters frame
1994 (list (cons 'foreground-color fg
)
1995 (cons 'background-color bg
)))
1996 (if (equal bg
(cdr (assq 'border-color params
)))
1997 (modify-frame-parameters frame
1998 (list (cons 'border-color fg
))))
1999 (if (equal bg
(cdr (assq 'mouse-color params
)))
2000 (modify-frame-parameters frame
2001 (list (cons 'mouse-color fg
))))
2002 (if (equal bg
(cdr (assq 'cursor-color params
)))
2003 (modify-frame-parameters frame
2004 (list (cons 'cursor-color fg
)))))))
2006 (declare-function x-create-frame
"xfns.c" (parms))
2007 (declare-function x-setup-function-keys
"term/common-win" (frame))
2009 (defun x-create-frame-with-faces (&optional parameters
)
2010 "Create and return a frame with frame parameters PARAMETERS.
2011 If PARAMETERS specify a frame name, handle X geometry resources
2012 for that name. If PARAMETERS includes a `reverse' parameter, or
2013 the X resource ``reverseVideo'' is present, handle that."
2014 (setq parameters
(x-handle-named-frame-geometry parameters
))
2015 (let* ((params (copy-tree parameters
))
2016 (visibility-spec (assq 'visibility parameters
))
2017 (delayed-params '(foreground-color background-color font
2018 border-color cursor-color mouse-color
2019 visibility scroll-bar-foreground
2020 scroll-bar-background
))
2022 (dolist (param delayed-params
)
2023 (setq params
(assq-delete-all param params
)))
2024 (setq frame
(x-create-frame `((visibility . nil
) .
,params
)))
2027 (x-setup-function-keys frame
)
2028 (x-handle-reverse-video frame parameters
)
2029 (frame-set-background-mode frame t
)
2030 (face-set-after-frame-default frame parameters
)
2031 (if (null visibility-spec
)
2032 (make-frame-visible frame
)
2033 (modify-frame-parameters frame
(list visibility-spec
)))
2036 (delete-frame frame
)))
2039 (defun face-set-after-frame-default (frame &optional parameters
)
2040 "Initialize the frame-local faces of FRAME.
2041 Calculate the face definitions using the face specs, custom theme
2042 settings, X resources, and `face-new-frame-defaults'.
2043 Finally, apply any relevant face attributes found amongst the
2044 frame parameters in PARAMETERS."
2045 (let ((window-system-p (memq (window-system frame
) '(x w32
))))
2046 ;; The `reverse' is so that `default' goes first.
2047 (dolist (face (nreverse (face-list)))
2050 ;; Initialize faces from face spec and custom theme.
2051 (face-spec-recalc face frame
)
2052 ;; Apply attributes specified by face-new-frame-defaults
2053 (internal-merge-in-global-face face frame
))
2054 ;; Don't let invalid specs prevent frame creation.
2057 ;; Apply attributes specified by frame parameters.
2058 (let ((face-params '((foreground-color default
:foreground
)
2059 (background-color default
:background
)
2060 (font default
:font
)
2061 (border-color border
:background
)
2062 (cursor-color cursor
:background
)
2063 (scroll-bar-foreground scroll-bar
:foreground
)
2064 (scroll-bar-background scroll-bar
:background
)
2065 (mouse-color mouse
:background
))))
2066 (dolist (param face-params
)
2067 (let* ((param-name (nth 0 param
))
2068 (value (cdr (assq param-name parameters
))))
2070 (set-face-attribute (nth 1 param
) frame
2071 (nth 2 param
) value
))))))
2073 (defun tty-handle-reverse-video (frame parameters
)
2074 "Handle the reverse-video frame parameter for terminal frames."
2075 (when (cdr (assq 'reverse parameters
))
2076 (let* ((params (frame-parameters frame
))
2077 (bg (cdr (assq 'foreground-color params
)))
2078 (fg (cdr (assq 'background-color params
))))
2079 (modify-frame-parameters frame
2080 (list (cons 'foreground-color fg
)
2081 (cons 'background-color bg
)))
2082 (if (equal bg
(cdr (assq 'mouse-color params
)))
2083 (modify-frame-parameters frame
2084 (list (cons 'mouse-color fg
))))
2085 (if (equal bg
(cdr (assq 'cursor-color params
)))
2086 (modify-frame-parameters frame
2087 (list (cons 'cursor-color fg
)))))))
2090 (defun tty-create-frame-with-faces (&optional parameters
)
2091 "Create and return a frame from optional frame parameters PARAMETERS.
2092 If PARAMETERS contains a `reverse' parameter, handle that."
2093 (let ((frame (make-terminal-frame parameters
))
2096 (with-selected-frame frame
2097 (tty-handle-reverse-video frame
(frame-parameters frame
))
2099 (unless (terminal-parameter frame
'terminal-initted
)
2100 (set-terminal-parameter frame
'terminal-initted t
)
2101 (set-locale-environment nil frame
)
2102 (tty-run-terminal-initialization frame nil t
))
2103 (frame-set-background-mode frame t
)
2104 (face-set-after-frame-default frame parameters
)
2107 (delete-frame frame
)))
2110 (defun tty-find-type (pred type
)
2111 "Return the longest prefix of TYPE to which PRED returns non-nil.
2112 TYPE should be a tty type name such as \"xterm-16color\".
2114 The function tries only those prefixes that are followed by a
2115 dash or underscore in the original type name, like \"xterm\" in
2119 (not (funcall pred type
)))
2120 ;; Strip off last hyphen and what follows, then try again
2122 (if (setq hyphend
(string-match-p "[-_][^-_]+$" type
))
2123 (substring type
0 hyphend
)
2127 (defvar tty-setup-hook nil
2128 "Hook run after running the initialization function of a new text terminal.
2129 Specifically, `tty-run-terminal-initialization' runs this.
2130 This can be used to fine tune the `input-decode-map', for example.")
2132 (defun tty-run-terminal-initialization (frame &optional type run-hook
)
2133 "Run the special initialization code for the terminal type of FRAME.
2134 The optional TYPE parameter may be used to override the autodetected
2135 terminal type to a different value.
2137 If optional argument RUN-HOOK is non-nil, then as a final step,
2138 this runs the hook `tty-setup-hook'.
2140 If you set `term-file-prefix' to nil, this function does nothing."
2141 (setq type
(or type
(tty-type frame
)))
2142 ;; Load library for our terminal type.
2143 ;; User init file can set term-file-prefix to nil to prevent this.
2144 (with-selected-frame frame
2145 (unless (null term-file-prefix
)
2146 (let* (term-init-func)
2147 ;; First, load the terminal initialization file, if it is
2148 ;; available and it hasn't been loaded already.
2149 (tty-find-type #'(lambda (type)
2150 (let ((file (locate-library (concat term-file-prefix type
))))
2152 (or (assoc file load-history
)
2155 ;; Next, try to find a matching initialization function, and call it.
2156 (tty-find-type #'(lambda (type)
2157 (fboundp (setq term-init-func
2158 (intern (concat "terminal-init-" type
)))))
2160 (when (fboundp term-init-func
)
2161 (funcall term-init-func
))
2162 (set-terminal-parameter frame
'terminal-initted term-init-func
)
2163 (if run-hook
(run-hooks 'tty-setup-hook
))))))
2165 ;; Called from C function init_display to initialize faces of the
2166 ;; dumped terminal frame on startup.
2168 (defun tty-set-up-initial-frame-faces ()
2169 (let ((frame (selected-frame)))
2170 (frame-set-background-mode frame t
)
2171 (face-set-after-frame-default frame
)))
2174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2178 (defgroup basic-faces nil
2179 "The standard faces of Emacs."
2183 '((t nil
)) ; If this were nil, face-defface-spec would not be set.
2184 "Basic default face."
2185 :group
'basic-faces
)
2190 :group
'basic-faces
)
2193 '((((supports :slant italic
))
2195 (((supports :underline t
))
2198 ;; Default to italic, even if it doesn't appear to be supported,
2199 ;; because in some cases the display engine will do its own
2200 ;; workaround (to `dim' on ttys).
2202 "Basic italic face."
2203 :group
'basic-faces
)
2205 (defface bold-italic
2206 '((t :weight bold
:slant italic
))
2207 "Basic bold-italic face."
2208 :group
'basic-faces
)
2211 '((((supports :underline t
))
2213 (((supports :weight bold
))
2216 "Basic underlined face."
2217 :group
'basic-faces
)
2219 (defface fixed-pitch
2220 '((t :family
"Monospace"))
2221 "The basic fixed-pitch face."
2222 :group
'basic-faces
)
2224 (defface variable-pitch
2225 '((t :family
"Sans Serif"))
2226 "The basic variable-pitch face."
2227 :group
'basic-faces
)
2230 '((((class color grayscale
) (min-colors 88) (background light
))
2231 :foreground
"grey50")
2232 (((class color grayscale
) (min-colors 88) (background dark
))
2233 :foreground
"grey70")
2234 (((class color
) (min-colors 8) (background light
))
2235 :foreground
"green")
2236 (((class color
) (min-colors 8) (background dark
))
2237 :foreground
"yellow"))
2238 "Basic face for shadowed text."
2243 '((((class color
) (min-colors 88) (background light
))
2244 :foreground
"RoyalBlue3" :underline t
)
2245 (((class color
) (background light
))
2246 :foreground
"blue" :underline t
)
2247 (((class color
) (min-colors 88) (background dark
))
2248 :foreground
"cyan1" :underline t
)
2249 (((class color
) (background dark
))
2250 :foreground
"cyan" :underline t
)
2251 (t :inherit underline
))
2252 "Basic face for unvisited links."
2256 (defface link-visited
2257 '((default :inherit link
)
2258 (((class color
) (background light
)) :foreground
"magenta4")
2259 (((class color
) (background dark
)) :foreground
"violet"))
2260 "Basic face for visited links."
2265 '((((class color
) (min-colors 88) (background light
))
2266 :background
"darkseagreen2")
2267 (((class color
) (min-colors 88) (background dark
))
2268 :background
"darkolivegreen")
2269 (((class color
) (min-colors 16) (background light
))
2270 :background
"darkseagreen2")
2271 (((class color
) (min-colors 16) (background dark
))
2272 :background
"darkolivegreen")
2273 (((class color
) (min-colors 8))
2274 :background
"green" :foreground
"black")
2275 (t :inverse-video t
))
2276 "Basic face for highlighting."
2277 :group
'basic-faces
)
2279 ;; Region face: under NS, default to the system-defined selection
2280 ;; color (optimized for the fixed white background of other apps),
2281 ;; if background is light.
2283 '((((class color
) (min-colors 88) (background dark
))
2284 :background
"blue3")
2285 (((class color
) (min-colors 88) (background light
) (type gtk
))
2286 :distant-foreground
"gtk_selection_fg_color"
2287 :background
"gtk_selection_bg_color")
2288 (((class color
) (min-colors 88) (background light
) (type ns
))
2289 :distant-foreground
"ns_selection_fg_color"
2290 :background
"ns_selection_bg_color")
2291 (((class color
) (min-colors 88) (background light
))
2292 :background
"lightgoldenrod2")
2293 (((class color
) (min-colors 16) (background dark
))
2294 :background
"blue3")
2295 (((class color
) (min-colors 16) (background light
))
2296 :background
"lightgoldenrod2")
2297 (((class color
) (min-colors 8))
2298 :background
"blue" :foreground
"white")
2299 (((type tty
) (class mono
))
2301 (t :background
"gray"))
2302 "Basic face for highlighting the region."
2304 :group
'basic-faces
)
2306 (defface secondary-selection
2307 '((((class color
) (min-colors 88) (background light
))
2308 :background
"yellow1")
2309 (((class color
) (min-colors 88) (background dark
))
2310 :background
"SkyBlue4")
2311 (((class color
) (min-colors 16) (background light
))
2312 :background
"yellow")
2313 (((class color
) (min-colors 16) (background dark
))
2314 :background
"SkyBlue4")
2315 (((class color
) (min-colors 8))
2316 :background
"cyan" :foreground
"black")
2317 (t :inverse-video t
))
2318 "Basic face for displaying the secondary selection."
2319 :group
'basic-faces
)
2321 (defface trailing-whitespace
2322 '((((class color
) (background light
))
2324 (((class color
) (background dark
))
2326 (t :inverse-video t
))
2327 "Basic face for highlighting trailing whitespace."
2329 :group
'basic-faces
)
2331 (defface escape-glyph
2332 '((((background dark
)) :foreground
"cyan")
2333 ;; See the comment in minibuffer-prompt for
2334 ;; the reason not to use blue on MS-DOS.
2335 (((type pc
)) :foreground
"magenta")
2336 ;; red4 is too dark, but some say blue is too loud.
2337 ;; brown seems to work ok. -- rms.
2338 (t :foreground
"brown"))
2339 "Face for characters displayed as sequences using `^' or `\\'."
2343 (defface nobreak-space
2344 '((((class color
) (min-colors 88)) :inherit escape-glyph
:underline t
)
2345 (((class color
) (min-colors 8)) :background
"magenta")
2346 (t :inverse-video t
))
2347 "Face for displaying nobreak space."
2351 (defgroup mode-line-faces nil
2352 "Faces used in the mode line."
2358 '((((class color
) (min-colors 88))
2359 :box
(:line-width -
1 :style released-button
)
2360 :background
"grey75" :foreground
"black")
2363 "Basic mode line face for selected window."
2365 :group
'mode-line-faces
2366 :group
'basic-faces
)
2368 (defface mode-line-inactive
2371 (((class color
) (min-colors 88) (background light
))
2373 :box
(:line-width -
1 :color
"grey75" :style nil
)
2374 :foreground
"grey20" :background
"grey90")
2375 (((class color
) (min-colors 88) (background dark
) )
2377 :box
(:line-width -
1 :color
"grey40" :style nil
)
2378 :foreground
"grey80" :background
"grey30"))
2379 "Basic mode line face for non-selected windows."
2381 :group
'mode-line-faces
2382 :group
'basic-faces
)
2383 (define-obsolete-face-alias 'modeline-inactive
'mode-line-inactive
"22.1")
2385 (defface mode-line-highlight
2386 '((((class color
) (min-colors 88))
2387 :box
(:line-width
2 :color
"grey40" :style released-button
))
2389 :inherit highlight
))
2390 "Basic mode line face for highlighting."
2392 :group
'mode-line-faces
2393 :group
'basic-faces
)
2394 (define-obsolete-face-alias 'modeline-highlight
'mode-line-highlight
"22.1")
2396 (defface mode-line-emphasis
2397 '((t (:weight bold
)))
2398 "Face used to emphasize certain mode line features.
2399 Use the face `mode-line-highlight' for features that can be selected."
2401 :group
'mode-line-faces
2402 :group
'basic-faces
)
2404 (defface mode-line-buffer-id
2405 '((t (:weight bold
)))
2406 "Face used for buffer identification parts of the mode line."
2408 :group
'mode-line-faces
2409 :group
'basic-faces
)
2410 (define-obsolete-face-alias 'modeline-buffer-id
'mode-line-buffer-id
"22.1")
2412 (defface header-line
2416 ;; This used to be `:inverse-video t', but that doesn't look very
2417 ;; good when combined with inverse-video mode-lines and multiple
2418 ;; windows. Underlining looks better, and is more consistent with
2419 ;; the window-system face variants, which deemphasize the
2420 ;; header-line in relation to the mode-line face. If a terminal
2421 ;; can't underline, then the header-line will end up without any
2422 ;; highlighting; this may be too confusing in general, although it
2423 ;; happens to look good with the only current use of header-lines,
2424 ;; the info browser. XXX
2425 :inverse-video nil
;Override the value inherited from mode-line.
2427 (((class color grayscale
) (background light
))
2428 :background
"grey90" :foreground
"grey20"
2430 (((class color grayscale
) (background dark
))
2431 :background
"grey20" :foreground
"grey90"
2433 (((class mono
) (background light
))
2434 :background
"white" :foreground
"black"
2438 (((class mono
) (background dark
))
2439 :background
"black" :foreground
"white"
2443 "Basic header-line face."
2445 :group
'basic-faces
)
2447 (defface vertical-border
2448 '((((type tty
)) :inherit mode-line-inactive
))
2449 "Face used for vertical window dividers on ttys."
2451 :group
'basic-faces
)
2453 (defface window-divider
'((t :foreground
"gray60"))
2454 "Basic face for window dividers.
2455 When a divider is less than 3 pixels wide, it is drawn solidly
2456 with the foreground of this face. For larger dividers this face
2457 is used for the inner part while the first pixel line/column is
2458 drawn with the `window-divider-first-pixel' face and the last
2459 pixel line/column with the `window-divider-last-pixel' face."
2462 :group
'basic-faces
)
2464 (defface window-divider-first-pixel
2465 '((t :foreground
"gray80"))
2466 "Basic face for first pixel line/column of window dividers.
2467 When a divider is at least 3 pixels wide, its first pixel
2468 line/column is drawn with the foreground of this face. If you do
2469 not want to accentuate the first pixel line/column, set this to
2470 the same as `window-divider' face."
2473 :group
'basic-faces
)
2475 (defface window-divider-last-pixel
2476 '((t :foreground
"gray40"))
2477 "Basic face for last pixel line/column of window dividers.
2478 When a divider is at least 3 pixels wide, its last pixel
2479 line/column is drawn with the foreground of this face. If you do
2480 not want to accentuate the last pixel line/column, set this to
2481 the same as `window-divider' face."
2484 :group
'basic-faces
)
2486 (defface minibuffer-prompt
2487 '((((background dark
)) :foreground
"cyan")
2488 ;; Don't use blue because many users of the MS-DOS port customize
2489 ;; their foreground color to be blue.
2490 (((type pc
)) :foreground
"magenta")
2491 (t :foreground
"medium blue"))
2492 "Face for minibuffer prompts.
2493 By default, Emacs automatically adds this face to the value of
2494 `minibuffer-prompt-properties', which is a list of text properties
2495 used to display the prompt text."
2497 :group
'basic-faces
)
2499 (setq minibuffer-prompt-properties
2500 (append minibuffer-prompt-properties
(list 'face
'minibuffer-prompt
)))
2503 '((((class color
) (background light
))
2504 :background
"grey95")
2505 (((class color
) (background dark
))
2506 :background
"grey10")
2508 :background
"gray"))
2509 "Basic face for the fringes to the left and right of windows under X."
2512 :group
'basic-faces
)
2514 (defface scroll-bar
'((t nil
))
2515 "Basic face for the scroll bar colors under X."
2518 :group
'basic-faces
)
2520 (defface border
'((t nil
))
2521 "Basic face for the frame border under X."
2524 :group
'basic-faces
)
2527 '((((background light
)) :background
"black")
2528 (((background dark
)) :background
"white"))
2529 "Basic face for the cursor color under X.
2530 Currently, only the `:background' attribute is meaningful; all
2531 other attributes are ignored. The cursor foreground color is
2532 taken from the background color of the underlying text.
2534 Note: Other faces cannot inherit from the cursor face."
2537 :group
'basic-faces
)
2539 (put 'cursor
'face-no-inherit t
)
2541 (defface mouse
'((t nil
))
2542 "Basic face for the mouse color under X."
2545 :group
'basic-faces
)
2549 :box
(:line-width
1 :style released-button
)
2550 :foreground
"black")
2551 (((type x w32 ns
) (class color
))
2552 :background
"grey75")
2553 (((type x
) (class mono
))
2554 :background
"grey"))
2555 "Basic tool-bar face."
2557 :group
'basic-faces
)
2566 "Basic face for the font and colors of the menu bar and popup menus."
2569 :group
'basic-faces
)
2571 (defface help-argument-name
'((t :inherit italic
))
2572 "Face to highlight argument names in *Help* buffers."
2575 (defface glyphless-char
2576 '((((type tty
)) :inherit underline
)
2577 (((type pc
)) :inherit escape-glyph
)
2579 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2580 It is used for characters of no fonts too."
2582 :group
'basic-faces
)
2585 '((default :weight bold
)
2586 (((class color
) (min-colors 88) (background light
)) :foreground
"Red1")
2587 (((class color
) (min-colors 88) (background dark
)) :foreground
"Pink")
2588 (((class color
) (min-colors 16) (background light
)) :foreground
"Red1")
2589 (((class color
) (min-colors 16) (background dark
)) :foreground
"Pink")
2590 (((class color
) (min-colors 8)) :foreground
"red")
2591 (t :inverse-video t
))
2592 "Basic face used to highlight errors and to denote failure."
2594 :group
'basic-faces
)
2597 '((default :weight bold
)
2598 (((class color
) (min-colors 16)) :foreground
"DarkOrange")
2599 (((class color
)) :foreground
"yellow"))
2600 "Basic face used to highlight warnings."
2602 :group
'basic-faces
)
2605 '((default :weight bold
)
2606 (((class color
) (min-colors 16) (background light
)) :foreground
"ForestGreen")
2607 (((class color
) (min-colors 88) (background dark
)) :foreground
"Green1")
2608 (((class color
) (min-colors 16) (background dark
)) :foreground
"Green")
2609 (((class color
)) :foreground
"green"))
2610 "Basic face used to indicate successful operation."
2612 :group
'basic-faces
)
2614 ;; Faces for TTY menus.
2615 (defface tty-menu-enabled-face
2617 :foreground
"yellow" :background
"blue" :weight bold
))
2618 "Face for displaying enabled items in TTY menus."
2619 :group
'basic-faces
)
2621 (defface tty-menu-disabled-face
2622 '((((class color
) (min-colors 16))
2623 :foreground
"lightgray" :background
"blue")
2625 :foreground
"white" :background
"blue"))
2626 "Face for displaying disabled items in TTY menus."
2627 :group
'basic-faces
)
2629 (defface tty-menu-selected-face
2630 '((t :background
"red"))
2631 "Face for displaying the currently selected item in TTY menus."
2632 :group
'basic-faces
)
2634 (defgroup paren-showing-faces nil
2635 "Faces used to highlight paren matches."
2636 :group
'paren-showing
2640 (defface show-paren-match
2641 '((((class color
) (background light
))
2642 :background
"turquoise") ; looks OK on tty (becomes cyan)
2643 (((class color
) (background dark
))
2644 :background
"steelblue3") ; looks OK on tty (becomes blue)
2645 (((background dark
))
2646 :background
"grey50")
2648 :background
"gray"))
2649 "Face used for a matching paren."
2650 :group
'paren-showing-faces
)
2652 (defface show-paren-mismatch
2653 '((((class color
)) (:foreground
"white" :background
"purple"))
2654 (t (:inverse-video t
)))
2655 "Face used for a mismatching paren."
2656 :group
'paren-showing-faces
)
2659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2660 ;;; Manipulating font names.
2661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2663 ;; This is here for compatibility with Emacs 20.2. For example,
2664 ;; international/fontset.el uses x-resolve-font-name. The following
2665 ;; functions are not used in the face implementation itself.
2667 (defvar x-font-regexp nil
)
2668 (defvar x-font-regexp-head nil
)
2669 (defvar x-font-regexp-weight nil
)
2670 (defvar x-font-regexp-slant nil
)
2672 (defconst x-font-regexp-weight-subnum
1)
2673 (defconst x-font-regexp-slant-subnum
2)
2674 (defconst x-font-regexp-swidth-subnum
3)
2675 (defconst x-font-regexp-adstyle-subnum
4)
2677 ;;; Regexps matching font names in "Host Portable Character Representation."
2682 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2683 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2684 (weight\? "\\([^-]*\\)") ; 1
2685 (slant "\\([ior]\\)") ; 2
2686 ; (slant\? "\\([ior?*]?\\)") ; 2
2687 (slant\? "\\([^-]?\\)") ; 2
2688 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2689 (swidth "\\([^-]*\\)") ; 3
2690 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2691 (adstyle "\\([^-]*\\)") ; 4
2692 (pixelsize "[0-9]+")
2693 (pointsize "[0-9][0-9]+")
2694 (resx "[0-9][0-9]+")
2695 (resy "[0-9][0-9]+")
2702 (purecopy (concat "\\`\\*?[-?*]"
2703 foundry - family - weight
\? - slant
\? - swidth - adstyle -
2704 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2705 registry - encoding
"\\*?\\'"
2707 (setq x-font-regexp-head
2708 (purecopy (concat "\\`[-?*]" foundry - family - weight
\? - slant
\?
2709 "\\([-*?]\\|\\'\\)")))
2710 (setq x-font-regexp-slant
(purecopy (concat - slant -
)))
2711 (setq x-font-regexp-weight
(purecopy (concat - weight -
)))
2715 (defun x-resolve-font-name (pattern &optional face frame
)
2716 "Return a font name matching PATTERN.
2717 All wildcards in PATTERN are instantiated.
2718 If PATTERN is nil, return the name of the frame's base font, which never
2720 Given optional arguments FACE and FRAME, return a font which is
2721 also the same size as FACE on FRAME, or fail."
2723 (setq face
(face-name face
)))
2727 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2728 (let ((fonts (x-list-fonts pattern face frame
1)))
2731 (if (string-match-p "\\*" pattern
)
2732 (if (null (face-font face
))
2733 (error "No matching fonts are the same height as the frame default font")
2734 (error "No matching fonts are the same height as face `%s'" face
))
2735 (if (null (face-font face
))
2736 (error "Height of font `%s' doesn't match the frame default font"
2738 (error "Height of font `%s' doesn't match face `%s'"
2740 (error "No fonts match `%s'" pattern
)))
2742 (cdr (assq 'font
(frame-parameters (selected-frame))))))
2744 (defcustom font-list-limit
100
2745 "This variable is obsolete and has no effect."
2748 (make-obsolete-variable 'font-list-limit nil
"24.3")
2752 ;;; faces.el ends here