1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992-1996, 1998-2014 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (defcustom term-file-prefix
(purecopy "term/")
29 "If non-nil, Emacs startup performs terminal-specific initialization.
30 It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
32 You may set this variable to nil in your init file if you do not wish
33 the terminal-initialization file to be loaded."
34 :type
'(choice (const :tag
"No terminal-specific initialization" nil
)
35 (string :tag
"Name of directory with term files"))
38 (declare-function xw-defined-colors
"term/common-win" (&optional frame
))
40 (defvar help-xref-stack-item
)
42 (defvar face-name-history nil
43 "History list for some commands that read face names.
44 Maximum length of the history list is determined by the value
45 of `history-length', which see.")
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 (defgroup font-selection nil
53 "Influencing face font selection."
57 (defcustom face-font-selection-order
58 '(:width
:height
:weight
:slant
)
59 "A list specifying how face font selection chooses fonts.
60 Each of the four symbols `:width', `:height', `:weight', and `:slant'
61 must appear once in the list, and the list must not contain any other
62 elements. Font selection first tries to find a best matching font
63 for those face attributes that appear before in the list. For
64 example, if `:slant' appears before `:height', font selection first
65 tries to find a font with a suitable slant, even if this results in
66 a font height that isn't optimal."
67 :tag
"Font selection order"
68 :type
'(list symbol symbol symbol symbol
)
69 :group
'font-selection
70 :set
#'(lambda (symbol value
)
71 (set-default symbol value
)
72 (internal-set-font-selection-order value
)))
75 ;; In the absence of Fontconfig support, Monospace and Sans Serif are
76 ;; unavailable, and we fall back on the courier and helv families,
77 ;; which are generally available.
78 (defcustom face-font-family-alternatives
79 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
80 '(("Monospace" "courier" "fixed")
81 ("courier" "CMU Typewriter Text" "fixed")
82 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
83 ("helv" "helvetica" "arial" "fixed")))
84 "Alist of alternative font family names.
85 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
86 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
88 :tag
"Alternative font families to try"
89 :type
'(repeat (repeat string
))
90 :group
'font-selection
91 :set
#'(lambda (symbol value
)
92 (set-default symbol value
)
93 (internal-set-alternative-font-family-alist value
)))
96 ;; This is defined originally in xfaces.c.
97 (defcustom face-font-registry-alternatives
98 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
100 '(("iso8859-1" "ms-oemlatin")
101 ("gb2312.1980" "gb2312" "gbk" "gb18030")
102 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
103 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
104 ("muletibetan-2" "muletibetan-0"))
105 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
106 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
107 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
108 ("muletibetan-2" "muletibetan-0"))))
109 "Alist of alternative font registry names.
110 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
111 If fonts of registry REGISTRY can be loaded, font selection
112 tries to find a best matching font among all fonts of registry
113 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
114 :tag
"Alternative font registries to try"
115 :type
'(repeat (repeat string
))
117 :group
'font-selection
118 :set
#'(lambda (symbol value
)
119 (set-default symbol value
)
120 (internal-set-alternative-font-registry-alist value
)))
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124 ;;; Creation, copying.
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 "Return a list of all defined faces."
130 (mapcar #'car face-new-frame-defaults
))
132 (defun make-face (face &optional no-init-from-resources
)
133 "Define a new face with name FACE, a symbol.
134 Do not call this directly from Lisp code; use `defface' instead.
136 If FACE is already known as a face, leave it unmodified. Return FACE.
138 NO-INIT-FROM-RESOURCES has been deprecated and is no longer used
139 and will go away. Handling of conditional X resources application
140 has been pushed down to make-x-resource-internal itself."
141 (interactive (list (read-from-minibuffer
142 "Make face: " nil nil t
'face-name-history
)))
144 ;; Make frame-local faces (this also makes the global one).
145 (dolist (frame (frame-list))
146 (internal-make-lisp-face face frame
))
147 ;; Add the face to the face menu.
148 (when (fboundp 'facemenu-add-new-face
)
149 (facemenu-add-new-face face
))
150 ;; Define frame-local faces for all frames from X resources.
151 (make-face-x-resource-internal face
))
154 ;; Handling of whether to apply X resources or not, has been pushed down
155 ;; to make-face-x-resource-internal itself, thus the optional arg is no
156 ;; longer evaluated at all and going away.
157 (set-advertised-calling-convention 'make-face
'(face) "24.4")
159 (defun make-empty-face (face)
160 "Define a new, empty face with name FACE.
161 Do not call this directly from Lisp code; use `defface' instead."
162 (interactive (list (read-from-minibuffer
163 "Make empty face: " nil nil t
'face-name-history
)))
166 (defun copy-face (old-face new-face
&optional frame new-frame
)
167 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
168 This function does not copy face customization data, so NEW-FACE
169 will not be made customizable. Most Lisp code should not call
170 this function; use `defface' with :inherit instead.
172 If NEW-FACE already exists as a face, modify it to be like
173 OLD-FACE. If NEW-FACE doesn't already exist, create it.
175 If the optional argument FRAME is a frame, change NEW-FACE on
176 FRAME only. If FRAME is t, copy the frame-independent default
177 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
178 the defaults as well as the faces on each existing frame.
180 If the optional fourth argument NEW-FRAME is given, copy the
181 information from face OLD-FACE on frame FRAME to NEW-FACE on
182 frame NEW-FRAME. In this case, FRAME must not be nil."
183 (let ((inhibit-quit t
))
187 (error "Copying face %s from all frames to one frame"
189 (make-empty-face new-face
)
190 (dolist (frame (frame-list))
191 (copy-face old-face new-face frame
))
192 (copy-face old-face new-face t
))
193 (make-empty-face new-face
)
194 (internal-copy-lisp-face old-face new-face frame new-frame
))
198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
199 ;;; Predicates, type checks.
200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
203 "Return non-nil if FACE is a face name; nil otherwise.
204 A face name can be a string or a symbol."
205 (internal-lisp-face-p face
))
208 (defun check-face (face)
209 "Signal an error if FACE doesn't name a face.
212 (error "Not a face: %s" face
))
216 ;; The ID returned is not to be confused with the internally used IDs
217 ;; of realized faces. The ID assigned to Lisp faces is used to
218 ;; support faces in display table entries.
220 (defun face-id (face &optional _frame
)
221 "Return the internal ID of face with name FACE.
222 If FACE is a face-alias, return the ID of the target face.
223 The optional argument FRAME is ignored, since the internal face ID
224 of a face name is the same for all frames."
227 (face-id (get face
'face-alias
))))
229 (defun face-equal (face1 face2
&optional frame
)
230 "Non-nil if faces FACE1 and FACE2 are equal.
231 Faces are considered equal if all their attributes are equal.
232 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
233 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
234 If FRAME is omitted or nil, use the selected frame."
235 (internal-lisp-face-equal-p face1 face2 frame
))
238 (defun face-differs-from-default-p (face &optional frame
)
239 "Return non-nil if FACE displays differently from the default face.
240 If the optional argument FRAME is given, report on face FACE in that frame.
241 If FRAME is t, report on the defaults for face FACE (for new frames).
242 If FRAME is omitted or nil, use the selected frame."
244 (delq :inherit
(mapcar 'car face-attribute-name-alist
)))
246 (while (and attrs
(not differs
))
247 (let* ((attr (pop attrs
))
248 (attr-val (face-attribute face attr frame t
)))
250 (not (eq attr-val
'unspecified
))
251 (display-supports-face-attributes-p (list attr attr-val
)
253 (setq differs attr
))))
257 (defun face-nontrivial-p (face &optional frame
)
258 "True if face FACE has some non-nil attribute.
259 If the optional argument FRAME is given, report on face FACE in that frame.
260 If FRAME is t, report on the defaults for face FACE (for new frames).
261 If FRAME is omitted or nil, use the selected frame."
262 (not (internal-lisp-face-empty-p face frame
)))
266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
267 ;;; Setting face attributes from X resources.
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
270 (defcustom face-x-resources
273 ;; FIXME; can we purecopy some of the conses too?
275 (cons (purecopy (car (cdr arg
))) (purecopy (cdr (cdr arg
))))))
276 '((:family
(".attributeFamily" .
"Face.AttributeFamily"))
277 (:foundry
(".attributeFoundry" .
"Face.AttributeFoundry"))
278 (:width
(".attributeWidth" .
"Face.AttributeWidth"))
279 (:height
(".attributeHeight" .
"Face.AttributeHeight"))
280 (:weight
(".attributeWeight" .
"Face.AttributeWeight"))
281 (:slant
(".attributeSlant" .
"Face.AttributeSlant"))
282 (:foreground
(".attributeForeground" .
"Face.AttributeForeground"))
284 (".attributeDistantForeground" .
"Face.AttributeDistantForeground"))
285 (:background
(".attributeBackground" .
"Face.AttributeBackground"))
286 (:overline
(".attributeOverline" .
"Face.AttributeOverline"))
287 (:strike-through
(".attributeStrikeThrough" .
"Face.AttributeStrikeThrough"))
288 (:box
(".attributeBox" .
"Face.AttributeBox"))
289 (:underline
(".attributeUnderline" .
"Face.AttributeUnderline"))
290 (:inverse-video
(".attributeInverse" .
"Face.AttributeInverse"))
292 (".attributeStipple" .
"Face.AttributeStipple")
293 (".attributeBackgroundPixmap" .
"Face.AttributeBackgroundPixmap"))
294 (:bold
(".attributeBold" .
"Face.AttributeBold"))
295 (:italic
(".attributeItalic" .
"Face.AttributeItalic"))
296 (:font
(".attributeFont" .
"Face.AttributeFont"))
297 (:inherit
(".attributeInherit" .
"Face.AttributeInherit"))))
298 "List of X resources and classes for face attributes.
299 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
300 the name of a face attribute, and each ENTRY is a cons of the form
301 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
302 X resource class for the attribute."
303 :type
'(repeat (cons symbol
(repeat (cons string string
))))
307 (declare-function internal-face-x-get-resource
"xfaces.c"
308 (resource class
&optional frame
))
310 (declare-function internal-set-lisp-face-attribute-from-resource
"xfaces.c"
311 (face attr value
&optional frame
))
313 (defun set-face-attribute-from-resource (face attribute resource class frame
)
314 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
315 Value is the attribute value specified by the resource, or nil
316 if not present. This function displays a message if the resource
317 specifies an invalid attribute."
318 (let* ((face-name (face-name face
))
319 (value (internal-face-x-get-resource (concat face-name resource
)
323 (internal-set-lisp-face-attribute-from-resource
324 face attribute
(downcase value
) frame
)
326 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
327 face-name frame attribute value
))))
331 (defun set-face-attributes-from-resources (face frame
)
332 "Set attributes of FACE from X resources for FRAME."
333 (when (memq (framep frame
) '(x w32
))
334 (dolist (definition face-x-resources
)
335 (let ((attribute (car definition
)))
336 (dolist (entry (cdr definition
))
337 (set-face-attribute-from-resource face attribute
(car entry
)
338 (cdr entry
) frame
))))))
341 (defun make-face-x-resource-internal (face &optional frame
)
342 "Fill frame-local FACE on FRAME from X resources.
343 FRAME nil or not specified means do it for all frames.
345 If `inhibit-x-resources' is non-nil, this function does nothing."
346 (unless inhibit-x-resources
347 (dolist (frame (if (null frame
) (frame-list) (list frame
)))
348 ;; `x-create-frame' already took care of correctly handling
349 ;; the reverse video case-- do _not_ touch the default face
350 (unless (and (eq face
'default
)
351 (frame-parameter frame
'reverse
))
352 (set-face-attributes-from-resources face frame
)))))
356 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
357 ;;; Retrieving face attributes.
358 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
360 (defun face-name (face)
361 "Return the name of face FACE."
362 (symbol-name (check-face face
)))
365 (defun face-all-attributes (face &optional frame
)
366 "Return an alist stating the attributes of FACE.
367 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
368 If FRAME is omitted or nil the value describes the default attributes,
369 but if you specify FRAME, the value describes the attributes
371 (mapcar (lambda (pair)
372 (let ((attr (car pair
)))
373 (cons attr
(face-attribute face attr
(or frame t
)))))
374 face-attribute-name-alist
))
376 (defun face-attribute (face attribute
&optional frame inherit
)
377 "Return the value of FACE's ATTRIBUTE on FRAME.
378 If the optional argument FRAME is given, report on face FACE in that frame.
379 If FRAME is t, report on the defaults for face FACE (for new frames).
380 If FRAME is omitted or nil, use the selected frame.
382 If INHERIT is nil, only attributes directly defined by FACE are considered,
383 so the return value may be `unspecified', or a relative value.
384 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
385 faces specified by its `:inherit' attribute; however the return value
386 may still be `unspecified' or relative.
387 If INHERIT is a face or a list of faces, then the result is further merged
388 with that face (or faces), until it becomes specified and absolute.
390 To ensure that the return value is always specified and absolute, use a
391 value of `default' for INHERIT; this will resolve any unspecified or
392 relative values by merging with the `default' face (which is always
393 completely specified)."
394 (let ((value (internal-get-lisp-face-attribute face attribute frame
)))
395 (when (and inherit
(face-attribute-relative-p attribute value
))
396 ;; VALUE is relative, so merge with inherited faces
397 (let ((inh-from (face-attribute face
:inherit frame
)))
398 (unless (or (null inh-from
) (eq inh-from
'unspecified
))
401 (face-attribute-merged-with attribute value inh-from frame
))
402 ;; The `inherit' attribute may point to non existent faces.
406 (face-attribute-relative-p attribute value
))
407 ;; We should merge with INHERIT as well
408 (setq value
(face-attribute-merged-with attribute value inherit frame
)))
411 (defun face-attribute-merged-with (attribute value faces
&optional frame
)
412 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
413 FACES may be either a single face or a list of faces.
414 \[This is an internal function.]"
415 (cond ((not (face-attribute-relative-p attribute value
))
420 (face-attribute-merged-with
422 (face-attribute-merged-with attribute value
(car faces
) frame
)
426 (merge-face-attribute attribute
428 (face-attribute faces attribute frame t
)))))
431 (defmacro face-attribute-specified-or
(value &rest body
)
432 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
433 (let ((temp (make-symbol "value")))
434 `(let ((,temp
,value
))
435 (if (not (eq ,temp
'unspecified
))
439 (defun face-foreground (face &optional frame inherit
)
440 "Return the foreground color name of FACE, or nil if unspecified.
441 If the optional argument FRAME is given, report on face FACE in that frame.
442 If FRAME is t, report on the defaults for face FACE (for new frames).
443 If FRAME is omitted or nil, use the selected frame.
445 If INHERIT is nil, only a foreground color directly defined by FACE is
446 considered, so the return value may be nil.
447 If INHERIT is t, and FACE doesn't define a foreground color, then any
448 foreground color that FACE inherits through its `:inherit' attribute
449 is considered as well; however the return value may still be nil.
450 If INHERIT is a face or a list of faces, then it is used to try to
451 resolve an unspecified foreground color.
453 To ensure that a valid color is always returned, use a value of
454 `default' for INHERIT; this will resolve any unspecified values by
455 merging with the `default' face (which is always completely specified)."
456 (face-attribute-specified-or (face-attribute face
:foreground frame inherit
)
459 (defun face-background (face &optional frame inherit
)
460 "Return the background color name of FACE, or nil if unspecified.
461 If the optional argument FRAME is given, report on face FACE in that frame.
462 If FRAME is t, report on the defaults for face FACE (for new frames).
463 If FRAME is omitted or nil, use the selected frame.
465 If INHERIT is nil, only a background color directly defined by FACE is
466 considered, so the return value may be nil.
467 If INHERIT is t, and FACE doesn't define a background color, then any
468 background color that FACE inherits through its `:inherit' attribute
469 is considered as well; however the return value may still be nil.
470 If INHERIT is a face or a list of faces, then it is used to try to
471 resolve an unspecified background color.
473 To ensure that a valid color is always returned, use a value of
474 `default' for INHERIT; this will resolve any unspecified values by
475 merging with the `default' face (which is always completely specified)."
476 (face-attribute-specified-or (face-attribute face
:background frame inherit
)
479 (defun face-stipple (face &optional frame inherit
)
480 "Return the stipple pixmap name of FACE, or nil if unspecified.
481 If the optional argument FRAME is given, report on face FACE in that frame.
482 If FRAME is t, report on the defaults for face FACE (for new frames).
483 If FRAME is omitted or nil, use the selected frame.
485 If INHERIT is nil, only a stipple directly defined by FACE is
486 considered, so the return value may be nil.
487 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
488 that FACE inherits through its `:inherit' attribute is considered as
489 well; however the return value may still be nil.
490 If INHERIT is a face or a list of faces, then it is used to try to
491 resolve an unspecified stipple.
493 To ensure that a valid stipple or nil is always returned, use a value of
494 `default' for INHERIT; this will resolve any unspecified values by merging
495 with the `default' face (which is always completely specified)."
496 (face-attribute-specified-or (face-attribute face
:stipple frame inherit
)
500 (defalias 'face-background-pixmap
'face-stipple
)
503 (defun face-underline-p (face &optional frame inherit
)
504 "Return non-nil if FACE specifies a non-nil underlining.
505 If the optional argument FRAME is given, report on face FACE in that frame.
506 If FRAME is t, report on the defaults for face FACE (for new frames).
507 If FRAME is omitted or nil, use the selected frame.
508 Optional argument INHERIT is passed to `face-attribute'."
509 (face-attribute-specified-or
510 (face-attribute face
:underline frame inherit
) nil
))
513 (defun face-inverse-video-p (face &optional frame inherit
)
514 "Return non-nil if FACE specifies a non-nil inverse-video.
515 If the optional argument FRAME is given, report on face FACE in that frame.
516 If FRAME is t, report on the defaults for face FACE (for new frames).
517 If FRAME is omitted or nil, use the selected frame.
518 Optional argument INHERIT is passed to `face-attribute'."
519 (eq (face-attribute face
:inverse-video frame inherit
) t
))
522 (defun face-bold-p (face &optional frame inherit
)
523 "Return non-nil if the font of FACE is bold on FRAME.
524 If the optional argument FRAME is given, report on face FACE in that frame.
525 If FRAME is t, report on the defaults for face FACE (for new frames).
526 If FRAME is omitted or nil, use the selected frame.
527 Optional argument INHERIT is passed to `face-attribute'.
528 Use `face-attribute' for finer control."
529 (let ((bold (face-attribute face
:weight frame inherit
)))
530 (memq bold
'(semi-bold bold extra-bold ultra-bold
))))
533 (defun face-italic-p (face &optional frame inherit
)
534 "Return non-nil if the font of FACE is italic on FRAME.
535 If the optional argument FRAME is given, report on face FACE in that frame.
536 If FRAME is t, report on the defaults for face FACE (for new frames).
537 If FRAME is omitted or nil, use the selected frame.
538 Optional argument INHERIT is passed to `face-attribute'.
539 Use `face-attribute' for finer control."
540 (let ((italic (face-attribute face
:slant frame inherit
)))
541 (memq italic
'(italic oblique
))))
545 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
546 ;;; Face documentation.
547 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
549 (defun face-documentation (face)
550 "Get the documentation string for FACE.
551 If FACE is a face-alias, get the documentation for the target face."
552 (let ((alias (get face
'face-alias
)))
554 (let ((doc (get alias
'face-documentation
)))
555 (format "%s is an alias for the face `%s'.%s" face alias
556 (if doc
(format "\n%s" doc
)
558 (get face
'face-documentation
))))
561 (defun set-face-documentation (face string
)
562 "Set the documentation string for FACE to STRING."
563 ;; Perhaps the text should go in DOC.
564 (put face
'face-documentation
(purecopy string
)))
567 (defalias 'face-doc-string
'face-documentation
)
568 (defalias 'set-face-doc-string
'set-face-documentation
)
572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
573 ;; Setting face attributes.
574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
577 (defun set-face-attribute (face frame
&rest args
)
578 "Set attributes of FACE on FRAME from ARGS.
579 This function overrides the face attributes specified by FACE's
580 face spec. It is mostly intended for internal use only.
582 If FRAME is nil, set the attributes for all existing frames, as
583 well as the default for new frames. If FRAME is t, change the
584 default for new frames only.
586 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a
587 valid face attribute name. All attributes can be set to
588 `unspecified'; this fact is not further mentioned below.
590 The following attributes are recognized:
594 VALUE must be a string specifying the font family
595 \(e.g. \"Monospace\") or a fontset.
599 VALUE must be a string specifying the font foundry,
600 e.g. ``adobe''. If a font foundry is specified, wild-cards `*'
605 VALUE specifies the relative proportionate width of the font to use.
606 It must be one of the symbols `ultra-condensed', `extra-condensed',
607 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
608 `extra-expanded', or `ultra-expanded'.
612 VALUE specifies the relative or absolute height of the font. An
613 absolute height is an integer, and specifies font height in units
614 of 1/10 pt. A relative height is either a floating point number,
615 which specifies a scaling factor for the underlying face height;
616 or a function that takes a single argument (the underlying face
617 height) and returns the new height. Note that for the `default'
618 face, you must specify an absolute height (since there is nothing
619 for it to be relative to).
623 VALUE specifies the weight of the font to use. It must be one of the
624 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
625 `semi-light', `light', `extra-light', `ultra-light'.
629 VALUE specifies the slant of the font to use. It must be one of the
630 symbols `italic', `oblique', `normal', `reverse-italic', or
633 `:foreground', `:background'
635 VALUE must be a color name, a string.
639 VALUE specifies whether characters in FACE should be underlined.
640 If VALUE is t, underline with foreground color of the face.
641 If VALUE is a string, underline with that color.
642 If VALUE is nil, explicitly don't underline.
644 Otherwise, VALUE must be a property list of the form:
646 `(:color COLOR :style STYLE)'.
648 COLOR can be a either a color name string or `foreground-color'.
649 STYLE can be either `line' or `wave'.
650 If a keyword/value pair is missing from the property list, a
651 default value will be used for the value.
652 The default value of COLOR is the foreground color of the face.
653 The default value of STYLE is `line'.
657 VALUE specifies whether characters in FACE should be overlined. If
658 VALUE is t, overline with foreground color of the face. If VALUE is a
659 string, overline with that color. If VALUE is nil, explicitly don't
664 VALUE specifies whether characters in FACE should be drawn with a line
665 striking through them. If VALUE is t, use the foreground color of the
666 face. If VALUE is a string, strike-through with that color. If VALUE
667 is nil, explicitly don't strike through.
671 VALUE specifies whether characters in FACE should have a box drawn
672 around them. If VALUE is nil, explicitly don't draw boxes. If
673 VALUE is t, draw a box with lines of width 1 in the foreground color
674 of the face. If VALUE is a string, the string must be a color name,
675 and the box is drawn in that color with a line width of 1. Otherwise,
676 VALUE must be a property list of the form `(:line-width WIDTH
677 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
678 the property list, a default value will be used for the value, as
679 specified below. WIDTH specifies the width of the lines to draw; it
680 defaults to 1. If WIDTH is negative, the absolute value is the width
681 of the lines, and draw top/bottom lines inside the characters area,
682 not around it. COLOR is the name of the color to draw in, default is
683 the foreground color of the face for simple boxes, and the background
684 color of the face for 3D boxes. STYLE specifies whether a 3D box
685 should be draw. If STYLE is `released-button', draw a box looking
686 like a released 3D button. If STYLE is `pressed-button' draw a box
687 that appears like a pressed button. If STYLE is nil, the default if
688 the property list doesn't contain a style specification, draw a 2D
693 VALUE specifies whether characters in FACE should be displayed in
694 inverse video. VALUE must be one of t or nil.
698 If VALUE is a string, it must be the name of a file of pixmap data.
699 The directories listed in the `x-bitmap-file-path' variable are
700 searched. Alternatively, VALUE may be a list of the form (WIDTH
701 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
702 is a string containing the raw bits of the bitmap. VALUE nil means
703 explicitly don't use a stipple pattern.
705 For convenience, attributes `:family', `:foundry', `:width',
706 `:height', `:weight', and `:slant' may also be set in one step
711 Set font-related face attributes from VALUE. VALUE must be a
712 valid font name or font object. Setting this attribute will also
713 set the `:family', `:foundry', `:width', `:height', `:weight',
714 and `:slant' attributes.
718 VALUE is the name of a face from which to inherit attributes, or
719 a list of face names. Attributes from inherited faces are merged
720 into the face like an underlying face would be, with higher
721 priority than underlying faces.
723 For backward compatibility, the keywords `:bold' and `:italic'
724 can be used to specify weight and slant respectively. This usage
725 is considered obsolete. For these two keywords, the VALUE must
726 be either t or nil. A value of t for `:bold' is equivalent to
727 setting `:weight' to `bold', and a value of t for `:italic' is
728 equivalent to setting `:slant' to `italic'. But if `:weight' is
729 specified in the face spec, `:bold' is ignored, and if `:slant'
730 is specified, `:italic' is ignored."
731 (setq args
(purecopy args
))
732 (let ((where (if (null frame
) 0 frame
))
735 ;; If we set the new-frame defaults, this face is modified outside Custom.
736 (if (memq where
'(0 t
))
737 (put (or (get face
'face-alias
) face
) 'face-modified t
))
738 ;; If family and/or foundry are specified, set it first. Certain
739 ;; face attributes, e.g. :weight semi-condensed, are not supported
740 ;; in every font. See bug#1127.
742 (cond ((eq (car spec
) :family
)
743 (setq family
(cadr spec
)))
744 ((eq (car spec
) :foundry
)
745 (setq foundry
(cadr spec
))))
746 (setq spec
(cddr spec
)))
747 (when (or family foundry
)
748 (when (and (stringp family
)
749 (string-match "\\([^-]*\\)-\\([^-]*\\)" family
))
751 (setq foundry
(match-string 1 family
)))
752 (setq family
(match-string 2 family
)))
753 (when (or (stringp family
) (eq family
'unspecified
))
754 (internal-set-lisp-face-attribute face
:family
(purecopy family
)
756 (when (or (stringp foundry
) (eq foundry
'unspecified
))
757 (internal-set-lisp-face-attribute face
:foundry
(purecopy foundry
)
760 (unless (memq (car args
) '(:family
:foundry
))
761 (internal-set-lisp-face-attribute face
(car args
)
762 (purecopy (cadr args
))
764 (setq args
(cddr args
)))))
766 (defun make-face-bold (face &optional frame _noerror
)
767 "Make the font of FACE be bold, if possible.
768 FRAME nil or not specified means change face on all frames.
769 Argument NOERROR is ignored and retained for compatibility.
770 Use `set-face-attribute' for finer control of the font weight."
771 (interactive (list (read-face-name "Make which face bold"
773 (set-face-attribute face frame
:weight
'bold
))
776 (defun make-face-unbold (face &optional frame _noerror
)
777 "Make the font of FACE be non-bold, if possible.
778 FRAME nil or not specified means change face on all frames.
779 Argument NOERROR is ignored and retained for compatibility."
780 (interactive (list (read-face-name "Make which face non-bold"
782 (set-face-attribute face frame
:weight
'normal
))
785 (defun make-face-italic (face &optional frame _noerror
)
786 "Make the font of FACE be italic, if possible.
787 FRAME nil or not specified means change face on all frames.
788 Argument NOERROR is ignored and retained for compatibility.
789 Use `set-face-attribute' for finer control of the font slant."
790 (interactive (list (read-face-name "Make which face italic"
792 (set-face-attribute face frame
:slant
'italic
))
795 (defun make-face-unitalic (face &optional frame _noerror
)
796 "Make the font of FACE be non-italic, if possible.
797 FRAME nil or not specified means change face on all frames.
798 Argument NOERROR is ignored and retained for compatibility."
799 (interactive (list (read-face-name "Make which face non-italic"
801 (set-face-attribute face frame
:slant
'normal
))
804 (defun make-face-bold-italic (face &optional frame _noerror
)
805 "Make the font of FACE be bold and italic, if possible.
806 FRAME nil or not specified means change face on all frames.
807 Argument NOERROR is ignored and retained for compatibility.
808 Use `set-face-attribute' for finer control of font weight and slant."
809 (interactive (list (read-face-name "Make which face bold-italic"
811 (set-face-attribute face frame
:weight
'bold
:slant
'italic
))
814 (defun set-face-font (face font
&optional frame
)
815 "Change font-related attributes of FACE to those of FONT (a string).
816 FRAME nil or not specified means change face on all frames.
817 This sets the attributes `:family', `:foundry', `:width',
818 `:height', `:weight', and `:slant'. When called interactively,
819 prompt for the face and font."
820 (interactive (read-face-and-attribute :font
))
821 (set-face-attribute face frame
:font font
))
824 ;; Implementation note: Emulating gray background colors with a
825 ;; stipple pattern is now part of the face realization process, and is
826 ;; done in C depending on the frame on which the face is realized.
828 (defun set-face-background (face color
&optional frame
)
829 "Change the background color of face FACE to COLOR (a string).
830 FRAME nil or not specified means change face on all frames.
831 COLOR can be a system-defined color name (see `list-colors-display')
832 or a hex spec of the form #RRGGBB.
833 When called interactively, prompts for the face and color."
834 (interactive (read-face-and-attribute :background
))
835 (set-face-attribute face frame
:background
(or color
'unspecified
)))
838 (defun set-face-foreground (face color
&optional frame
)
839 "Change the foreground color of face FACE to COLOR (a string).
840 FRAME nil or not specified means change face on all frames.
841 COLOR can be a system-defined color name (see `list-colors-display')
842 or a hex spec of the form #RRGGBB.
843 When called interactively, prompts for the face and color."
844 (interactive (read-face-and-attribute :foreground
))
845 (set-face-attribute face frame
:foreground
(or color
'unspecified
)))
848 (defun set-face-stipple (face stipple
&optional frame
)
849 "Change the stipple pixmap of face FACE to STIPPLE.
850 FRAME nil or not specified means change face on all frames.
851 STIPPLE should be a string, the name of a file of pixmap data.
852 The directories listed in the `x-bitmap-file-path' variable are searched.
854 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
855 where WIDTH and HEIGHT are the size in pixels,
856 and DATA is a string, containing the raw bits of the bitmap."
857 (interactive (read-face-and-attribute :stipple
))
858 (set-face-attribute face frame
:stipple
(or stipple
'unspecified
)))
861 (defun set-face-underline (face underline
&optional frame
)
862 "Specify whether face FACE is underlined.
863 UNDERLINE nil means FACE explicitly doesn't underline.
864 UNDERLINE t means FACE underlines with its foreground color.
865 If UNDERLINE is a string, underline with that color.
867 UNDERLINE may also be a list of the form (:color COLOR :style STYLE),
868 where COLOR is a string or `foreground-color', and STYLE is either
869 `line' or `wave'. :color may be omitted, which means to use the
870 foreground color. :style may be omitted, which means to use a line.
872 FRAME nil or not specified means change face on all frames.
873 Use `set-face-attribute' to ``unspecify'' underlining."
874 (interactive (read-face-and-attribute :underline
))
875 (set-face-attribute face frame
:underline underline
))
877 (define-obsolete-function-alias 'set-face-underline-p
878 'set-face-underline
"24.3")
881 (defun set-face-inverse-video (face inverse-video-p
&optional frame
)
882 "Specify whether face FACE is in inverse video.
883 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
884 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
885 FRAME nil or not specified means change face on all frames.
886 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
888 (let ((list (read-face-and-attribute :inverse-video
)))
889 (list (car list
) (if (cadr list
) t
))))
890 (set-face-attribute face frame
:inverse-video inverse-video-p
))
892 (define-obsolete-function-alias 'set-face-inverse-video-p
893 'set-face-inverse-video
"24.4")
895 (defun set-face-bold (face bold-p
&optional frame
)
896 "Specify whether face FACE is bold.
897 BOLD-P non-nil means FACE should explicitly display bold.
898 BOLD-P nil means FACE should explicitly display non-bold.
899 FRAME nil or not specified means change face on all frames.
900 Use `set-face-attribute' or `modify-face' for finer control."
902 (make-face-unbold face frame
)
903 (make-face-bold face frame
)))
905 (define-obsolete-function-alias 'set-face-bold-p
'set-face-bold
"24.4")
908 (defun set-face-italic (face italic-p
&optional frame
)
909 "Specify whether face FACE is italic.
910 ITALIC-P non-nil means FACE should explicitly display italic.
911 ITALIC-P nil means FACE should explicitly display non-italic.
912 FRAME nil or not specified means change face on all frames.
913 Use `set-face-attribute' or `modify-face' for finer control."
915 (make-face-unitalic face frame
)
916 (make-face-italic face frame
)))
918 (define-obsolete-function-alias 'set-face-italic-p
'set-face-italic
"24.4")
921 (defalias 'set-face-background-pixmap
'set-face-stipple
)
924 (defun invert-face (face &optional frame
)
925 "Swap the foreground and background colors of FACE.
926 If FRAME is omitted or nil, it means change face on all frames.
927 If FACE specifies neither foreground nor background color,
928 set its foreground and background to the background and foreground
929 of the default face. Value is FACE."
930 (interactive (list (read-face-name "Invert face" (face-at-point t
))))
931 (let ((fg (face-attribute face
:foreground frame
))
932 (bg (face-attribute face
:background frame
)))
933 (if (not (and (eq fg
'unspecified
) (eq bg
'unspecified
)))
934 (set-face-attribute face frame
:foreground bg
:background fg
)
935 (set-face-attribute face frame
937 (face-attribute 'default
:background frame
)
939 (face-attribute 'default
:foreground frame
))))
943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
944 ;;; Interactively modifying faces.
945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
947 (defvar crm-separator
) ; from crm.el
949 (defun read-face-name (prompt &optional default multiple
)
950 "Read one or more face names, prompting with PROMPT.
951 PROMPT should not end in a space or a colon.
953 Return DEFAULT if the user enters the empty string.
954 If DEFAULT is non-nil, it should be a single face or a list of face names
955 \(symbols or strings). In the latter case, return the `car' of DEFAULT
956 \(if MULTIPLE is nil, see below), or DEFAULT (if MULTIPLE is non-nil).
958 If MULTIPLE is non-nil, this function uses `completing-read-multiple'
959 to read multiple faces with \"[ \\t]*,[ \\t]*\" as the separator regexp
960 and it returns a list of face names. Otherwise, it reads and returns
962 (if (and default
(not (stringp default
)))
964 (cond ((symbolp default
)
965 (symbol-name default
))
967 (mapconcat (lambda (f) (if (symbolp f
) (symbol-name f
) f
))
969 ;; If we only want one, and the default is more than one,
970 ;; discard the unwanted ones.
971 (t (symbol-name (car default
))))))
972 (when (and default
(not multiple
))
974 ;; For compatibility with `completing-read-multiple' use `crm-separator'
975 ;; to define DEFAULT if MULTIPLE is nil.
976 (setq default
(car (split-string default crm-separator t
))))
978 (let ((prompt (if default
979 (format "%s (default `%s'): " prompt default
)
980 (format "%s: " prompt
)))
981 aliasfaces nonaliasfaces faces
)
982 ;; Build up the completion tables.
983 (mapatoms (lambda (s)
985 (if (get s
'face-alias
)
986 (push (symbol-name s
) aliasfaces
)
987 (push (symbol-name s
) nonaliasfaces
)))))
990 (dolist (face (completing-read-multiple
992 (completion-table-in-turn nonaliasfaces aliasfaces
)
993 nil t nil
'face-name-history default
))
994 ;; Ignore elements that are not faces
995 ;; (for example, because DEFAULT was "all faces")
996 (if (facep face
) (push (intern face
) faces
)))
998 (let ((face (completing-read
1000 (completion-table-in-turn nonaliasfaces aliasfaces
)
1001 nil t nil
'face-name-history default
)))
1002 (if (facep face
) (intern face
))))))
1004 ;; Not defined without X, but behind window-system test.
1005 (defvar x-bitmap-file-path
)
1007 (defun face-valid-attribute-values (attribute &optional frame
)
1008 "Return valid values for face attribute ATTRIBUTE.
1009 The optional argument FRAME is used to determine available fonts
1010 and colors. If it is nil or not specified, the selected frame is used.
1011 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
1012 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1017 (if (window-system frame
)
1018 (mapcar (lambda (x) (cons x x
))
1020 ;; Only one font on TTYs.
1021 (list (cons "default" "default"))))
1025 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1028 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1031 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1034 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1035 (internal-lisp-face-attribute-values attribute
)))
1036 ((or `:underline
`:overline
`:strike-through
`:box
)
1037 (if (window-system frame
)
1038 (nconc (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1039 (internal-lisp-face-attribute-values attribute
))
1040 (mapcar #'(lambda (c) (cons c c
))
1041 (defined-colors frame
)))
1042 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1043 (internal-lisp-face-attribute-values attribute
))))
1044 ((or `:foreground
`:background
)
1045 (mapcar #'(lambda (c) (cons c c
))
1046 (defined-colors frame
)))
1050 (and (memq (window-system frame
) '(x ns
)) ; No stipple on w32
1053 (mapcar (lambda (dir)
1054 (and (file-readable-p dir
)
1055 (file-directory-p dir
)
1056 (directory-files dir
)))
1057 x-bitmap-file-path
)))))
1059 (cons '("none" . nil
)
1060 (mapcar #'(lambda (c) (cons (symbol-name c
) c
))
1063 (error "Internal error")))))
1064 (if (and (listp valid
) (not (memq attribute
'(:inherit
))))
1065 (nconc (list (cons "unspecified" 'unspecified
)) valid
)
1069 (defconst face-attribute-name-alist
1070 '((:family .
"font family")
1071 (:foundry .
"font foundry")
1072 (:width .
"character set width")
1073 (:height .
"height in 1/10 pt")
1074 (:weight .
"weight")
1076 (:underline .
"underline")
1077 (:overline .
"overline")
1078 (:strike-through .
"strike-through")
1080 (:inverse-video .
"inverse-video display")
1081 (:foreground .
"foreground color")
1082 (:background .
"background color")
1083 (:stipple .
"background stipple")
1084 (:inherit .
"inheritance"))
1085 "An alist of descriptive names for face attributes.
1086 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1087 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1088 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1091 (defun face-descriptive-attribute-name (attribute)
1092 "Return a descriptive name for ATTRIBUTE."
1093 (cdr (assq attribute face-attribute-name-alist
)))
1096 (defun face-read-string (face default name
&optional completion-alist
)
1097 "Interactively read a face attribute string value.
1098 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1099 default string to return if no new value is entered. NAME is a
1100 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1101 alist of valid values, if non-nil.
1103 Entering nothing accepts the default string DEFAULT.
1104 Value is the new attribute value."
1105 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1106 ;; each word in a string separately).
1107 (setq name
(concat (upcase (substring name
0 1)) (substring name
1)))
1108 (let* ((completion-ignore-case t
)
1109 (value (completing-read
1111 (format "%s for face `%s' (default %s): "
1113 (format "%s for face `%s': " name face
))
1114 completion-alist nil nil nil nil default
)))
1115 (if (equal value
"") default value
)))
1118 (defun face-read-integer (face default name
)
1119 "Interactively read an integer face attribute value.
1120 FACE is the face whose attribute is read. DEFAULT is the default
1121 value to return if no new value is entered. NAME is a descriptive
1122 name of the attribute for prompting. Value is the new attribute value."
1124 (face-read-string face
1125 (format "%s" default
)
1127 (list (cons "unspecified" 'unspecified
)))))
1128 (cond ((equal new-value
"unspecified")
1130 ((member new-value
'("unspecified-fg" "unspecified-bg"))
1133 (string-to-number new-value
)))))
1136 ;; FIXME this does allow you to enter the list forms of :box,
1137 ;; :stipple, or :underline, because face-valid-attribute-values does
1138 ;; not return those forms.
1139 (defun read-face-attribute (face attribute
&optional frame
)
1140 "Interactively read a new value for FACE's ATTRIBUTE.
1141 Optional argument FRAME nil or unspecified means read an attribute value
1142 of a global face. Value is the new attribute value."
1143 (let* ((old-value (face-attribute face attribute frame
))
1144 (attribute-name (face-descriptive-attribute-name attribute
))
1145 (valid (face-valid-attribute-values attribute frame
))
1147 ;; Represent complex attribute values as strings by printing them
1148 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1149 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1150 ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'.
1151 (and (memq attribute
'(:box
:stipple
:underline
))
1152 (or (consp old-value
)
1153 (vectorp old-value
))
1154 (setq old-value
(prin1-to-string old-value
)))
1155 (cond ((listp valid
)
1157 (or (car (rassoc old-value valid
))
1158 (format "%s" old-value
))))
1160 (face-read-string face default attribute-name valid
))
1161 (if (equal new-value default
)
1162 ;; Nothing changed, so don't bother with all the stuff
1163 ;; below. In particular, this avoids a non-tty color
1164 ;; from being canonicalized for a tty when the user
1165 ;; just uses the default.
1166 (setq new-value old-value
)
1167 ;; Terminal frames can support colors that don't appear
1168 ;; explicitly in VALID, using color approximation code
1169 ;; in tty-colors.el.
1170 (when (and (memq attribute
'(:foreground
:background
))
1171 (not (memq (window-system frame
) '(x w32 ns
)))
1172 (not (member new-value
1174 "unspecified-fg" "unspecified-bg"))))
1175 (setq new-value
(car (tty-color-desc new-value frame
))))
1176 (when (assoc new-value valid
)
1177 (setq new-value
(cdr (assoc new-value valid
)))))))
1178 ((eq valid
'integerp
)
1179 (setq new-value
(face-read-integer face old-value attribute-name
)))
1180 (t (error "Internal error")))
1181 ;; Convert stipple and box value text we read back to a list or
1182 ;; vector if it looks like one. This makes the assumption that a
1183 ;; pixmap file name won't start with an open-paren.
1184 (and (memq attribute
'(:stipple
:box
:underline
))
1186 (string-match-p "^[[(]" new-value
)
1187 (setq new-value
(read new-value
)))
1190 (declare-function fontset-list
"fontset.c" ())
1191 (declare-function x-list-fonts
"xfaces.c"
1192 (pattern &optional face frame maximum width
))
1194 (defun read-face-font (face &optional frame
)
1195 "Read the name of a font for FACE on FRAME.
1196 If optional argument FRAME is nil or omitted, use the selected frame."
1197 (let ((completion-ignore-case t
))
1198 (completing-read (format "Set font attributes of face `%s' from font: " face
)
1199 (append (fontset-list) (x-list-fonts "*" nil frame
)))))
1202 (defun read-all-face-attributes (face &optional frame
)
1203 "Interactively read all attributes for FACE.
1204 If optional argument FRAME is nil or omitted, use the selected frame.
1205 Value is a property list of attribute names and new values."
1207 (dolist (attribute face-attribute-name-alist result
)
1208 (setq result
(cons (car attribute
)
1209 (cons (read-face-attribute face
(car attribute
) frame
)
1212 (defun modify-face (&optional face foreground background stipple
1213 bold-p italic-p underline inverse-p frame
)
1214 "Modify attributes of faces interactively.
1215 If optional argument FRAME is nil or omitted, modify the face used
1216 for newly created frame, i.e. the global face.
1217 For non-interactive use, `set-face-attribute' is preferred.
1218 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1219 and the face and its settings are obtained by querying the user."
1222 (set-face-attribute face frame
1223 :foreground
(or foreground
'unspecified
)
1224 :background
(or background
'unspecified
)
1226 :weight
(if bold-p
'bold
'normal
)
1227 :slant
(if italic-p
'italic
'normal
)
1228 :underline underline
1229 :inverse-video inverse-p
)
1230 (setq face
(read-face-name "Modify face" (face-at-point t
)))
1231 (apply #'set-face-attribute face frame
1232 (read-all-face-attributes face frame
))))
1234 (defun read-face-and-attribute (attribute &optional frame
)
1235 "Read face name and face attribute value.
1236 ATTRIBUTE is the attribute whose new value is read.
1237 FRAME nil or unspecified means read attribute value of global face.
1238 Value is a list (FACE NEW-VALUE) where FACE is the face read
1239 \(a symbol), and NEW-VALUE is value read."
1240 (cond ((eq attribute
:font
)
1241 (let* ((prompt "Set font-related attributes of face")
1242 (face (read-face-name prompt
(face-at-point t
)))
1243 (font (read-face-font face frame
)))
1246 (let* ((attribute-name (face-descriptive-attribute-name attribute
))
1247 (prompt (format "Set %s of face" attribute-name
))
1248 (face (read-face-name prompt
(face-at-point t
)))
1249 (new-value (read-face-attribute face attribute frame
)))
1250 (list face new-value
)))))
1254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1258 (defconst list-faces-sample-text
1259 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1260 "Text string to display as the sample text for `list-faces-display'.")
1263 ;; The name list-faces would be more consistent, but let's avoid a
1264 ;; conflict with Lucid, which uses that name differently.
1266 (defvar help-xref-stack
)
1267 (defun list-faces-display (&optional regexp
)
1268 "List all faces, using the same sample text in each.
1269 The sample text is a string that comes from the variable
1270 `list-faces-sample-text'.
1272 If REGEXP is non-nil, list only those faces with names matching
1273 this regular expression. When called interactively with a prefix
1274 argument, prompt for a regular expression using `read-regexp'."
1275 (interactive (list (and current-prefix-arg
1276 (read-regexp "List faces matching regexp"))))
1277 (let ((all-faces (zerop (length regexp
)))
1278 (frame (selected-frame))
1281 disp-frame window face-name
)
1282 ;; We filter and take the max length in one pass
1286 (let ((s (symbol-name f
)))
1287 (when (or all-faces
(string-match-p regexp s
))
1288 (setq max-length
(max (length s
) max-length
))
1290 (sort (face-list) #'string-lessp
))))
1292 (error "No faces matching \"%s\"" regexp
))
1293 (setq max-length
(1+ max-length
)
1294 line-format
(format "%%-%ds" max-length
))
1295 (with-help-window "*Faces*"
1296 (with-current-buffer standard-output
1297 (setq truncate-lines t
)
1299 (substitute-command-keys
1301 "\\<help-mode-map>Use "
1302 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1303 "\\[help-follow] on a face name to customize it\n"
1304 "or on its sample text for a description of the face.\n\n")))
1305 (setq help-xref-stack nil
)
1306 (dolist (face faces
)
1307 (setq face-name
(symbol-name face
))
1308 (insert (format line-format face-name
))
1309 ;; Hyperlink to a customization buffer for the face. Using
1310 ;; the help xref mechanism may not be the best way.
1313 (search-backward face-name
)
1314 (setq help-xref-stack-item
`(list-faces-display ,regexp
))
1315 (help-xref-button 0 'help-customize-face face
)))
1317 (line-beg (line-beginning-position)))
1318 (insert list-faces-sample-text
)
1319 ;; Hyperlink to a help buffer for the face.
1322 (search-backward list-faces-sample-text
)
1323 (help-xref-button 0 'help-face face
)))
1325 (put-text-property beg
(1- (point)) 'face face
)
1326 ;; Make all face commands default to the proper face
1327 ;; anywhere in the line.
1328 (put-text-property line-beg
(1- (point)) 'read-face-name face
)
1329 ;; If the sample text has multiple lines, line up all of them.
1333 (insert-char ?\s max-length
)
1335 (goto-char (point-min))))
1336 ;; If the *Faces* buffer appears in a different frame,
1337 ;; copy all the face definitions from FRAME,
1338 ;; so that the display will reflect the frame that was selected.
1339 (setq window
(get-buffer-window (get-buffer "*Faces*") t
))
1340 (setq disp-frame
(if window
(window-frame window
)
1341 (car (frame-list))))
1342 (or (eq frame disp-frame
)
1343 (dolist (face (face-list))
1344 (copy-face face face frame disp-frame
)))))
1347 (defun describe-face (face &optional frame
)
1348 "Display the properties of face FACE on FRAME.
1349 Interactively, FACE defaults to the faces of the character after point
1350 and FRAME defaults to the selected frame.
1352 If the optional argument FRAME is given, report on face FACE in that frame.
1353 If FRAME is t, report on the defaults for face FACE (for new frames).
1354 If FRAME is omitted or nil, use the selected frame."
1355 (interactive (list (read-face-name "Describe face"
1356 (or (face-at-point t
) 'default
)
1358 (let* ((attrs '((:family .
"Family")
1359 (:foundry .
"Foundry")
1361 (:height .
"Height")
1362 (:weight .
"Weight")
1364 (:foreground .
"Foreground")
1365 (:distant-foreground .
"DistantForeground")
1366 (:background .
"Background")
1367 (:underline .
"Underline")
1368 (:overline .
"Overline")
1369 (:strike-through .
"Strike-through")
1371 (:inverse-video .
"Inverse")
1372 (:stipple .
"Stipple")
1374 (:fontset .
"Fontset")
1375 (:inherit .
"Inherit")))
1376 (max-width (apply #'max
(mapcar #'(lambda (x) (length (cdr x
)))
1378 (help-setup-xref (list #'describe-face face
)
1379 (called-interactively-p 'interactive
))
1381 (setq face
'default
))
1382 (if (not (listp face
))
1383 (setq face
(list face
)))
1384 (with-help-window (help-buffer)
1385 (with-current-buffer standard-output
1387 (if (stringp f
) (setq f
(intern f
)))
1388 ;; We may get called for anonymous faces (i.e., faces
1389 ;; expressed using prop-value plists). Those can't be
1390 ;; usefully customized, so ignore them.
1392 (insert "Face: " (symbol-name f
))
1394 (insert " undefined face.\n")
1395 (let ((customize-label "customize this face")
1397 (insert (concat " (" (propertize "sample" 'font-lock-face f
) ")"))
1398 (princ (concat " (" customize-label
")\n"))
1399 ;; FIXME not sure how much of this belongs here, and
1400 ;; how much in `face-documentation'. The latter is
1401 ;; not used much, but needs to return nil for
1402 ;; undocumented faces.
1403 (let ((alias (get f
'face-alias
))
1409 (format "\n %s is an alias for the face `%s'.\n%s"
1411 (if (setq obsolete
(get f
'obsolete-face
))
1412 (format " This face is obsolete%s; use `%s' instead.\n"
1413 (if (stringp obsolete
)
1414 (format " since %s" obsolete
)
1418 (insert "\nDocumentation:\n"
1419 (or (face-documentation face
)
1420 "Not documented as a face.")
1422 (with-current-buffer standard-output
1425 (concat "\\(" customize-label
"\\)") nil t
)
1426 (help-xref-button 1 'help-customize-face f
)))
1427 (setq file-name
(find-lisp-object-file-name f
'defface
))
1429 (princ "Defined in `")
1430 (princ (file-name-nondirectory file-name
))
1432 ;; Make a hyperlink to the library.
1434 (re-search-backward "`\\([^`']+\\)'" nil t
)
1435 (help-xref-button 1 'help-face-def f file-name
))
1440 (let ((attr (face-attribute f
(car a
) frame
)))
1441 (insert (make-string (- max-width
(length (cdr a
))) ?\s
)
1442 (cdr a
) ": " (format "%s" attr
))
1443 (if (and (eq (car a
) :inherit
)
1444 (not (eq attr
'unspecified
)))
1445 ;; Make a hyperlink to the parent face.
1447 (re-search-backward ": \\([^:]+\\)" nil t
)
1448 (help-xref-button 1 'help-face attr
)))
1453 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1454 ;;; Face specifications (defface).
1455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1457 ;; Parameter FRAME Is kept for call compatibility to with previous
1458 ;; face implementation.
1460 (defun face-attr-construct (face &optional _frame
)
1461 "Return a `defface'-style attribute list for FACE.
1462 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1463 face attributes of FACE where ATTRIBUTE is the attribute name and
1464 VALUE is the specified value of that attribute.
1465 Argument FRAME is ignored and retained for compatibility."
1467 (dolist (entry face-attribute-name-alist result
)
1468 (let* ((attribute (car entry
))
1469 (value (face-attribute face attribute
)))
1470 (unless (eq value
'unspecified
)
1471 (setq result
(nconc (list attribute value
) result
)))))))
1474 (defun face-spec-set-match-display (display frame
)
1475 "Non-nil if DISPLAY matches FRAME.
1476 DISPLAY is part of a spec such as can be used in `defface'.
1477 If FRAME is nil, the current FRAME is used."
1478 (let* ((conjuncts display
)
1479 conjunct req options
1480 ;; t means we have succeeded against all the conjuncts in
1481 ;; DISPLAY that have been tested so far.
1483 (if (eq conjuncts t
)
1484 (setq conjuncts nil
))
1485 (while (and conjuncts match
)
1486 (setq conjunct
(car conjuncts
)
1487 conjuncts
(cdr conjuncts
)
1489 options
(cdr conjunct
)
1490 match
(cond ((eq req
'type
)
1491 (or (memq (window-system frame
) options
)
1492 (and (memq 'graphic options
)
1493 (memq (window-system frame
) '(x w32 ns
)))
1494 ;; FIXME: This should be revisited to use
1495 ;; display-graphic-p, provided that the
1496 ;; color selection depends on the number
1497 ;; of supported colors, and all defface's
1498 ;; are changed to look at number of colors
1499 ;; instead of (type graphic) etc.
1500 (if (null (window-system frame
))
1502 (or (and (memq 'motif options
)
1504 (and (memq 'gtk options
)
1506 (and (memq 'lucid options
)
1507 (featurep 'x-toolkit
)
1508 (not (featurep 'motif
))
1509 (not (featurep 'gtk
)))
1510 (and (memq 'x-toolkit options
)
1511 (featurep 'x-toolkit
))))))
1512 ((eq req
'min-colors
)
1513 (>= (display-color-cells frame
) (car options
)))
1515 (memq (frame-parameter frame
'display-type
) options
))
1516 ((eq req
'background
)
1517 (memq (frame-parameter frame
'background-mode
)
1520 (display-supports-face-attributes-p options frame
))
1521 (t (error "Unknown req `%S' with options `%S'"
1526 (defun face-spec-choose (spec &optional frame no-match-retval
)
1527 "Return the proper attributes for FRAME, out of SPEC.
1529 If no match is found or SPEC is nil, return nil, unless NO-MATCH-RETVAL
1530 is given, in which case return its value instead."
1532 (setq frame
(selected-frame)))
1534 result defaults match-found
)
1536 (let* ((entry (pop tail
))
1537 (display (car entry
))
1540 ;; Get the attributes as actually specified by this alternative.
1542 (if (null (cdr attrs
)) ;; was (listp (car attrs))
1543 ;; Old-style entry, the attribute list is the
1548 ;; If the condition is `default', that sets the default
1549 ;; for following conditions.
1550 (if (eq display
'default
)
1551 (setq defaults thisval
)
1552 ;; Otherwise, if it matches, use it.
1553 (when (face-spec-set-match-display display frame
)
1554 (setq result thisval
1557 ;; If defaults have been found, it's safe to just append those to the result
1558 ;; list (which at this point will be either nil or contain actual specs) and
1559 ;; return it to the caller. Since there will most definitely be something to
1560 ;; return in this case, there's no need to know/check if a match was found.
1562 (append result defaults
)
1568 (defun face-spec-reset-face (face &optional frame
)
1569 "Reset all attributes of FACE on FRAME to unspecified."
1570 (apply 'set-face-attribute face frame
1571 (if (eq face
'default
)
1572 ;; For the default face, avoid making any attribute
1573 ;; unspecified. Instead, set attributes to default values
1574 ;; (see also realize_default_face in xfaces.c).
1576 '(:underline nil
:overline nil
:strike-through nil
1577 :box nil
:inverse-video nil
:stipple nil
:inherit nil
)
1578 ;; `display-graphic-p' is unavailable when running
1579 ;; temacs, prior to loading frame.el.
1580 (when (fboundp 'display-graphic-p
)
1581 (unless (display-graphic-p frame
)
1582 `(:family
"default" :foundry
"default" :width normal
1583 :height
1 :weight normal
:slant normal
1584 :foreground
,(if (frame-parameter nil
'reverse
)
1587 :background
,(if (frame-parameter nil
'reverse
)
1589 "unspecified-bg")))))
1590 ;; For all other faces, unspecify all attributes.
1592 (mapcar (lambda (x) (list (car x
) 'unspecified
))
1593 face-attribute-name-alist
)))))
1595 (defun face-spec-set (face spec
&optional spec-type
)
1596 "Set the face spec SPEC for FACE.
1597 See `defface' for the format of SPEC.
1599 The appearance of each face is controlled by its specs (set via
1600 this function), and by the internal frame-specific face
1601 attributes (set via `set-face-attribute').
1603 This function also defines FACE as a valid face name if it is not
1604 already one, and (re)calculates its attributes on existing
1607 The argument SPEC-TYPE determines which spec to set:
1608 nil or `face-override-spec' means the override spec (which is
1609 usually what you want if calling this function outside of
1611 `customized-face' or `saved-face' means the customized spec or
1612 the saved custom spec;
1613 `face-defface-spec' means the default spec
1614 (usually set only via `defface');
1615 `reset' means to ignore SPEC, but clear the `customized-face'
1616 and `face-override-spec' specs;
1617 Any other value means not to set any spec, but to run the
1618 function for its other effects."
1619 (if (get face
'face-alias
)
1620 (setq face
(get face
'face-alias
)))
1621 ;; Save SPEC to the relevant symbol property.
1623 (setq spec-type
'face-override-spec
))
1624 (if (memq spec-type
'(face-defface-spec face-override-spec
1625 customized-face saved-face
))
1626 (put face spec-type spec
))
1627 (if (memq spec-type
'(reset saved-face
))
1628 (put face
'customized-face nil
))
1629 ;; Setting the face spec via Custom empties out any override spec,
1630 ;; similar to how setting a variable via Custom changes its values.
1631 (if (memq spec-type
'(customized-face saved-face reset
))
1632 (put face
'face-override-spec nil
))
1633 ;; If we reset the face based on its custom spec, it is unmodified
1634 ;; as far as Custom is concerned.
1635 (unless (eq face
'face-override-spec
)
1636 (put face
'face-modified nil
))
1637 ;; Initialize the face if it does not exist, then recalculate.
1638 (make-empty-face face
)
1639 (dolist (frame (frame-list))
1640 (face-spec-recalc face frame
)))
1642 (defun face-spec-recalc (face frame
)
1643 "Reset the face attributes of FACE on FRAME according to its specs.
1644 The following sources are applied in this order:
1646 face reset to default values if it's the default face, otherwise set
1647 to unspecified (through `face-spec-reset-face')
1649 (theme and user customization)
1650 or: if none of the above exist, and none match the current frame or
1651 inherited from the defface spec instead of overwriting it
1652 entirely, the following is applied instead:
1653 (defface default spec)
1654 (X resources (if applicable))
1656 defface override spec"
1657 (while (get face
'face-alias
)
1658 (setq face
(get face
'face-alias
)))
1659 (face-spec-reset-face face frame
)
1660 ;; If FACE is customized or themed, set the custom spec from
1661 ;; `theme-face' records.
1662 (let ((theme-faces (get face
'theme-face
))
1664 spec theme-face-applied
)
1666 (dolist (elt (reverse theme-faces
))
1667 (setq spec
(face-spec-choose (cadr elt
) frame no-match-found
))
1668 (unless (eq spec no-match-found
)
1669 (face-spec-set-2 face frame spec
)
1670 (setq theme-face-applied t
))))
1671 ;; If there was a spec applicable to FRAME, that overrides the
1672 ;; defface spec entirely (rather than inheriting from it). If
1673 ;; there was no spec applicable to FRAME, apply the defface spec
1674 ;; as well as any applicable X resources.
1675 (unless theme-face-applied
1676 (setq spec
(face-spec-choose (face-default-spec face
) frame
))
1677 (face-spec-set-2 face frame spec
)
1678 (make-face-x-resource-internal face frame
))
1679 (setq spec
(face-spec-choose (get face
'face-override-spec
) frame
))
1680 (face-spec-set-2 face frame spec
)))
1682 (defun face-spec-set-2 (face frame spec
)
1683 "Set the face attributes of FACE on FRAME according to SPEC."
1686 (when (assq (car spec
) face-x-resources
)
1687 (push (car spec
) attrs
)
1688 (push (cadr spec
) attrs
))
1689 (setq spec
(cddr spec
)))
1690 (apply 'set-face-attribute face frame
(nreverse attrs
))))
1692 (defun face-attr-match-p (face attrs
&optional frame
)
1693 "Return t if attributes of FACE match values in plist ATTRS.
1694 Optional parameter FRAME is the frame whose definition of FACE
1695 is used. If nil or omitted, use the selected frame."
1697 (setq frame
(selected-frame)))
1698 (let* ((list face-attribute-name-alist
)
1700 (bold (and (plist-member attrs
:bold
)
1701 (not (plist-member attrs
:weight
))))
1702 (italic (and (plist-member attrs
:italic
)
1703 (not (plist-member attrs
:slant
))))
1704 (plist (if (or bold italic
)
1705 (copy-sequence attrs
)
1707 ;; Handle the Emacs 20 :bold and :italic properties.
1709 (plist-put plist
:weight
(if bold
'bold
'normal
)))
1711 (plist-put plist
:slant
(if italic
'italic
'normal
)))
1712 (while (and match list
)
1713 (let* ((attr (caar list
))
1715 (if (plist-member plist attr
)
1716 (plist-get plist attr
)
1718 (value-now (face-attribute face attr frame
)))
1719 (setq match
(equal specified-value value-now
))
1720 (setq list
(cdr list
))))
1723 (defsubst face-spec-match-p
(face spec
&optional frame
)
1724 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1725 (face-attr-match-p face
(face-spec-choose spec frame
) frame
))
1727 (defsubst face-default-spec
(face)
1728 "Return the default face-spec for FACE, ignoring any user customization.
1729 If there is no default for FACE, return nil."
1730 (get face
'face-defface-spec
))
1732 (defsubst face-user-default-spec
(face)
1733 "Return the user's customized face-spec for FACE, or the default if none.
1734 If there is neither a user setting nor a default for FACE, return nil."
1735 (or (get face
'customized-face
)
1736 (get face
'saved-face
)
1737 (face-default-spec face
)))
1740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1741 ;;; Frame-type independent color support.
1742 ;;; We keep the old x-* names as aliases for back-compatibility.
1743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1745 (defun defined-colors (&optional frame
)
1746 "Return a list of colors supported for a particular frame.
1747 The argument FRAME specifies which frame to try.
1748 The value may be different for frames on different display types.
1749 If FRAME doesn't support colors, the value is nil.
1750 If FRAME is nil, that stands for the selected frame."
1751 (if (memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1752 (xw-defined-colors frame
)
1753 (mapcar 'car
(tty-color-alist frame
))))
1754 (defalias 'x-defined-colors
'defined-colors
)
1756 (declare-function xw-color-defined-p
"xfns.c" (color &optional frame
))
1758 (defun color-defined-p (color &optional frame
)
1759 "Return non-nil if COLOR is supported on frame FRAME.
1760 COLOR should be a string naming a color (e.g. \"white\"), or a
1761 string specifying a color's RGB components (e.g. \"#ff12ec\"), or
1762 the symbol `unspecified'.
1764 This function returns nil if COLOR is the symbol `unspecified',
1765 or one of the strings \"unspecified-fg\" or \"unspecified-bg\".
1767 If FRAME is omitted or nil, use the selected frame."
1768 (unless (member color
'(unspecified "unspecified-bg" "unspecified-fg"))
1769 (if (member (framep (or frame
(selected-frame))) '(x w32 ns
))
1770 (xw-color-defined-p color frame
)
1771 (numberp (tty-color-translate color frame
)))))
1772 (defalias 'x-color-defined-p
'color-defined-p
)
1774 (declare-function xw-color-values
"xfns.c" (color &optional frame
))
1776 (defun color-values (color &optional frame
)
1777 "Return a description of the color named COLOR on frame FRAME.
1778 COLOR should be a string naming a color (e.g. \"white\"), or a
1779 string specifying a color's RGB components (e.g. \"#ff12ec\").
1781 Return a list of three integers, (RED GREEN BLUE), each between 0
1782 and either 65280 or 65535 (the maximum depends on the system).
1783 Use `color-name-to-rgb' if you want RGB floating-point values
1786 If FRAME is omitted or nil, use the selected frame.
1787 If FRAME cannot display COLOR, the value is nil.
1789 COLOR can also be the symbol `unspecified' or one of the strings
1790 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1791 return value is nil."
1793 ((member color
'(unspecified "unspecified-fg" "unspecified-bg"))
1795 ((memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1796 (xw-color-values color frame
))
1798 (tty-color-values color frame
))))
1800 (defalias 'x-color-values
'color-values
)
1802 (declare-function xw-display-color-p
"xfns.c" (&optional terminal
))
1804 (defun display-color-p (&optional display
)
1805 "Return t if DISPLAY supports color.
1806 The optional argument DISPLAY specifies which display to ask about.
1807 DISPLAY should be either a frame or a display name (a string).
1808 If omitted or nil, that stands for the selected frame's display."
1809 (if (memq (framep-on-display display
) '(x w32 ns
))
1810 (xw-display-color-p display
)
1811 (tty-display-color-p display
)))
1812 (defalias 'x-display-color-p
'display-color-p
)
1814 (declare-function x-display-grayscale-p
"xfns.c" (&optional terminal
))
1816 (defun display-grayscale-p (&optional display
)
1817 "Return non-nil if frames on DISPLAY can display shades of gray."
1818 (let ((frame-type (framep-on-display display
)))
1820 ((memq frame-type
'(x w32 ns
))
1821 (x-display-grayscale-p display
))
1823 (> (tty-color-gray-shades display
) 2)))))
1825 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg
)
1826 "Read a color name or RGB triplet.
1827 Completion is available for color names, but not for RGB triplets.
1829 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1830 components can have one to four digits, but all three components
1831 must have the same number of digits. Each digit is a hex value
1832 between 0 and F; either upper case or lower case for A through F
1835 In addition to standard color names and RGB hex values, the
1836 following are available as color candidates. In each case, the
1837 corresponding color is used.
1839 * `foreground at point' - foreground under the cursor
1840 * `background at point' - background under the cursor
1842 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1844 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1845 convert an input color name to an RGB hex string. Return the RGB
1848 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1849 to enter an empty color name (the empty string).
1851 Interactively, or with optional arg MSG non-nil, print the
1852 resulting color name in the echo area."
1853 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1854 (let* ((completion-ignore-case t
)
1855 (colors (or facemenu-color-alist
1856 (append '("foreground at point" "background at point")
1857 (if allow-empty-name
'(""))
1859 (color (completing-read
1860 (or prompt
"Color (name or #RGB triplet): ")
1861 ;; Completing function for reading colors, accepting
1862 ;; both color names and RGB triplets.
1863 (lambda (string pred flag
)
1865 ((null flag
) ; Try completion.
1866 (or (try-completion string colors pred
)
1867 (if (color-defined-p string
)
1869 ((eq flag t
) ; List all completions.
1870 (or (all-completions string colors pred
)
1871 (if (color-defined-p string
)
1873 ((eq flag
'lambda
) ; Test completion.
1874 (or (member string colors
)
1875 (color-defined-p string
)))))
1878 ;; Process named colors.
1879 (when (member color colors
)
1880 (cond ((string-equal color
"foreground at point")
1881 (setq color
(foreground-color-at-point)))
1882 ((string-equal color
"background at point")
1883 (setq color
(background-color-at-point))))
1884 (when (and convert-to-RGB
1885 (not (string-equal color
"")))
1886 (let ((components (x-color-values color
)))
1887 (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color
)
1888 (setq color
(format "#%04X%04X%04X"
1889 (logand 65535 (nth 0 components
))
1890 (logand 65535 (nth 1 components
))
1891 (logand 65535 (nth 2 components
))))))))
1892 (when msg
(message "Color: `%s'" color
))
1895 (defun face-at-point (&optional thing multiple
)
1896 "Return the face of the character after point.
1897 If it has more than one face, return the first one.
1898 If THING is non-nil try first to get a face name from the buffer.
1899 IF MULTIPLE is non-nil, return a list of all faces.
1900 Return nil if there is no face."
1903 ;; Try to get a face name from the buffer.
1904 (let ((face (intern-soft (thing-at-point 'symbol
))))
1906 (push face faces
))))
1907 ;; Add the named faces that the `read-face-name' or `face' property uses.
1908 (let ((faceprop (or (get-char-property (point) 'read-face-name
)
1909 (get-char-property (point) 'face
))))
1910 (cond ((facep faceprop
)
1911 (push faceprop faces
))
1912 ((and (listp faceprop
)
1913 ;; Don't treat an attribute spec as a list of faces.
1914 (not (keywordp (car faceprop
)))
1915 (not (memq (car faceprop
)
1916 '(foreground-color background-color
))))
1917 (dolist (face faceprop
)
1919 (push face faces
))))))
1920 (setq faces
(delete-dups (nreverse faces
)))
1921 (if multiple faces
(car faces
))))
1923 (defun foreground-color-at-point ()
1924 "Return the foreground color of the character after point."
1925 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1926 ;; Need also pick up any face properties that are not associated with named faces.
1927 (let ((face (or (face-at-point)
1928 (get-char-property (point) 'read-face-name
)
1929 (get-char-property (point) 'face
))))
1930 (cond ((and face
(symbolp face
))
1931 (let ((value (face-foreground face nil
'default
)))
1932 (if (member value
'("unspecified-fg" "unspecified-bg"))
1936 (cond ((memq 'foreground-color face
) (cdr (memq 'foreground-color face
)))
1937 ((memq ':foreground face
) (cadr (memq ':foreground face
)))))
1938 (t nil
)))) ; Invalid face value.
1940 (defun background-color-at-point ()
1941 "Return the background color of the character after point."
1942 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1943 ;; Need also pick up any face properties that are not associated with named faces.
1944 (let ((face (or (face-at-point)
1945 (get-char-property (point) 'read-face-name
)
1946 (get-char-property (point) 'face
))))
1947 (cond ((and face
(symbolp face
))
1948 (let ((value (face-background face nil
'default
)))
1949 (if (member value
'("unspecified-fg" "unspecified-bg"))
1953 (cond ((memq 'background-color face
) (cdr (memq 'background-color face
)))
1954 ((memq ':background face
) (cadr (memq ':background face
)))))
1955 (t nil
)))) ; Invalid face value.
1958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1962 (declare-function x-display-list
"xfns.c" ())
1963 (declare-function x-open-connection
"xfns.c"
1964 (display &optional xrm-string must-succeed
))
1965 (declare-function x-get-resource
"frame.c"
1966 (attribute class
&optional component subclass
))
1967 (declare-function x-parse-geometry
"frame.c" (string))
1968 (defvar x-display-name
)
1970 (defun x-handle-named-frame-geometry (parameters)
1971 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1972 Value is the new parameter list."
1973 ;; Note that `x-resource-name' has a global meaning.
1974 (let ((x-resource-name (cdr (assq 'name parameters
))))
1975 (when x-resource-name
1976 ;; Before checking X resources, we must have an X connection.
1979 (x-open-connection (or (cdr (assq 'display parameters
))
1981 (let (res-geometry parsed
)
1982 (and (setq res-geometry
(x-get-resource "geometry" "Geometry"))
1983 (setq parsed
(x-parse-geometry res-geometry
))
1985 (append parameters parsed
1986 ;; If the resource specifies a position,
1987 ;; take note of that.
1988 (if (or (assq 'top parsed
) (assq 'left parsed
))
1989 '((user-position . t
) (user-size . t
)))))))))
1993 (defun x-handle-reverse-video (frame parameters
)
1994 "Handle the reverse-video frame parameter and X resource.
1995 `x-create-frame' does not handle this one."
1996 (when (cdr (or (assq 'reverse parameters
)
1997 (let ((resource (x-get-resource "reverseVideo"
2000 (cons nil
(member (downcase resource
)
2001 '("on" "true")))))))
2002 (let* ((params (frame-parameters frame
))
2003 (bg (cdr (assq 'foreground-color params
)))
2004 (fg (cdr (assq 'background-color params
))))
2005 (modify-frame-parameters frame
2006 (list (cons 'foreground-color fg
)
2007 (cons 'background-color bg
)))
2008 (if (equal bg
(cdr (assq 'border-color params
)))
2009 (modify-frame-parameters frame
2010 (list (cons 'border-color fg
))))
2011 (if (equal bg
(cdr (assq 'mouse-color params
)))
2012 (modify-frame-parameters frame
2013 (list (cons 'mouse-color fg
))))
2014 (if (equal bg
(cdr (assq 'cursor-color params
)))
2015 (modify-frame-parameters frame
2016 (list (cons 'cursor-color fg
)))))))
2018 (declare-function x-create-frame
"xfns.c" (parms))
2019 (declare-function x-setup-function-keys
"term/common-win" (frame))
2021 (defun x-create-frame-with-faces (&optional parameters
)
2022 "Create and return a frame with frame parameters PARAMETERS.
2023 If PARAMETERS specify a frame name, handle X geometry resources
2024 for that name. If PARAMETERS includes a `reverse' parameter, or
2025 the X resource ``reverseVideo'' is present, handle that."
2026 (setq parameters
(x-handle-named-frame-geometry parameters
))
2027 (let* ((params (copy-tree parameters
))
2028 (visibility-spec (assq 'visibility parameters
))
2029 (delayed-params '(foreground-color background-color font
2030 border-color cursor-color mouse-color
2031 visibility scroll-bar-foreground
2032 scroll-bar-background
))
2034 (dolist (param delayed-params
)
2035 (setq params
(assq-delete-all param params
)))
2036 (setq frame
(x-create-frame `((visibility . nil
) .
,params
)))
2039 (x-setup-function-keys frame
)
2040 (x-handle-reverse-video frame parameters
)
2041 (frame-set-background-mode frame t
)
2042 (face-set-after-frame-default frame parameters
)
2043 (if (null visibility-spec
)
2044 (make-frame-visible frame
)
2045 (modify-frame-parameters frame
(list visibility-spec
)))
2048 (delete-frame frame
)))
2051 (defun face-set-after-frame-default (frame &optional parameters
)
2052 "Initialize the frame-local faces of FRAME.
2053 Calculate the face definitions using the face specs, custom theme
2054 settings, X resources, and `face-new-frame-defaults'.
2055 Finally, apply any relevant face attributes found amongst the
2056 frame parameters in PARAMETERS."
2057 (let ((window-system-p (memq (window-system frame
) '(x w32
))))
2058 ;; The `reverse' is so that `default' goes first.
2059 (dolist (face (nreverse (face-list)))
2062 ;; Initialize faces from face spec and custom theme.
2063 (face-spec-recalc face frame
)
2064 ;; Apply attributes specified by face-new-frame-defaults
2065 (internal-merge-in-global-face face frame
))
2066 ;; Don't let invalid specs prevent frame creation.
2069 ;; Apply attributes specified by frame parameters.
2070 (let ((face-params '((foreground-color default
:foreground
)
2071 (background-color default
:background
)
2072 (font default
:font
)
2073 (border-color border
:background
)
2074 (cursor-color cursor
:background
)
2075 (scroll-bar-foreground scroll-bar
:foreground
)
2076 (scroll-bar-background scroll-bar
:background
)
2077 (mouse-color mouse
:background
))))
2078 (dolist (param face-params
)
2079 (let* ((param-name (nth 0 param
))
2080 (value (cdr (assq param-name parameters
))))
2082 (set-face-attribute (nth 1 param
) frame
2083 (nth 2 param
) value
))))))
2085 (defun tty-handle-reverse-video (frame parameters
)
2086 "Handle the reverse-video frame parameter for terminal frames."
2087 (when (cdr (assq 'reverse parameters
))
2088 (let* ((params (frame-parameters frame
))
2089 (bg (cdr (assq 'foreground-color params
)))
2090 (fg (cdr (assq 'background-color params
))))
2091 (modify-frame-parameters frame
2092 (list (cons 'foreground-color fg
)
2093 (cons 'background-color bg
)))
2094 (if (equal bg
(cdr (assq 'mouse-color params
)))
2095 (modify-frame-parameters frame
2096 (list (cons 'mouse-color fg
))))
2097 (if (equal bg
(cdr (assq 'cursor-color params
)))
2098 (modify-frame-parameters frame
2099 (list (cons 'cursor-color fg
)))))))
2102 (defun tty-create-frame-with-faces (&optional parameters
)
2103 "Create and return a frame from optional frame parameters PARAMETERS.
2104 If PARAMETERS contains a `reverse' parameter, handle that."
2105 (let ((frame (make-terminal-frame parameters
))
2108 (with-selected-frame frame
2109 (tty-handle-reverse-video frame
(frame-parameters frame
))
2111 (unless (terminal-parameter frame
'terminal-initted
)
2112 (set-terminal-parameter frame
'terminal-initted t
)
2113 (set-locale-environment nil frame
)
2114 (tty-run-terminal-initialization frame nil t
))
2115 (frame-set-background-mode frame t
)
2116 (face-set-after-frame-default frame parameters
)
2119 (delete-frame frame
)))
2122 (defun tty-find-type (pred type
)
2123 "Return the longest prefix of TYPE to which PRED returns non-nil.
2124 TYPE should be a tty type name such as \"xterm-16color\".
2126 The function tries only those prefixes that are followed by a
2127 dash or underscore in the original type name, like \"xterm\" in
2131 (not (funcall pred type
)))
2132 ;; Strip off last hyphen and what follows, then try again
2134 (if (setq hyphend
(string-match-p "[-_][^-_]+$" type
))
2135 (substring type
0 hyphend
)
2139 (defvar tty-setup-hook nil
2140 "Hook run after running the initialization function of a new text terminal.
2141 Specifically, `tty-run-terminal-initialization' runs this.
2142 This can be used to fine tune the `input-decode-map', for example.")
2144 (defun tty-run-terminal-initialization (frame &optional type run-hook
)
2145 "Run the special initialization code for the terminal type of FRAME.
2146 The optional TYPE parameter may be used to override the autodetected
2147 terminal type to a different value.
2149 If optional argument RUN-HOOK is non-nil, then as a final step,
2150 this runs the hook `tty-setup-hook'.
2152 If you set `term-file-prefix' to nil, this function does nothing."
2153 (setq type
(or type
(tty-type frame
)))
2154 ;; Load library for our terminal type.
2155 ;; User init file can set term-file-prefix to nil to prevent this.
2156 (with-selected-frame frame
2157 (unless (null term-file-prefix
)
2158 (let* (term-init-func)
2159 ;; First, load the terminal initialization file, if it is
2160 ;; available and it hasn't been loaded already.
2161 (tty-find-type #'(lambda (type)
2162 (let ((file (locate-library (concat term-file-prefix type
))))
2164 (or (assoc file load-history
)
2167 ;; Next, try to find a matching initialization function, and call it.
2168 (tty-find-type #'(lambda (type)
2169 (fboundp (setq term-init-func
2170 (intern (concat "terminal-init-" type
)))))
2172 (when (fboundp term-init-func
)
2173 (funcall term-init-func
))
2174 (set-terminal-parameter frame
'terminal-initted term-init-func
)
2175 (if run-hook
(run-hooks 'tty-setup-hook
))))))
2177 ;; Called from C function init_display to initialize faces of the
2178 ;; dumped terminal frame on startup.
2180 (defun tty-set-up-initial-frame-faces ()
2181 (let ((frame (selected-frame)))
2182 (frame-set-background-mode frame t
)
2183 (face-set-after-frame-default frame
)))
2186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190 (defgroup basic-faces nil
2191 "The standard faces of Emacs."
2195 '((t nil
)) ; If this were nil, face-defface-spec would not be set.
2196 "Basic default face."
2197 :group
'basic-faces
)
2202 :group
'basic-faces
)
2205 '((((supports :slant italic
))
2207 (((supports :underline t
))
2210 ;; Default to italic, even if it doesn't appear to be supported,
2211 ;; because in some cases the display engine will do its own
2212 ;; workaround (to `dim' on ttys).
2214 "Basic italic face."
2215 :group
'basic-faces
)
2217 (defface bold-italic
2218 '((t :weight bold
:slant italic
))
2219 "Basic bold-italic face."
2220 :group
'basic-faces
)
2223 '((((supports :underline t
))
2225 (((supports :weight bold
))
2228 "Basic underlined face."
2229 :group
'basic-faces
)
2231 (defface fixed-pitch
2232 '((t :family
"Monospace"))
2233 "The basic fixed-pitch face."
2234 :group
'basic-faces
)
2236 (defface variable-pitch
2237 '((t :family
"Sans Serif"))
2238 "The basic variable-pitch face."
2239 :group
'basic-faces
)
2242 '((((class color grayscale
) (min-colors 88) (background light
))
2243 :foreground
"grey50")
2244 (((class color grayscale
) (min-colors 88) (background dark
))
2245 :foreground
"grey70")
2246 (((class color
) (min-colors 8) (background light
))
2247 :foreground
"green")
2248 (((class color
) (min-colors 8) (background dark
))
2249 :foreground
"yellow"))
2250 "Basic face for shadowed text."
2255 '((((class color
) (min-colors 88) (background light
))
2256 :foreground
"RoyalBlue3" :underline t
)
2257 (((class color
) (background light
))
2258 :foreground
"blue" :underline t
)
2259 (((class color
) (min-colors 88) (background dark
))
2260 :foreground
"cyan1" :underline t
)
2261 (((class color
) (background dark
))
2262 :foreground
"cyan" :underline t
)
2263 (t :inherit underline
))
2264 "Basic face for unvisited links."
2268 (defface link-visited
2269 '((default :inherit link
)
2270 (((class color
) (background light
)) :foreground
"magenta4")
2271 (((class color
) (background dark
)) :foreground
"violet"))
2272 "Basic face for visited links."
2277 '((((class color
) (min-colors 88) (background light
))
2278 :background
"darkseagreen2")
2279 (((class color
) (min-colors 88) (background dark
))
2280 :background
"darkolivegreen")
2281 (((class color
) (min-colors 16) (background light
))
2282 :background
"darkseagreen2")
2283 (((class color
) (min-colors 16) (background dark
))
2284 :background
"darkolivegreen")
2285 (((class color
) (min-colors 8))
2286 :background
"green" :foreground
"black")
2287 (t :inverse-video t
))
2288 "Basic face for highlighting."
2289 :group
'basic-faces
)
2291 ;; Region face: under NS, default to the system-defined selection
2292 ;; color (optimized for the fixed white background of other apps),
2293 ;; if background is light.
2295 '((((class color
) (min-colors 88) (background dark
))
2296 :background
"blue3")
2297 (((class color
) (min-colors 88) (background light
) (type gtk
))
2298 :distant-foreground
"gtk_selection_fg_color"
2299 :background
"gtk_selection_bg_color")
2300 (((class color
) (min-colors 88) (background light
) (type ns
))
2301 :distant-foreground
"ns_selection_fg_color"
2302 :background
"ns_selection_bg_color")
2303 (((class color
) (min-colors 88) (background light
))
2304 :background
"lightgoldenrod2")
2305 (((class color
) (min-colors 16) (background dark
))
2306 :background
"blue3")
2307 (((class color
) (min-colors 16) (background light
))
2308 :background
"lightgoldenrod2")
2309 (((class color
) (min-colors 8))
2310 :background
"blue" :foreground
"white")
2311 (((type tty
) (class mono
))
2313 (t :background
"gray"))
2314 "Basic face for highlighting the region."
2316 :group
'basic-faces
)
2318 (defface secondary-selection
2319 '((((class color
) (min-colors 88) (background light
))
2320 :background
"yellow1")
2321 (((class color
) (min-colors 88) (background dark
))
2322 :background
"SkyBlue4")
2323 (((class color
) (min-colors 16) (background light
))
2324 :background
"yellow")
2325 (((class color
) (min-colors 16) (background dark
))
2326 :background
"SkyBlue4")
2327 (((class color
) (min-colors 8))
2328 :background
"cyan" :foreground
"black")
2329 (t :inverse-video t
))
2330 "Basic face for displaying the secondary selection."
2331 :group
'basic-faces
)
2333 (defface trailing-whitespace
2334 '((((class color
) (background light
))
2336 (((class color
) (background dark
))
2338 (t :inverse-video t
))
2339 "Basic face for highlighting trailing whitespace."
2341 :group
'basic-faces
)
2343 (defface escape-glyph
2344 '((((background dark
)) :foreground
"cyan")
2345 ;; See the comment in minibuffer-prompt for
2346 ;; the reason not to use blue on MS-DOS.
2347 (((type pc
)) :foreground
"magenta")
2348 ;; red4 is too dark, but some say blue is too loud.
2349 ;; brown seems to work ok. -- rms.
2350 (t :foreground
"brown"))
2351 "Face for characters displayed as sequences using `^' or `\\'."
2355 (defface nobreak-space
2356 '((((class color
) (min-colors 88)) :inherit escape-glyph
:underline t
)
2357 (((class color
) (min-colors 8)) :background
"magenta")
2358 (t :inverse-video t
))
2359 "Face for displaying nobreak space."
2363 (defgroup mode-line-faces nil
2364 "Faces used in the mode line."
2370 '((((class color
) (min-colors 88))
2371 :box
(:line-width -
1 :style released-button
)
2372 :background
"grey75" :foreground
"black")
2375 "Basic mode line face for selected window."
2377 :group
'mode-line-faces
2378 :group
'basic-faces
)
2380 (defface mode-line-inactive
2383 (((class color
) (min-colors 88) (background light
))
2385 :box
(:line-width -
1 :color
"grey75" :style nil
)
2386 :foreground
"grey20" :background
"grey90")
2387 (((class color
) (min-colors 88) (background dark
) )
2389 :box
(:line-width -
1 :color
"grey40" :style nil
)
2390 :foreground
"grey80" :background
"grey30"))
2391 "Basic mode line face for non-selected windows."
2393 :group
'mode-line-faces
2394 :group
'basic-faces
)
2395 (define-obsolete-face-alias 'modeline-inactive
'mode-line-inactive
"22.1")
2397 (defface mode-line-highlight
2398 '((((class color
) (min-colors 88))
2399 :box
(:line-width
2 :color
"grey40" :style released-button
))
2401 :inherit highlight
))
2402 "Basic mode line face for highlighting."
2404 :group
'mode-line-faces
2405 :group
'basic-faces
)
2406 (define-obsolete-face-alias 'modeline-highlight
'mode-line-highlight
"22.1")
2408 (defface mode-line-emphasis
2409 '((t (:weight bold
)))
2410 "Face used to emphasize certain mode line features.
2411 Use the face `mode-line-highlight' for features that can be selected."
2413 :group
'mode-line-faces
2414 :group
'basic-faces
)
2416 (defface mode-line-buffer-id
2417 '((t (:weight bold
)))
2418 "Face used for buffer identification parts of the mode line."
2420 :group
'mode-line-faces
2421 :group
'basic-faces
)
2422 (define-obsolete-face-alias 'modeline-buffer-id
'mode-line-buffer-id
"22.1")
2424 (defface header-line
2428 ;; This used to be `:inverse-video t', but that doesn't look very
2429 ;; good when combined with inverse-video mode-lines and multiple
2430 ;; windows. Underlining looks better, and is more consistent with
2431 ;; the window-system face variants, which deemphasize the
2432 ;; header-line in relation to the mode-line face. If a terminal
2433 ;; can't underline, then the header-line will end up without any
2434 ;; highlighting; this may be too confusing in general, although it
2435 ;; happens to look good with the only current use of header-lines,
2436 ;; the info browser. XXX
2437 :inverse-video nil
;Override the value inherited from mode-line.
2439 (((class color grayscale
) (background light
))
2440 :background
"grey90" :foreground
"grey20"
2442 (((class color grayscale
) (background dark
))
2443 :background
"grey20" :foreground
"grey90"
2445 (((class mono
) (background light
))
2446 :background
"white" :foreground
"black"
2450 (((class mono
) (background dark
))
2451 :background
"black" :foreground
"white"
2455 "Basic header-line face."
2457 :group
'basic-faces
)
2459 (defface vertical-border
2460 '((((type tty
)) :inherit mode-line-inactive
))
2461 "Face used for vertical window dividers on ttys."
2463 :group
'basic-faces
)
2465 (defface window-divider
'((t :foreground
"gray60"))
2466 "Basic face for window dividers.
2467 When a divider is less than 3 pixels wide, it is drawn solidly
2468 with the foreground of this face. For larger dividers this face
2469 is used for the inner part while the first pixel line/column is
2470 drawn with the `window-divider-first-pixel' face and the last
2471 pixel line/column with the `window-divider-last-pixel' face."
2474 :group
'basic-faces
)
2476 (defface window-divider-first-pixel
2477 '((t :foreground
"gray80"))
2478 "Basic face for first pixel line/column of window dividers.
2479 When a divider is at least 3 pixels wide, its first pixel
2480 line/column is drawn with the foreground of this face. If you do
2481 not want to accentuate the first pixel line/column, set this to
2482 the same as `window-divider' face."
2485 :group
'basic-faces
)
2487 (defface window-divider-last-pixel
2488 '((t :foreground
"gray40"))
2489 "Basic face for last pixel line/column of window dividers.
2490 When a divider is at least 3 pixels wide, its last pixel
2491 line/column is drawn with the foreground of this face. If you do
2492 not want to accentuate the last pixel line/column, set this to
2493 the same as `window-divider' face."
2496 :group
'basic-faces
)
2498 (defface minibuffer-prompt
2499 '((((background dark
)) :foreground
"cyan")
2500 ;; Don't use blue because many users of the MS-DOS port customize
2501 ;; their foreground color to be blue.
2502 (((type pc
)) :foreground
"magenta")
2503 (t :foreground
"medium blue"))
2504 "Face for minibuffer prompts.
2505 By default, Emacs automatically adds this face to the value of
2506 `minibuffer-prompt-properties', which is a list of text properties
2507 used to display the prompt text."
2509 :group
'basic-faces
)
2511 (setq minibuffer-prompt-properties
2512 (append minibuffer-prompt-properties
(list 'face
'minibuffer-prompt
)))
2515 '((((class color
) (background light
))
2516 :background
"grey95")
2517 (((class color
) (background dark
))
2518 :background
"grey10")
2520 :background
"gray"))
2521 "Basic face for the fringes to the left and right of windows under X."
2524 :group
'basic-faces
)
2526 (defface scroll-bar
'((t nil
))
2527 "Basic face for the scroll bar colors under X."
2530 :group
'basic-faces
)
2532 (defface border
'((t nil
))
2533 "Basic face for the frame border under X."
2536 :group
'basic-faces
)
2539 '((((background light
)) :background
"black")
2540 (((background dark
)) :background
"white"))
2541 "Basic face for the cursor color under X.
2542 Currently, only the `:background' attribute is meaningful; all
2543 other attributes are ignored. The cursor foreground color is
2544 taken from the background color of the underlying text.
2546 Note: Other faces cannot inherit from the cursor face."
2549 :group
'basic-faces
)
2551 (put 'cursor
'face-no-inherit t
)
2553 (defface mouse
'((t nil
))
2554 "Basic face for the mouse color under X."
2557 :group
'basic-faces
)
2561 :box
(:line-width
1 :style released-button
)
2562 :foreground
"black")
2563 (((type x w32 ns
) (class color
))
2564 :background
"grey75")
2565 (((type x
) (class mono
))
2566 :background
"grey"))
2567 "Basic tool-bar face."
2569 :group
'basic-faces
)
2578 "Basic face for the font and colors of the menu bar and popup menus."
2581 :group
'basic-faces
)
2583 (defface help-argument-name
'((t :inherit italic
))
2584 "Face to highlight argument names in *Help* buffers."
2587 (defface glyphless-char
2588 '((((type tty
)) :inherit underline
)
2589 (((type pc
)) :inherit escape-glyph
)
2591 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2592 It is used for characters of no fonts too."
2594 :group
'basic-faces
)
2597 '((default :weight bold
)
2598 (((class color
) (min-colors 88) (background light
)) :foreground
"Red1")
2599 (((class color
) (min-colors 88) (background dark
)) :foreground
"Pink")
2600 (((class color
) (min-colors 16) (background light
)) :foreground
"Red1")
2601 (((class color
) (min-colors 16) (background dark
)) :foreground
"Pink")
2602 (((class color
) (min-colors 8)) :foreground
"red")
2603 (t :inverse-video t
))
2604 "Basic face used to highlight errors and to denote failure."
2606 :group
'basic-faces
)
2609 '((default :weight bold
)
2610 (((class color
) (min-colors 16)) :foreground
"DarkOrange")
2611 (((class color
)) :foreground
"yellow"))
2612 "Basic face used to highlight warnings."
2614 :group
'basic-faces
)
2617 '((default :weight bold
)
2618 (((class color
) (min-colors 16) (background light
)) :foreground
"ForestGreen")
2619 (((class color
) (min-colors 88) (background dark
)) :foreground
"Green1")
2620 (((class color
) (min-colors 16) (background dark
)) :foreground
"Green")
2621 (((class color
)) :foreground
"green"))
2622 "Basic face used to indicate successful operation."
2624 :group
'basic-faces
)
2626 ;; Faces for TTY menus.
2627 (defface tty-menu-enabled-face
2629 :foreground
"yellow" :background
"blue" :weight bold
))
2630 "Face for displaying enabled items in TTY menus."
2631 :group
'basic-faces
)
2633 (defface tty-menu-disabled-face
2634 '((((class color
) (min-colors 16))
2635 :foreground
"lightgray" :background
"blue")
2637 :foreground
"white" :background
"blue"))
2638 "Face for displaying disabled items in TTY menus."
2639 :group
'basic-faces
)
2641 (defface tty-menu-selected-face
2642 '((t :background
"red"))
2643 "Face for displaying the currently selected item in TTY menus."
2644 :group
'basic-faces
)
2646 (defgroup paren-showing-faces nil
2647 "Faces used to highlight paren matches."
2648 :group
'paren-showing
2652 (defface show-paren-match
2653 '((((class color
) (background light
))
2654 :background
"turquoise") ; looks OK on tty (becomes cyan)
2655 (((class color
) (background dark
))
2656 :background
"steelblue3") ; looks OK on tty (becomes blue)
2657 (((background dark
))
2658 :background
"grey50")
2660 :background
"gray"))
2661 "Face used for a matching paren."
2662 :group
'paren-showing-faces
)
2664 (defface show-paren-mismatch
2665 '((((class color
)) (:foreground
"white" :background
"purple"))
2666 (t (:inverse-video t
)))
2667 "Face used for a mismatching paren."
2668 :group
'paren-showing-faces
)
2671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2672 ;;; Manipulating font names.
2673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2675 ;; This is here for compatibility with Emacs 20.2. For example,
2676 ;; international/fontset.el uses x-resolve-font-name. The following
2677 ;; functions are not used in the face implementation itself.
2679 (defvar x-font-regexp nil
)
2680 (defvar x-font-regexp-head nil
)
2681 (defvar x-font-regexp-weight nil
)
2682 (defvar x-font-regexp-slant nil
)
2684 (defconst x-font-regexp-weight-subnum
1)
2685 (defconst x-font-regexp-slant-subnum
2)
2686 (defconst x-font-regexp-swidth-subnum
3)
2687 (defconst x-font-regexp-adstyle-subnum
4)
2689 ;;; Regexps matching font names in "Host Portable Character Representation."
2694 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2695 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2696 (weight\? "\\([^-]*\\)") ; 1
2697 (slant "\\([ior]\\)") ; 2
2698 ; (slant\? "\\([ior?*]?\\)") ; 2
2699 (slant\? "\\([^-]?\\)") ; 2
2700 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2701 (swidth "\\([^-]*\\)") ; 3
2702 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2703 (adstyle "\\([^-]*\\)") ; 4
2704 (pixelsize "[0-9]+")
2705 (pointsize "[0-9][0-9]+")
2706 (resx "[0-9][0-9]+")
2707 (resy "[0-9][0-9]+")
2714 (purecopy (concat "\\`\\*?[-?*]"
2715 foundry - family - weight
\? - slant
\? - swidth - adstyle -
2716 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2717 registry - encoding
"\\*?\\'"
2719 (setq x-font-regexp-head
2720 (purecopy (concat "\\`[-?*]" foundry - family - weight
\? - slant
\?
2721 "\\([-*?]\\|\\'\\)")))
2722 (setq x-font-regexp-slant
(purecopy (concat - slant -
)))
2723 (setq x-font-regexp-weight
(purecopy (concat - weight -
)))
2727 (defun x-resolve-font-name (pattern &optional face frame
)
2728 "Return a font name matching PATTERN.
2729 All wildcards in PATTERN are instantiated.
2730 If PATTERN is nil, return the name of the frame's base font, which never
2732 Given optional arguments FACE and FRAME, return a font which is
2733 also the same size as FACE on FRAME, or fail."
2737 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2738 (let ((fonts (x-list-fonts pattern face frame
1)))
2741 (if (string-match-p "\\*" pattern
)
2742 (if (null (face-font face
))
2743 (error "No matching fonts are the same height as the frame default font")
2744 (error "No matching fonts are the same height as face `%s'" face
))
2745 (if (null (face-font face
))
2746 (error "Height of font `%s' doesn't match the frame default font"
2748 (error "Height of font `%s' doesn't match face `%s'"
2750 (error "No fonts match `%s'" pattern
)))
2752 (cdr (assq 'font
(frame-parameters (selected-frame))))))
2754 (defcustom font-list-limit
100
2755 "This variable is obsolete and has no effect."
2758 (make-obsolete-variable 'font-list-limit nil
"24.3")
2762 ;;; faces.el ends here