1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992-1996, 1998-2017 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <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 (defcustom term-file-aliases
39 '(("apollo" .
"vt100")
50 "Alist of terminal type aliases.
51 Entries are of the form (TYPE . ALIAS), where both elements are strings.
52 This means to treat a terminal of type TYPE as if it were of type ALIAS."
53 :type
'(alist :key-type
(string :tag
"Terminal")
54 :value-type
(string :tag
"Alias"))
58 (declare-function xw-defined-colors
"term/common-win" (&optional frame
))
60 (defvar help-xref-stack-item
)
62 (defvar face-name-history nil
63 "History list for some commands that read face names.
64 Maximum length of the history list is determined by the value
65 of `history-length', which see.")
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72 (defgroup font-selection nil
73 "Influencing face font selection."
77 (defcustom face-font-selection-order
78 '(:width
:height
:weight
:slant
)
79 "A list specifying how face font selection chooses fonts.
80 Each of the four symbols `:width', `:height', `:weight', and `:slant'
81 must appear once in the list, and the list must not contain any other
82 elements. Font selection first tries to find a best matching font
83 for those face attributes that appear before in the list. For
84 example, if `:slant' appears before `:height', font selection first
85 tries to find a font with a suitable slant, even if this results in
86 a font height that isn't optimal."
87 :tag
"Font selection order"
88 :type
'(list symbol symbol symbol symbol
)
89 :group
'font-selection
90 :set
#'(lambda (symbol value
)
91 (set-default symbol value
)
92 (internal-set-font-selection-order value
)))
95 ;; In the absence of Fontconfig support, Monospace and Sans Serif are
96 ;; unavailable, and we fall back on the courier and helv families,
97 ;; which are generally available.
98 (defcustom face-font-family-alternatives
99 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
100 '(("Monospace" "courier" "fixed")
102 ;; Monospace Serif is an Emacs invention, intended to work around
103 ;; portability problems when using Courier. It should work well
104 ;; when combined with Monospaced and with other standard fonts.
107 ;; This looks good on GNU/Linux.
109 ;; This looks good on MS-Windows and OS X.
111 ;; This looks good on macOS. "Courier" looks good too, but is
112 ;; jagged on GNU/Linux and so is listed later as "courier".
114 ;; Although these are anti-aliased, they are a bit faint compared
116 "FreeMono" "Nimbus Mono L"
117 ;; These are aliased and look jagged.
119 ;; Omit Courier New, as it is the default MS-Windows font and so
120 ;; would look no different, and is pretty faint on other platforms.
123 ;; This is present for backward compatibility.
124 ("courier" "CMU Typewriter Text" "fixed")
126 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
127 ("helv" "helvetica" "arial" "fixed")))
128 "Alist of alternative font family names.
129 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
130 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
132 :tag
"Alternative font families to try"
133 :type
'(repeat (repeat string
))
134 :group
'font-selection
135 :set
#'(lambda (symbol value
)
136 (set-default symbol value
)
137 (internal-set-alternative-font-family-alist value
)))
140 ;; This is defined originally in xfaces.c.
141 (defcustom face-font-registry-alternatives
142 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
144 '(("iso8859-1" "ms-oemlatin")
145 ("gb2312.1980" "gb2312" "gbk" "gb18030")
146 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
147 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
148 ("muletibetan-2" "muletibetan-0"))
149 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
150 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
151 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
152 ("muletibetan-2" "muletibetan-0"))))
153 "Alist of alternative font registry names.
154 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
155 If fonts of registry REGISTRY can be loaded, font selection
156 tries to find a best matching font among all fonts of registry
157 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
158 :tag
"Alternative font registries to try"
159 :type
'(repeat (repeat string
))
161 :group
'font-selection
162 :set
#'(lambda (symbol value
)
163 (set-default symbol value
)
164 (internal-set-alternative-font-registry-alist value
)))
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 ;;; Creation, copying.
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173 "Return a list of all defined faces."
174 (mapcar #'car face-new-frame-defaults
))
176 (defun make-face (face)
177 "Define a new face with name FACE, a symbol.
178 Do not call this directly from Lisp code; use `defface' instead.
180 If FACE is already known as a face, leave it unmodified. Return FACE."
181 (interactive (list (read-from-minibuffer
182 "Make face: " nil nil t
'face-name-history
)))
184 ;; Make frame-local faces (this also makes the global one).
185 (dolist (frame (frame-list))
186 (internal-make-lisp-face face frame
))
187 ;; Add the face to the face menu.
188 (when (fboundp 'facemenu-add-new-face
)
189 (facemenu-add-new-face face
))
190 ;; Define frame-local faces for all frames from X resources.
191 (make-face-x-resource-internal face
))
194 (defun make-empty-face (face)
195 "Define a new, empty face with name FACE.
196 Do not call this directly from Lisp code; use `defface' instead."
197 (interactive (list (read-from-minibuffer
198 "Make empty face: " nil nil t
'face-name-history
)))
201 (defun copy-face (old-face new-face
&optional frame new-frame
)
202 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
203 This function does not copy face customization data, so NEW-FACE
204 will not be made customizable. Most Lisp code should not call
205 this function; use `defface' with :inherit instead.
207 If NEW-FACE already exists as a face, modify it to be like
208 OLD-FACE. If NEW-FACE doesn't already exist, create it.
210 If the optional argument FRAME is a frame, change NEW-FACE on
211 FRAME only. If FRAME is t, copy the frame-independent default
212 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
213 the defaults as well as the faces on each existing frame.
215 If the optional fourth argument NEW-FRAME is given, copy the
216 information from face OLD-FACE on frame FRAME to NEW-FACE on
217 frame NEW-FRAME. In this case, FRAME must not be nil."
218 (let ((inhibit-quit t
))
222 (error "Copying face %s from all frames to one frame"
224 (make-empty-face new-face
)
225 (dolist (frame (frame-list))
226 (copy-face old-face new-face frame
))
227 (copy-face old-face new-face t
))
228 (make-empty-face new-face
)
229 (internal-copy-lisp-face old-face new-face frame new-frame
))
233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
234 ;;; Predicates, type checks.
235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
238 "Return non-nil if FACE is a face name; nil otherwise.
239 A face name can be a string or a symbol."
240 (internal-lisp-face-p face
))
243 (defun check-face (face)
244 "Signal an error if FACE doesn't name a face.
247 (error "Not a face: %s" face
))
251 ;; The ID returned is not to be confused with the internally used IDs
252 ;; of realized faces. The ID assigned to Lisp faces is used to
253 ;; support faces in display table entries.
255 (defun face-id (face &optional _frame
)
256 "Return the internal ID of face with name FACE.
257 If FACE is a face-alias, return the ID of the target face.
258 The optional argument FRAME is ignored, since the internal face ID
259 of a face name is the same for all frames."
262 (face-id (get face
'face-alias
))))
264 (defun face-equal (face1 face2
&optional frame
)
265 "Non-nil if faces FACE1 and FACE2 are equal.
266 Faces are considered equal if all their attributes are equal.
267 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
268 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
269 If FRAME is omitted or nil, use the selected frame."
270 (internal-lisp-face-equal-p face1 face2 frame
))
273 (defun face-differs-from-default-p (face &optional frame
)
274 "Return non-nil if FACE displays differently from the default face.
275 If the optional argument FRAME is given, report on face FACE in that frame.
276 If FRAME is t, report on the defaults for face FACE (for new frames).
277 If FRAME is omitted or nil, use the selected frame."
279 (delq :inherit
(mapcar 'car face-attribute-name-alist
)))
281 (while (and attrs
(not differs
))
282 (let* ((attr (pop attrs
))
283 (attr-val (face-attribute face attr frame t
)))
285 (not (eq attr-val
'unspecified
))
286 (display-supports-face-attributes-p (list attr attr-val
)
288 (setq differs attr
))))
292 (defun face-nontrivial-p (face &optional frame
)
293 "True if face FACE has some non-nil attribute.
294 If the optional argument FRAME is given, report on face FACE in that frame.
295 If FRAME is t, report on the defaults for face FACE (for new frames).
296 If FRAME is omitted or nil, use the selected frame."
297 (not (internal-lisp-face-empty-p face frame
)))
300 (defun face-list-p (face-or-list)
301 "True if FACE-OR-LIST is a list of faces.
302 Return nil if FACE-OR-LIST is a non-nil atom, or a cons cell whose car
303 is either `foreground-color', `background-color', or a keyword."
304 ;; The logic of merge_face_ref (xfaces.c) is recreated here.
305 (and (listp face-or-list
)
306 (not (memq (car face-or-list
)
307 '(foreground-color background-color
)))
308 (not (keywordp (car face-or-list
)))))
312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
313 ;;; Setting face attributes from X resources.
314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
316 (defcustom face-x-resources
319 ;; FIXME; can we purecopy some of the conses too?
321 (cons (purecopy (car (cdr arg
))) (purecopy (cdr (cdr arg
))))))
322 '((:family
(".attributeFamily" .
"Face.AttributeFamily"))
323 (:foundry
(".attributeFoundry" .
"Face.AttributeFoundry"))
324 (:width
(".attributeWidth" .
"Face.AttributeWidth"))
325 (:height
(".attributeHeight" .
"Face.AttributeHeight"))
326 (:weight
(".attributeWeight" .
"Face.AttributeWeight"))
327 (:slant
(".attributeSlant" .
"Face.AttributeSlant"))
328 (:foreground
(".attributeForeground" .
"Face.AttributeForeground"))
330 (".attributeDistantForeground" .
"Face.AttributeDistantForeground"))
331 (:background
(".attributeBackground" .
"Face.AttributeBackground"))
332 (:overline
(".attributeOverline" .
"Face.AttributeOverline"))
333 (:strike-through
(".attributeStrikeThrough" .
"Face.AttributeStrikeThrough"))
334 (:box
(".attributeBox" .
"Face.AttributeBox"))
335 (:underline
(".attributeUnderline" .
"Face.AttributeUnderline"))
336 (:inverse-video
(".attributeInverse" .
"Face.AttributeInverse"))
338 (".attributeStipple" .
"Face.AttributeStipple")
339 (".attributeBackgroundPixmap" .
"Face.AttributeBackgroundPixmap"))
340 (:bold
(".attributeBold" .
"Face.AttributeBold"))
341 (:italic
(".attributeItalic" .
"Face.AttributeItalic"))
342 (:font
(".attributeFont" .
"Face.AttributeFont"))
343 (:inherit
(".attributeInherit" .
"Face.AttributeInherit"))))
344 "List of X resources and classes for face attributes.
345 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
346 the name of a face attribute, and each ENTRY is a cons of the form
347 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
348 X resource class for the attribute."
349 :type
'(repeat (cons symbol
(repeat (cons string string
))))
353 (declare-function internal-face-x-get-resource
"xfaces.c"
354 (resource class
&optional frame
))
356 (declare-function internal-set-lisp-face-attribute-from-resource
"xfaces.c"
357 (face attr value
&optional frame
))
359 (defun set-face-attribute-from-resource (face attribute resource class frame
)
360 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
361 Value is the attribute value specified by the resource, or nil
362 if not present. This function displays a message if the resource
363 specifies an invalid attribute."
364 (let* ((face-name (face-name face
))
365 (value (internal-face-x-get-resource (concat face-name resource
)
369 (internal-set-lisp-face-attribute-from-resource
370 face attribute
(downcase value
) frame
)
372 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
373 face-name frame attribute value
))))
377 (defun set-face-attributes-from-resources (face frame
)
378 "Set attributes of FACE from X resources for FRAME."
379 (when (memq (framep frame
) '(x w32
))
380 (dolist (definition face-x-resources
)
381 (let ((attribute (car definition
)))
382 (dolist (entry (cdr definition
))
383 (set-face-attribute-from-resource face attribute
(car entry
)
384 (cdr entry
) frame
))))))
387 (defun make-face-x-resource-internal (face &optional frame
)
388 "Fill frame-local FACE on FRAME from X resources.
389 FRAME nil or not specified means do it for all frames.
391 If `inhibit-x-resources' is non-nil, this function does nothing."
392 (unless inhibit-x-resources
393 (dolist (frame (if (null frame
) (frame-list) (list frame
)))
394 ;; `x-create-frame' already took care of correctly handling
395 ;; the reverse video case-- do _not_ touch the default face
396 (unless (and (eq face
'default
)
397 (frame-parameter frame
'reverse
))
398 (set-face-attributes-from-resources face frame
)))))
402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
403 ;;; Retrieving face attributes.
404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
406 (defun face-name (face)
407 "Return the name of face FACE."
408 (symbol-name (check-face face
)))
411 (defun face-all-attributes (face &optional frame
)
412 "Return an alist stating the attributes of FACE.
413 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
414 If FRAME is omitted or nil the value describes the default attributes,
415 but if you specify FRAME, the value describes the attributes
417 (mapcar (lambda (pair)
418 (let ((attr (car pair
)))
419 (cons attr
(face-attribute face attr
(or frame t
)))))
420 face-attribute-name-alist
))
422 (defun face-attribute (face attribute
&optional frame inherit
)
423 "Return the value of FACE's ATTRIBUTE on FRAME.
424 If the optional argument FRAME is given, report on face FACE in that frame.
425 If FRAME is t, report on the defaults for face FACE (for new frames).
426 If FRAME is omitted or nil, use the selected frame.
428 If INHERIT is nil, only attributes directly defined by FACE are considered,
429 so the return value may be `unspecified', or a relative value.
430 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
431 faces specified by its `:inherit' attribute; however the return value
432 may still be `unspecified' or relative.
433 If INHERIT is a face or a list of faces, then the result is further merged
434 with that face (or faces), until it becomes specified and absolute.
436 To ensure that the return value is always specified and absolute, use a
437 value of `default' for INHERIT; this will resolve any unspecified or
438 relative values by merging with the `default' face (which is always
439 completely specified)."
440 (let ((value (internal-get-lisp-face-attribute face attribute frame
)))
441 (when (and inherit
(face-attribute-relative-p attribute value
))
442 ;; VALUE is relative, so merge with inherited faces
443 (let ((inh-from (face-attribute face
:inherit frame
)))
444 (unless (or (null inh-from
) (eq inh-from
'unspecified
))
447 (face-attribute-merged-with attribute value inh-from frame
))
448 ;; The `inherit' attribute may point to non existent faces.
452 (face-attribute-relative-p attribute value
))
453 ;; We should merge with INHERIT as well
454 (setq value
(face-attribute-merged-with attribute value inherit frame
)))
457 (defun face-attribute-merged-with (attribute value faces
&optional frame
)
458 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
459 FACES may be either a single face or a list of faces.
460 [This is an internal function.]"
461 (cond ((not (face-attribute-relative-p attribute value
))
466 (face-attribute-merged-with
468 (face-attribute-merged-with attribute value
(car faces
) frame
)
472 (merge-face-attribute attribute
474 (face-attribute faces attribute frame t
)))))
477 (defmacro face-attribute-specified-or
(value &rest body
)
478 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
479 (let ((temp (make-symbol "value")))
480 `(let ((,temp
,value
))
481 (if (not (eq ,temp
'unspecified
))
485 (defun face-foreground (face &optional frame inherit
)
486 "Return the foreground color name of FACE, or nil if unspecified.
487 If the optional argument FRAME is given, report on face FACE in that frame.
488 If FRAME is t, report on the defaults for face FACE (for new frames).
489 If FRAME is omitted or nil, use the selected frame.
491 If INHERIT is nil, only a foreground color directly defined by FACE is
492 considered, so the return value may be nil.
493 If INHERIT is t, and FACE doesn't define a foreground color, then any
494 foreground color that FACE inherits through its `:inherit' attribute
495 is considered as well; however the return value may still be nil.
496 If INHERIT is a face or a list of faces, then it is used to try to
497 resolve an unspecified foreground color.
499 To ensure that a valid color is always returned, use a value of
500 `default' for INHERIT; this will resolve any unspecified values by
501 merging with the `default' face (which is always completely specified)."
502 (face-attribute-specified-or (face-attribute face
:foreground frame inherit
)
505 (defun face-background (face &optional frame inherit
)
506 "Return the background color name of FACE, or nil if unspecified.
507 If the optional argument FRAME is given, report on face FACE in that frame.
508 If FRAME is t, report on the defaults for face FACE (for new frames).
509 If FRAME is omitted or nil, use the selected frame.
511 If INHERIT is nil, only a background color directly defined by FACE is
512 considered, so the return value may be nil.
513 If INHERIT is t, and FACE doesn't define a background color, then any
514 background color that FACE inherits through its `:inherit' attribute
515 is considered as well; however the return value may still be nil.
516 If INHERIT is a face or a list of faces, then it is used to try to
517 resolve an unspecified background color.
519 To ensure that a valid color is always returned, use a value of
520 `default' for INHERIT; this will resolve any unspecified values by
521 merging with the `default' face (which is always completely specified)."
522 (face-attribute-specified-or (face-attribute face
:background frame inherit
)
525 (defun face-stipple (face &optional frame inherit
)
526 "Return the stipple pixmap name of FACE, or nil if unspecified.
527 If the optional argument FRAME is given, report on face FACE in that frame.
528 If FRAME is t, report on the defaults for face FACE (for new frames).
529 If FRAME is omitted or nil, use the selected frame.
531 If INHERIT is nil, only a stipple directly defined by FACE is
532 considered, so the return value may be nil.
533 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
534 that FACE inherits through its `:inherit' attribute is considered as
535 well; however the return value may still be nil.
536 If INHERIT is a face or a list of faces, then it is used to try to
537 resolve an unspecified stipple.
539 To ensure that a valid stipple or nil is always returned, use a value of
540 `default' for INHERIT; this will resolve any unspecified values by merging
541 with the `default' face (which is always completely specified)."
542 (face-attribute-specified-or (face-attribute face
:stipple frame inherit
)
546 (defalias 'face-background-pixmap
'face-stipple
)
549 (defun face-underline-p (face &optional frame inherit
)
550 "Return non-nil if FACE specifies a non-nil underlining.
551 If the optional argument FRAME is given, report on face FACE in that frame.
552 If FRAME is t, report on the defaults for face FACE (for new frames).
553 If FRAME is omitted or nil, use the selected frame.
554 Optional argument INHERIT is passed to `face-attribute'."
555 (face-attribute-specified-or
556 (face-attribute face
:underline frame inherit
) nil
))
559 (defun face-inverse-video-p (face &optional frame inherit
)
560 "Return non-nil if FACE specifies a non-nil inverse-video.
561 If the optional argument FRAME is given, report on face FACE in that frame.
562 If FRAME is t, report on the defaults for face FACE (for new frames).
563 If FRAME is omitted or nil, use the selected frame.
564 Optional argument INHERIT is passed to `face-attribute'."
565 (eq (face-attribute face
:inverse-video frame inherit
) t
))
568 (defun face-bold-p (face &optional frame inherit
)
569 "Return non-nil if the font of FACE is bold on FRAME.
570 If the optional argument FRAME is given, report on face FACE in that frame.
571 If FRAME is t, report on the defaults for face FACE (for new frames).
572 If FRAME is omitted or nil, use the selected frame.
573 Optional argument INHERIT is passed to `face-attribute'.
574 Use `face-attribute' for finer control."
575 (let ((bold (face-attribute face
:weight frame inherit
)))
576 (memq bold
'(semi-bold bold extra-bold ultra-bold
))))
579 (defun face-italic-p (face &optional frame inherit
)
580 "Return non-nil if the font of FACE is italic on FRAME.
581 If the optional argument FRAME is given, report on face FACE in that frame.
582 If FRAME is t, report on the defaults for face FACE (for new frames).
583 If FRAME is omitted or nil, use the selected frame.
584 Optional argument INHERIT is passed to `face-attribute'.
585 Use `face-attribute' for finer control."
586 (let ((italic (face-attribute face
:slant frame inherit
)))
587 (memq italic
'(italic oblique
))))
591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
592 ;;; Face documentation.
593 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
595 (defun face-documentation (face)
596 "Get the documentation string for FACE.
597 If FACE is a face-alias, get the documentation for the target face."
598 (let ((alias (get face
'face-alias
)))
600 (let ((doc (get alias
'face-documentation
)))
601 (format "%s is an alias for the face `%s'.%s" face alias
602 (if doc
(format "\n%s" doc
)
604 (get face
'face-documentation
))))
607 (defun set-face-documentation (face string
)
608 "Set the documentation string for FACE to STRING."
609 ;; Perhaps the text should go in DOC.
610 (put face
'face-documentation
(purecopy string
)))
613 (defalias 'face-doc-string
'face-documentation
)
614 (defalias 'set-face-doc-string
'set-face-documentation
)
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
619 ;; Setting face attributes.
620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
623 (defun set-face-attribute (face frame
&rest args
)
624 "Set attributes of FACE on FRAME from ARGS.
625 This function overrides the face attributes specified by FACE's
626 face spec. It is mostly intended for internal use only.
628 If FRAME is nil, set the attributes for all existing frames, as
629 well as the default for new frames. If FRAME is t, change the
630 default for new frames only.
632 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a
633 valid face attribute name. All attributes can be set to
634 `unspecified'; this fact is not further mentioned below.
636 The following attributes are recognized:
640 VALUE must be a string specifying the font family
641 \(e.g. \"Monospace\") or a fontset.
645 VALUE must be a string specifying the font foundry,
646 e.g., \"adobe\". If a font foundry is specified, wild-cards `*'
651 VALUE specifies the relative proportionate width of the font to use.
652 It must be one of the symbols `ultra-condensed', `extra-condensed',
653 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
654 `extra-expanded', or `ultra-expanded'.
658 VALUE specifies the relative or absolute height of the font. An
659 absolute height is an integer, and specifies font height in units
660 of 1/10 pt. A relative height is either a floating point number,
661 which specifies a scaling factor for the underlying face height;
662 or a function that takes a single argument (the underlying face
663 height) and returns the new height. Note that for the `default'
664 face, you must specify an absolute height (since there is nothing
665 for it to be relative to).
669 VALUE specifies the weight of the font to use. It must be one of the
670 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
671 `semi-light', `light', `extra-light', `ultra-light'.
675 VALUE specifies the slant of the font to use. It must be one of the
676 symbols `italic', `oblique', `normal', `reverse-italic', or
679 `:foreground', `:background'
681 VALUE must be a color name, a string.
685 VALUE specifies whether characters in FACE should be underlined.
686 If VALUE is t, underline with foreground color of the face.
687 If VALUE is a string, underline with that color.
688 If VALUE is nil, explicitly don't underline.
690 Otherwise, VALUE must be a property list of the form:
692 `(:color COLOR :style STYLE)'.
694 COLOR can be a either a color name string or `foreground-color'.
695 STYLE can be either `line' or `wave'.
696 If a keyword/value pair is missing from the property list, a
697 default value will be used for the value.
698 The default value of COLOR is the foreground color of the face.
699 The default value of STYLE is `line'.
703 VALUE specifies whether characters in FACE should be overlined. If
704 VALUE is t, overline with foreground color of the face. If VALUE is a
705 string, overline with that color. If VALUE is nil, explicitly don't
710 VALUE specifies whether characters in FACE should be drawn with a line
711 striking through them. If VALUE is t, use the foreground color of the
712 face. If VALUE is a string, strike-through with that color. If VALUE
713 is nil, explicitly don't strike through.
717 VALUE specifies whether characters in FACE should have a box drawn
718 around them. If VALUE is nil, explicitly don't draw boxes. If
719 VALUE is t, draw a box with lines of width 1 in the foreground color
720 of the face. If VALUE is a string, the string must be a color name,
721 and the box is drawn in that color with a line width of 1. Otherwise,
722 VALUE must be a property list of the form `(:line-width WIDTH
723 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
724 the property list, a default value will be used for the value, as
725 specified below. WIDTH specifies the width of the lines to draw; it
726 defaults to 1. If WIDTH is negative, the absolute value is the width
727 of the lines, and draw top/bottom lines inside the characters area,
728 not around it. COLOR is the name of the color to draw in, default is
729 the foreground color of the face for simple boxes, and the background
730 color of the face for 3D boxes. STYLE specifies whether a 3D box
731 should be draw. If STYLE is `released-button', draw a box looking
732 like a released 3D button. If STYLE is `pressed-button' draw a box
733 that appears like a pressed button. If STYLE is nil, the default if
734 the property list doesn't contain a style specification, draw a 2D
739 VALUE specifies whether characters in FACE should be displayed in
740 inverse video. VALUE must be one of t or nil.
744 If VALUE is a string, it must be the name of a file of pixmap data.
745 The directories listed in the `x-bitmap-file-path' variable are
746 searched. Alternatively, VALUE may be a list of the form (WIDTH
747 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
748 is a string containing the raw bits of the bitmap. VALUE nil means
749 explicitly don't use a stipple pattern.
751 For convenience, attributes `:family', `:foundry', `:width',
752 `:height', `:weight', and `:slant' may also be set in one step
757 Set font-related face attributes from VALUE. VALUE must be a
758 valid font name or font object. Setting this attribute will also
759 set the `:family', `:foundry', `:width', `:height', `:weight',
760 and `:slant' attributes.
764 VALUE is the name of a face from which to inherit attributes, or
765 a list of face names. Attributes from inherited faces are merged
766 into the face like an underlying face would be, with higher
767 priority than underlying faces.
769 For backward compatibility, the keywords `:bold' and `:italic'
770 can be used to specify weight and slant respectively. This usage
771 is considered obsolete. For these two keywords, the VALUE must
772 be either t or nil. A value of t for `:bold' is equivalent to
773 setting `:weight' to `bold', and a value of t for `:italic' is
774 equivalent to setting `:slant' to `italic'. But if `:weight' is
775 specified in the face spec, `:bold' is ignored, and if `:slant'
776 is specified, `:italic' is ignored."
777 (setq args
(purecopy args
))
778 (let ((where (if (null frame
) 0 frame
))
780 family foundry orig-family orig-foundry
)
781 ;; If we set the new-frame defaults, this face is modified outside Custom.
782 (if (memq where
'(0 t
))
783 (put (or (get face
'face-alias
) face
) 'face-modified t
))
784 ;; If family and/or foundry are specified, set it first. Certain
785 ;; face attributes, e.g. :weight semi-condensed, are not supported
786 ;; in every font. See bug#1127.
788 (cond ((eq (car spec
) :family
)
789 (setq family
(cadr spec
)))
790 ((eq (car spec
) :foundry
)
791 (setq foundry
(cadr spec
))))
792 (setq spec
(cddr spec
)))
793 (when (or family foundry
)
794 (when (and (stringp family
)
795 (string-match "\\([^-]*\\)-\\([^-]*\\)" family
))
796 (setq orig-foundry foundry
799 (setq foundry
(match-string 1 family
)))
800 (setq family
(match-string 2 family
))
801 ;; Reject bogus "families" that are all-digits -- those are some
802 ;; weird font names, like Foobar-12, that end in a number.
803 (when (string-match "\\`[0-9]*\\'" family
)
804 (setq family orig-family
)
805 (setq foundry orig-foundry
)))
806 (when (or (stringp family
) (eq family
'unspecified
))
807 (internal-set-lisp-face-attribute face
:family
(purecopy family
)
809 (when (or (stringp foundry
) (eq foundry
'unspecified
))
810 (internal-set-lisp-face-attribute face
:foundry
(purecopy foundry
)
813 (unless (memq (car args
) '(:family
:foundry
))
814 (internal-set-lisp-face-attribute face
(car args
)
815 (purecopy (cadr args
))
817 (setq args
(cddr args
)))))
819 (defun make-face-bold (face &optional frame _noerror
)
820 "Make the font of FACE be bold, if possible.
821 FRAME nil or not specified means change face on all frames.
822 Argument NOERROR is ignored and retained for compatibility.
823 Use `set-face-attribute' for finer control of the font weight."
824 (interactive (list (read-face-name "Make which face bold"
826 (set-face-attribute face frame
:weight
'bold
))
829 (defun make-face-unbold (face &optional frame _noerror
)
830 "Make the font of FACE be non-bold, if possible.
831 FRAME nil or not specified means change face on all frames.
832 Argument NOERROR is ignored and retained for compatibility."
833 (interactive (list (read-face-name "Make which face non-bold"
835 (set-face-attribute face frame
:weight
'normal
))
838 (defun make-face-italic (face &optional frame _noerror
)
839 "Make the font of FACE be italic, if possible.
840 FRAME nil or not specified means change face on all frames.
841 Argument NOERROR is ignored and retained for compatibility.
842 Use `set-face-attribute' for finer control of the font slant."
843 (interactive (list (read-face-name "Make which face italic"
845 (set-face-attribute face frame
:slant
'italic
))
848 (defun make-face-unitalic (face &optional frame _noerror
)
849 "Make the font of FACE be non-italic, if possible.
850 FRAME nil or not specified means change face on all frames.
851 Argument NOERROR is ignored and retained for compatibility."
852 (interactive (list (read-face-name "Make which face non-italic"
854 (set-face-attribute face frame
:slant
'normal
))
857 (defun make-face-bold-italic (face &optional frame _noerror
)
858 "Make the font of FACE be bold and italic, if possible.
859 FRAME nil or not specified means change face on all frames.
860 Argument NOERROR is ignored and retained for compatibility.
861 Use `set-face-attribute' for finer control of font weight and slant."
862 (interactive (list (read-face-name "Make which face bold-italic"
864 (set-face-attribute face frame
:weight
'bold
:slant
'italic
))
867 (defun set-face-font (face font
&optional frame
)
868 "Change font-related attributes of FACE to those of FONT (a string).
869 FRAME nil or not specified means change face on all frames.
870 This sets the attributes `:family', `:foundry', `:width',
871 `:height', `:weight', and `:slant'. When called interactively,
872 prompt for the face and font."
873 (interactive (read-face-and-attribute :font
))
874 (set-face-attribute face frame
:font font
))
877 ;; Implementation note: Emulating gray background colors with a
878 ;; stipple pattern is now part of the face realization process, and is
879 ;; done in C depending on the frame on which the face is realized.
881 (defun set-face-background (face color
&optional frame
)
882 "Change the background color of face FACE to COLOR (a string).
883 FRAME nil or not specified means change face on all frames.
884 COLOR can be a system-defined color name (see `list-colors-display')
885 or a hex spec of the form #RRGGBB.
886 When called interactively, prompts for the face and color."
887 (interactive (read-face-and-attribute :background
))
888 (set-face-attribute face frame
:background
(or color
'unspecified
)))
891 (defun set-face-foreground (face color
&optional frame
)
892 "Change the foreground color of face FACE to COLOR (a string).
893 FRAME nil or not specified means change face on all frames.
894 COLOR can be a system-defined color name (see `list-colors-display')
895 or a hex spec of the form #RRGGBB.
896 When called interactively, prompts for the face and color."
897 (interactive (read-face-and-attribute :foreground
))
898 (set-face-attribute face frame
:foreground
(or color
'unspecified
)))
901 (defun set-face-stipple (face stipple
&optional frame
)
902 "Change the stipple pixmap of face FACE to STIPPLE.
903 FRAME nil or not specified means change face on all frames.
904 STIPPLE should be a string, the name of a file of pixmap data.
905 The directories listed in the `x-bitmap-file-path' variable are searched.
907 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
908 where WIDTH and HEIGHT are the size in pixels,
909 and DATA is a string, containing the raw bits of the bitmap."
910 (interactive (read-face-and-attribute :stipple
))
911 (set-face-attribute face frame
:stipple
(or stipple
'unspecified
)))
914 (defun set-face-underline (face underline
&optional frame
)
915 "Specify whether face FACE is underlined.
916 UNDERLINE nil means FACE explicitly doesn't underline.
917 UNDERLINE t means FACE underlines with its foreground color.
918 If UNDERLINE is a string, underline with that color.
920 UNDERLINE may also be a list of the form (:color COLOR :style STYLE),
921 where COLOR is a string or `foreground-color', and STYLE is either
922 `line' or `wave'. :color may be omitted, which means to use the
923 foreground color. :style may be omitted, which means to use a line.
925 FRAME nil or not specified means change face on all frames.
926 Use `set-face-attribute' to \"unspecify\" underlining."
927 (interactive (read-face-and-attribute :underline
))
928 (set-face-attribute face frame
:underline underline
))
930 (define-obsolete-function-alias 'set-face-underline-p
931 'set-face-underline
"24.3")
934 (defun set-face-inverse-video (face inverse-video-p
&optional frame
)
935 "Specify whether face FACE is in inverse video.
936 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
937 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
938 FRAME nil or not specified means change face on all frames.
939 Use `set-face-attribute' to \"unspecify\" the inverse video attribute."
941 (let ((list (read-face-and-attribute :inverse-video
)))
942 (list (car list
) (if (cadr list
) t
))))
943 (set-face-attribute face frame
:inverse-video inverse-video-p
))
945 (define-obsolete-function-alias 'set-face-inverse-video-p
946 'set-face-inverse-video
"24.4")
948 (defun set-face-bold (face bold-p
&optional frame
)
949 "Specify whether face FACE is bold.
950 BOLD-P non-nil means FACE should explicitly display bold.
951 BOLD-P nil means FACE should explicitly display non-bold.
952 FRAME nil or not specified means change face on all frames.
953 Use `set-face-attribute' or `modify-face' for finer control."
955 (make-face-unbold face frame
)
956 (make-face-bold face frame
)))
958 (define-obsolete-function-alias 'set-face-bold-p
'set-face-bold
"24.4")
961 (defun set-face-italic (face italic-p
&optional frame
)
962 "Specify whether face FACE is italic.
963 ITALIC-P non-nil means FACE should explicitly display italic.
964 ITALIC-P nil means FACE should explicitly display non-italic.
965 FRAME nil or not specified means change face on all frames.
966 Use `set-face-attribute' or `modify-face' for finer control."
968 (make-face-unitalic face frame
)
969 (make-face-italic face frame
)))
971 (define-obsolete-function-alias 'set-face-italic-p
'set-face-italic
"24.4")
974 (defalias 'set-face-background-pixmap
'set-face-stipple
)
977 (defun invert-face (face &optional frame
)
978 "Swap the foreground and background colors of FACE.
979 If FRAME is omitted or nil, it means change face on all frames.
980 If FACE specifies neither foreground nor background color,
981 set its foreground and background to the background and foreground
982 of the default face. Value is FACE."
983 (interactive (list (read-face-name "Invert face" (face-at-point t
))))
984 (let ((fg (face-attribute face
:foreground frame
))
985 (bg (face-attribute face
:background frame
)))
986 (if (not (and (eq fg
'unspecified
) (eq bg
'unspecified
)))
987 (set-face-attribute face frame
:foreground bg
:background fg
)
988 (set-face-attribute face frame
990 (face-attribute 'default
:background frame
)
992 (face-attribute 'default
:foreground frame
))))
996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
997 ;;; Interactively modifying faces.
998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1000 (defvar crm-separator
) ; from crm.el
1002 (defun read-face-name (prompt &optional default multiple
)
1003 "Read one or more face names, prompting with PROMPT.
1004 PROMPT should not end in a space or a colon.
1006 Return DEFAULT if the user enters the empty string.
1007 If DEFAULT is non-nil, it should be a single face or a list of face names
1008 \(symbols or strings). In the latter case, return the `car' of DEFAULT
1009 \(if MULTIPLE is nil, see below), or DEFAULT (if MULTIPLE is non-nil).
1011 If MULTIPLE is non-nil, this function uses `completing-read-multiple'
1012 to read multiple faces with \"[ \\t]*,[ \\t]*\" as the separator regexp
1013 and it returns a list of face names. Otherwise, it reads and returns
1014 a single face name."
1015 (if (and default
(not (stringp default
)))
1017 (cond ((symbolp default
)
1018 (symbol-name default
))
1020 (mapconcat (lambda (f) (if (symbolp f
) (symbol-name f
) f
))
1022 ;; If we only want one, and the default is more than one,
1023 ;; discard the unwanted ones.
1024 (t (symbol-name (car default
))))))
1025 (when (and default
(not multiple
))
1027 ;; For compatibility with `completing-read-multiple' use `crm-separator'
1028 ;; to define DEFAULT if MULTIPLE is nil.
1029 (setq default
(car (split-string default crm-separator t
))))
1031 (let ((prompt (if default
1032 (format-message "%s (default `%s'): " prompt default
)
1033 (format "%s: " prompt
)))
1034 aliasfaces nonaliasfaces faces
)
1035 ;; Build up the completion tables.
1036 (mapatoms (lambda (s)
1038 (if (get s
'face-alias
)
1039 (push (symbol-name s
) aliasfaces
)
1040 (push (symbol-name s
) nonaliasfaces
)))))
1043 (dolist (face (completing-read-multiple
1045 (completion-table-in-turn nonaliasfaces aliasfaces
)
1046 nil t nil
'face-name-history default
))
1047 ;; Ignore elements that are not faces
1048 ;; (for example, because DEFAULT was "all faces")
1049 (if (facep face
) (push (intern face
) faces
)))
1051 (let ((face (completing-read
1053 (completion-table-in-turn nonaliasfaces aliasfaces
)
1054 nil t nil
'face-name-history default
)))
1055 (if (facep face
) (intern face
))))))
1057 ;; Not defined without X, but behind window-system test.
1058 (defvar x-bitmap-file-path
)
1060 (defun face-valid-attribute-values (attribute &optional frame
)
1061 "Return valid values for face attribute ATTRIBUTE.
1062 The optional argument FRAME is used to determine available fonts
1063 and colors. If it is nil or not specified, the selected frame is used.
1064 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
1065 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1070 (if (window-system frame
)
1071 (mapcar (lambda (x) (cons x x
))
1073 ;; Only one font on TTYs.
1074 (list (cons "default" "default"))))
1078 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1081 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1084 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1087 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1088 (internal-lisp-face-attribute-values attribute
)))
1089 ((or `:underline
`:overline
`:strike-through
`:box
)
1090 (if (window-system frame
)
1091 (nconc (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1092 (internal-lisp-face-attribute-values attribute
))
1093 (mapcar #'(lambda (c) (cons c c
))
1094 (defined-colors frame
)))
1095 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1096 (internal-lisp-face-attribute-values attribute
))))
1097 ((or `:foreground
`:background
)
1098 (mapcar #'(lambda (c) (cons c c
))
1099 (defined-colors frame
)))
1103 (and (memq (window-system frame
) '(x ns
)) ; No stipple on w32
1106 (mapcar (lambda (dir)
1107 (and (file-readable-p dir
)
1108 (file-directory-p dir
)
1109 (directory-files dir
)))
1110 x-bitmap-file-path
)))))
1112 (cons '("none" . nil
)
1113 (mapcar #'(lambda (c) (cons (symbol-name c
) c
))
1116 (error "Internal error")))))
1117 (if (and (listp valid
) (not (memq attribute
'(:inherit
))))
1118 (nconc (list (cons "unspecified" 'unspecified
)) valid
)
1122 (defconst face-attribute-name-alist
1123 '((:family .
"font family")
1124 (:foundry .
"font foundry")
1125 (:width .
"character set width")
1126 (:height .
"height in 1/10 pt")
1127 (:weight .
"weight")
1129 (:underline .
"underline")
1130 (:overline .
"overline")
1131 (:strike-through .
"strike-through")
1133 (:inverse-video .
"inverse-video display")
1134 (:foreground .
"foreground color")
1135 (:background .
"background color")
1136 (:stipple .
"background stipple")
1137 (:inherit .
"inheritance"))
1138 "An alist of descriptive names for face attributes.
1139 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1140 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1141 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1144 (defun face-descriptive-attribute-name (attribute)
1145 "Return a descriptive name for ATTRIBUTE."
1146 (cdr (assq attribute face-attribute-name-alist
)))
1149 (defun face-read-string (face default name
&optional completion-alist
)
1150 "Interactively read a face attribute string value.
1151 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1152 default string to return if no new value is entered. NAME is a
1153 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1154 alist of valid values, if non-nil.
1156 Entering nothing accepts the default string DEFAULT.
1157 Value is the new attribute value."
1158 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1159 ;; each word in a string separately).
1160 (setq name
(concat (upcase (substring name
0 1)) (substring name
1)))
1161 (let* ((completion-ignore-case t
)
1162 (value (completing-read
1163 (format-message (if default
1164 "%s for face `%s' (default %s): "
1165 "%s for face `%s': ")
1167 completion-alist nil nil nil nil default
)))
1168 (if (equal value
"") default value
)))
1171 (defun face-read-integer (face default name
)
1172 "Interactively read an integer face attribute value.
1173 FACE is the face whose attribute is read. DEFAULT is the default
1174 value to return if no new value is entered. NAME is a descriptive
1175 name of the attribute for prompting. Value is the new attribute value."
1177 (face-read-string face
1178 (format "%s" default
)
1180 (list (cons "unspecified" 'unspecified
)))))
1181 (cond ((equal new-value
"unspecified")
1183 ((member new-value
'("unspecified-fg" "unspecified-bg"))
1186 (string-to-number new-value
)))))
1189 ;; FIXME this does allow you to enter the list forms of :box,
1190 ;; :stipple, or :underline, because face-valid-attribute-values does
1191 ;; not return those forms.
1192 (defun read-face-attribute (face attribute
&optional frame
)
1193 "Interactively read a new value for FACE's ATTRIBUTE.
1194 Optional argument FRAME nil or unspecified means read an attribute value
1195 of a global face. Value is the new attribute value."
1196 (let* ((old-value (face-attribute face attribute frame
))
1197 (attribute-name (face-descriptive-attribute-name attribute
))
1198 (valid (face-valid-attribute-values attribute frame
))
1200 ;; Represent complex attribute values as strings by printing them
1201 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1202 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1203 ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'.
1204 (and (memq attribute
'(:box
:stipple
:underline
))
1205 (or (consp old-value
)
1206 (vectorp old-value
))
1207 (setq old-value
(prin1-to-string old-value
)))
1208 (cond ((listp valid
)
1210 (or (car (rassoc old-value valid
))
1211 (format "%s" old-value
))))
1213 (face-read-string face default attribute-name valid
))
1214 (if (equal new-value default
)
1215 ;; Nothing changed, so don't bother with all the stuff
1216 ;; below. In particular, this avoids a non-tty color
1217 ;; from being canonicalized for a tty when the user
1218 ;; just uses the default.
1219 (setq new-value old-value
)
1220 ;; Terminal frames can support colors that don't appear
1221 ;; explicitly in VALID, using color approximation code
1222 ;; in tty-colors.el.
1223 (when (and (memq attribute
'(:foreground
:background
))
1224 (not (memq (window-system frame
) '(x w32 ns
)))
1225 (not (member new-value
1227 "unspecified-fg" "unspecified-bg"))))
1228 (setq new-value
(car (tty-color-desc new-value frame
))))
1229 (when (assoc new-value valid
)
1230 (setq new-value
(cdr (assoc new-value valid
)))))))
1231 ((eq valid
'integerp
)
1232 (setq new-value
(face-read-integer face old-value attribute-name
)))
1233 (t (error "Internal error")))
1234 ;; Convert stipple and box value text we read back to a list or
1235 ;; vector if it looks like one. This makes the assumption that a
1236 ;; pixmap file name won't start with an open-paren.
1237 (and (memq attribute
'(:stipple
:box
:underline
))
1239 (string-match-p "^[[(]" new-value
)
1240 (setq new-value
(read new-value
)))
1243 (declare-function fontset-list
"fontset.c" ())
1244 (declare-function x-list-fonts
"xfaces.c"
1245 (pattern &optional face frame maximum width
))
1247 (defun read-face-font (face &optional frame
)
1248 "Read the name of a font for FACE on FRAME.
1249 If optional argument FRAME is nil or omitted, use the selected frame."
1250 (let ((completion-ignore-case t
))
1251 (completing-read (format-message
1252 "Set font attributes of face `%s' from font: " face
)
1253 (append (fontset-list) (x-list-fonts "*" nil frame
)))))
1256 (defun read-all-face-attributes (face &optional frame
)
1257 "Interactively read all attributes for FACE.
1258 If optional argument FRAME is nil or omitted, use the selected frame.
1259 Value is a property list of attribute names and new values."
1261 (dolist (attribute face-attribute-name-alist result
)
1262 (setq result
(cons (car attribute
)
1263 (cons (read-face-attribute face
(car attribute
) frame
)
1266 (defun modify-face (&optional face foreground background stipple
1267 bold-p italic-p underline inverse-p frame
)
1268 "Modify attributes of faces interactively.
1269 If optional argument FRAME is nil or omitted, modify the face used
1270 for newly created frame, i.e. the global face.
1271 For non-interactive use, `set-face-attribute' is preferred.
1272 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1273 and the face and its settings are obtained by querying the user."
1276 (set-face-attribute face frame
1277 :foreground
(or foreground
'unspecified
)
1278 :background
(or background
'unspecified
)
1280 :weight
(if bold-p
'bold
'normal
)
1281 :slant
(if italic-p
'italic
'normal
)
1282 :underline underline
1283 :inverse-video inverse-p
)
1284 (setq face
(read-face-name "Modify face" (face-at-point t
)))
1285 (apply #'set-face-attribute face frame
1286 (read-all-face-attributes face frame
))))
1288 (defun read-face-and-attribute (attribute &optional frame
)
1289 "Read face name and face attribute value.
1290 ATTRIBUTE is the attribute whose new value is read.
1291 FRAME nil or unspecified means read attribute value of global face.
1292 Value is a list (FACE NEW-VALUE) where FACE is the face read
1293 \(a symbol), and NEW-VALUE is value read."
1294 (cond ((eq attribute
:font
)
1295 (let* ((prompt "Set font-related attributes of face")
1296 (face (read-face-name prompt
(face-at-point t
)))
1297 (font (read-face-font face frame
)))
1300 (let* ((attribute-name (face-descriptive-attribute-name attribute
))
1301 (prompt (format "Set %s of face" attribute-name
))
1302 (face (read-face-name prompt
(face-at-point t
)))
1303 (new-value (read-face-attribute face attribute frame
)))
1304 (list face new-value
)))))
1308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1310 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1312 (defconst list-faces-sample-text
1313 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1314 "Text string to display as the sample text for `list-faces-display'.")
1317 ;; The name list-faces would be more consistent, but let's avoid a
1318 ;; conflict with Lucid, which uses that name differently.
1320 (defvar help-xref-stack
)
1321 (defun list-faces-display (&optional regexp
)
1322 "List all faces, using the same sample text in each.
1323 The sample text is a string that comes from the variable
1324 `list-faces-sample-text'.
1326 If REGEXP is non-nil, list only those faces with names matching
1327 this regular expression. When called interactively with a prefix
1328 argument, prompt for a regular expression using `read-regexp'."
1329 (interactive (list (and current-prefix-arg
1330 (read-regexp "List faces matching regexp"))))
1331 (let ((all-faces (zerop (length regexp
)))
1332 (frame (selected-frame))
1335 disp-frame window face-name
)
1336 ;; We filter and take the max length in one pass
1340 (let ((s (symbol-name f
)))
1341 (when (or all-faces
(string-match-p regexp s
))
1342 (setq max-length
(max (length s
) max-length
))
1344 (sort (face-list) #'string-lessp
))))
1346 (error "No faces matching \"%s\"" regexp
))
1347 (setq max-length
(1+ max-length
)
1348 line-format
(format "%%-%ds" max-length
))
1349 (with-help-window "*Faces*"
1350 (with-current-buffer standard-output
1351 (setq truncate-lines t
)
1353 (substitute-command-keys
1355 "\\<help-mode-map>Use "
1356 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1357 "\\[help-follow] on a face name to customize it\n"
1358 "or on its sample text for a description of the face.\n\n")))
1359 (setq help-xref-stack nil
)
1360 (dolist (face faces
)
1361 (setq face-name
(symbol-name face
))
1362 (insert (format line-format face-name
))
1363 ;; Hyperlink to a customization buffer for the face. Using
1364 ;; the help xref mechanism may not be the best way.
1367 (search-backward face-name
)
1368 (setq help-xref-stack-item
`(list-faces-display ,regexp
))
1369 (help-xref-button 0 'help-customize-face face
)))
1371 (line-beg (line-beginning-position)))
1372 (insert list-faces-sample-text
)
1373 ;; Hyperlink to a help buffer for the face.
1376 (search-backward list-faces-sample-text
)
1377 (help-xref-button 0 'help-face face
)))
1379 (put-text-property beg
(1- (point)) 'face face
)
1380 ;; Make all face commands default to the proper face
1381 ;; anywhere in the line.
1382 (put-text-property line-beg
(1- (point)) 'read-face-name face
)
1383 ;; If the sample text has multiple lines, line up all of them.
1387 (insert-char ?\s max-length
)
1389 (goto-char (point-min))))
1390 ;; If the *Faces* buffer appears in a different frame,
1391 ;; copy all the face definitions from FRAME,
1392 ;; so that the display will reflect the frame that was selected.
1393 (setq window
(get-buffer-window (get-buffer "*Faces*") t
))
1394 (setq disp-frame
(if window
(window-frame window
)
1395 (car (frame-list))))
1396 (or (eq frame disp-frame
)
1397 (dolist (face (face-list))
1398 (copy-face face face frame disp-frame
)))))
1401 (defun describe-face (face &optional frame
)
1402 "Display the properties of face FACE on FRAME.
1403 Interactively, FACE defaults to the faces of the character after point
1404 and FRAME defaults to the selected frame.
1406 If the optional argument FRAME is given, report on face FACE in that frame.
1407 If FRAME is t, report on the defaults for face FACE (for new frames).
1408 If FRAME is omitted or nil, use the selected frame."
1409 (interactive (list (read-face-name "Describe face"
1410 (or (face-at-point t
) 'default
)
1412 (let* ((attrs '((:family .
"Family")
1413 (:foundry .
"Foundry")
1415 (:height .
"Height")
1416 (:weight .
"Weight")
1418 (:foreground .
"Foreground")
1419 (:distant-foreground .
"DistantForeground")
1420 (:background .
"Background")
1421 (:underline .
"Underline")
1422 (:overline .
"Overline")
1423 (:strike-through .
"Strike-through")
1425 (:inverse-video .
"Inverse")
1426 (:stipple .
"Stipple")
1428 (:fontset .
"Fontset")
1429 (:inherit .
"Inherit")))
1430 (max-width (apply #'max
(mapcar #'(lambda (x) (length (cdr x
)))
1432 (help-setup-xref (list #'describe-face face
)
1433 (called-interactively-p 'interactive
))
1435 (setq face
'default
))
1436 (if (not (listp face
))
1437 (setq face
(list face
)))
1438 (with-help-window (help-buffer)
1439 (with-current-buffer standard-output
1441 (if (stringp f
) (setq f
(intern f
)))
1442 ;; We may get called for anonymous faces (i.e., faces
1443 ;; expressed using prop-value plists). Those can't be
1444 ;; usefully customized, so ignore them.
1446 (insert "Face: " (symbol-name f
))
1448 (insert " undefined face.\n")
1449 (let ((customize-label "customize this face")
1451 (insert (concat " (" (propertize "sample" 'font-lock-face f
) ")"))
1452 (princ (concat " (" customize-label
")\n"))
1453 ;; FIXME not sure how much of this belongs here, and
1454 ;; how much in `face-documentation'. The latter is
1455 ;; not used much, but needs to return nil for
1456 ;; undocumented faces.
1457 (let ((alias (get f
'face-alias
))
1464 "\n %s is an alias for the face `%s'.\n%s"
1466 (if (setq obsolete
(get f
'obsolete-face
))
1468 " This face is obsolete%s; use `%s' instead.\n"
1469 (if (stringp obsolete
)
1470 (format " since %s" obsolete
)
1474 (insert "\nDocumentation:\n"
1475 (substitute-command-keys
1476 (or (face-documentation face
)
1477 "Not documented as a face."))
1479 (with-current-buffer standard-output
1482 (concat "\\(" customize-label
"\\)") nil t
)
1483 (help-xref-button 1 'help-customize-face f
)))
1484 (setq file-name
(find-lisp-object-file-name f
'defface
))
1486 (princ (substitute-command-keys "Defined in `"))
1487 (princ (file-name-nondirectory file-name
))
1488 (princ (substitute-command-keys "'"))
1489 ;; Make a hyperlink to the library.
1492 (substitute-command-keys "`\\([^`']+\\)'") nil t
)
1493 (help-xref-button 1 'help-face-def f file-name
))
1498 (let ((attr (face-attribute f
(car a
) frame
)))
1499 (insert (make-string (- max-width
(length (cdr a
))) ?\s
)
1500 (cdr a
) ": " (format "%s" attr
))
1501 (if (and (eq (car a
) :inherit
)
1502 (not (eq attr
'unspecified
)))
1503 ;; Make a hyperlink to the parent face.
1505 (re-search-backward ": \\([^:]+\\)" nil t
)
1506 (help-xref-button 1 'help-face attr
)))
1511 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1512 ;;; Face specifications (defface).
1513 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1515 ;; Parameter FRAME Is kept for call compatibility to with previous
1516 ;; face implementation.
1518 (defun face-attr-construct (face &optional _frame
)
1519 "Return a `defface'-style attribute list for FACE.
1520 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1521 face attributes of FACE where ATTRIBUTE is the attribute name and
1522 VALUE is the specified value of that attribute.
1523 Argument FRAME is ignored and retained for compatibility."
1525 (dolist (entry face-attribute-name-alist result
)
1526 (let* ((attribute (car entry
))
1527 (value (face-attribute face attribute
)))
1528 (unless (eq value
'unspecified
)
1529 (setq result
(nconc (list attribute value
) result
)))))))
1532 (defun face-spec-set-match-display (display frame
)
1533 "Non-nil if DISPLAY matches FRAME.
1534 DISPLAY is part of a spec such as can be used in `defface'.
1535 If FRAME is nil, the current FRAME is used."
1536 (let* ((conjuncts display
)
1537 conjunct req options
1538 ;; t means we have succeeded against all the conjuncts in
1539 ;; DISPLAY that have been tested so far.
1541 (if (eq conjuncts t
)
1542 (setq conjuncts nil
))
1543 (while (and conjuncts match
)
1544 (setq conjunct
(car conjuncts
)
1545 conjuncts
(cdr conjuncts
)
1547 options
(cdr conjunct
)
1548 match
(cond ((eq req
'type
)
1549 (or (memq (window-system frame
) options
)
1550 (and (memq 'graphic options
)
1551 (memq (window-system frame
) '(x w32 ns
)))
1552 ;; FIXME: This should be revisited to use
1553 ;; display-graphic-p, provided that the
1554 ;; color selection depends on the number
1555 ;; of supported colors, and all defface's
1556 ;; are changed to look at number of colors
1557 ;; instead of (type graphic) etc.
1558 (if (null (window-system frame
))
1560 (or (and (memq 'motif options
)
1562 (and (memq 'gtk options
)
1564 (and (memq 'lucid options
)
1565 (featurep 'x-toolkit
)
1566 (not (featurep 'motif
))
1567 (not (featurep 'gtk
)))
1568 (and (memq 'x-toolkit options
)
1569 (featurep 'x-toolkit
))))))
1570 ((eq req
'min-colors
)
1571 (>= (display-color-cells frame
) (car options
)))
1573 (memq (frame-parameter frame
'display-type
) options
))
1574 ((eq req
'background
)
1575 (memq (frame-parameter frame
'background-mode
)
1578 (display-supports-face-attributes-p options frame
))
1579 (t (error "Unknown req `%S' with options `%S'"
1584 (defun face-spec-choose (spec &optional frame no-match-retval
)
1585 "Return the proper attributes for FRAME, out of SPEC.
1587 If no match is found or SPEC is nil, return nil, unless NO-MATCH-RETVAL
1588 is given, in which case return its value instead."
1590 (setq frame
(selected-frame)))
1592 result defaults match-found
)
1594 (let* ((entry (pop tail
))
1595 (display (car entry
))
1598 ;; Get the attributes as actually specified by this alternative.
1600 (if (null (cdr attrs
)) ;; was (listp (car attrs))
1601 ;; Old-style entry, the attribute list is the
1606 ;; If the condition is `default', that sets the default
1607 ;; for following conditions.
1608 (if (eq display
'default
)
1609 (setq defaults thisval
)
1610 ;; Otherwise, if it matches, use it.
1611 (when (face-spec-set-match-display display frame
)
1612 (setq result thisval
1615 ;; If defaults have been found, it's safe to just append those to the result
1616 ;; list (which at this point will be either nil or contain actual specs) and
1617 ;; return it to the caller. Since there will most definitely be something to
1618 ;; return in this case, there's no need to know/check if a match was found.
1620 (append result defaults
)
1625 ;; When over 80 faces get processed at frame creation time, all but
1626 ;; one specifying all attributes as "unspecified", generating this
1627 ;; list every time means a lot of consing.
1628 (defconst face--attributes-unspecified
1630 (mapcar (lambda (x) (list (car x
) 'unspecified
))
1631 face-attribute-name-alist
)))
1633 (defun face-spec-reset-face (face &optional frame
)
1634 "Reset all attributes of FACE on FRAME to unspecified."
1635 (apply 'set-face-attribute face frame
1636 (if (eq face
'default
)
1637 ;; For the default face, avoid making any attribute
1638 ;; unspecified. Instead, set attributes to default values
1639 ;; (see also realize_default_face in xfaces.c).
1641 '(:underline nil
:overline nil
:strike-through nil
1642 :box nil
:inverse-video nil
:stipple nil
:inherit nil
)
1643 ;; `display-graphic-p' is unavailable when running
1644 ;; temacs, prior to loading frame.el.
1645 (when (fboundp 'display-graphic-p
)
1646 (unless (display-graphic-p frame
)
1647 `(:family
"default" :foundry
"default" :width normal
1648 :height
1 :weight normal
:slant normal
1649 :foreground
,(if (frame-parameter nil
'reverse
)
1652 :background
,(if (frame-parameter nil
'reverse
)
1654 "unspecified-bg")))))
1655 ;; For all other faces, unspecify all attributes.
1656 face--attributes-unspecified
)))
1658 (defun face-spec-set (face spec
&optional spec-type
)
1659 "Set the face spec SPEC for FACE.
1660 See `defface' for the format of SPEC.
1662 The appearance of each face is controlled by its specs (set via
1663 this function), and by the internal frame-specific face
1664 attributes (set via `set-face-attribute').
1666 This function also defines FACE as a valid face name if it is not
1667 already one, and (re)calculates its attributes on existing
1670 The argument SPEC-TYPE determines which spec to set:
1671 nil or `face-override-spec' means the override spec (which is
1672 usually what you want if calling this function outside of
1674 `customized-face' or `saved-face' means the customized spec or
1675 the saved custom spec;
1676 `face-defface-spec' means the default spec
1677 (usually set only via `defface');
1678 `reset' means to ignore SPEC, but clear the `customized-face'
1679 and `face-override-spec' specs;
1680 Any other value means not to set any spec, but to run the
1681 function for its other effects."
1682 (if (get face
'face-alias
)
1683 (setq face
(get face
'face-alias
)))
1684 ;; Save SPEC to the relevant symbol property.
1686 (setq spec-type
'face-override-spec
))
1687 (if (memq spec-type
'(face-defface-spec face-override-spec
1688 customized-face saved-face
))
1689 (put face spec-type spec
))
1690 (if (memq spec-type
'(reset saved-face
))
1691 (put face
'customized-face nil
))
1692 ;; Setting the face spec via Custom empties out any override spec,
1693 ;; similar to how setting a variable via Custom changes its values.
1694 (if (memq spec-type
'(customized-face saved-face reset
))
1695 (put face
'face-override-spec nil
))
1696 ;; If we reset the face based on its custom spec, it is unmodified
1697 ;; as far as Custom is concerned.
1698 (unless (eq face
'face-override-spec
)
1699 (put face
'face-modified nil
))
1700 ;; Initialize the face if it does not exist, then recalculate.
1701 (make-empty-face face
)
1702 (dolist (frame (frame-list))
1703 (face-spec-recalc face frame
)))
1705 (defun face-spec-recalc (face frame
)
1706 "Reset the face attributes of FACE on FRAME according to its specs.
1707 The following sources are applied in this order:
1709 face reset to default values if it's the default face, otherwise set
1710 to unspecified (through `face-spec-reset-face')
1712 (theme and user customization)
1713 or: if none of the above exist, and none match the current frame or
1714 inherited from the defface spec instead of overwriting it
1715 entirely, the following is applied instead:
1716 (defface default spec)
1717 (X resources (if applicable))
1719 defface override spec"
1720 (while (get face
'face-alias
)
1721 (setq face
(get face
'face-alias
)))
1722 (face-spec-reset-face face frame
)
1723 ;; If FACE is customized or themed, set the custom spec from
1724 ;; `theme-face' records.
1725 (let ((theme-faces (get face
'theme-face
))
1727 spec theme-face-applied
)
1729 (dolist (elt (reverse theme-faces
))
1730 (setq spec
(face-spec-choose (cadr elt
) frame no-match-found
))
1731 (unless (eq spec no-match-found
)
1732 (face-spec-set-2 face frame spec
)
1733 (setq theme-face-applied t
))))
1734 ;; If there was a spec applicable to FRAME, that overrides the
1735 ;; defface spec entirely (rather than inheriting from it). If
1736 ;; there was no spec applicable to FRAME, apply the defface spec
1737 ;; as well as any applicable X resources.
1738 (unless theme-face-applied
1739 (setq spec
(face-spec-choose (face-default-spec face
) frame
))
1740 (face-spec-set-2 face frame spec
)
1741 (make-face-x-resource-internal face frame
))
1742 (setq spec
(face-spec-choose (get face
'face-override-spec
) frame
))
1743 (face-spec-set-2 face frame spec
)))
1745 (defun face-spec-set-2 (face frame spec
)
1746 "Set the face attributes of FACE on FRAME according to SPEC."
1749 (when (assq (car spec
) face-x-resources
)
1750 (push (car spec
) attrs
)
1751 (push (cadr spec
) attrs
))
1752 (setq spec
(cddr spec
)))
1753 (apply 'set-face-attribute face frame
(nreverse attrs
))))
1755 (defun face-attr-match-p (face attrs
&optional frame
)
1756 "Return t if attributes of FACE match values in plist ATTRS.
1757 Optional parameter FRAME is the frame whose definition of FACE
1758 is used. If nil or omitted, use the selected frame."
1760 (setq frame
(selected-frame)))
1761 (let* ((list face-attribute-name-alist
)
1763 (bold (and (plist-member attrs
:bold
)
1764 (not (plist-member attrs
:weight
))))
1765 (italic (and (plist-member attrs
:italic
)
1766 (not (plist-member attrs
:slant
))))
1767 (plist (if (or bold italic
)
1768 (copy-sequence attrs
)
1770 ;; Handle the Emacs 20 :bold and :italic properties.
1772 (plist-put plist
:weight
(if bold
'bold
'normal
)))
1774 (plist-put plist
:slant
(if italic
'italic
'normal
)))
1775 (while (and match list
)
1776 (let* ((attr (caar list
))
1778 (if (plist-member plist attr
)
1779 (plist-get plist attr
)
1781 (value-now (face-attribute face attr frame
)))
1782 (setq match
(equal specified-value value-now
))
1783 (setq list
(cdr list
))))
1786 (defsubst face-spec-match-p
(face spec
&optional frame
)
1787 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1788 (face-attr-match-p face
(face-spec-choose spec frame
) frame
))
1790 (defsubst face-default-spec
(face)
1791 "Return the default face-spec for FACE, ignoring any user customization.
1792 If there is no default for FACE, return nil."
1793 (get face
'face-defface-spec
))
1795 (defsubst face-user-default-spec
(face)
1796 "Return the user's customized face-spec for FACE, or the default if none.
1797 If there is neither a user setting nor a default for FACE, return nil."
1798 (or (get face
'customized-face
)
1799 (get face
'saved-face
)
1800 (face-default-spec face
)))
1803 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1804 ;;; Frame-type independent color support.
1805 ;;; We keep the old x-* names as aliases for back-compatibility.
1806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1808 (defun defined-colors (&optional frame
)
1809 "Return a list of colors supported for a particular frame.
1810 The argument FRAME specifies which frame to try.
1811 The value may be different for frames on different display types.
1812 If FRAME doesn't support colors, the value is nil.
1813 If FRAME is nil, that stands for the selected frame."
1814 (if (memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1815 (xw-defined-colors frame
)
1816 (mapcar 'car
(tty-color-alist frame
))))
1817 (defalias 'x-defined-colors
'defined-colors
)
1819 (declare-function xw-color-defined-p
"xfns.c" (color &optional frame
))
1821 (defun color-defined-p (color &optional frame
)
1822 "Return non-nil if COLOR is supported on frame FRAME.
1823 COLOR should be a string naming a color (e.g. \"white\"), or a
1824 string specifying a color's RGB components (e.g. \"#ff12ec\"), or
1825 the symbol `unspecified'.
1827 This function returns nil if COLOR is the symbol `unspecified',
1828 or one of the strings \"unspecified-fg\" or \"unspecified-bg\".
1830 If FRAME is omitted or nil, use the selected frame."
1831 (unless (member color
'(unspecified "unspecified-bg" "unspecified-fg"))
1832 (if (member (framep (or frame
(selected-frame))) '(x w32 ns
))
1833 (xw-color-defined-p color frame
)
1834 (numberp (tty-color-translate color frame
)))))
1835 (defalias 'x-color-defined-p
'color-defined-p
)
1837 (declare-function xw-color-values
"xfns.c" (color &optional frame
))
1839 (defun color-values (color &optional frame
)
1840 "Return a description of the color named COLOR on frame FRAME.
1841 COLOR should be a string naming a color (e.g. \"white\"), or a
1842 string specifying a color's RGB components (e.g. \"#ff12ec\").
1844 Return a list of three integers, (RED GREEN BLUE), each between 0
1845 and either 65280 or 65535 (the maximum depends on the system).
1846 Use `color-name-to-rgb' if you want RGB floating-point values
1849 If FRAME is omitted or nil, use the selected frame.
1850 If FRAME cannot display COLOR, the value is nil.
1852 COLOR can also be the symbol `unspecified' or one of the strings
1853 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1854 return value is nil."
1856 ((member color
'(unspecified "unspecified-fg" "unspecified-bg"))
1858 ((memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1859 (xw-color-values color frame
))
1861 (tty-color-values color frame
))))
1863 (defalias 'x-color-values
'color-values
)
1865 (declare-function xw-display-color-p
"xfns.c" (&optional terminal
))
1867 (defun display-color-p (&optional display
)
1868 "Return t if DISPLAY supports color.
1869 The optional argument DISPLAY specifies which display to ask about.
1870 DISPLAY should be either a frame or a display name (a string).
1871 If omitted or nil, that stands for the selected frame's display."
1872 (if (memq (framep-on-display display
) '(x w32 ns
))
1873 (xw-display-color-p display
)
1874 (tty-display-color-p display
)))
1875 (defalias 'x-display-color-p
'display-color-p
)
1877 (declare-function x-display-grayscale-p
"xfns.c" (&optional terminal
))
1879 (defun display-grayscale-p (&optional display
)
1880 "Return non-nil if frames on DISPLAY can display shades of gray.
1881 DISPLAY should be either a frame or a display name (a string).
1882 If omitted or nil, that stands for the selected frame's display."
1883 (let ((frame-type (framep-on-display display
)))
1885 ((memq frame-type
'(x w32 ns
))
1886 (x-display-grayscale-p display
))
1888 (> (tty-color-gray-shades display
) 2)))))
1890 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg
)
1891 "Read a color name or RGB triplet.
1892 Completion is available for color names, but not for RGB triplets.
1894 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1895 components can have one to four digits, but all three components
1896 must have the same number of digits. Each digit is a hex value
1897 between 0 and F; either upper case or lower case for A through F
1900 In addition to standard color names and RGB hex values, the
1901 following are available as color candidates. In each case, the
1902 corresponding color is used.
1904 * `foreground at point' - foreground under the cursor
1905 * `background at point' - background under the cursor
1907 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1909 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1910 convert an input color name to an RGB hex string. Return the RGB
1913 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1914 to enter an empty color name (the empty string).
1916 Interactively, or with optional arg MSG non-nil, print the
1917 resulting color name in the echo area."
1918 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1919 (let* ((completion-ignore-case t
)
1920 (colors (or facemenu-color-alist
1921 (append '("foreground at point" "background at point")
1922 (if allow-empty-name
'(""))
1924 (color (completing-read
1925 (or prompt
"Color (name or #RGB triplet): ")
1926 ;; Completing function for reading colors, accepting
1927 ;; both color names and RGB triplets.
1928 (lambda (string pred flag
)
1930 ((null flag
) ; Try completion.
1931 (or (try-completion string colors pred
)
1932 (if (color-defined-p string
)
1934 ((eq flag t
) ; List all completions.
1935 (or (all-completions string colors pred
)
1936 (if (color-defined-p string
)
1938 ((eq flag
'lambda
) ; Test completion.
1939 (or (member string colors
)
1940 (color-defined-p string
)))))
1943 ;; Process named colors.
1944 (when (member color colors
)
1945 (cond ((string-equal color
"foreground at point")
1946 (setq color
(foreground-color-at-point)))
1947 ((string-equal color
"background at point")
1948 (setq color
(background-color-at-point))))
1949 (when (and convert-to-RGB
1950 (not (string-equal color
"")))
1951 (let ((components (x-color-values color
)))
1952 (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color
)
1953 (setq color
(format "#%04X%04X%04X"
1954 (logand 65535 (nth 0 components
))
1955 (logand 65535 (nth 1 components
))
1956 (logand 65535 (nth 2 components
))))))))
1957 (when msg
(message "Color: `%s'" color
))
1960 (defun face-at-point (&optional thing multiple
)
1961 "Return the face of the character after point.
1962 If it has more than one face, return the first one.
1963 If THING is non-nil try first to get a face name from the buffer.
1964 IF MULTIPLE is non-nil, return a list of all faces.
1965 Return nil if there is no face."
1968 ;; Try to get a face name from the buffer.
1969 (let ((face (intern-soft (thing-at-point 'symbol
))))
1971 (push face faces
))))
1972 ;; Add the named faces that the `read-face-name' or `face' property uses.
1973 (let ((faceprop (or (get-char-property (point) 'read-face-name
)
1974 (get-char-property (point) 'face
))))
1975 (cond ((facep faceprop
)
1976 (push faceprop faces
))
1977 ((face-list-p faceprop
)
1978 (dolist (face faceprop
)
1980 (push face faces
))))))
1982 (delete-dups (nreverse faces
))
1983 (car (last faces
)))))
1985 (defun faces--attribute-at-point (attribute &optional attribute-unnamed
)
1986 "Return the face ATTRIBUTE at point.
1987 ATTRIBUTE is a keyword.
1988 If ATTRIBUTE-UNNAMED is non-nil, it is a symbol to look for in
1989 unnamed faces (e.g, `foreground-color')."
1990 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1991 ;; Need also pick up any face properties that are not associated with named faces.
1992 (let ((faces (or (get-char-property (point) 'read-face-name
)
1993 ;; If `font-lock-mode' is on, `font-lock-face' takes precedence.
1995 (get-char-property (point) 'font-lock-face
))
1996 (get-char-property (point) 'face
)))
1998 (dolist (face (if (face-list-p faces
)
2002 ((and face
(symbolp face
))
2003 (let ((value (face-attribute-specified-or
2004 (face-attribute face attribute nil t
)
2006 (unless (member value
'(nil "unspecified-fg" "unspecified-bg"))
2007 (setq found value
))))
2009 (setq found
(cond ((and attribute-unnamed
2010 (memq attribute-unnamed face
))
2011 (cdr (memq attribute-unnamed face
)))
2012 ((memq attribute face
) (cadr (memq attribute face
))))))))
2014 (face-attribute 'default attribute
))))
2016 (defun foreground-color-at-point ()
2017 "Return the foreground color of the character after point."
2018 (faces--attribute-at-point :foreground
'foreground-color
))
2020 (defun background-color-at-point ()
2021 "Return the background color of the character after point."
2022 (faces--attribute-at-point :background
'background-color
))
2025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2029 (declare-function x-display-list
"xfns.c" ())
2030 (declare-function x-open-connection
"xfns.c"
2031 (display &optional xrm-string must-succeed
))
2032 (declare-function x-get-resource
"frame.c"
2033 (attribute class
&optional component subclass
))
2034 (declare-function x-parse-geometry
"frame.c" (string))
2035 (defvar x-display-name
)
2037 (defun x-handle-named-frame-geometry (parameters)
2038 "Add geometry parameters for a named frame to parameter list PARAMETERS.
2039 Value is the new parameter list."
2040 ;; Note that `x-resource-name' has a global meaning.
2041 (let ((x-resource-name (cdr (assq 'name parameters
))))
2042 (when x-resource-name
2043 ;; Before checking X resources, we must have an X connection.
2046 (x-open-connection (or (cdr (assq 'display parameters
))
2048 (let (res-geometry parsed
)
2049 (and (setq res-geometry
(x-get-resource "geometry" "Geometry"))
2050 (setq parsed
(x-parse-geometry res-geometry
))
2052 (append parameters parsed
2053 ;; If the resource specifies a position,
2054 ;; take note of that.
2055 (if (or (assq 'top parsed
) (assq 'left parsed
))
2056 '((user-position . t
) (user-size . t
)))))))))
2060 (defun x-handle-reverse-video (frame parameters
)
2061 "Handle the reverse-video frame parameter and X resource.
2062 `x-create-frame' does not handle this one."
2063 (when (cdr (or (assq 'reverse parameters
)
2064 (let ((resource (x-get-resource "reverseVideo"
2067 (cons nil
(member (downcase resource
)
2068 '("on" "true")))))))
2069 (let* ((params (frame-parameters frame
))
2070 (bg (cdr (assq 'foreground-color params
)))
2071 (fg (cdr (assq 'background-color params
))))
2072 (modify-frame-parameters frame
2073 (list (cons 'foreground-color fg
)
2074 (cons 'background-color bg
)))
2075 (if (equal bg
(cdr (assq 'border-color params
)))
2076 (modify-frame-parameters frame
2077 (list (cons 'border-color fg
))))
2078 (if (equal bg
(cdr (assq 'mouse-color params
)))
2079 (modify-frame-parameters frame
2080 (list (cons 'mouse-color fg
))))
2081 (if (equal bg
(cdr (assq 'cursor-color params
)))
2082 (modify-frame-parameters frame
2083 (list (cons 'cursor-color fg
)))))))
2085 (declare-function x-create-frame
"xfns.c" (parms))
2086 (declare-function x-setup-function-keys
"term/common-win" (frame))
2088 (defun x-create-frame-with-faces (&optional parameters
)
2089 "Create and return a frame with frame parameters PARAMETERS.
2090 If PARAMETERS specify a frame name, handle X geometry resources
2091 for that name. If PARAMETERS includes a `reverse' parameter, or
2092 the X resource \"reverseVideo\" is present, handle that."
2093 (setq parameters
(x-handle-named-frame-geometry parameters
))
2094 (let* ((params (copy-tree parameters
))
2095 (visibility-spec (assq 'visibility parameters
))
2096 (delayed-params '(foreground-color background-color font
2097 border-color cursor-color mouse-color
2098 visibility scroll-bar-foreground
2099 scroll-bar-background
))
2101 (dolist (param delayed-params
)
2102 (setq params
(assq-delete-all param params
)))
2103 (setq frame
(x-create-frame `((visibility . nil
) .
,params
)))
2106 (x-setup-function-keys frame
)
2107 (x-handle-reverse-video frame parameters
)
2108 (frame-set-background-mode frame t
)
2109 (face-set-after-frame-default frame parameters
)
2110 (if (null visibility-spec
)
2111 (make-frame-visible frame
)
2112 (modify-frame-parameters frame
(list visibility-spec
)))
2115 (delete-frame frame
)))
2118 (defun face-set-after-frame-default (frame &optional parameters
)
2119 "Initialize the frame-local faces of FRAME.
2120 Calculate the face definitions using the face specs, custom theme
2121 settings, X resources, and `face-new-frame-defaults'.
2122 Finally, apply any relevant face attributes found amongst the
2123 frame parameters in PARAMETERS."
2124 ;; The `reverse' is so that `default' goes first.
2125 (dolist (face (nreverse (face-list)))
2128 ;; Initialize faces from face spec and custom theme.
2129 (face-spec-recalc face frame
)
2130 ;; Apply attributes specified by face-new-frame-defaults
2131 (internal-merge-in-global-face face frame
))
2132 ;; Don't let invalid specs prevent frame creation.
2135 ;; Apply attributes specified by frame parameters.
2136 (let ((face-params '((foreground-color default
:foreground
)
2137 (background-color default
:background
)
2138 (font default
:font
)
2139 (border-color border
:background
)
2140 (cursor-color cursor
:background
)
2141 (scroll-bar-foreground scroll-bar
:foreground
)
2142 (scroll-bar-background scroll-bar
:background
)
2143 (mouse-color mouse
:background
))))
2144 (dolist (param face-params
)
2145 (let* ((param-name (nth 0 param
))
2146 (value (cdr (assq param-name parameters
))))
2148 (set-face-attribute (nth 1 param
) frame
2149 (nth 2 param
) value
))))))
2151 (defun tty-handle-reverse-video (frame parameters
)
2152 "Handle the reverse-video frame parameter for terminal frames."
2153 (when (cdr (assq 'reverse parameters
))
2154 (let* ((params (frame-parameters frame
))
2155 (bg (cdr (assq 'foreground-color params
)))
2156 (fg (cdr (assq 'background-color params
))))
2157 (modify-frame-parameters frame
2158 (list (cons 'foreground-color fg
)
2159 (cons 'background-color bg
)))
2160 (if (equal bg
(cdr (assq 'mouse-color params
)))
2161 (modify-frame-parameters frame
2162 (list (cons 'mouse-color fg
))))
2163 (if (equal bg
(cdr (assq 'cursor-color params
)))
2164 (modify-frame-parameters frame
2165 (list (cons 'cursor-color fg
)))))))
2168 (defun tty-create-frame-with-faces (&optional parameters
)
2169 "Create and return a frame from optional frame parameters PARAMETERS.
2170 If PARAMETERS contains a `reverse' parameter, handle that."
2171 (let ((frame (make-terminal-frame parameters
))
2174 (with-selected-frame frame
2175 (tty-handle-reverse-video frame
(frame-parameters frame
))
2177 (unless (terminal-parameter frame
'terminal-initted
)
2178 (set-terminal-parameter frame
'terminal-initted t
)
2179 (set-locale-environment nil frame
)
2180 (tty-run-terminal-initialization frame nil t
))
2181 (frame-set-background-mode frame t
)
2182 (face-set-after-frame-default frame parameters
)
2185 (delete-frame frame
)))
2188 (defun tty-find-type (pred type
)
2189 "Return the longest prefix of TYPE to which PRED returns non-nil.
2190 TYPE should be a tty type name such as \"xterm-16color\".
2192 The function tries only those prefixes that are followed by a
2193 dash or underscore in the original type name, like \"xterm\" in
2197 (not (funcall pred type
)))
2198 ;; Strip off last hyphen and what follows, then try again
2200 (if (setq hyphend
(string-match-p "[-_][^-_]+$" type
))
2201 (substring type
0 hyphend
)
2205 (defvar tty-setup-hook nil
2206 "Hook run after running the initialization function of a new text terminal.
2207 Specifically, `tty-run-terminal-initialization' runs this.
2208 This can be used to fine tune the `input-decode-map', for example.")
2210 (defun tty-run-terminal-initialization (frame &optional type run-hook
)
2211 "Run the special initialization code for the terminal type of FRAME.
2212 The optional TYPE parameter may be used to override the autodetected
2213 terminal type to a different value.
2215 This consults `term-file-aliases' to map terminal types to their aliases.
2217 If optional argument RUN-HOOK is non-nil, then as a final step,
2218 this runs the hook `tty-setup-hook'.
2220 If you set `term-file-prefix' to nil, this function does nothing."
2221 (setq type
(or type
(tty-type frame
)))
2222 (let ((alias (tty-find-type
2223 (lambda (typ) (assoc typ term-file-aliases
)) type
)))
2224 (if alias
(setq type
(cdr (assoc alias term-file-aliases
)))))
2225 ;; Load library for our terminal type.
2226 ;; User init file can set term-file-prefix to nil to prevent this.
2227 (with-selected-frame frame
2228 (unless (null term-file-prefix
)
2229 (let* (term-init-func)
2230 ;; First, load the terminal initialization file, if it is
2231 ;; available and it hasn't been loaded already.
2232 (tty-find-type #'(lambda (type)
2233 (let ((file (locate-library (concat term-file-prefix type
))))
2235 (or (assoc file load-history
)
2238 ;; Next, try to find a matching initialization function, and call it.
2239 (tty-find-type #'(lambda (type)
2240 (fboundp (setq term-init-func
2241 (intern (concat "terminal-init-" type
)))))
2243 (when (fboundp term-init-func
)
2244 (funcall term-init-func
))
2245 (set-terminal-parameter frame
'terminal-initted term-init-func
)
2246 (if run-hook
(run-hooks 'tty-setup-hook
))))))
2248 ;; Called from C function init_display to initialize faces of the
2249 ;; dumped terminal frame on startup.
2251 (defun tty-set-up-initial-frame-faces ()
2252 (let ((frame (selected-frame)))
2253 (frame-set-background-mode frame t
)
2254 (face-set-after-frame-default frame
)))
2257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2261 (defgroup basic-faces nil
2262 "The standard faces of Emacs."
2266 '((t nil
)) ; If this were nil, face-defface-spec would not be set.
2267 "Basic default face."
2268 :group
'basic-faces
)
2273 :group
'basic-faces
)
2276 '((((supports :slant italic
))
2278 (((supports :underline t
))
2281 ;; Default to italic, even if it doesn't appear to be supported,
2282 ;; because in some cases the display engine will do its own
2283 ;; workaround (to `dim' on ttys).
2285 "Basic italic face."
2286 :group
'basic-faces
)
2288 (defface bold-italic
2289 '((t :weight bold
:slant italic
))
2290 "Basic bold-italic face."
2291 :group
'basic-faces
)
2294 '((((supports :underline t
))
2296 (((supports :weight bold
))
2299 "Basic underlined face."
2300 :group
'basic-faces
)
2302 (defface fixed-pitch
2303 '((t :family
"Monospace"))
2304 "The basic fixed-pitch face."
2305 :group
'basic-faces
)
2307 (defface fixed-pitch-serif
2308 '((t :family
"Monospace Serif"))
2309 "The basic fixed-pitch face with serifs."
2310 :group
'basic-faces
)
2312 (defface variable-pitch
2314 ;; This is a workaround for an issue discussed in
2315 ;; http://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00746.html.
2316 ;; We need (a) the splash screen not to pick up bold-italics variant of
2317 ;; the font, and (b) still be able to request bold/italic/larger size
2318 ;; variants in the likes of EWW.
2319 :family
"Arial" :foundry
"outline")
2320 (t :family
"Sans Serif"))
2321 "The basic variable-pitch face."
2322 :group
'basic-faces
)
2325 '((((class color grayscale
) (min-colors 88) (background light
))
2326 :foreground
"grey50")
2327 (((class color grayscale
) (min-colors 88) (background dark
))
2328 :foreground
"grey70")
2329 (((class color
) (min-colors 8) (background light
))
2330 :foreground
"green")
2331 (((class color
) (min-colors 8) (background dark
))
2332 :foreground
"yellow"))
2333 "Basic face for shadowed text."
2338 '((((class color
) (min-colors 88) (background light
))
2339 :foreground
"RoyalBlue3" :underline t
)
2340 (((class color
) (background light
))
2341 :foreground
"blue" :underline t
)
2342 (((class color
) (min-colors 88) (background dark
))
2343 :foreground
"cyan1" :underline t
)
2344 (((class color
) (background dark
))
2345 :foreground
"cyan" :underline t
)
2346 (t :inherit underline
))
2347 "Basic face for unvisited links."
2351 (defface link-visited
2352 '((default :inherit link
)
2353 (((class color
) (background light
)) :foreground
"magenta4")
2354 (((class color
) (background dark
)) :foreground
"violet"))
2355 "Basic face for visited links."
2360 '((((class color
) (min-colors 88) (background light
))
2361 :background
"darkseagreen2")
2362 (((class color
) (min-colors 88) (background dark
))
2363 :background
"darkolivegreen")
2364 (((class color
) (min-colors 16) (background light
))
2365 :background
"darkseagreen2")
2366 (((class color
) (min-colors 16) (background dark
))
2367 :background
"darkolivegreen")
2368 (((class color
) (min-colors 8))
2369 :background
"green" :foreground
"black")
2370 (t :inverse-video t
))
2371 "Basic face for highlighting."
2372 :group
'basic-faces
)
2374 ;; Region face: under NS, default to the system-defined selection
2375 ;; color (optimized for the fixed white background of other apps),
2376 ;; if background is light.
2378 '((((class color
) (min-colors 88) (background dark
))
2379 :background
"blue3")
2380 (((class color
) (min-colors 88) (background light
) (type gtk
))
2381 :distant-foreground
"gtk_selection_fg_color"
2382 :background
"gtk_selection_bg_color")
2383 (((class color
) (min-colors 88) (background light
) (type ns
))
2384 :distant-foreground
"ns_selection_fg_color"
2385 :background
"ns_selection_bg_color")
2386 (((class color
) (min-colors 88) (background light
))
2387 :background
"lightgoldenrod2")
2388 (((class color
) (min-colors 16) (background dark
))
2389 :background
"blue3")
2390 (((class color
) (min-colors 16) (background light
))
2391 :background
"lightgoldenrod2")
2392 (((class color
) (min-colors 8))
2393 :background
"blue" :foreground
"white")
2394 (((type tty
) (class mono
))
2396 (t :background
"gray"))
2397 "Basic face for highlighting the region."
2399 :group
'basic-faces
)
2401 (defface secondary-selection
2402 '((((class color
) (min-colors 88) (background light
))
2403 :background
"yellow1")
2404 (((class color
) (min-colors 88) (background dark
))
2405 :background
"SkyBlue4")
2406 (((class color
) (min-colors 16) (background light
))
2407 :background
"yellow")
2408 (((class color
) (min-colors 16) (background dark
))
2409 :background
"SkyBlue4")
2410 (((class color
) (min-colors 8))
2411 :background
"cyan" :foreground
"black")
2412 (t :inverse-video t
))
2413 "Basic face for displaying the secondary selection."
2414 :group
'basic-faces
)
2416 (defface trailing-whitespace
2417 '((((class color
) (background light
))
2419 (((class color
) (background dark
))
2421 (t :inverse-video t
))
2422 "Basic face for highlighting trailing whitespace."
2424 :group
'basic-faces
)
2426 (defface escape-glyph
2427 '((((background dark
)) :foreground
"cyan")
2428 ;; See the comment in minibuffer-prompt for
2429 ;; the reason not to use blue on MS-DOS.
2430 (((type pc
)) :foreground
"magenta")
2431 ;; red4 is too dark, but some say blue is too loud.
2432 ;; brown seems to work ok. -- rms.
2433 (t :foreground
"brown"))
2434 "Face for characters displayed as sequences using `^' or `\\'."
2438 (defface nobreak-space
2439 '((((class color
) (min-colors 88)) :inherit escape-glyph
:underline t
)
2440 (((class color
) (min-colors 8)) :background
"magenta")
2441 (t :inverse-video t
))
2442 "Face for displaying nobreak space."
2446 (defgroup mode-line-faces nil
2447 "Faces used in the mode line."
2453 '((((class color
) (min-colors 88))
2454 :box
(:line-width -
1 :style released-button
)
2455 :background
"grey75" :foreground
"black")
2458 "Basic mode line face for selected window."
2460 :group
'mode-line-faces
2461 :group
'basic-faces
)
2463 (defface mode-line-inactive
2466 (((class color
) (min-colors 88) (background light
))
2468 :box
(:line-width -
1 :color
"grey75" :style nil
)
2469 :foreground
"grey20" :background
"grey90")
2470 (((class color
) (min-colors 88) (background dark
) )
2472 :box
(:line-width -
1 :color
"grey40" :style nil
)
2473 :foreground
"grey80" :background
"grey30"))
2474 "Basic mode line face for non-selected windows."
2476 :group
'mode-line-faces
2477 :group
'basic-faces
)
2478 (define-obsolete-face-alias 'modeline-inactive
'mode-line-inactive
"22.1")
2480 (defface mode-line-highlight
2481 '((((class color
) (min-colors 88))
2482 :box
(:line-width
2 :color
"grey40" :style released-button
))
2484 :inherit highlight
))
2485 "Basic mode line face for highlighting."
2487 :group
'mode-line-faces
2488 :group
'basic-faces
)
2489 (define-obsolete-face-alias 'modeline-highlight
'mode-line-highlight
"22.1")
2491 (defface mode-line-emphasis
2492 '((t (:weight bold
)))
2493 "Face used to emphasize certain mode line features.
2494 Use the face `mode-line-highlight' for features that can be selected."
2496 :group
'mode-line-faces
2497 :group
'basic-faces
)
2499 (defface mode-line-buffer-id
2500 '((t (:weight bold
)))
2501 "Face used for buffer identification parts of the mode line."
2503 :group
'mode-line-faces
2504 :group
'basic-faces
)
2505 (define-obsolete-face-alias 'modeline-buffer-id
'mode-line-buffer-id
"22.1")
2507 (defface header-line
2511 ;; This used to be `:inverse-video t', but that doesn't look very
2512 ;; good when combined with inverse-video mode-lines and multiple
2513 ;; windows. Underlining looks better, and is more consistent with
2514 ;; the window-system face variants, which deemphasize the
2515 ;; header-line in relation to the mode-line face. If a terminal
2516 ;; can't underline, then the header-line will end up without any
2517 ;; highlighting; this may be too confusing in general, although it
2518 ;; happens to look good with the only current use of header-lines,
2519 ;; the info browser. XXX
2520 :inverse-video nil
;Override the value inherited from mode-line.
2522 (((class color grayscale
) (background light
))
2523 :background
"grey90" :foreground
"grey20"
2525 (((class color grayscale
) (background dark
))
2526 :background
"grey20" :foreground
"grey90"
2528 (((class mono
) (background light
))
2529 :background
"white" :foreground
"black"
2533 (((class mono
) (background dark
))
2534 :background
"black" :foreground
"white"
2538 "Basic header-line face."
2540 :group
'basic-faces
)
2542 (defface vertical-border
2543 '((((type tty
)) :inherit mode-line-inactive
))
2544 "Face used for vertical window dividers on ttys."
2546 :group
'basic-faces
)
2548 (defface window-divider
'((t :foreground
"gray60"))
2549 "Basic face for window dividers.
2550 When a divider is less than 3 pixels wide, it is drawn solidly
2551 with the foreground of this face. For larger dividers this face
2552 is used for the inner part while the first pixel line/column is
2553 drawn with the `window-divider-first-pixel' face and the last
2554 pixel line/column with the `window-divider-last-pixel' face."
2556 :group
'window-divider
2557 :group
'basic-faces
)
2559 (defface window-divider-first-pixel
2560 '((t :foreground
"gray80"))
2561 "Basic face for first pixel line/column of window dividers.
2562 When a divider is at least 3 pixels wide, its first pixel
2563 line/column is drawn with the foreground of this face. If you do
2564 not want to accentuate the first pixel line/column, set this to
2565 the same as `window-divider' face."
2567 :group
'window-divider
2568 :group
'basic-faces
)
2570 (defface window-divider-last-pixel
2571 '((t :foreground
"gray40"))
2572 "Basic face for last pixel line/column of window dividers.
2573 When a divider is at least 3 pixels wide, its last pixel
2574 line/column is drawn with the foreground of this face. If you do
2575 not want to accentuate the last pixel line/column, set this to
2576 the same as `window-divider' face."
2578 :group
'window-divider
2579 :group
'basic-faces
)
2581 (defface minibuffer-prompt
2582 '((((background dark
)) :foreground
"cyan")
2583 ;; Don't use blue because many users of the MS-DOS port customize
2584 ;; their foreground color to be blue.
2585 (((type pc
)) :foreground
"magenta")
2586 (t :foreground
"medium blue"))
2587 "Face for minibuffer prompts.
2588 By default, Emacs automatically adds this face to the value of
2589 `minibuffer-prompt-properties', which is a list of text properties
2590 used to display the prompt text."
2592 :group
'basic-faces
)
2594 (setq minibuffer-prompt-properties
2595 (append minibuffer-prompt-properties
(list 'face
'minibuffer-prompt
)))
2598 '((((class color
) (background light
))
2599 :background
"grey95")
2600 (((class color
) (background dark
))
2601 :background
"grey10")
2603 :background
"gray"))
2604 "Basic face for the fringes to the left and right of windows under X."
2607 :group
'basic-faces
)
2609 (defface scroll-bar
'((t nil
))
2610 "Basic face for the scroll bar colors under X."
2613 :group
'basic-faces
)
2615 (defface border
'((t nil
))
2616 "Basic face for the frame border under X."
2619 :group
'basic-faces
)
2622 '((((background light
)) :background
"black")
2623 (((background dark
)) :background
"white"))
2624 "Basic face for the cursor color under X.
2625 Currently, only the `:background' attribute is meaningful; all
2626 other attributes are ignored. The cursor foreground color is
2627 taken from the background color of the underlying text.
2629 Note: Other faces cannot inherit from the cursor face."
2632 :group
'basic-faces
)
2634 (put 'cursor
'face-no-inherit t
)
2636 (defface mouse
'((t nil
))
2637 "Basic face for the mouse color under X."
2640 :group
'basic-faces
)
2644 :box
(:line-width
1 :style released-button
)
2645 :foreground
"black")
2646 (((type x w32 ns
) (class color
))
2647 :background
"grey75")
2648 (((type x
) (class mono
))
2649 :background
"grey"))
2650 "Basic tool-bar face."
2652 :group
'basic-faces
)
2661 "Basic face for the font and colors of the menu bar and popup menus."
2664 :group
'basic-faces
)
2666 (defface help-argument-name
'((t :inherit italic
))
2667 "Face to highlight argument names in *Help* buffers."
2670 (defface glyphless-char
2671 '((((type tty
)) :inherit underline
)
2672 (((type pc
)) :inherit escape-glyph
)
2674 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2675 It is used for characters of no fonts too."
2677 :group
'basic-faces
)
2680 '((default :weight bold
)
2681 (((class color
) (min-colors 88) (background light
)) :foreground
"Red1")
2682 (((class color
) (min-colors 88) (background dark
)) :foreground
"Pink")
2683 (((class color
) (min-colors 16) (background light
)) :foreground
"Red1")
2684 (((class color
) (min-colors 16) (background dark
)) :foreground
"Pink")
2685 (((class color
) (min-colors 8)) :foreground
"red")
2686 (t :inverse-video t
))
2687 "Basic face used to highlight errors and to denote failure."
2689 :group
'basic-faces
)
2692 '((default :weight bold
)
2693 (((class color
) (min-colors 16)) :foreground
"DarkOrange")
2694 (((class color
)) :foreground
"yellow"))
2695 "Basic face used to highlight warnings."
2697 :group
'basic-faces
)
2700 '((default :weight bold
)
2701 (((class color
) (min-colors 16) (background light
)) :foreground
"ForestGreen")
2702 (((class color
) (min-colors 88) (background dark
)) :foreground
"Green1")
2703 (((class color
) (min-colors 16) (background dark
)) :foreground
"Green")
2704 (((class color
)) :foreground
"green"))
2705 "Basic face used to indicate successful operation."
2707 :group
'basic-faces
)
2709 ;; Faces for TTY menus.
2710 (defface tty-menu-enabled-face
2712 :foreground
"yellow" :background
"blue" :weight bold
))
2713 "Face for displaying enabled items in TTY menus."
2714 :group
'basic-faces
)
2716 (defface tty-menu-disabled-face
2717 '((((class color
) (min-colors 16))
2718 :foreground
"lightgray" :background
"blue")
2720 :foreground
"white" :background
"blue"))
2721 "Face for displaying disabled items in TTY menus."
2722 :group
'basic-faces
)
2724 (defface tty-menu-selected-face
2725 '((t :background
"red"))
2726 "Face for displaying the currently selected item in TTY menus."
2727 :group
'basic-faces
)
2729 (defgroup paren-showing-faces nil
2730 "Faces used to highlight paren matches."
2731 :group
'paren-showing
2735 (defface show-paren-match
2736 '((((class color
) (background light
))
2737 :background
"turquoise") ; looks OK on tty (becomes cyan)
2738 (((class color
) (background dark
))
2739 :background
"steelblue3") ; looks OK on tty (becomes blue)
2740 (((background dark
) (min-colors 4))
2741 :background
"grey50")
2742 (((background light
) (min-colors 4))
2745 :inherit underline
))
2746 "Face used for a matching paren."
2747 :group
'paren-showing-faces
)
2749 (defface show-paren-mismatch
2750 '((((class color
)) (:foreground
"white" :background
"purple"))
2751 (t (:inverse-video t
)))
2752 "Face used for a mismatching paren."
2753 :group
'paren-showing-faces
)
2756 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2757 ;;; Manipulating font names.
2758 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2760 ;; This is here for compatibility with Emacs 20.2. For example,
2761 ;; international/fontset.el uses x-resolve-font-name. The following
2762 ;; functions are not used in the face implementation itself.
2764 (defvar x-font-regexp nil
)
2765 (defvar x-font-regexp-head nil
)
2766 (defvar x-font-regexp-weight nil
)
2767 (defvar x-font-regexp-slant nil
)
2769 (defconst x-font-regexp-weight-subnum
1)
2770 (defconst x-font-regexp-slant-subnum
2)
2771 (defconst x-font-regexp-swidth-subnum
3)
2772 (defconst x-font-regexp-adstyle-subnum
4)
2774 ;;; Regexps matching font names in "Host Portable Character Representation."
2779 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2780 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2781 (weight\? "\\([^-]*\\)") ; 1
2782 (slant "\\([ior]\\)") ; 2
2783 ; (slant\? "\\([ior?*]?\\)") ; 2
2784 (slant\? "\\([^-]?\\)") ; 2
2785 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2786 (swidth "\\([^-]*\\)") ; 3
2787 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2788 (adstyle "\\([^-]*\\)") ; 4
2789 (pixelsize "[0-9]+")
2790 (pointsize "[0-9][0-9]+")
2791 (resx "[0-9][0-9]+")
2792 (resy "[0-9][0-9]+")
2799 (purecopy (concat "\\`\\*?[-?*]"
2800 foundry - family - weight
\? - slant
\? - swidth - adstyle -
2801 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2802 registry - encoding
"\\*?\\'"
2804 (setq x-font-regexp-head
2805 (purecopy (concat "\\`[-?*]" foundry - family - weight
\? - slant
\?
2806 "\\([-*?]\\|\\'\\)")))
2807 (setq x-font-regexp-slant
(purecopy (concat - slant -
)))
2808 (setq x-font-regexp-weight
(purecopy (concat - weight -
)))
2812 (defun x-resolve-font-name (pattern &optional face frame
)
2813 "Return a font name matching PATTERN.
2814 All wildcards in PATTERN are instantiated.
2815 If PATTERN is nil, return the name of the frame's base font, which never
2817 Given optional arguments FACE and FRAME, return a font which is
2818 also the same size as FACE on FRAME, or fail."
2822 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2823 (let ((fonts (x-list-fonts pattern face frame
1)))
2826 (if (string-match-p "\\*" pattern
)
2827 (if (null (face-font face
))
2828 (error "No matching fonts are the same height as the frame default font")
2829 (error "No matching fonts are the same height as face `%s'" face
))
2830 (if (null (face-font face
))
2831 (error "Height of font `%s' doesn't match the frame default font"
2833 (error "Height of font `%s' doesn't match face `%s'"
2835 (error "No fonts match `%s'" pattern
)))
2837 (cdr (assq 'font
(frame-parameters (selected-frame))))))
2839 (defcustom font-list-limit
100
2840 "This variable is obsolete and has no effect."
2843 (make-obsolete-variable 'font-list-limit nil
"24.3")
2847 ;;; faces.el ends here