1 ;;; faces.el --- Lisp faces -*- lexical-binding: t -*-
3 ;; Copyright (C) 1992-1996, 1998-2017 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 <https://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 (defcustom term-file-aliases
39 '(("apollo" .
"vt100")
50 "Alist of terminal type aliases.
51 Entries are of the form (TYPE . ALIAS), where both elements are strings.
52 This means to treat a terminal of type TYPE as if it were of type ALIAS."
53 :type
'(alist :key-type
(string :tag
"Terminal")
54 :value-type
(string :tag
"Alias"))
58 (declare-function xw-defined-colors
"term/common-win" (&optional frame
))
60 (defvar help-xref-stack-item
)
62 (defvar face-name-history nil
63 "History list for some commands that read face names.
64 Maximum length of the history list is determined by the value
65 of `history-length', which see.")
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72 (defgroup font-selection nil
73 "Influencing face font selection."
77 (defcustom face-font-selection-order
78 '(:width
:height
:weight
:slant
)
79 "A list specifying how face font selection chooses fonts.
80 Each of the four symbols `:width', `:height', `:weight', and `:slant'
81 must appear once in the list, and the list must not contain any other
82 elements. Font selection first tries to find a best matching font
83 for those face attributes that appear before in the list. For
84 example, if `:slant' appears before `:height', font selection first
85 tries to find a font with a suitable slant, even if this results in
86 a font height that isn't optimal."
87 :tag
"Font selection order"
88 :type
'(list symbol symbol symbol symbol
)
89 :group
'font-selection
90 :set
#'(lambda (symbol value
)
91 (set-default symbol value
)
92 (internal-set-font-selection-order value
)))
95 ;; In the absence of Fontconfig support, Monospace and Sans Serif are
96 ;; unavailable, and we fall back on the courier and helv families,
97 ;; which are generally available.
98 (defcustom face-font-family-alternatives
99 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
100 '(("Monospace" "courier" "fixed")
102 ;; Monospace Serif is an Emacs invention, intended to work around
103 ;; portability problems when using Courier. It should work well
104 ;; when combined with Monospaced and with other standard fonts.
105 ;; One of its uses is for 'tex-verbatim' and 'Info-quoted' faces,
106 ;; so the result must be different from the default face's font,
107 ;; and must be monospaced. For 'tex-verbatim', it is desirable
108 ;; that the font really is a Serif font, so as to look like
112 ;; This looks good on GNU/Linux.
114 ;; This looks good on MS-Windows and OS X. Note that this is
115 ;; actually a sans-serif font, but it's here for lack of a better
118 ;; This looks good on macOS. "Courier" looks good too, but is
119 ;; jagged on GNU/Linux and so is listed later as "courier".
121 ;; Although these are anti-aliased, they are a bit faint compared
123 "FreeMono" "Nimbus Mono L"
124 ;; These are aliased and look jagged.
126 ;; Omit Courier New, as it is the default MS-Windows font and so
127 ;; would look no different, and is pretty faint on other platforms.
130 ;; This is present for backward compatibility.
131 ("courier" "CMU Typewriter Text" "fixed")
133 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
134 ("helv" "helvetica" "arial" "fixed")))
135 "Alist of alternative font family names.
136 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
137 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
139 :tag
"Alternative font families to try"
140 :type
'(repeat (repeat string
))
141 :group
'font-selection
142 :set
#'(lambda (symbol value
)
143 (set-default symbol value
)
144 (internal-set-alternative-font-family-alist value
)))
147 ;; This is defined originally in xfaces.c.
148 (defcustom face-font-registry-alternatives
149 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
151 '(("iso8859-1" "ms-oemlatin")
152 ("gb2312.1980" "gb2312" "gbk" "gb18030")
153 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
154 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
155 ("muletibetan-2" "muletibetan-0"))
156 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
157 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
158 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
159 ("muletibetan-2" "muletibetan-0"))))
160 "Alist of alternative font registry names.
161 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
162 If fonts of registry REGISTRY can be loaded, font selection
163 tries to find a best matching font among all fonts of registry
164 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
165 :tag
"Alternative font registries to try"
166 :type
'(repeat (repeat string
))
168 :group
'font-selection
169 :set
#'(lambda (symbol value
)
170 (set-default symbol value
)
171 (internal-set-alternative-font-registry-alist value
)))
174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175 ;;; Creation, copying.
176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
180 "Return a list of all defined faces."
181 (mapcar #'car face-new-frame-defaults
))
183 (defun make-face (face)
184 "Define a new face with name FACE, a symbol.
185 Do not call this directly from Lisp code; use `defface' instead.
187 If FACE is already known as a face, leave it unmodified. Return FACE."
188 (interactive (list (read-from-minibuffer
189 "Make face: " nil nil t
'face-name-history
)))
191 ;; Make frame-local faces (this also makes the global one).
192 (dolist (frame (frame-list))
193 (internal-make-lisp-face face frame
))
194 ;; Add the face to the face menu.
195 (when (fboundp 'facemenu-add-new-face
)
196 (facemenu-add-new-face face
))
197 ;; Define frame-local faces for all frames from X resources.
198 (make-face-x-resource-internal face
))
201 (defun make-empty-face (face)
202 "Define a new, empty face with name FACE.
203 Do not call this directly from Lisp code; use `defface' instead."
204 (interactive (list (read-from-minibuffer
205 "Make empty face: " nil nil t
'face-name-history
)))
208 (defun copy-face (old-face new-face
&optional frame new-frame
)
209 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
210 This function does not copy face customization data, so NEW-FACE
211 will not be made customizable. Most Lisp code should not call
212 this function; use `defface' with :inherit instead.
214 If NEW-FACE already exists as a face, modify it to be like
215 OLD-FACE. If NEW-FACE doesn't already exist, create it.
217 If the optional argument FRAME is a frame, change NEW-FACE on
218 FRAME only. If FRAME is t, copy the frame-independent default
219 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
220 the defaults as well as the faces on each existing frame.
222 If the optional fourth argument NEW-FRAME is given, copy the
223 information from face OLD-FACE on frame FRAME to NEW-FACE on
224 frame NEW-FRAME. In this case, FRAME must not be nil."
225 (let ((inhibit-quit t
))
229 (error "Copying face %s from all frames to one frame"
231 (make-empty-face new-face
)
232 (dolist (frame (frame-list))
233 (copy-face old-face new-face frame
))
234 (copy-face old-face new-face t
))
235 (make-empty-face new-face
)
236 (internal-copy-lisp-face old-face new-face frame new-frame
))
240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
241 ;;; Predicates, type checks.
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
245 "Return non-nil if FACE is a face name; nil otherwise.
246 A face name can be a string or a symbol."
247 (internal-lisp-face-p face
))
250 (defun check-face (face)
251 "Signal an error if FACE doesn't name a face.
254 (error "Not a face: %s" face
))
258 ;; The ID returned is not to be confused with the internally used IDs
259 ;; of realized faces. The ID assigned to Lisp faces is used to
260 ;; support faces in display table entries.
262 (defun face-id (face &optional _frame
)
263 "Return the internal ID of face with name FACE.
264 If FACE is a face-alias, return the ID of the target face.
265 The optional argument FRAME is ignored, since the internal face ID
266 of a face name is the same for all frames."
269 (face-id (get face
'face-alias
))))
271 (defun face-equal (face1 face2
&optional frame
)
272 "Non-nil if faces FACE1 and FACE2 are equal.
273 Faces are considered equal if all their attributes are equal.
274 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
275 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
276 If FRAME is omitted or nil, use the selected frame."
277 (internal-lisp-face-equal-p face1 face2 frame
))
280 (defun face-differs-from-default-p (face &optional frame
)
281 "Return non-nil if FACE displays differently from the default face.
282 If the optional argument FRAME is given, report on face FACE in that frame.
283 If FRAME is t, report on the defaults for face FACE (for new frames).
284 If FRAME is omitted or nil, use the selected frame."
286 (delq :inherit
(mapcar 'car face-attribute-name-alist
)))
288 (while (and attrs
(not differs
))
289 (let* ((attr (pop attrs
))
290 (attr-val (face-attribute face attr frame t
)))
292 (not (eq attr-val
'unspecified
))
293 (display-supports-face-attributes-p (list attr attr-val
)
295 (setq differs attr
))))
299 (defun face-nontrivial-p (face &optional frame
)
300 "True if face FACE has some non-nil attribute.
301 If the optional argument FRAME is given, report on face FACE in that frame.
302 If FRAME is t, report on the defaults for face FACE (for new frames).
303 If FRAME is omitted or nil, use the selected frame."
304 (not (internal-lisp-face-empty-p face frame
)))
307 (defun face-list-p (face-or-list)
308 "True if FACE-OR-LIST is a list of faces.
309 Return nil if FACE-OR-LIST is a non-nil atom, or a cons cell whose car
310 is either `foreground-color', `background-color', or a keyword."
311 ;; The logic of merge_face_ref (xfaces.c) is recreated here.
312 (and (listp face-or-list
)
313 (not (memq (car face-or-list
)
314 '(foreground-color background-color
)))
315 (not (keywordp (car face-or-list
)))))
319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
320 ;;; Setting face attributes from X resources.
321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
323 (defcustom face-x-resources
326 ;; FIXME; can we purecopy some of the conses too?
328 (cons (purecopy (car (cdr arg
))) (purecopy (cdr (cdr arg
))))))
329 '((:family
(".attributeFamily" .
"Face.AttributeFamily"))
330 (:foundry
(".attributeFoundry" .
"Face.AttributeFoundry"))
331 (:width
(".attributeWidth" .
"Face.AttributeWidth"))
332 (:height
(".attributeHeight" .
"Face.AttributeHeight"))
333 (:weight
(".attributeWeight" .
"Face.AttributeWeight"))
334 (:slant
(".attributeSlant" .
"Face.AttributeSlant"))
335 (:foreground
(".attributeForeground" .
"Face.AttributeForeground"))
337 (".attributeDistantForeground" .
"Face.AttributeDistantForeground"))
338 (:background
(".attributeBackground" .
"Face.AttributeBackground"))
339 (:overline
(".attributeOverline" .
"Face.AttributeOverline"))
340 (:strike-through
(".attributeStrikeThrough" .
"Face.AttributeStrikeThrough"))
341 (:box
(".attributeBox" .
"Face.AttributeBox"))
342 (:underline
(".attributeUnderline" .
"Face.AttributeUnderline"))
343 (:inverse-video
(".attributeInverse" .
"Face.AttributeInverse"))
345 (".attributeStipple" .
"Face.AttributeStipple")
346 (".attributeBackgroundPixmap" .
"Face.AttributeBackgroundPixmap"))
347 (:bold
(".attributeBold" .
"Face.AttributeBold"))
348 (:italic
(".attributeItalic" .
"Face.AttributeItalic"))
349 (:font
(".attributeFont" .
"Face.AttributeFont"))
350 (:inherit
(".attributeInherit" .
"Face.AttributeInherit"))))
351 "List of X resources and classes for face attributes.
352 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
353 the name of a face attribute, and each ENTRY is a cons of the form
354 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
355 X resource class for the attribute."
356 :type
'(repeat (cons symbol
(repeat (cons string string
))))
360 (declare-function internal-face-x-get-resource
"xfaces.c"
361 (resource class
&optional frame
))
363 (declare-function internal-set-lisp-face-attribute-from-resource
"xfaces.c"
364 (face attr value
&optional frame
))
366 (defun set-face-attribute-from-resource (face attribute resource class frame
)
367 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
368 Value is the attribute value specified by the resource, or nil
369 if not present. This function displays a message if the resource
370 specifies an invalid attribute."
371 (let* ((face-name (face-name face
))
372 (value (internal-face-x-get-resource (concat face-name resource
)
376 (internal-set-lisp-face-attribute-from-resource
377 face attribute
(downcase value
) frame
)
379 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
380 face-name frame attribute value
))))
384 (defun set-face-attributes-from-resources (face frame
)
385 "Set attributes of FACE from X resources for FRAME."
386 (when (memq (framep frame
) '(x w32
))
387 (dolist (definition face-x-resources
)
388 (let ((attribute (car definition
)))
389 (dolist (entry (cdr definition
))
390 (set-face-attribute-from-resource face attribute
(car entry
)
391 (cdr entry
) frame
))))))
394 (defun make-face-x-resource-internal (face &optional frame
)
395 "Fill frame-local FACE on FRAME from X resources.
396 FRAME nil or not specified means do it for all frames.
398 If `inhibit-x-resources' is non-nil, this function does nothing."
399 (unless inhibit-x-resources
400 (dolist (frame (if (null frame
) (frame-list) (list frame
)))
401 ;; `x-create-frame' already took care of correctly handling
402 ;; the reverse video case-- do _not_ touch the default face
403 (unless (and (eq face
'default
)
404 (frame-parameter frame
'reverse
))
405 (set-face-attributes-from-resources face frame
)))))
409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
410 ;;; Retrieving face attributes.
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
413 (defun face-name (face)
414 "Return the name of face FACE."
415 (symbol-name (check-face face
)))
418 (defun face-all-attributes (face &optional frame
)
419 "Return an alist stating the attributes of FACE.
420 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
421 If FRAME is omitted or nil the value describes the default attributes,
422 but if you specify FRAME, the value describes the attributes
424 (mapcar (lambda (pair)
425 (let ((attr (car pair
)))
426 (cons attr
(face-attribute face attr
(or frame t
)))))
427 face-attribute-name-alist
))
429 (defun face-attribute (face attribute
&optional frame inherit
)
430 "Return the value of FACE's ATTRIBUTE on FRAME.
431 If the optional argument FRAME is given, report on face FACE in that frame.
432 If FRAME is t, report on the defaults for face FACE (for new frames).
433 If FRAME is omitted or nil, use the selected frame.
435 If INHERIT is nil, only attributes directly defined by FACE are considered,
436 so the return value may be `unspecified', or a relative value.
437 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
438 faces specified by its `:inherit' attribute; however the return value
439 may still be `unspecified' or relative.
440 If INHERIT is a face or a list of faces, then the result is further merged
441 with that face (or faces), until it becomes specified and absolute.
443 To ensure that the return value is always specified and absolute, use a
444 value of `default' for INHERIT; this will resolve any unspecified or
445 relative values by merging with the `default' face (which is always
446 completely specified)."
447 (let ((value (internal-get-lisp-face-attribute face attribute frame
)))
448 (when (and inherit
(face-attribute-relative-p attribute value
))
449 ;; VALUE is relative, so merge with inherited faces
450 (let ((inh-from (face-attribute face
:inherit frame
)))
451 (unless (or (null inh-from
) (eq inh-from
'unspecified
))
454 (face-attribute-merged-with attribute value inh-from frame
))
455 ;; The `inherit' attribute may point to non existent faces.
459 (face-attribute-relative-p attribute value
))
460 ;; We should merge with INHERIT as well
461 (setq value
(face-attribute-merged-with attribute value inherit frame
)))
464 (defun face-attribute-merged-with (attribute value faces
&optional frame
)
465 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
466 FACES may be either a single face or a list of faces.
467 [This is an internal function.]"
468 (cond ((not (face-attribute-relative-p attribute value
))
473 (face-attribute-merged-with
475 (face-attribute-merged-with attribute value
(car faces
) frame
)
479 (merge-face-attribute attribute
481 (face-attribute faces attribute frame t
)))))
484 (defmacro face-attribute-specified-or
(value &rest body
)
485 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
486 (let ((temp (make-symbol "value")))
487 `(let ((,temp
,value
))
488 (if (not (eq ,temp
'unspecified
))
492 (defun face-foreground (face &optional frame inherit
)
493 "Return the foreground color name of FACE, or nil if unspecified.
494 If the optional argument FRAME is given, report on face FACE in that frame.
495 If FRAME is t, report on the defaults for face FACE (for new frames).
496 If FRAME is omitted or nil, use the selected frame.
498 If INHERIT is nil, only a foreground color directly defined by FACE is
499 considered, so the return value may be nil.
500 If INHERIT is t, and FACE doesn't define a foreground color, then any
501 foreground color that FACE inherits through its `:inherit' attribute
502 is considered as well; however the return value may still be nil.
503 If INHERIT is a face or a list of faces, then it is used to try to
504 resolve an unspecified foreground color.
506 To ensure that a valid color is always returned, use a value of
507 `default' for INHERIT; this will resolve any unspecified values by
508 merging with the `default' face (which is always completely specified)."
509 (face-attribute-specified-or (face-attribute face
:foreground frame inherit
)
512 (defun face-background (face &optional frame inherit
)
513 "Return the background color name of FACE, or nil if unspecified.
514 If the optional argument FRAME is given, report on face FACE in that frame.
515 If FRAME is t, report on the defaults for face FACE (for new frames).
516 If FRAME is omitted or nil, use the selected frame.
518 If INHERIT is nil, only a background color directly defined by FACE is
519 considered, so the return value may be nil.
520 If INHERIT is t, and FACE doesn't define a background color, then any
521 background color that FACE inherits through its `:inherit' attribute
522 is considered as well; however the return value may still be nil.
523 If INHERIT is a face or a list of faces, then it is used to try to
524 resolve an unspecified background color.
526 To ensure that a valid color is always returned, use a value of
527 `default' for INHERIT; this will resolve any unspecified values by
528 merging with the `default' face (which is always completely specified)."
529 (face-attribute-specified-or (face-attribute face
:background frame inherit
)
532 (defun face-stipple (face &optional frame inherit
)
533 "Return the stipple pixmap name of FACE, or nil if unspecified.
534 If the optional argument FRAME is given, report on face FACE in that frame.
535 If FRAME is t, report on the defaults for face FACE (for new frames).
536 If FRAME is omitted or nil, use the selected frame.
538 If INHERIT is nil, only a stipple directly defined by FACE is
539 considered, so the return value may be nil.
540 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
541 that FACE inherits through its `:inherit' attribute is considered as
542 well; however the return value may still be nil.
543 If INHERIT is a face or a list of faces, then it is used to try to
544 resolve an unspecified stipple.
546 To ensure that a valid stipple or nil is always returned, use a value of
547 `default' for INHERIT; this will resolve any unspecified values by merging
548 with the `default' face (which is always completely specified)."
549 (face-attribute-specified-or (face-attribute face
:stipple frame inherit
)
553 (defalias 'face-background-pixmap
'face-stipple
)
556 (defun face-underline-p (face &optional frame inherit
)
557 "Return non-nil if FACE specifies a non-nil underlining.
558 If the optional argument FRAME is given, report on face FACE in that frame.
559 If FRAME is t, report on the defaults for face FACE (for new frames).
560 If FRAME is omitted or nil, use the selected frame.
561 Optional argument INHERIT is passed to `face-attribute'."
562 (face-attribute-specified-or
563 (face-attribute face
:underline frame inherit
) nil
))
566 (defun face-inverse-video-p (face &optional frame inherit
)
567 "Return non-nil if FACE specifies a non-nil inverse-video.
568 If the optional argument FRAME is given, report on face FACE in that frame.
569 If FRAME is t, report on the defaults for face FACE (for new frames).
570 If FRAME is omitted or nil, use the selected frame.
571 Optional argument INHERIT is passed to `face-attribute'."
572 (eq (face-attribute face
:inverse-video frame inherit
) t
))
575 (defun face-bold-p (face &optional frame inherit
)
576 "Return non-nil if the font of FACE is bold on FRAME.
577 If the optional argument FRAME is given, report on face FACE in that frame.
578 If FRAME is t, report on the defaults for face FACE (for new frames).
579 If FRAME is omitted or nil, use the selected frame.
580 Optional argument INHERIT is passed to `face-attribute'.
581 Use `face-attribute' for finer control."
582 (let ((bold (face-attribute face
:weight frame inherit
)))
583 (memq bold
'(semi-bold bold extra-bold ultra-bold
))))
586 (defun face-italic-p (face &optional frame inherit
)
587 "Return non-nil if the font of FACE is italic on FRAME.
588 If the optional argument FRAME is given, report on face FACE in that frame.
589 If FRAME is t, report on the defaults for face FACE (for new frames).
590 If FRAME is omitted or nil, use the selected frame.
591 Optional argument INHERIT is passed to `face-attribute'.
592 Use `face-attribute' for finer control."
593 (let ((italic (face-attribute face
:slant frame inherit
)))
594 (memq italic
'(italic oblique
))))
598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
599 ;;; Face documentation.
600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
602 (defun face-documentation (face)
603 "Get the documentation string for FACE.
604 If FACE is a face-alias, get the documentation for the target face."
605 (let ((alias (get face
'face-alias
)))
607 (let ((doc (get alias
'face-documentation
)))
608 (format "%s is an alias for the face `%s'.%s" face alias
609 (if doc
(format "\n%s" doc
)
611 (get face
'face-documentation
))))
614 (defun set-face-documentation (face string
)
615 "Set the documentation string for FACE to STRING."
616 ;; Perhaps the text should go in DOC.
617 (put face
'face-documentation
(purecopy string
)))
620 (defalias 'face-doc-string
'face-documentation
)
621 (defalias 'set-face-doc-string
'set-face-documentation
)
625 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
626 ;; Setting face attributes.
627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
630 (defun set-face-attribute (face frame
&rest args
)
631 "Set attributes of FACE on FRAME from ARGS.
632 This function overrides the face attributes specified by FACE's
633 face spec. It is mostly intended for internal use only.
635 If FRAME is nil, set the attributes for all existing frames, as
636 well as the default for new frames. If FRAME is t, change the
637 default for new frames only.
639 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a
640 valid face attribute name. All attributes can be set to
641 `unspecified'; this fact is not further mentioned below.
643 The following attributes are recognized:
647 VALUE must be a string specifying the font family
648 \(e.g. \"Monospace\").
652 VALUE must be a string specifying the font foundry,
653 e.g., \"adobe\". If a font foundry is specified, wild-cards `*'
658 VALUE specifies the relative proportionate width of the font to use.
659 It must be one of the symbols `ultra-condensed', `extra-condensed',
660 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
661 `extra-expanded', or `ultra-expanded'.
665 VALUE specifies the relative or absolute height of the font. An
666 absolute height is an integer, and specifies font height in units
667 of 1/10 pt. A relative height is either a floating point number,
668 which specifies a scaling factor for the underlying face height;
669 or a function that takes a single argument (the underlying face
670 height) and returns the new height. Note that for the `default'
671 face, you must specify an absolute height (since there is nothing
672 for it to be relative to).
676 VALUE specifies the weight of the font to use. It must be one of the
677 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
678 `semi-light', `light', `extra-light', `ultra-light'.
682 VALUE specifies the slant of the font to use. It must be one of the
683 symbols `italic', `oblique', `normal', `reverse-italic', or
686 `:foreground', `:background'
688 VALUE must be a color name, a string.
692 VALUE specifies whether characters in FACE should be underlined.
693 If VALUE is t, underline with foreground color of the face.
694 If VALUE is a string, underline with that color.
695 If VALUE is nil, explicitly don't underline.
697 Otherwise, VALUE must be a property list of the form:
699 `(:color COLOR :style STYLE)'.
701 COLOR can be a either a color name string or `foreground-color'.
702 STYLE can be either `line' or `wave'.
703 If a keyword/value pair is missing from the property list, a
704 default value will be used for the value.
705 The default value of COLOR is the foreground color of the face.
706 The default value of STYLE is `line'.
710 VALUE specifies whether characters in FACE should be overlined. If
711 VALUE is t, overline with foreground color of the face. If VALUE is a
712 string, overline with that color. If VALUE is nil, explicitly don't
717 VALUE specifies whether characters in FACE should be drawn with a line
718 striking through them. If VALUE is t, use the foreground color of the
719 face. If VALUE is a string, strike-through with that color. If VALUE
720 is nil, explicitly don't strike through.
724 VALUE specifies whether characters in FACE should have a box drawn
725 around them. If VALUE is nil, explicitly don't draw boxes. If
726 VALUE is t, draw a box with lines of width 1 in the foreground color
727 of the face. If VALUE is a string, the string must be a color name,
728 and the box is drawn in that color with a line width of 1. Otherwise,
729 VALUE must be a property list of the form `(:line-width WIDTH
730 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
731 the property list, a default value will be used for the value, as
732 specified below. WIDTH specifies the width of the lines to draw; it
733 defaults to 1. If WIDTH is negative, the absolute value is the width
734 of the lines, and draw top/bottom lines inside the characters area,
735 not around it. COLOR is the name of the color to draw in, default is
736 the foreground color of the face for simple boxes, and the background
737 color of the face for 3D boxes. STYLE specifies whether a 3D box
738 should be draw. If STYLE is `released-button', draw a box looking
739 like a released 3D button. If STYLE is `pressed-button' draw a box
740 that appears like a pressed button. If STYLE is nil, the default if
741 the property list doesn't contain a style specification, draw a 2D
746 VALUE specifies whether characters in FACE should be displayed in
747 inverse video. VALUE must be one of t or nil.
751 If VALUE is a string, it must be the name of a file of pixmap data.
752 The directories listed in the `x-bitmap-file-path' variable are
753 searched. Alternatively, VALUE may be a list of the form (WIDTH
754 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
755 is a string containing the raw bits of the bitmap. VALUE nil means
756 explicitly don't use a stipple pattern.
758 For convenience, attributes `:family', `:foundry', `:width',
759 `:height', `:weight', and `:slant' may also be set in one step
764 Set font-related face attributes from VALUE.
765 VALUE must be a valid font name or font object. It can also
766 be a fontset name. Setting this attribute will also set
767 the `:family', `:foundry', `:width', `:height', `:weight',
768 and `:slant' attributes.
772 VALUE is the name of a face from which to inherit attributes, or
773 a list of face names. Attributes from inherited faces are merged
774 into the face like an underlying face would be, with higher
775 priority than underlying faces.
777 For backward compatibility, the keywords `:bold' and `:italic'
778 can be used to specify weight and slant respectively. This usage
779 is considered obsolete. For these two keywords, the VALUE must
780 be either t or nil. A value of t for `:bold' is equivalent to
781 setting `:weight' to `bold', and a value of t for `:italic' is
782 equivalent to setting `:slant' to `italic'. But if `:weight' is
783 specified in the face spec, `:bold' is ignored, and if `:slant'
784 is specified, `:italic' is ignored."
785 (setq args
(purecopy args
))
786 (let ((where (if (null frame
) 0 frame
))
788 family foundry orig-family orig-foundry
)
789 ;; If we set the new-frame defaults, this face is modified outside Custom.
790 (if (memq where
'(0 t
))
791 (put (or (get face
'face-alias
) face
) 'face-modified t
))
792 ;; If family and/or foundry are specified, set it first. Certain
793 ;; face attributes, e.g. :weight semi-condensed, are not supported
794 ;; in every font. See bug#1127.
796 (cond ((eq (car spec
) :family
)
797 (setq family
(cadr spec
)))
798 ((eq (car spec
) :foundry
)
799 (setq foundry
(cadr spec
))))
800 (setq spec
(cddr spec
)))
801 (when (or family foundry
)
802 (when (and (stringp family
)
803 (string-match "\\([^-]*\\)-\\([^-]*\\)" family
))
804 (setq orig-foundry foundry
807 (setq foundry
(match-string 1 family
)))
808 (setq family
(match-string 2 family
))
809 ;; Reject bogus "families" that are all-digits -- those are some
810 ;; weird font names, like Foobar-12, that end in a number.
811 (when (string-match "\\`[0-9]*\\'" family
)
812 (setq family orig-family
)
813 (setq foundry orig-foundry
)))
814 (when (or (stringp family
) (eq family
'unspecified
))
815 (internal-set-lisp-face-attribute face
:family
(purecopy family
)
817 (when (or (stringp foundry
) (eq foundry
'unspecified
))
818 (internal-set-lisp-face-attribute face
:foundry
(purecopy foundry
)
821 (unless (memq (car args
) '(:family
:foundry
))
822 (internal-set-lisp-face-attribute face
(car args
)
823 (purecopy (cadr args
))
825 (setq args
(cddr args
)))))
827 (defun make-face-bold (face &optional frame _noerror
)
828 "Make the font of FACE be bold, if possible.
829 FRAME nil or not specified means change face on all frames.
830 Argument NOERROR is ignored and retained for compatibility.
831 Use `set-face-attribute' for finer control of the font weight."
832 (interactive (list (read-face-name "Make which face bold"
834 (set-face-attribute face frame
:weight
'bold
))
837 (defun make-face-unbold (face &optional frame _noerror
)
838 "Make the font of FACE be non-bold, if possible.
839 FRAME nil or not specified means change face on all frames.
840 Argument NOERROR is ignored and retained for compatibility."
841 (interactive (list (read-face-name "Make which face non-bold"
843 (set-face-attribute face frame
:weight
'normal
))
846 (defun make-face-italic (face &optional frame _noerror
)
847 "Make the font of FACE be italic, if possible.
848 FRAME nil or not specified means change face on all frames.
849 Argument NOERROR is ignored and retained for compatibility.
850 Use `set-face-attribute' for finer control of the font slant."
851 (interactive (list (read-face-name "Make which face italic"
853 (set-face-attribute face frame
:slant
'italic
))
856 (defun make-face-unitalic (face &optional frame _noerror
)
857 "Make the font of FACE be non-italic, if possible.
858 FRAME nil or not specified means change face on all frames.
859 Argument NOERROR is ignored and retained for compatibility."
860 (interactive (list (read-face-name "Make which face non-italic"
862 (set-face-attribute face frame
:slant
'normal
))
865 (defun make-face-bold-italic (face &optional frame _noerror
)
866 "Make the font of FACE be bold and italic, if possible.
867 FRAME nil or not specified means change face on all frames.
868 Argument NOERROR is ignored and retained for compatibility.
869 Use `set-face-attribute' for finer control of font weight and slant."
870 (interactive (list (read-face-name "Make which face bold-italic"
872 (set-face-attribute face frame
:weight
'bold
:slant
'italic
))
875 (defun set-face-font (face font
&optional frame
)
876 "Change font-related attributes of FACE to those of FONT (a string).
877 FRAME nil or not specified means change face on all frames.
878 This sets the attributes `:family', `:foundry', `:width',
879 `:height', `:weight', and `:slant'. When called interactively,
880 prompt for the face and font."
881 (interactive (read-face-and-attribute :font
))
882 (set-face-attribute face frame
:font font
))
885 ;; Implementation note: Emulating gray background colors with a
886 ;; stipple pattern is now part of the face realization process, and is
887 ;; done in C depending on the frame on which the face is realized.
889 (defun set-face-background (face color
&optional frame
)
890 "Change the background color of face FACE to COLOR (a string).
891 FRAME nil or not specified means change face on all frames.
892 COLOR can be a system-defined color name (see `list-colors-display')
893 or a hex spec of the form #RRGGBB.
894 When called interactively, prompts for the face and color."
895 (interactive (read-face-and-attribute :background
))
896 (set-face-attribute face frame
:background
(or color
'unspecified
)))
899 (defun set-face-foreground (face color
&optional frame
)
900 "Change the foreground color of face FACE to COLOR (a string).
901 FRAME nil or not specified means change face on all frames.
902 COLOR can be a system-defined color name (see `list-colors-display')
903 or a hex spec of the form #RRGGBB.
904 When called interactively, prompts for the face and color."
905 (interactive (read-face-and-attribute :foreground
))
906 (set-face-attribute face frame
:foreground
(or color
'unspecified
)))
909 (defun set-face-stipple (face stipple
&optional frame
)
910 "Change the stipple pixmap of face FACE to STIPPLE.
911 FRAME nil or not specified means change face on all frames.
912 STIPPLE should be a string, the name of a file of pixmap data.
913 The directories listed in the `x-bitmap-file-path' variable are searched.
915 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
916 where WIDTH and HEIGHT are the size in pixels,
917 and DATA is a string, containing the raw bits of the bitmap."
918 (interactive (read-face-and-attribute :stipple
))
919 (set-face-attribute face frame
:stipple
(or stipple
'unspecified
)))
922 (defun set-face-underline (face underline
&optional frame
)
923 "Specify whether face FACE is underlined.
924 UNDERLINE nil means FACE explicitly doesn't underline.
925 UNDERLINE t means FACE underlines with its foreground color.
926 If UNDERLINE is a string, underline with that color.
928 UNDERLINE may also be a list of the form (:color COLOR :style STYLE),
929 where COLOR is a string or `foreground-color', and STYLE is either
930 `line' or `wave'. :color may be omitted, which means to use the
931 foreground color. :style may be omitted, which means to use a line.
933 FRAME nil or not specified means change face on all frames.
934 Use `set-face-attribute' to \"unspecify\" underlining."
935 (interactive (read-face-and-attribute :underline
))
936 (set-face-attribute face frame
:underline underline
))
938 (define-obsolete-function-alias 'set-face-underline-p
939 'set-face-underline
"24.3")
942 (defun set-face-inverse-video (face inverse-video-p
&optional frame
)
943 "Specify whether face FACE is in inverse video.
944 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
945 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
946 FRAME nil or not specified means change face on all frames.
947 Use `set-face-attribute' to \"unspecify\" the inverse video attribute."
949 (let ((list (read-face-and-attribute :inverse-video
)))
950 (list (car list
) (if (cadr list
) t
))))
951 (set-face-attribute face frame
:inverse-video inverse-video-p
))
953 (define-obsolete-function-alias 'set-face-inverse-video-p
954 'set-face-inverse-video
"24.4")
956 (defun set-face-bold (face bold-p
&optional frame
)
957 "Specify whether face FACE is bold.
958 BOLD-P non-nil means FACE should explicitly display bold.
959 BOLD-P nil means FACE should explicitly display non-bold.
960 FRAME nil or not specified means change face on all frames.
961 Use `set-face-attribute' or `modify-face' for finer control."
963 (make-face-unbold face frame
)
964 (make-face-bold face frame
)))
966 (define-obsolete-function-alias 'set-face-bold-p
'set-face-bold
"24.4")
969 (defun set-face-italic (face italic-p
&optional frame
)
970 "Specify whether face FACE is italic.
971 ITALIC-P non-nil means FACE should explicitly display italic.
972 ITALIC-P nil means FACE should explicitly display non-italic.
973 FRAME nil or not specified means change face on all frames.
974 Use `set-face-attribute' or `modify-face' for finer control."
976 (make-face-unitalic face frame
)
977 (make-face-italic face frame
)))
979 (define-obsolete-function-alias 'set-face-italic-p
'set-face-italic
"24.4")
982 (defalias 'set-face-background-pixmap
'set-face-stipple
)
985 (defun invert-face (face &optional frame
)
986 "Swap the foreground and background colors of FACE.
987 If FRAME is omitted or nil, it means change face on all frames.
988 If FACE specifies neither foreground nor background color,
989 set its foreground and background to the background and foreground
990 of the default face. Value is FACE."
991 (interactive (list (read-face-name "Invert face" (face-at-point t
))))
992 (let ((fg (face-attribute face
:foreground frame
))
993 (bg (face-attribute face
:background frame
)))
994 (if (not (and (eq fg
'unspecified
) (eq bg
'unspecified
)))
995 (set-face-attribute face frame
:foreground bg
:background fg
)
996 (set-face-attribute face frame
998 (face-attribute 'default
:background frame
)
1000 (face-attribute 'default
:foreground frame
))))
1004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1005 ;;; Interactively modifying faces.
1006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1008 (defvar crm-separator
) ; from crm.el
1010 (defun read-face-name (prompt &optional default multiple
)
1011 "Read one or more face names, prompting with PROMPT.
1012 PROMPT should not end in a space or a colon.
1014 If DEFAULT is non-nil, it should be a face (a symbol) or a face
1015 name (a string). It can also be a list of faces or face names.
1017 If MULTIPLE is non-nil, the return value from this function is a
1018 list of faces. Otherwise a single face is returned.
1020 If the user enter the empty string at the prompt, DEFAULT is
1021 returned after a possible transformation according to MULTIPLE.
1022 That is, if DEFAULT is a list and MULTIPLE is nil, the first
1023 element of DEFAULT is returned. If DEFAULT isn't a list, but
1024 MULTIPLE is non-nil, a one-element list containing DEFAULT is
1025 returned. Otherwise, DEFAULT is returned verbatim."
1026 (unless (listp default
)
1027 (setq default
(list default
)))
1031 (mapconcat (lambda (f) (if (symbolp f
) (symbol-name f
) f
))
1033 ;; If we only want one, and the default is more than one,
1034 ;; discard the unwanted ones.
1035 (setq default
(car default
))
1036 (if (symbolp default
)
1037 (symbol-name default
)
1039 (when (and default
(not multiple
))
1041 ;; For compatibility with `completing-read-multiple' use `crm-separator'
1042 ;; to define DEFAULT if MULTIPLE is nil.
1043 (setq default
(car (split-string default crm-separator t
))))
1045 ;; Older versions of `read-face-name' did not append ": " to the
1046 ;; prompt, so there are third party libraries that have that in the
1047 ;; prompt. If so, remove it.
1048 (setq prompt
(replace-regexp-in-string ": ?\\'" "" prompt
))
1049 (let ((prompt (if default
1050 (format-message "%s (default `%s'): " prompt default
)
1051 (format "%s: " prompt
)))
1052 aliasfaces nonaliasfaces faces
)
1053 ;; Build up the completion tables.
1054 (mapatoms (lambda (s)
1056 (if (get s
'face-alias
)
1057 (push (symbol-name s
) aliasfaces
)
1058 (push (symbol-name s
) nonaliasfaces
)))))
1061 (dolist (face (completing-read-multiple
1063 (completion-table-in-turn nonaliasfaces aliasfaces
)
1064 nil t nil
'face-name-history default
))
1065 ;; Ignore elements that are not faces
1066 ;; (for example, because DEFAULT was "all faces")
1067 (if (facep face
) (push (intern face
) faces
)))
1069 (let ((face (completing-read
1071 (completion-table-in-turn nonaliasfaces aliasfaces
)
1072 nil t nil
'face-name-history default
)))
1073 (if (facep face
) (intern face
))))))
1075 ;; Not defined without X, but behind window-system test.
1076 (defvar x-bitmap-file-path
)
1078 (defun face-valid-attribute-values (attribute &optional frame
)
1079 "Return valid values for face attribute ATTRIBUTE.
1080 The optional argument FRAME is used to determine available fonts
1081 and colors. If it is nil or not specified, the selected frame is used.
1082 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
1083 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1088 (if (window-system frame
)
1089 (mapcar (lambda (x) (cons x x
))
1091 ;; Only one font on TTYs.
1092 (list (cons "default" "default"))))
1096 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1099 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1102 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1105 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1106 (internal-lisp-face-attribute-values attribute
)))
1107 ((or `:underline
`:overline
`:strike-through
`:box
)
1108 (if (window-system frame
)
1109 (nconc (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1110 (internal-lisp-face-attribute-values attribute
))
1111 (mapcar #'(lambda (c) (cons c c
))
1112 (defined-colors frame
)))
1113 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1114 (internal-lisp-face-attribute-values attribute
))))
1115 ((or `:foreground
`:background
)
1116 (mapcar #'(lambda (c) (cons c c
))
1117 (defined-colors frame
)))
1121 (and (memq (window-system frame
) '(x ns
)) ; No stipple on w32
1124 (mapcar (lambda (dir)
1125 (and (file-readable-p dir
)
1126 (file-directory-p dir
)
1127 (directory-files dir
)))
1128 x-bitmap-file-path
)))))
1130 (cons '("none" . nil
)
1131 (mapcar #'(lambda (c) (cons (symbol-name c
) c
))
1134 (error "Internal error")))))
1135 (if (and (listp valid
) (not (memq attribute
'(:inherit
))))
1136 (nconc (list (cons "unspecified" 'unspecified
)) valid
)
1140 (defconst face-attribute-name-alist
1141 '((:family .
"font family")
1142 (:foundry .
"font foundry")
1143 (:width .
"character set width")
1144 (:height .
"height in 1/10 pt")
1145 (:weight .
"weight")
1147 (:underline .
"underline")
1148 (:overline .
"overline")
1149 (:strike-through .
"strike-through")
1151 (:inverse-video .
"inverse-video display")
1152 (:foreground .
"foreground color")
1153 (:background .
"background color")
1154 (:stipple .
"background stipple")
1155 (:inherit .
"inheritance"))
1156 "An alist of descriptive names for face attributes.
1157 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1158 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1159 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1162 (defun face-descriptive-attribute-name (attribute)
1163 "Return a descriptive name for ATTRIBUTE."
1164 (cdr (assq attribute face-attribute-name-alist
)))
1167 (defun face-read-string (face default name
&optional completion-alist
)
1168 "Interactively read a face attribute string value.
1169 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1170 default string to return if no new value is entered. NAME is a
1171 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1172 alist of valid values, if non-nil.
1174 Entering nothing accepts the default string DEFAULT.
1175 Value is the new attribute value."
1176 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1177 ;; each word in a string separately).
1178 (setq name
(concat (upcase (substring name
0 1)) (substring name
1)))
1179 (let* ((completion-ignore-case t
)
1180 (value (completing-read
1181 (format-message (if default
1182 "%s for face `%s' (default %s): "
1183 "%s for face `%s': ")
1185 completion-alist nil nil nil nil default
)))
1186 (if (equal value
"") default value
)))
1189 (defun face-read-integer (face default name
)
1190 "Interactively read an integer face attribute value.
1191 FACE is the face whose attribute is read. DEFAULT is the default
1192 value to return if no new value is entered. NAME is a descriptive
1193 name of the attribute for prompting. Value is the new attribute value."
1195 (face-read-string face
1196 (format "%s" default
)
1198 (list (cons "unspecified" 'unspecified
)))))
1199 (cond ((equal new-value
"unspecified")
1201 ((member new-value
'("unspecified-fg" "unspecified-bg"))
1204 (string-to-number new-value
)))))
1207 ;; FIXME this does allow you to enter the list forms of :box,
1208 ;; :stipple, or :underline, because face-valid-attribute-values does
1209 ;; not return those forms.
1210 (defun read-face-attribute (face attribute
&optional frame
)
1211 "Interactively read a new value for FACE's ATTRIBUTE.
1212 Optional argument FRAME nil or unspecified means read an attribute value
1213 of a global face. Value is the new attribute value."
1214 (let* ((old-value (face-attribute face attribute frame
))
1215 (attribute-name (face-descriptive-attribute-name attribute
))
1216 (valid (face-valid-attribute-values attribute frame
))
1218 ;; Represent complex attribute values as strings by printing them
1219 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1220 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1221 ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'.
1222 (and (memq attribute
'(:box
:stipple
:underline
))
1223 (or (consp old-value
)
1224 (vectorp old-value
))
1225 (setq old-value
(prin1-to-string old-value
)))
1226 (cond ((listp valid
)
1228 (or (car (rassoc old-value valid
))
1229 (format "%s" old-value
))))
1231 (face-read-string face default attribute-name valid
))
1232 (if (equal new-value default
)
1233 ;; Nothing changed, so don't bother with all the stuff
1234 ;; below. In particular, this avoids a non-tty color
1235 ;; from being canonicalized for a tty when the user
1236 ;; just uses the default.
1237 (setq new-value old-value
)
1238 ;; Terminal frames can support colors that don't appear
1239 ;; explicitly in VALID, using color approximation code
1240 ;; in tty-colors.el.
1241 (when (and (memq attribute
'(:foreground
:background
))
1242 (not (memq (window-system frame
) '(x w32 ns
)))
1243 (not (member new-value
1245 "unspecified-fg" "unspecified-bg"))))
1246 (setq new-value
(car (tty-color-desc new-value frame
))))
1247 (when (assoc new-value valid
)
1248 (setq new-value
(cdr (assoc new-value valid
)))))))
1249 ((eq valid
'integerp
)
1250 (setq new-value
(face-read-integer face old-value attribute-name
)))
1251 (t (error "Internal error")))
1252 ;; Convert stipple and box value text we read back to a list or
1253 ;; vector if it looks like one. This makes the assumption that a
1254 ;; pixmap file name won't start with an open-paren.
1255 (and (memq attribute
'(:stipple
:box
:underline
))
1257 (string-match-p "^[[(]" new-value
)
1258 (setq new-value
(read new-value
)))
1261 (declare-function fontset-list
"fontset.c" ())
1262 (declare-function x-list-fonts
"xfaces.c"
1263 (pattern &optional face frame maximum width
))
1265 (defun read-face-font (face &optional frame
)
1266 "Read the name of a font for FACE on FRAME.
1267 If optional argument FRAME is nil or omitted, use the selected frame."
1268 (let ((completion-ignore-case t
))
1269 (completing-read (format-message
1270 "Set font attributes of face `%s' from font: " face
)
1271 (append (fontset-list) (x-list-fonts "*" nil frame
)))))
1274 (defun read-all-face-attributes (face &optional frame
)
1275 "Interactively read all attributes for FACE.
1276 If optional argument FRAME is nil or omitted, use the selected frame.
1277 Value is a property list of attribute names and new values."
1279 (dolist (attribute face-attribute-name-alist result
)
1280 (setq result
(cons (car attribute
)
1281 (cons (read-face-attribute face
(car attribute
) frame
)
1284 (defun modify-face (&optional face foreground background stipple
1285 bold-p italic-p underline inverse-p frame
)
1286 "Modify attributes of faces interactively.
1287 If optional argument FRAME is nil or omitted, modify the face used
1288 for newly created frame, i.e. the global face.
1289 For non-interactive use, `set-face-attribute' is preferred.
1290 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1291 and the face and its settings are obtained by querying the user."
1294 (set-face-attribute face frame
1295 :foreground
(or foreground
'unspecified
)
1296 :background
(or background
'unspecified
)
1298 :weight
(if bold-p
'bold
'normal
)
1299 :slant
(if italic-p
'italic
'normal
)
1300 :underline underline
1301 :inverse-video inverse-p
)
1302 (setq face
(read-face-name "Modify face" (face-at-point t
)))
1303 (apply #'set-face-attribute face frame
1304 (read-all-face-attributes face frame
))))
1306 (defun read-face-and-attribute (attribute &optional frame
)
1307 "Read face name and face attribute value.
1308 ATTRIBUTE is the attribute whose new value is read.
1309 FRAME nil or unspecified means read attribute value of global face.
1310 Value is a list (FACE NEW-VALUE) where FACE is the face read
1311 \(a symbol), and NEW-VALUE is value read."
1312 (cond ((eq attribute
:font
)
1313 (let* ((prompt "Set font-related attributes of face")
1314 (face (read-face-name prompt
(face-at-point t
)))
1315 (font (read-face-font face frame
)))
1318 (let* ((attribute-name (face-descriptive-attribute-name attribute
))
1319 (prompt (format "Set %s of face" attribute-name
))
1320 (face (read-face-name prompt
(face-at-point t
)))
1321 (new-value (read-face-attribute face attribute frame
)))
1322 (list face new-value
)))))
1326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1330 (defconst list-faces-sample-text
1331 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1332 "Text string to display as the sample text for `list-faces-display'.")
1335 ;; The name list-faces would be more consistent, but let's avoid a
1336 ;; conflict with Lucid, which uses that name differently.
1338 (defvar help-xref-stack
)
1339 (defun list-faces-display (&optional regexp
)
1340 "List all faces, using the same sample text in each.
1341 The sample text is a string that comes from the variable
1342 `list-faces-sample-text'.
1344 If REGEXP is non-nil, list only those faces with names matching
1345 this regular expression. When called interactively with a prefix
1346 argument, prompt for a regular expression using `read-regexp'."
1347 (interactive (list (and current-prefix-arg
1348 (read-regexp "List faces matching regexp"))))
1349 (let ((all-faces (zerop (length regexp
)))
1350 (frame (selected-frame))
1353 disp-frame window face-name
)
1354 ;; We filter and take the max length in one pass
1358 (let ((s (symbol-name f
)))
1359 (when (or all-faces
(string-match-p regexp s
))
1360 (setq max-length
(max (length s
) max-length
))
1362 (sort (face-list) #'string-lessp
))))
1364 (error "No faces matching \"%s\"" regexp
))
1365 (setq max-length
(1+ max-length
)
1366 line-format
(format "%%-%ds" max-length
))
1367 (with-help-window "*Faces*"
1368 (with-current-buffer standard-output
1369 (setq truncate-lines t
)
1371 (substitute-command-keys
1373 "\\<help-mode-map>Use "
1374 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1375 "\\[help-follow] on a face name to customize it\n"
1376 "or on its sample text for a description of the face.\n\n")))
1377 (setq help-xref-stack nil
)
1378 (dolist (face faces
)
1379 (setq face-name
(symbol-name face
))
1380 (insert (format line-format face-name
))
1381 ;; Hyperlink to a customization buffer for the face. Using
1382 ;; the help xref mechanism may not be the best way.
1385 (search-backward face-name
)
1386 (setq help-xref-stack-item
`(list-faces-display ,regexp
))
1387 (help-xref-button 0 'help-customize-face face
)))
1389 (line-beg (line-beginning-position)))
1390 (insert list-faces-sample-text
)
1391 ;; Hyperlink to a help buffer for the face.
1394 (search-backward list-faces-sample-text
)
1395 (help-xref-button 0 'help-face face
)))
1397 (put-text-property beg
(1- (point)) 'face face
)
1398 ;; Make all face commands default to the proper face
1399 ;; anywhere in the line.
1400 (put-text-property line-beg
(1- (point)) 'read-face-name face
)
1401 ;; If the sample text has multiple lines, line up all of them.
1405 (insert-char ?\s max-length
)
1407 (goto-char (point-min))))
1408 ;; If the *Faces* buffer appears in a different frame,
1409 ;; copy all the face definitions from FRAME,
1410 ;; so that the display will reflect the frame that was selected.
1411 (setq window
(get-buffer-window (get-buffer "*Faces*") t
))
1412 (setq disp-frame
(if window
(window-frame window
)
1413 (car (frame-list))))
1414 (or (eq frame disp-frame
)
1415 (dolist (face (face-list))
1416 (copy-face face face frame disp-frame
)))))
1419 (defun describe-face (face &optional frame
)
1420 "Display the properties of face FACE on FRAME.
1421 Interactively, FACE defaults to the faces of the character after point
1422 and FRAME defaults to the selected frame.
1424 If the optional argument FRAME is given, report on face FACE in that frame.
1425 If FRAME is t, report on the defaults for face FACE (for new frames).
1426 If FRAME is omitted or nil, use the selected frame."
1427 (interactive (list (read-face-name "Describe face"
1428 (or (face-at-point t
) 'default
)
1430 (let* ((attrs '((:family .
"Family")
1431 (:foundry .
"Foundry")
1433 (:height .
"Height")
1434 (:weight .
"Weight")
1436 (:foreground .
"Foreground")
1437 (:distant-foreground .
"DistantForeground")
1438 (:background .
"Background")
1439 (:underline .
"Underline")
1440 (:overline .
"Overline")
1441 (:strike-through .
"Strike-through")
1443 (:inverse-video .
"Inverse")
1444 (:stipple .
"Stipple")
1446 (:fontset .
"Fontset")
1447 (:inherit .
"Inherit")))
1448 (max-width (apply #'max
(mapcar #'(lambda (x) (length (cdr x
)))
1450 (help-setup-xref (list #'describe-face face
)
1451 (called-interactively-p 'interactive
))
1453 (setq face
'default
))
1454 (if (not (listp face
))
1455 (setq face
(list face
)))
1456 (with-help-window (help-buffer)
1457 (with-current-buffer standard-output
1458 (dolist (f face
(buffer-string))
1459 (if (stringp f
) (setq f
(intern f
)))
1460 ;; We may get called for anonymous faces (i.e., faces
1461 ;; expressed using prop-value plists). Those can't be
1462 ;; usefully customized, so ignore them.
1464 (insert "Face: " (symbol-name f
))
1466 (insert " undefined face.\n")
1467 (let ((customize-label "customize this face")
1469 (insert (concat " (" (propertize "sample" 'font-lock-face f
) ")"))
1470 (princ (concat " (" customize-label
")\n"))
1471 ;; FIXME not sure how much of this belongs here, and
1472 ;; how much in `face-documentation'. The latter is
1473 ;; not used much, but needs to return nil for
1474 ;; undocumented faces.
1475 (let ((alias (get f
'face-alias
))
1482 "\n %s is an alias for the face `%s'.\n%s"
1484 (if (setq obsolete
(get f
'obsolete-face
))
1486 " This face is obsolete%s; use `%s' instead.\n"
1487 (if (stringp obsolete
)
1488 (format " since %s" obsolete
)
1492 (insert "\nDocumentation:\n"
1493 (substitute-command-keys
1494 (or (face-documentation face
)
1495 "Not documented as a face."))
1497 (with-current-buffer standard-output
1500 (concat "\\(" customize-label
"\\)") nil t
)
1501 (help-xref-button 1 'help-customize-face f
)))
1502 (setq file-name
(find-lisp-object-file-name f
'defface
))
1504 (princ (substitute-command-keys "Defined in `"))
1505 (princ (file-name-nondirectory file-name
))
1506 (princ (substitute-command-keys "'"))
1507 ;; Make a hyperlink to the library.
1510 (substitute-command-keys "`\\([^`']+\\)'") nil t
)
1511 (help-xref-button 1 'help-face-def f file-name
))
1516 (let ((attr (face-attribute f
(car a
) frame
)))
1517 (insert (make-string (- max-width
(length (cdr a
))) ?\s
)
1518 (cdr a
) ": " (format "%s" attr
))
1519 (if (and (eq (car a
) :inherit
)
1520 (not (eq attr
'unspecified
)))
1521 ;; Make a hyperlink to the parent face.
1523 (re-search-backward ": \\([^:]+\\)" nil t
)
1524 (help-xref-button 1 'help-face attr
)))
1529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1530 ;;; Face specifications (defface).
1531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1533 ;; Parameter FRAME Is kept for call compatibility to with previous
1534 ;; face implementation.
1536 (defun face-attr-construct (face &optional _frame
)
1537 "Return a `defface'-style attribute list for FACE.
1538 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1539 face attributes of FACE where ATTRIBUTE is the attribute name and
1540 VALUE is the specified value of that attribute.
1541 Argument FRAME is ignored and retained for compatibility."
1543 (dolist (entry face-attribute-name-alist result
)
1544 (let* ((attribute (car entry
))
1545 (value (face-attribute face attribute
)))
1546 (unless (eq value
'unspecified
)
1547 (setq result
(nconc (list attribute value
) result
)))))))
1550 (defun face-spec-set-match-display (display frame
)
1551 "Non-nil if DISPLAY matches FRAME.
1552 DISPLAY is part of a spec such as can be used in `defface'.
1553 If FRAME is nil, the current FRAME is used."
1554 (let* ((conjuncts display
)
1555 conjunct req options
1556 ;; t means we have succeeded against all the conjuncts in
1557 ;; DISPLAY that have been tested so far.
1559 (if (eq conjuncts t
)
1560 (setq conjuncts nil
))
1561 (while (and conjuncts match
)
1562 (setq conjunct
(car conjuncts
)
1563 conjuncts
(cdr conjuncts
)
1565 options
(cdr conjunct
)
1566 match
(cond ((eq req
'type
)
1567 (or (memq (window-system frame
) options
)
1568 (and (memq 'graphic options
)
1569 (memq (window-system frame
) '(x w32 ns
)))
1570 ;; FIXME: This should be revisited to use
1571 ;; display-graphic-p, provided that the
1572 ;; color selection depends on the number
1573 ;; of supported colors, and all defface's
1574 ;; are changed to look at number of colors
1575 ;; instead of (type graphic) etc.
1576 (if (null (window-system frame
))
1578 (or (and (memq 'motif options
)
1580 (and (memq 'gtk options
)
1582 (and (memq 'lucid options
)
1583 (featurep 'x-toolkit
)
1584 (not (featurep 'motif
))
1585 (not (featurep 'gtk
)))
1586 (and (memq 'x-toolkit options
)
1587 (featurep 'x-toolkit
))))))
1588 ((eq req
'min-colors
)
1589 (>= (display-color-cells frame
) (car options
)))
1591 (memq (frame-parameter frame
'display-type
) options
))
1592 ((eq req
'background
)
1593 (memq (frame-parameter frame
'background-mode
)
1596 (display-supports-face-attributes-p options frame
))
1597 (t (error "Unknown req `%S' with options `%S'"
1602 (defun face-spec-choose (spec &optional frame no-match-retval
)
1603 "Return the proper attributes for FRAME, out of SPEC.
1605 Value is a plist of face attributes in the form of attribute-value pairs.
1606 If no match is found or SPEC is nil, return nil, unless NO-MATCH-RETVAL
1607 is given, in which case return its value instead."
1609 (setq frame
(selected-frame)))
1611 result defaults match-found
)
1613 (let* ((entry (pop tail
))
1614 (display (car entry
))
1617 ;; Get the attributes as actually specified by this alternative.
1619 (if (null (cdr attrs
)) ;; was (listp (car attrs))
1620 ;; Old-style entry, the attribute list is the
1625 ;; If the condition is `default', that sets the default
1626 ;; for following conditions.
1627 (if (eq display
'default
)
1628 (setq defaults thisval
)
1629 ;; Otherwise, if it matches, use it.
1630 (when (face-spec-set-match-display display frame
)
1631 (setq result thisval
1634 ;; If defaults have been found, it's safe to just append those to the result
1635 ;; list (which at this point will be either nil or contain actual specs) and
1636 ;; return it to the caller. Since there will most definitely be something to
1637 ;; return in this case, there's no need to know/check if a match was found.
1639 (append result defaults
)
1644 ;; When over 80 faces get processed at frame creation time, all but
1645 ;; one specifying all attributes as "unspecified", generating this
1646 ;; list every time means a lot of consing.
1647 (defconst face--attributes-unspecified
1649 (mapcar (lambda (x) (list (car x
) 'unspecified
))
1650 face-attribute-name-alist
)))
1652 (defun face-spec-reset-face (face &optional frame
)
1653 "Reset all attributes of FACE on FRAME to unspecified."
1654 (apply 'set-face-attribute face frame
1655 (if (eq face
'default
)
1656 ;; For the default face, avoid making any attribute
1657 ;; unspecified. Instead, set attributes to default values
1658 ;; (see also realize_default_face in xfaces.c).
1660 '(:underline nil
:overline nil
:strike-through nil
1661 :box nil
:inverse-video nil
:stipple nil
:inherit nil
)
1662 ;; `display-graphic-p' is unavailable when running
1663 ;; temacs, prior to loading frame.el.
1664 (when (fboundp 'display-graphic-p
)
1665 (unless (display-graphic-p frame
)
1666 `(:family
"default" :foundry
"default" :width normal
1667 :height
1 :weight normal
:slant normal
1668 :foreground
,(if (frame-parameter nil
'reverse
)
1671 :background
,(if (frame-parameter nil
'reverse
)
1673 "unspecified-bg")))))
1674 ;; For all other faces, unspecify all attributes.
1675 face--attributes-unspecified
)))
1677 (defun face-spec-set (face spec
&optional spec-type
)
1678 "Set the FACE's spec SPEC, define FACE, and recalculate its attributes.
1679 See `defface' for the format of SPEC.
1681 The appearance of each face is controlled by its specs (set via
1682 this function), and by the internal frame-specific face
1683 attributes (set via `set-face-attribute').
1685 This function also defines FACE as a valid face name if it is not
1686 already one, and (re)calculates its attributes on existing
1689 The optional argument SPEC-TYPE determines which spec to set:
1690 nil, omitted or `face-override-spec' means the override spec,
1691 which overrides all the other types of spec mentioned below
1692 (this is usually what you want if calling this function
1693 outside of Custom code);
1694 `customized-face' or `saved-face' means the customized spec or
1695 the saved custom spec;
1696 `face-defface-spec' means the default spec
1697 (usually set only via `defface');
1698 `reset' means to ignore SPEC, but clear the `customized-face'
1699 and `face-override-spec' specs;
1700 Any other value means not to set any spec, but to run the
1701 function for defining FACE and recalculating its attributes."
1702 (if (get face
'face-alias
)
1703 (setq face
(get face
'face-alias
)))
1704 ;; Save SPEC to the relevant symbol property.
1706 (setq spec-type
'face-override-spec
))
1707 (if (memq spec-type
'(face-defface-spec face-override-spec
1708 customized-face saved-face
))
1709 (put face spec-type spec
))
1710 (if (memq spec-type
'(reset saved-face
))
1711 (put face
'customized-face nil
))
1712 ;; Setting the face spec via Custom empties out any override spec,
1713 ;; similar to how setting a variable via Custom changes its values.
1714 (if (memq spec-type
'(customized-face saved-face reset
))
1715 (put face
'face-override-spec nil
))
1716 ;; If we reset the face based on its custom spec, it is unmodified
1717 ;; as far as Custom is concerned.
1718 (unless (eq face
'face-override-spec
)
1719 (put face
'face-modified nil
))
1720 ;; Initialize the face if it does not exist, then recalculate.
1721 (make-empty-face face
)
1722 (dolist (frame (frame-list))
1723 (face-spec-recalc face frame
)))
1725 (defun face-spec-recalc (face frame
)
1726 "Reset the face attributes of FACE on FRAME according to its specs.
1727 The following sources are applied in this order:
1729 face reset to default values if it's the default face, otherwise set
1730 to unspecified (through `face-spec-reset-face')
1732 (theme and user customization)
1733 or: if none of the above exist, and none match the current frame or
1734 inherited from the defface spec instead of overwriting it
1735 entirely, the following is applied instead:
1736 (defface default spec)
1737 (X resources (if applicable))
1739 defface override spec"
1740 (while (get face
'face-alias
)
1741 (setq face
(get face
'face-alias
)))
1742 (face-spec-reset-face face frame
)
1743 ;; If FACE is customized or themed, set the custom spec from
1744 ;; `theme-face' records.
1745 (let ((theme-faces (get face
'theme-face
))
1747 face-attrs theme-face-applied
)
1749 (dolist (elt (reverse theme-faces
))
1750 (setq face-attrs
(face-spec-choose (cadr elt
) frame no-match-found
))
1751 (unless (eq face-attrs no-match-found
)
1752 (face-spec-set-2 face frame face-attrs
)
1753 (setq theme-face-applied t
))))
1754 ;; If there was a spec applicable to FRAME, that overrides the
1755 ;; defface spec entirely (rather than inheriting from it). If
1756 ;; there was no spec applicable to FRAME, apply the defface spec
1757 ;; as well as any applicable X resources.
1758 (unless theme-face-applied
1759 (setq face-attrs
(face-spec-choose (face-default-spec face
) frame
))
1760 (face-spec-set-2 face frame face-attrs
)
1761 (make-face-x-resource-internal face frame
))
1762 (setq face-attrs
(face-spec-choose (get face
'face-override-spec
) frame
))
1763 (face-spec-set-2 face frame face-attrs
)))
1765 (defun face-spec-set-2 (face frame face-attrs
)
1766 "Set the face attributes of FACE on FRAME according to FACE-ATTRS.
1767 FACE-ATTRS is a plist of face attributes in the form of attribute-value
1771 (when (assq (car face-attrs
) face-x-resources
)
1772 (push (car face-attrs
) attrs
)
1773 (push (cadr face-attrs
) attrs
))
1774 (setq face-attrs
(cddr face-attrs
)))
1775 (apply 'set-face-attribute face frame
(nreverse attrs
))))
1777 (defun face-attr-match-p (face attrs
&optional frame
)
1778 "Return t if attributes of FACE match values in plist ATTRS.
1779 Optional parameter FRAME is the frame whose definition of FACE
1780 is used. If nil or omitted, use the selected frame."
1782 (setq frame
(selected-frame)))
1783 (let* ((list face-attribute-name-alist
)
1785 (bold (and (plist-member attrs
:bold
)
1786 (not (plist-member attrs
:weight
))))
1787 (italic (and (plist-member attrs
:italic
)
1788 (not (plist-member attrs
:slant
))))
1789 (plist (if (or bold italic
)
1790 (copy-sequence attrs
)
1792 ;; Handle the Emacs 20 :bold and :italic properties.
1794 (plist-put plist
:weight
(if bold
'bold
'normal
)))
1796 (plist-put plist
:slant
(if italic
'italic
'normal
)))
1797 (while (and match list
)
1798 (let* ((attr (caar list
))
1800 (if (plist-member plist attr
)
1801 (plist-get plist attr
)
1803 (value-now (face-attribute face attr frame
)))
1804 (setq match
(equal specified-value value-now
))
1805 (setq list
(cdr list
))))
1808 (defsubst face-spec-match-p
(face spec
&optional frame
)
1809 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1810 (face-attr-match-p face
(face-spec-choose spec frame
) frame
))
1812 (defsubst face-default-spec
(face)
1813 "Return the default face-spec for FACE, ignoring any user customization.
1814 If there is no default for FACE, return nil."
1815 (get face
'face-defface-spec
))
1817 (defsubst face-user-default-spec
(face)
1818 "Return the user's customized face-spec for FACE, or the default if none.
1819 If there is neither a user setting nor a default for FACE, return nil."
1820 (or (get face
'customized-face
)
1821 (get face
'saved-face
)
1822 (face-default-spec face
)))
1825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1826 ;;; Frame-type independent color support.
1827 ;;; We keep the old x-* names as aliases for back-compatibility.
1828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1830 (defun defined-colors (&optional frame
)
1831 "Return a list of colors supported for a particular frame.
1832 The argument FRAME specifies which frame to try.
1833 The value may be different for frames on different display types.
1834 If FRAME doesn't support colors, the value is nil.
1835 If FRAME is nil, that stands for the selected frame."
1836 (if (memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1837 (xw-defined-colors frame
)
1838 (mapcar 'car
(tty-color-alist frame
))))
1839 (defalias 'x-defined-colors
'defined-colors
)
1841 (defun defined-colors-with-face-attributes (&optional frame
)
1842 "Return a list of colors supported for a particular frame.
1843 See `defined-colors' for arguments and return value. In contrast
1844 to `define-colors' the elements of the returned list are color
1845 strings with text properties, that make the color names render
1846 with the color they represent as background color."
1848 (lambda (color-name)
1849 (let ((foreground (readable-foreground-color color-name
))
1850 (color (copy-sequence color-name
)))
1851 (propertize color
'face
(list :foreground foreground
1852 :background color
))))
1853 (defined-colors frame
)))
1855 (defun readable-foreground-color (color)
1856 "Return a readable foreground color for background COLOR."
1857 (let* ((rgb (color-values color
))
1858 (max (apply #'max rgb
))
1859 (black (car (color-values "black")))
1860 (white (car (color-values "white"))))
1861 ;; Select black or white depending on which one is less similar to
1862 ;; the brightest component.
1863 (if (> (abs (- max black
)) (abs (- max white
)))
1867 (declare-function xw-color-defined-p
"xfns.c" (color &optional frame
))
1869 (defun color-defined-p (color &optional frame
)
1870 "Return non-nil if COLOR is supported on frame FRAME.
1871 COLOR should be a string naming a color (e.g. \"white\"), or a
1872 string specifying a color's RGB components (e.g. \"#ff12ec\"), or
1873 the symbol `unspecified'.
1875 This function returns nil if COLOR is the symbol `unspecified',
1876 or one of the strings \"unspecified-fg\" or \"unspecified-bg\".
1878 If FRAME is omitted or nil, use the selected frame."
1879 (unless (member color
'(unspecified "unspecified-bg" "unspecified-fg"))
1880 (if (member (framep (or frame
(selected-frame))) '(x w32 ns
))
1881 (xw-color-defined-p color frame
)
1882 (numberp (tty-color-translate color frame
)))))
1883 (defalias 'x-color-defined-p
'color-defined-p
)
1885 (declare-function xw-color-values
"xfns.c" (color &optional frame
))
1887 (defun color-values (color &optional frame
)
1888 "Return a description of the color named COLOR on frame FRAME.
1889 COLOR should be a string naming a color (e.g. \"white\"), or a
1890 string specifying a color's RGB components (e.g. \"#ff12ec\").
1892 Return a list of three integers, (RED GREEN BLUE), each between 0
1893 and either 65280 or 65535 (the maximum depends on the system).
1894 Use `color-name-to-rgb' if you want RGB floating-point values
1897 If FRAME is omitted or nil, use the selected frame.
1898 If FRAME cannot display COLOR, the value is nil.
1900 COLOR can also be the symbol `unspecified' or one of the strings
1901 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1902 return value is nil."
1904 ((member color
'(unspecified "unspecified-fg" "unspecified-bg"))
1906 ((memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1907 (xw-color-values color frame
))
1909 (tty-color-values color frame
))))
1911 (defalias 'x-color-values
'color-values
)
1913 (declare-function xw-display-color-p
"xfns.c" (&optional terminal
))
1915 (defun display-color-p (&optional display
)
1916 "Return t if DISPLAY supports color.
1917 The optional argument DISPLAY specifies which display to ask about.
1918 DISPLAY should be either a frame or a display name (a string).
1919 If omitted or nil, that stands for the selected frame's display."
1920 (if (memq (framep-on-display display
) '(x w32 ns
))
1921 (xw-display-color-p display
)
1922 (tty-display-color-p display
)))
1923 (defalias 'x-display-color-p
'display-color-p
)
1925 (declare-function x-display-grayscale-p
"xfns.c" (&optional terminal
))
1927 (defun display-grayscale-p (&optional display
)
1928 "Return non-nil if frames on DISPLAY can display shades of gray.
1929 DISPLAY should be either a frame or a display name (a string).
1930 If omitted or nil, that stands for the selected frame's display."
1931 (let ((frame-type (framep-on-display display
)))
1933 ((memq frame-type
'(x w32 ns
))
1934 (x-display-grayscale-p display
))
1936 (> (tty-color-gray-shades display
) 2)))))
1938 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg
)
1939 "Read a color name or RGB triplet.
1940 Completion is available for color names, but not for RGB triplets.
1942 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1943 components can have one to four digits, but all three components
1944 must have the same number of digits. Each digit is a hex value
1945 between 0 and F; either upper case or lower case for A through F
1948 In addition to standard color names and RGB hex values, the
1949 following are available as color candidates. In each case, the
1950 corresponding color is used.
1952 * `foreground at point' - foreground under the cursor
1953 * `background at point' - background under the cursor
1955 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1957 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1958 convert an input color name to an RGB hex string. Return the RGB
1961 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1962 to enter an empty color name (the empty string).
1964 Interactively, or with optional arg MSG non-nil, print the
1965 resulting color name in the echo area."
1966 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1967 (let* ((completion-ignore-case t
)
1968 (colors (or facemenu-color-alist
1969 (append '("foreground at point" "background at point")
1970 (if allow-empty-name
'(""))
1971 (if (display-color-p)
1972 (defined-colors-with-face-attributes)
1973 (defined-colors)))))
1974 (color (completing-read
1975 (or prompt
"Color (name or #RGB triplet): ")
1976 ;; Completing function for reading colors, accepting
1977 ;; both color names and RGB triplets.
1978 (lambda (string pred flag
)
1980 ((null flag
) ; Try completion.
1981 (or (try-completion string colors pred
)
1982 (if (color-defined-p string
)
1984 ((eq flag t
) ; List all completions.
1985 (or (all-completions string colors pred
)
1986 (if (color-defined-p string
)
1988 ((eq flag
'lambda
) ; Test completion.
1989 (or (member string colors
)
1990 (color-defined-p string
)))))
1993 ;; Process named colors.
1994 (when (member color colors
)
1995 (cond ((string-equal color
"foreground at point")
1996 (setq color
(foreground-color-at-point)))
1997 ((string-equal color
"background at point")
1998 (setq color
(background-color-at-point))))
1999 (when (and convert-to-RGB
2000 (not (string-equal color
"")))
2001 (let ((components (x-color-values color
)))
2002 (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color
)
2003 (setq color
(format "#%04X%04X%04X"
2004 (logand 65535 (nth 0 components
))
2005 (logand 65535 (nth 1 components
))
2006 (logand 65535 (nth 2 components
))))))))
2007 (when msg
(message "Color: `%s'" color
))
2010 (defun face-at-point (&optional thing multiple
)
2011 "Return the face of the character after point.
2012 If it has more than one face, return the first one.
2013 If THING is non-nil try first to get a face name from the buffer.
2014 IF MULTIPLE is non-nil, return a list of all faces.
2015 Return nil if there is no face."
2018 ;; Try to get a face name from the buffer.
2019 (let ((face (intern-soft (thing-at-point 'symbol
))))
2021 (push face faces
))))
2022 ;; Add the named faces that the `read-face-name' or `face' property uses.
2023 (let ((faceprop (or (get-char-property (point) 'read-face-name
)
2024 (get-char-property (point) 'face
))))
2025 (cond ((facep faceprop
)
2026 (push faceprop faces
))
2027 ((face-list-p faceprop
)
2028 (dolist (face faceprop
)
2030 (push face faces
))))))
2032 (delete-dups (nreverse faces
))
2033 (car (last faces
)))))
2035 (defun faces--attribute-at-point (attribute &optional attribute-unnamed
)
2036 "Return the face ATTRIBUTE at point.
2037 ATTRIBUTE is a keyword.
2038 If ATTRIBUTE-UNNAMED is non-nil, it is a symbol to look for in
2039 unnamed faces (e.g, `foreground-color')."
2040 ;; `face-at-point' alone is not sufficient. It only gets named faces.
2041 ;; Need also pick up any face properties that are not associated with named faces.
2042 (let ((faces (or (get-char-property (point) 'read-face-name
)
2043 ;; If `font-lock-mode' is on, `font-lock-face' takes precedence.
2045 (get-char-property (point) 'font-lock-face
))
2046 (get-char-property (point) 'face
)))
2048 (dolist (face (if (face-list-p faces
)
2052 ((and face
(symbolp face
))
2053 (let ((value (face-attribute-specified-or
2054 (face-attribute face attribute nil t
)
2056 (unless (member value
'(nil "unspecified-fg" "unspecified-bg"))
2057 (setq found value
))))
2059 (setq found
(cond ((and attribute-unnamed
2060 (memq attribute-unnamed face
))
2061 (cdr (memq attribute-unnamed face
)))
2062 ((memq attribute face
) (cadr (memq attribute face
))))))))
2064 (face-attribute 'default attribute
))))
2066 (defun foreground-color-at-point ()
2067 "Return the foreground color of the character after point."
2068 (faces--attribute-at-point :foreground
'foreground-color
))
2070 (defun background-color-at-point ()
2071 "Return the background color of the character after point."
2072 (faces--attribute-at-point :background
'background-color
))
2075 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2079 (declare-function x-display-list
"xfns.c" ())
2080 (declare-function x-open-connection
"xfns.c"
2081 (display &optional xrm-string must-succeed
))
2082 (declare-function x-get-resource
"frame.c"
2083 (attribute class
&optional component subclass
))
2084 (declare-function x-parse-geometry
"frame.c" (string))
2085 (defvar x-display-name
)
2087 (defun x-handle-named-frame-geometry (parameters)
2088 "Add geometry parameters for a named frame to parameter list PARAMETERS.
2089 Value is the new parameter list."
2090 ;; Note that `x-resource-name' has a global meaning.
2091 (let ((x-resource-name (cdr (assq 'name parameters
))))
2092 (when x-resource-name
2093 ;; Before checking X resources, we must have an X connection.
2096 (x-open-connection (or (cdr (assq 'display parameters
))
2098 (let (res-geometry parsed
)
2099 (and (setq res-geometry
(x-get-resource "geometry" "Geometry"))
2100 (setq parsed
(x-parse-geometry res-geometry
))
2102 (append parameters parsed
2103 ;; If the resource specifies a position,
2104 ;; take note of that.
2105 (if (or (assq 'top parsed
) (assq 'left parsed
))
2106 '((user-position . t
) (user-size . t
)))))))))
2110 (defun x-handle-reverse-video (frame parameters
)
2111 "Handle the reverse-video frame parameter and X resource.
2112 `x-create-frame' does not handle this one."
2113 (when (cdr (or (assq 'reverse parameters
)
2114 (let ((resource (x-get-resource "reverseVideo"
2117 (cons nil
(member (downcase resource
)
2118 '("on" "true")))))))
2119 (let* ((params (frame-parameters frame
))
2120 (bg (cdr (assq 'foreground-color params
)))
2121 (fg (cdr (assq 'background-color params
))))
2122 (modify-frame-parameters frame
2123 (list (cons 'foreground-color fg
)
2124 (cons 'background-color bg
)))
2125 (if (equal bg
(cdr (assq 'border-color params
)))
2126 (modify-frame-parameters frame
2127 (list (cons 'border-color fg
))))
2128 (if (equal bg
(cdr (assq 'mouse-color params
)))
2129 (modify-frame-parameters frame
2130 (list (cons 'mouse-color fg
))))
2131 (if (equal bg
(cdr (assq 'cursor-color params
)))
2132 (modify-frame-parameters frame
2133 (list (cons 'cursor-color fg
)))))))
2135 (declare-function x-create-frame
"xfns.c" (parms))
2136 (declare-function x-setup-function-keys
"term/common-win" (frame))
2138 (defun x-create-frame-with-faces (&optional parameters
)
2139 "Create and return a frame with frame parameters PARAMETERS.
2140 If PARAMETERS specify a frame name, handle X geometry resources
2141 for that name. If PARAMETERS includes a `reverse' parameter, or
2142 the X resource \"reverseVideo\" is present, handle that."
2143 (setq parameters
(x-handle-named-frame-geometry parameters
))
2144 (let* ((params (copy-tree parameters
))
2145 (visibility-spec (assq 'visibility parameters
))
2146 (delayed-params '(foreground-color background-color font
2147 border-color cursor-color mouse-color
2148 visibility scroll-bar-foreground
2149 scroll-bar-background
))
2151 (dolist (param delayed-params
)
2152 (setq params
(assq-delete-all param params
)))
2153 (setq frame
(x-create-frame `((visibility . nil
) .
,params
)))
2156 (x-setup-function-keys frame
)
2157 (x-handle-reverse-video frame parameters
)
2158 (frame-set-background-mode frame t
)
2159 (face-set-after-frame-default frame parameters
)
2160 (if (null visibility-spec
)
2161 (make-frame-visible frame
)
2162 (modify-frame-parameters frame
(list visibility-spec
)))
2165 (delete-frame frame
)))
2168 (defun face-set-after-frame-default (frame &optional parameters
)
2169 "Initialize the frame-local faces of FRAME.
2170 Calculate the face definitions using the face specs, custom theme
2171 settings, X resources, and `face-new-frame-defaults'.
2172 Finally, apply any relevant face attributes found amongst the
2173 frame parameters in PARAMETERS."
2174 ;; The `reverse' is so that `default' goes first.
2175 (dolist (face (nreverse (face-list)))
2178 ;; Initialize faces from face spec and custom theme.
2179 (face-spec-recalc face frame
)
2180 ;; Apply attributes specified by face-new-frame-defaults
2181 (internal-merge-in-global-face face frame
))
2182 ;; Don't let invalid specs prevent frame creation.
2185 ;; Apply attributes specified by frame parameters.
2186 (let ((face-params '((foreground-color default
:foreground
)
2187 (background-color default
:background
)
2188 (font default
:font
)
2189 (border-color border
:background
)
2190 (cursor-color cursor
:background
)
2191 (scroll-bar-foreground scroll-bar
:foreground
)
2192 (scroll-bar-background scroll-bar
:background
)
2193 (mouse-color mouse
:background
))))
2194 (dolist (param face-params
)
2195 (let* ((param-name (nth 0 param
))
2196 (value (cdr (assq param-name parameters
))))
2198 (set-face-attribute (nth 1 param
) frame
2199 (nth 2 param
) value
))))))
2201 (defun tty-handle-reverse-video (frame parameters
)
2202 "Handle the reverse-video frame parameter for terminal frames."
2203 (when (cdr (assq 'reverse parameters
))
2204 (let* ((params (frame-parameters frame
))
2205 (bg (cdr (assq 'foreground-color params
)))
2206 (fg (cdr (assq 'background-color params
))))
2207 (modify-frame-parameters frame
2208 (list (cons 'foreground-color fg
)
2209 (cons 'background-color bg
)))
2210 (if (equal bg
(cdr (assq 'mouse-color params
)))
2211 (modify-frame-parameters frame
2212 (list (cons 'mouse-color fg
))))
2213 (if (equal bg
(cdr (assq 'cursor-color params
)))
2214 (modify-frame-parameters frame
2215 (list (cons 'cursor-color fg
)))))))
2218 (defun tty-create-frame-with-faces (&optional parameters
)
2219 "Create and return a frame from optional frame parameters PARAMETERS.
2220 If PARAMETERS contains a `reverse' parameter, handle that."
2221 (let ((frame (make-terminal-frame parameters
))
2224 (with-selected-frame frame
2225 (tty-handle-reverse-video frame
(frame-parameters frame
))
2227 (unless (terminal-parameter frame
'terminal-initted
)
2228 (set-terminal-parameter frame
'terminal-initted t
)
2229 (set-locale-environment nil frame
)
2230 (tty-run-terminal-initialization frame nil t
))
2231 (frame-set-background-mode frame t
)
2232 (face-set-after-frame-default frame parameters
)
2235 (delete-frame frame
)))
2238 (defun tty-find-type (pred type
)
2239 "Return the longest prefix of TYPE to which PRED returns non-nil.
2240 TYPE should be a tty type name such as \"xterm-16color\".
2242 The function tries only those prefixes that are followed by a
2243 dash or underscore in the original type name, like \"xterm\" in
2247 (not (funcall pred type
)))
2248 ;; Strip off last hyphen and what follows, then try again
2250 (if (setq hyphend
(string-match-p "[-_][^-_]+$" type
))
2251 (substring type
0 hyphend
)
2255 (defvar tty-setup-hook nil
2256 "Hook run after running the initialization function of a new text terminal.
2257 Specifically, `tty-run-terminal-initialization' runs this.
2258 This can be used to fine tune the `input-decode-map', for example.")
2260 (defun tty-run-terminal-initialization (frame &optional type run-hook
)
2261 "Run the special initialization code for the terminal type of FRAME.
2262 The optional TYPE parameter may be used to override the autodetected
2263 terminal type to a different value.
2265 This consults `term-file-aliases' to map terminal types to their aliases.
2267 If optional argument RUN-HOOK is non-nil, then as a final step,
2268 this runs the hook `tty-setup-hook'.
2270 If you set `term-file-prefix' to nil, this function does nothing."
2271 (setq type
(or type
(tty-type frame
)))
2272 (let ((alias (tty-find-type
2273 (lambda (typ) (assoc typ term-file-aliases
)) type
)))
2274 (if alias
(setq type
(cdr (assoc alias term-file-aliases
)))))
2275 ;; Load library for our terminal type.
2276 ;; User init file can set term-file-prefix to nil to prevent this.
2277 (with-selected-frame frame
2278 (unless (null term-file-prefix
)
2279 (let* (term-init-func)
2280 ;; First, load the terminal initialization file, if it is
2281 ;; available and it hasn't been loaded already.
2282 (tty-find-type #'(lambda (type)
2283 (let ((file (locate-library (concat term-file-prefix type
))))
2285 (or (assoc file load-history
)
2288 ;; Next, try to find a matching initialization function, and call it.
2289 (tty-find-type #'(lambda (type)
2290 (fboundp (setq term-init-func
2291 (intern (concat "terminal-init-" type
)))))
2293 (when (fboundp term-init-func
)
2294 (funcall term-init-func
))
2295 (set-terminal-parameter frame
'terminal-initted term-init-func
)
2296 (if run-hook
(run-hooks 'tty-setup-hook
))))))
2298 ;; Called from C function init_display to initialize faces of the
2299 ;; dumped terminal frame on startup.
2301 (defun tty-set-up-initial-frame-faces ()
2302 (let ((frame (selected-frame)))
2303 (frame-set-background-mode frame t
)
2304 (face-set-after-frame-default frame
)))
2307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2311 (defgroup basic-faces nil
2312 "The standard faces of Emacs."
2316 '((t nil
)) ; If this were nil, face-defface-spec would not be set.
2317 "Basic default face."
2318 :group
'basic-faces
)
2323 :group
'basic-faces
)
2326 '((((supports :slant italic
))
2328 (((supports :underline t
))
2331 ;; Default to italic, even if it doesn't appear to be supported,
2332 ;; because in some cases the display engine will do its own
2333 ;; workaround (to `dim' on ttys).
2335 "Basic italic face."
2336 :group
'basic-faces
)
2338 (defface bold-italic
2339 '((t :weight bold
:slant italic
))
2340 "Basic bold-italic face."
2341 :group
'basic-faces
)
2344 '((((supports :underline t
))
2346 (((supports :weight bold
))
2349 "Basic underlined face."
2350 :group
'basic-faces
)
2352 (defface fixed-pitch
2353 '((t :family
"Monospace"))
2354 "The basic fixed-pitch face."
2355 :group
'basic-faces
)
2357 (defface fixed-pitch-serif
2358 '((t :family
"Monospace Serif"))
2359 "The basic fixed-pitch face with serifs."
2360 :group
'basic-faces
)
2362 (defface variable-pitch
2364 ;; This is a workaround for an issue discussed in
2365 ;; https://lists.gnu.org/r/emacs-devel/2016-04/msg00746.html.
2366 ;; We need (a) the splash screen not to pick up bold-italics variant of
2367 ;; the font, and (b) still be able to request bold/italic/larger size
2368 ;; variants in the likes of EWW.
2369 :family
"Arial" :foundry
"outline")
2370 (t :family
"Sans Serif"))
2371 "The basic variable-pitch face."
2372 :group
'basic-faces
)
2375 '((((class color grayscale
) (min-colors 88) (background light
))
2376 :foreground
"grey50")
2377 (((class color grayscale
) (min-colors 88) (background dark
))
2378 :foreground
"grey70")
2379 (((class color
) (min-colors 8) (background light
))
2380 :foreground
"green")
2381 (((class color
) (min-colors 8) (background dark
))
2382 :foreground
"yellow"))
2383 "Basic face for shadowed text."
2388 '((((class color
) (min-colors 88) (background light
))
2389 :foreground
"RoyalBlue3" :underline t
)
2390 (((class color
) (background light
))
2391 :foreground
"blue" :underline t
)
2392 (((class color
) (min-colors 88) (background dark
))
2393 :foreground
"cyan1" :underline t
)
2394 (((class color
) (background dark
))
2395 :foreground
"cyan" :underline t
)
2396 (t :inherit underline
))
2397 "Basic face for unvisited links."
2401 (defface link-visited
2402 '((default :inherit link
)
2403 (((class color
) (background light
)) :foreground
"magenta4")
2404 (((class color
) (background dark
)) :foreground
"violet"))
2405 "Basic face for visited links."
2410 '((((class color
) (min-colors 88) (background light
))
2411 :background
"darkseagreen2")
2412 (((class color
) (min-colors 88) (background dark
))
2413 :background
"darkolivegreen")
2414 (((class color
) (min-colors 16) (background light
))
2415 :background
"darkseagreen2")
2416 (((class color
) (min-colors 16) (background dark
))
2417 :background
"darkolivegreen")
2418 (((class color
) (min-colors 8))
2419 :background
"green" :foreground
"black")
2420 (t :inverse-video t
))
2421 "Basic face for highlighting."
2422 :group
'basic-faces
)
2424 ;; Region face: under NS, default to the system-defined selection
2425 ;; color (optimized for the fixed white background of other apps),
2426 ;; if background is light.
2428 '((((class color
) (min-colors 88) (background dark
))
2429 :background
"blue3")
2430 (((class color
) (min-colors 88) (background light
) (type gtk
))
2431 :distant-foreground
"gtk_selection_fg_color"
2432 :background
"gtk_selection_bg_color")
2433 (((class color
) (min-colors 88) (background light
) (type ns
))
2434 :distant-foreground
"ns_selection_fg_color"
2435 :background
"ns_selection_bg_color")
2436 (((class color
) (min-colors 88) (background light
))
2437 :background
"lightgoldenrod2")
2438 (((class color
) (min-colors 16) (background dark
))
2439 :background
"blue3")
2440 (((class color
) (min-colors 16) (background light
))
2441 :background
"lightgoldenrod2")
2442 (((class color
) (min-colors 8))
2443 :background
"blue" :foreground
"white")
2444 (((type tty
) (class mono
))
2446 (t :background
"gray"))
2447 "Basic face for highlighting the region."
2449 :group
'basic-faces
)
2451 (defface secondary-selection
2452 '((((class color
) (min-colors 88) (background light
))
2453 :background
"yellow1")
2454 (((class color
) (min-colors 88) (background dark
))
2455 :background
"SkyBlue4")
2456 (((class color
) (min-colors 16) (background light
))
2457 :background
"yellow")
2458 (((class color
) (min-colors 16) (background dark
))
2459 :background
"SkyBlue4")
2460 (((class color
) (min-colors 8))
2461 :background
"cyan" :foreground
"black")
2462 (t :inverse-video t
))
2463 "Basic face for displaying the secondary selection."
2464 :group
'basic-faces
)
2466 (defface trailing-whitespace
2467 '((((class color
) (background light
))
2469 (((class color
) (background dark
))
2471 (t :inverse-video t
))
2472 "Basic face for highlighting trailing whitespace."
2474 :group
'basic-faces
)
2476 ;; Definition stolen from linum.el.
2477 (defface line-number
2478 '((t :inherit
(shadow default
)))
2479 "Face for displaying line numbers.
2480 This face is used when `display-line-numbers' is non-nil.
2482 If you customize the font of this face, make sure it is a
2483 monospaced font, otherwise line numbers will not line up,
2484 and text lines might move horizontally as you move through
2488 :group
'display-line-numbers
)
2490 (defface line-number-current-line
2491 '((t :inherit line-number
))
2492 "Face for displaying the current line number.
2493 This face is used when `display-line-numbers' is non-nil.
2495 If you customize the font of this face, make sure it is a
2496 monospaced font, otherwise line numbers will not line up,
2497 and text lines might move horizontally as you move through
2498 the buffer. Similarly, making this face's font different
2499 from that of the `line-number' face could produce such
2503 :group
'display-line-numbers
)
2505 (defface escape-glyph
2506 '((((background dark
)) :foreground
"cyan")
2507 ;; See the comment in minibuffer-prompt for
2508 ;; the reason not to use blue on MS-DOS.
2509 (((type pc
)) :foreground
"magenta")
2510 ;; red4 is too dark, but some say blue is too loud.
2511 ;; brown seems to work ok. -- rms.
2512 (t :foreground
"brown"))
2513 "Face for characters displayed as sequences using `^' or `\\'."
2518 '((((background dark
)) :foreground
"cyan")
2519 (((type pc
)) :foreground
"magenta")
2520 (t :foreground
"brown"))
2521 "Face for lookalike characters."
2525 (defface nobreak-space
2526 '((((class color
) (min-colors 88)) :inherit escape-glyph
:underline t
)
2527 (((class color
) (min-colors 8)) :background
"magenta")
2528 (t :inverse-video t
))
2529 "Face for displaying nobreak space."
2533 (defface nobreak-hyphen
2534 '((((background dark
)) :foreground
"cyan")
2535 (((type pc
)) :foreground
"magenta")
2536 (t :foreground
"brown"))
2537 "Face for displaying nobreak hyphens."
2541 (defgroup mode-line-faces nil
2542 "Faces used in the mode line."
2548 '((((class color
) (min-colors 88))
2549 :box
(:line-width -
1 :style released-button
)
2550 :background
"grey75" :foreground
"black")
2553 "Basic mode line face for selected window."
2555 :group
'mode-line-faces
2556 :group
'basic-faces
)
2558 (defface mode-line-inactive
2561 (((class color
) (min-colors 88) (background light
))
2563 :box
(:line-width -
1 :color
"grey75" :style nil
)
2564 :foreground
"grey20" :background
"grey90")
2565 (((class color
) (min-colors 88) (background dark
) )
2567 :box
(:line-width -
1 :color
"grey40" :style nil
)
2568 :foreground
"grey80" :background
"grey30"))
2569 "Basic mode line face for non-selected windows."
2571 :group
'mode-line-faces
2572 :group
'basic-faces
)
2574 (defface mode-line-highlight
2575 '((((class color
) (min-colors 88))
2576 :box
(:line-width
2 :color
"grey40" :style released-button
))
2578 :inherit highlight
))
2579 "Basic mode line face for highlighting."
2581 :group
'mode-line-faces
2582 :group
'basic-faces
)
2584 (defface mode-line-emphasis
2585 '((t (:weight bold
)))
2586 "Face used to emphasize certain mode line features.
2587 Use the face `mode-line-highlight' for features that can be selected."
2589 :group
'mode-line-faces
2590 :group
'basic-faces
)
2592 (defface mode-line-buffer-id
2593 '((t (:weight bold
)))
2594 "Face used for buffer identification parts of the mode line."
2596 :group
'mode-line-faces
2597 :group
'basic-faces
)
2599 (defface header-line
2603 ;; This used to be `:inverse-video t', but that doesn't look very
2604 ;; good when combined with inverse-video mode-lines and multiple
2605 ;; windows. Underlining looks better, and is more consistent with
2606 ;; the window-system face variants, which deemphasize the
2607 ;; header-line in relation to the mode-line face. If a terminal
2608 ;; can't underline, then the header-line will end up without any
2609 ;; highlighting; this may be too confusing in general, although it
2610 ;; happens to look good with the only current use of header-lines,
2611 ;; the info browser. XXX
2612 :inverse-video nil
;Override the value inherited from mode-line.
2614 (((class color grayscale
) (background light
))
2615 :background
"grey90" :foreground
"grey20"
2617 (((class color grayscale
) (background dark
))
2618 :background
"grey20" :foreground
"grey90"
2620 (((class mono
) (background light
))
2621 :background
"white" :foreground
"black"
2625 (((class mono
) (background dark
))
2626 :background
"black" :foreground
"white"
2630 "Basic header-line face."
2632 :group
'basic-faces
)
2634 (defface header-line-highlight
'((t :inherit highlight
))
2635 "Basic header line face for highlighting."
2637 :group
'basic-faces
)
2639 (defface vertical-border
2640 '((((type tty
)) :inherit mode-line-inactive
))
2641 "Face used for vertical window dividers on ttys."
2643 :group
'basic-faces
)
2645 (defface window-divider
'((t :foreground
"gray60"))
2646 "Basic face for window dividers.
2647 When a divider is less than 3 pixels wide, it is drawn solidly
2648 with the foreground of this face. For larger dividers this face
2649 is used for the inner part while the first pixel line/column is
2650 drawn with the `window-divider-first-pixel' face and the last
2651 pixel line/column with the `window-divider-last-pixel' face."
2653 :group
'window-divider
2654 :group
'basic-faces
)
2656 (defface window-divider-first-pixel
2657 '((t :foreground
"gray80"))
2658 "Basic face for first pixel line/column of window dividers.
2659 When a divider is at least 3 pixels wide, its first pixel
2660 line/column is drawn with the foreground of this face. If you do
2661 not want to accentuate the first pixel line/column, set this to
2662 the same as `window-divider' face."
2664 :group
'window-divider
2665 :group
'basic-faces
)
2667 (defface window-divider-last-pixel
2668 '((t :foreground
"gray40"))
2669 "Basic face for last pixel line/column of window dividers.
2670 When a divider is at least 3 pixels wide, its last pixel
2671 line/column is drawn with the foreground of this face. If you do
2672 not want to accentuate the last pixel line/column, set this to
2673 the same as `window-divider' face."
2675 :group
'window-divider
2676 :group
'basic-faces
)
2678 (defface internal-border
2680 "Basic face for the internal border."
2683 :group
'basic-faces
)
2685 (defface minibuffer-prompt
2686 '((((background dark
)) :foreground
"cyan")
2687 ;; Don't use blue because many users of the MS-DOS port customize
2688 ;; their foreground color to be blue.
2689 (((type pc
)) :foreground
"magenta")
2690 (t :foreground
"medium blue"))
2691 "Face for minibuffer prompts.
2692 By default, Emacs automatically adds this face to the value of
2693 `minibuffer-prompt-properties', which is a list of text properties
2694 used to display the prompt text."
2696 :group
'basic-faces
)
2698 (setq minibuffer-prompt-properties
2699 (append minibuffer-prompt-properties
(list 'face
'minibuffer-prompt
)))
2702 '((((class color
) (background light
))
2703 :background
"grey95")
2704 (((class color
) (background dark
))
2705 :background
"grey10")
2707 :background
"gray"))
2708 "Basic face for the fringes to the left and right of windows under X."
2711 :group
'basic-faces
)
2713 (defface scroll-bar
'((t nil
))
2714 "Basic face for the scroll bar colors under X."
2717 :group
'basic-faces
)
2719 (defface border
'((t nil
))
2720 "Basic face for the frame border under X."
2723 :group
'basic-faces
)
2726 '((((background light
)) :background
"black")
2727 (((background dark
)) :background
"white"))
2728 "Basic face for the cursor color under X.
2729 Currently, only the `:background' attribute is meaningful; all
2730 other attributes are ignored. The cursor foreground color is
2731 taken from the background color of the underlying text.
2733 Note: Other faces cannot inherit from the cursor face."
2736 :group
'basic-faces
)
2738 (put 'cursor
'face-no-inherit t
)
2740 (defface mouse
'((t nil
))
2741 "Basic face for the mouse color under X."
2744 :group
'basic-faces
)
2748 :box
(:line-width
1 :style released-button
)
2749 :foreground
"black")
2750 (((type x w32 ns
) (class color
))
2751 :background
"grey75")
2752 (((type x
) (class mono
))
2753 :background
"grey"))
2754 "Basic tool-bar face."
2756 :group
'basic-faces
)
2765 "Basic face for the font and colors of the menu bar and popup menus."
2768 :group
'basic-faces
)
2770 (defface help-argument-name
'((t :inherit italic
))
2771 "Face to highlight argument names in *Help* buffers."
2774 (defface glyphless-char
2775 '((((type tty
)) :inherit underline
)
2776 (((type pc
)) :inherit escape-glyph
)
2778 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2779 It is used for characters of no fonts too."
2781 :group
'basic-faces
)
2784 '((default :weight bold
)
2785 (((class color
) (min-colors 88) (background light
)) :foreground
"Red1")
2786 (((class color
) (min-colors 88) (background dark
)) :foreground
"Pink")
2787 (((class color
) (min-colors 16) (background light
)) :foreground
"Red1")
2788 (((class color
) (min-colors 16) (background dark
)) :foreground
"Pink")
2789 (((class color
) (min-colors 8)) :foreground
"red")
2790 (t :inverse-video t
))
2791 "Basic face used to highlight errors and to denote failure."
2793 :group
'basic-faces
)
2796 '((default :weight bold
)
2797 (((class color
) (min-colors 16)) :foreground
"DarkOrange")
2798 (((class color
)) :foreground
"yellow"))
2799 "Basic face used to highlight warnings."
2801 :group
'basic-faces
)
2804 '((default :weight bold
)
2805 (((class color
) (min-colors 16) (background light
)) :foreground
"ForestGreen")
2806 (((class color
) (min-colors 88) (background dark
)) :foreground
"Green1")
2807 (((class color
) (min-colors 16) (background dark
)) :foreground
"Green")
2808 (((class color
)) :foreground
"green"))
2809 "Basic face used to indicate successful operation."
2811 :group
'basic-faces
)
2813 (defface read-multiple-choice-face
2814 '((t (:inherit underline
2816 "Face for the symbol name in `read-multiple-choice' output."
2820 ;; Faces for TTY menus.
2821 (defface tty-menu-enabled-face
2823 :foreground
"yellow" :background
"blue" :weight bold
))
2824 "Face for displaying enabled items in TTY menus."
2825 :group
'basic-faces
)
2827 (defface tty-menu-disabled-face
2828 '((((class color
) (min-colors 16))
2829 :foreground
"lightgray" :background
"blue")
2831 :foreground
"white" :background
"blue"))
2832 "Face for displaying disabled items in TTY menus."
2833 :group
'basic-faces
)
2835 (defface tty-menu-selected-face
2836 '((t :background
"red"))
2837 "Face for displaying the currently selected item in TTY menus."
2838 :group
'basic-faces
)
2840 (defgroup paren-showing-faces nil
2841 "Faces used to highlight paren matches."
2842 :group
'paren-showing
2846 (defface show-paren-match
2847 '((((class color
) (background light
))
2848 :background
"turquoise") ; looks OK on tty (becomes cyan)
2849 (((class color
) (background dark
))
2850 :background
"steelblue3") ; looks OK on tty (becomes blue)
2851 (((background dark
) (min-colors 4))
2852 :background
"grey50")
2853 (((background light
) (min-colors 4))
2856 :inherit underline
))
2857 "Face used for a matching paren."
2858 :group
'paren-showing-faces
)
2860 (defface show-paren-match-expression
2861 '((t :inherit show-paren-match
))
2862 "Face used for a matching paren when highlighting the whole expression.
2863 This face is used by `show-paren-mode'."
2864 :group
'paren-showing-faces
2867 (defface show-paren-mismatch
2868 '((((class color
)) (:foreground
"white" :background
"purple"))
2869 (t (:inverse-video t
)))
2870 "Face used for a mismatching paren."
2871 :group
'paren-showing-faces
)
2874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2875 ;;; Manipulating font names.
2876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2878 ;; This is here for compatibility with Emacs 20.2. For example,
2879 ;; international/fontset.el uses x-resolve-font-name. The following
2880 ;; functions are not used in the face implementation itself.
2882 (defvar x-font-regexp nil
)
2883 (defvar x-font-regexp-head nil
)
2884 (defvar x-font-regexp-weight nil
)
2885 (defvar x-font-regexp-slant nil
)
2887 (defconst x-font-regexp-weight-subnum
1)
2888 (defconst x-font-regexp-slant-subnum
2)
2889 (defconst x-font-regexp-swidth-subnum
3)
2890 (defconst x-font-regexp-adstyle-subnum
4)
2892 ;;; Regexps matching font names in "Host Portable Character Representation."
2897 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2898 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2899 (weight\? "\\([^-]*\\)") ; 1
2900 (slant "\\([ior]\\)") ; 2
2901 ; (slant\? "\\([ior?*]?\\)") ; 2
2902 (slant\? "\\([^-]?\\)") ; 2
2903 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2904 (swidth "\\([^-]*\\)") ; 3
2905 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2906 (adstyle "\\([^-]*\\)") ; 4
2907 (pixelsize "[0-9]+")
2908 (pointsize "[0-9][0-9]+")
2909 (resx "[0-9][0-9]+")
2910 (resy "[0-9][0-9]+")
2917 (purecopy (concat "\\`\\*?[-?*]"
2918 foundry - family - weight
\? - slant
\? - swidth - adstyle -
2919 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2920 registry - encoding
"\\*?\\'"
2922 (setq x-font-regexp-head
2923 (purecopy (concat "\\`[-?*]" foundry - family - weight
\? - slant
\?
2924 "\\([-*?]\\|\\'\\)")))
2925 (setq x-font-regexp-slant
(purecopy (concat - slant -
)))
2926 (setq x-font-regexp-weight
(purecopy (concat - weight -
)))
2930 (defun x-resolve-font-name (pattern &optional face frame
)
2931 "Return a font name matching PATTERN.
2932 All wildcards in PATTERN are instantiated.
2933 If PATTERN is nil, return the name of the frame's base font, which never
2935 Given optional arguments FACE and FRAME, return a font which is
2936 also the same size as FACE on FRAME, or fail."
2940 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2941 (let ((fonts (x-list-fonts pattern face frame
1)))
2944 (if (string-match-p "\\*" pattern
)
2945 (if (null (face-font face
))
2946 (error "No matching fonts are the same height as the frame default font")
2947 (error "No matching fonts are the same height as face `%s'" face
))
2948 (if (null (face-font face
))
2949 (error "Height of font `%s' doesn't match the frame default font"
2951 (error "Height of font `%s' doesn't match face `%s'"
2953 (error "No fonts match `%s'" pattern
)))
2955 (frame-parameter nil
'font
)))
2957 (defcustom font-list-limit
100
2958 "This variable is obsolete and has no effect."
2961 (make-obsolete-variable 'font-list-limit nil
"24.3")
2965 ;;; faces.el ends here