1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992-1996, 1998-2014 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (defcustom term-file-prefix
(purecopy "term/")
29 "If non-nil, Emacs startup performs terminal-specific initialization.
30 It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
32 You may set this variable to nil in your init file if you do not wish
33 the terminal-initialization file to be loaded."
34 :type
'(choice (const :tag
"No terminal-specific initialization" nil
)
35 (string :tag
"Name of directory with term files"))
38 (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")
101 ("courier" "CMU Typewriter Text" "fixed")
102 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
103 ("helv" "helvetica" "arial" "fixed")))
104 "Alist of alternative font family names.
105 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
106 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
108 :tag
"Alternative font families to try"
109 :type
'(repeat (repeat string
))
110 :group
'font-selection
111 :set
#'(lambda (symbol value
)
112 (set-default symbol value
)
113 (internal-set-alternative-font-family-alist value
)))
116 ;; This is defined originally in xfaces.c.
117 (defcustom face-font-registry-alternatives
118 (mapcar (lambda (arg) (mapcar 'purecopy arg
))
120 '(("iso8859-1" "ms-oemlatin")
121 ("gb2312.1980" "gb2312" "gbk" "gb18030")
122 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
123 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
124 ("muletibetan-2" "muletibetan-0"))
125 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
126 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
127 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
128 ("muletibetan-2" "muletibetan-0"))))
129 "Alist of alternative font registry names.
130 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
131 If fonts of registry REGISTRY can be loaded, font selection
132 tries to find a best matching font among all fonts of registry
133 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
134 :tag
"Alternative font registries to try"
135 :type
'(repeat (repeat string
))
137 :group
'font-selection
138 :set
#'(lambda (symbol value
)
139 (set-default symbol value
)
140 (internal-set-alternative-font-registry-alist value
)))
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144 ;;; Creation, copying.
145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
149 "Return a list of all defined faces."
150 (mapcar #'car face-new-frame-defaults
))
152 (defun make-face (face)
153 "Define a new face with name FACE, a symbol.
154 Do not call this directly from Lisp code; use `defface' instead.
156 If FACE is already known as a face, leave it unmodified. Return FACE."
157 (interactive (list (read-from-minibuffer
158 "Make face: " nil nil t
'face-name-history
)))
160 ;; Make frame-local faces (this also makes the global one).
161 (dolist (frame (frame-list))
162 (internal-make-lisp-face face frame
))
163 ;; Add the face to the face menu.
164 (when (fboundp 'facemenu-add-new-face
)
165 (facemenu-add-new-face face
))
166 ;; Define frame-local faces for all frames from X resources.
167 (make-face-x-resource-internal face
))
170 (defun make-empty-face (face)
171 "Define a new, empty face with name FACE.
172 Do not call this directly from Lisp code; use `defface' instead."
173 (interactive (list (read-from-minibuffer
174 "Make empty face: " nil nil t
'face-name-history
)))
177 (defun copy-face (old-face new-face
&optional frame new-frame
)
178 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
179 This function does not copy face customization data, so NEW-FACE
180 will not be made customizable. Most Lisp code should not call
181 this function; use `defface' with :inherit instead.
183 If NEW-FACE already exists as a face, modify it to be like
184 OLD-FACE. If NEW-FACE doesn't already exist, create it.
186 If the optional argument FRAME is a frame, change NEW-FACE on
187 FRAME only. If FRAME is t, copy the frame-independent default
188 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
189 the defaults as well as the faces on each existing frame.
191 If the optional fourth argument NEW-FRAME is given, copy the
192 information from face OLD-FACE on frame FRAME to NEW-FACE on
193 frame NEW-FRAME. In this case, FRAME must not be nil."
194 (let ((inhibit-quit t
))
198 (error "Copying face %s from all frames to one frame"
200 (make-empty-face new-face
)
201 (dolist (frame (frame-list))
202 (copy-face old-face new-face frame
))
203 (copy-face old-face new-face t
))
204 (make-empty-face new-face
)
205 (internal-copy-lisp-face old-face new-face frame new-frame
))
209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
210 ;;; Predicates, type checks.
211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
214 "Return non-nil if FACE is a face name; nil otherwise.
215 A face name can be a string or a symbol."
216 (internal-lisp-face-p face
))
219 (defun check-face (face)
220 "Signal an error if FACE doesn't name a face.
223 (error "Not a face: %s" face
))
227 ;; The ID returned is not to be confused with the internally used IDs
228 ;; of realized faces. The ID assigned to Lisp faces is used to
229 ;; support faces in display table entries.
231 (defun face-id (face &optional _frame
)
232 "Return the internal ID of face with name FACE.
233 If FACE is a face-alias, return the ID of the target face.
234 The optional argument FRAME is ignored, since the internal face ID
235 of a face name is the same for all frames."
238 (face-id (get face
'face-alias
))))
240 (defun face-equal (face1 face2
&optional frame
)
241 "Non-nil if faces FACE1 and FACE2 are equal.
242 Faces are considered equal if all their attributes are equal.
243 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
244 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
245 If FRAME is omitted or nil, use the selected frame."
246 (internal-lisp-face-equal-p face1 face2 frame
))
249 (defun face-differs-from-default-p (face &optional frame
)
250 "Return non-nil if FACE displays differently from the default face.
251 If the optional argument FRAME is given, report on face FACE in that frame.
252 If FRAME is t, report on the defaults for face FACE (for new frames).
253 If FRAME is omitted or nil, use the selected frame."
255 (delq :inherit
(mapcar 'car face-attribute-name-alist
)))
257 (while (and attrs
(not differs
))
258 (let* ((attr (pop attrs
))
259 (attr-val (face-attribute face attr frame t
)))
261 (not (eq attr-val
'unspecified
))
262 (display-supports-face-attributes-p (list attr attr-val
)
264 (setq differs attr
))))
268 (defun face-nontrivial-p (face &optional frame
)
269 "True if face FACE has some non-nil attribute.
270 If the optional argument FRAME is given, report on face FACE in that frame.
271 If FRAME is t, report on the defaults for face FACE (for new frames).
272 If FRAME is omitted or nil, use the selected frame."
273 (not (internal-lisp-face-empty-p face frame
)))
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278 ;;; Setting face attributes from X resources.
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
281 (defcustom face-x-resources
284 ;; FIXME; can we purecopy some of the conses too?
286 (cons (purecopy (car (cdr arg
))) (purecopy (cdr (cdr arg
))))))
287 '((:family
(".attributeFamily" .
"Face.AttributeFamily"))
288 (:foundry
(".attributeFoundry" .
"Face.AttributeFoundry"))
289 (:width
(".attributeWidth" .
"Face.AttributeWidth"))
290 (:height
(".attributeHeight" .
"Face.AttributeHeight"))
291 (:weight
(".attributeWeight" .
"Face.AttributeWeight"))
292 (:slant
(".attributeSlant" .
"Face.AttributeSlant"))
293 (:foreground
(".attributeForeground" .
"Face.AttributeForeground"))
295 (".attributeDistantForeground" .
"Face.AttributeDistantForeground"))
296 (:background
(".attributeBackground" .
"Face.AttributeBackground"))
297 (:overline
(".attributeOverline" .
"Face.AttributeOverline"))
298 (:strike-through
(".attributeStrikeThrough" .
"Face.AttributeStrikeThrough"))
299 (:box
(".attributeBox" .
"Face.AttributeBox"))
300 (:underline
(".attributeUnderline" .
"Face.AttributeUnderline"))
301 (:inverse-video
(".attributeInverse" .
"Face.AttributeInverse"))
303 (".attributeStipple" .
"Face.AttributeStipple")
304 (".attributeBackgroundPixmap" .
"Face.AttributeBackgroundPixmap"))
305 (:bold
(".attributeBold" .
"Face.AttributeBold"))
306 (:italic
(".attributeItalic" .
"Face.AttributeItalic"))
307 (:font
(".attributeFont" .
"Face.AttributeFont"))
308 (:inherit
(".attributeInherit" .
"Face.AttributeInherit"))))
309 "List of X resources and classes for face attributes.
310 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
311 the name of a face attribute, and each ENTRY is a cons of the form
312 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
313 X resource class for the attribute."
314 :type
'(repeat (cons symbol
(repeat (cons string string
))))
318 (declare-function internal-face-x-get-resource
"xfaces.c"
319 (resource class
&optional frame
))
321 (declare-function internal-set-lisp-face-attribute-from-resource
"xfaces.c"
322 (face attr value
&optional frame
))
324 (defun set-face-attribute-from-resource (face attribute resource class frame
)
325 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
326 Value is the attribute value specified by the resource, or nil
327 if not present. This function displays a message if the resource
328 specifies an invalid attribute."
329 (let* ((face-name (face-name face
))
330 (value (internal-face-x-get-resource (concat face-name resource
)
334 (internal-set-lisp-face-attribute-from-resource
335 face attribute
(downcase value
) frame
)
337 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
338 face-name frame attribute value
))))
342 (defun set-face-attributes-from-resources (face frame
)
343 "Set attributes of FACE from X resources for FRAME."
344 (when (memq (framep frame
) '(x w32
))
345 (dolist (definition face-x-resources
)
346 (let ((attribute (car definition
)))
347 (dolist (entry (cdr definition
))
348 (set-face-attribute-from-resource face attribute
(car entry
)
349 (cdr entry
) frame
))))))
352 (defun make-face-x-resource-internal (face &optional frame
)
353 "Fill frame-local FACE on FRAME from X resources.
354 FRAME nil or not specified means do it for all frames.
356 If `inhibit-x-resources' is non-nil, this function does nothing."
357 (unless inhibit-x-resources
358 (dolist (frame (if (null frame
) (frame-list) (list frame
)))
359 ;; `x-create-frame' already took care of correctly handling
360 ;; the reverse video case-- do _not_ touch the default face
361 (unless (and (eq face
'default
)
362 (frame-parameter frame
'reverse
))
363 (set-face-attributes-from-resources face frame
)))))
367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
368 ;;; Retrieving face attributes.
369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
371 (defun face-name (face)
372 "Return the name of face FACE."
373 (symbol-name (check-face face
)))
376 (defun face-all-attributes (face &optional frame
)
377 "Return an alist stating the attributes of FACE.
378 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
379 If FRAME is omitted or nil the value describes the default attributes,
380 but if you specify FRAME, the value describes the attributes
382 (mapcar (lambda (pair)
383 (let ((attr (car pair
)))
384 (cons attr
(face-attribute face attr
(or frame t
)))))
385 face-attribute-name-alist
))
387 (defun face-attribute (face attribute
&optional frame inherit
)
388 "Return the value of FACE's ATTRIBUTE on FRAME.
389 If the optional argument FRAME is given, report on face FACE in that frame.
390 If FRAME is t, report on the defaults for face FACE (for new frames).
391 If FRAME is omitted or nil, use the selected frame.
393 If INHERIT is nil, only attributes directly defined by FACE are considered,
394 so the return value may be `unspecified', or a relative value.
395 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
396 faces specified by its `:inherit' attribute; however the return value
397 may still be `unspecified' or relative.
398 If INHERIT is a face or a list of faces, then the result is further merged
399 with that face (or faces), until it becomes specified and absolute.
401 To ensure that the return value is always specified and absolute, use a
402 value of `default' for INHERIT; this will resolve any unspecified or
403 relative values by merging with the `default' face (which is always
404 completely specified)."
405 (let ((value (internal-get-lisp-face-attribute face attribute frame
)))
406 (when (and inherit
(face-attribute-relative-p attribute value
))
407 ;; VALUE is relative, so merge with inherited faces
408 (let ((inh-from (face-attribute face
:inherit frame
)))
409 (unless (or (null inh-from
) (eq inh-from
'unspecified
))
412 (face-attribute-merged-with attribute value inh-from frame
))
413 ;; The `inherit' attribute may point to non existent faces.
417 (face-attribute-relative-p attribute value
))
418 ;; We should merge with INHERIT as well
419 (setq value
(face-attribute-merged-with attribute value inherit frame
)))
422 (defun face-attribute-merged-with (attribute value faces
&optional frame
)
423 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
424 FACES may be either a single face or a list of faces.
425 \[This is an internal function.]"
426 (cond ((not (face-attribute-relative-p attribute value
))
431 (face-attribute-merged-with
433 (face-attribute-merged-with attribute value
(car faces
) frame
)
437 (merge-face-attribute attribute
439 (face-attribute faces attribute frame t
)))))
442 (defmacro face-attribute-specified-or
(value &rest body
)
443 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
444 (let ((temp (make-symbol "value")))
445 `(let ((,temp
,value
))
446 (if (not (eq ,temp
'unspecified
))
450 (defun face-foreground (face &optional frame inherit
)
451 "Return the foreground color name of FACE, or nil if unspecified.
452 If the optional argument FRAME is given, report on face FACE in that frame.
453 If FRAME is t, report on the defaults for face FACE (for new frames).
454 If FRAME is omitted or nil, use the selected frame.
456 If INHERIT is nil, only a foreground color directly defined by FACE is
457 considered, so the return value may be nil.
458 If INHERIT is t, and FACE doesn't define a foreground color, then any
459 foreground color that FACE inherits through its `:inherit' attribute
460 is considered as well; however the return value may still be nil.
461 If INHERIT is a face or a list of faces, then it is used to try to
462 resolve an unspecified foreground color.
464 To ensure that a valid color is always returned, use a value of
465 `default' for INHERIT; this will resolve any unspecified values by
466 merging with the `default' face (which is always completely specified)."
467 (face-attribute-specified-or (face-attribute face
:foreground frame inherit
)
470 (defun face-background (face &optional frame inherit
)
471 "Return the background color name of FACE, or nil if unspecified.
472 If the optional argument FRAME is given, report on face FACE in that frame.
473 If FRAME is t, report on the defaults for face FACE (for new frames).
474 If FRAME is omitted or nil, use the selected frame.
476 If INHERIT is nil, only a background color directly defined by FACE is
477 considered, so the return value may be nil.
478 If INHERIT is t, and FACE doesn't define a background color, then any
479 background color that FACE inherits through its `:inherit' attribute
480 is considered as well; however the return value may still be nil.
481 If INHERIT is a face or a list of faces, then it is used to try to
482 resolve an unspecified background color.
484 To ensure that a valid color is always returned, use a value of
485 `default' for INHERIT; this will resolve any unspecified values by
486 merging with the `default' face (which is always completely specified)."
487 (face-attribute-specified-or (face-attribute face
:background frame inherit
)
490 (defun face-stipple (face &optional frame inherit
)
491 "Return the stipple pixmap name of FACE, or nil if unspecified.
492 If the optional argument FRAME is given, report on face FACE in that frame.
493 If FRAME is t, report on the defaults for face FACE (for new frames).
494 If FRAME is omitted or nil, use the selected frame.
496 If INHERIT is nil, only a stipple directly defined by FACE is
497 considered, so the return value may be nil.
498 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
499 that FACE inherits through its `:inherit' attribute is considered as
500 well; however the return value may still be nil.
501 If INHERIT is a face or a list of faces, then it is used to try to
502 resolve an unspecified stipple.
504 To ensure that a valid stipple or nil is always returned, use a value of
505 `default' for INHERIT; this will resolve any unspecified values by merging
506 with the `default' face (which is always completely specified)."
507 (face-attribute-specified-or (face-attribute face
:stipple frame inherit
)
511 (defalias 'face-background-pixmap
'face-stipple
)
514 (defun face-underline-p (face &optional frame inherit
)
515 "Return non-nil if FACE specifies a non-nil underlining.
516 If the optional argument FRAME is given, report on face FACE in that frame.
517 If FRAME is t, report on the defaults for face FACE (for new frames).
518 If FRAME is omitted or nil, use the selected frame.
519 Optional argument INHERIT is passed to `face-attribute'."
520 (face-attribute-specified-or
521 (face-attribute face
:underline frame inherit
) nil
))
524 (defun face-inverse-video-p (face &optional frame inherit
)
525 "Return non-nil if FACE specifies a non-nil inverse-video.
526 If the optional argument FRAME is given, report on face FACE in that frame.
527 If FRAME is t, report on the defaults for face FACE (for new frames).
528 If FRAME is omitted or nil, use the selected frame.
529 Optional argument INHERIT is passed to `face-attribute'."
530 (eq (face-attribute face
:inverse-video frame inherit
) t
))
533 (defun face-bold-p (face &optional frame inherit
)
534 "Return non-nil if the font of FACE is bold on FRAME.
535 If the optional argument FRAME is given, report on face FACE in that frame.
536 If FRAME is t, report on the defaults for face FACE (for new frames).
537 If FRAME is omitted or nil, use the selected frame.
538 Optional argument INHERIT is passed to `face-attribute'.
539 Use `face-attribute' for finer control."
540 (let ((bold (face-attribute face
:weight frame inherit
)))
541 (memq bold
'(semi-bold bold extra-bold ultra-bold
))))
544 (defun face-italic-p (face &optional frame inherit
)
545 "Return non-nil if the font of FACE is italic on FRAME.
546 If the optional argument FRAME is given, report on face FACE in that frame.
547 If FRAME is t, report on the defaults for face FACE (for new frames).
548 If FRAME is omitted or nil, use the selected frame.
549 Optional argument INHERIT is passed to `face-attribute'.
550 Use `face-attribute' for finer control."
551 (let ((italic (face-attribute face
:slant frame inherit
)))
552 (memq italic
'(italic oblique
))))
556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
557 ;;; Face documentation.
558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
560 (defun face-documentation (face)
561 "Get the documentation string for FACE.
562 If FACE is a face-alias, get the documentation for the target face."
563 (let ((alias (get face
'face-alias
)))
565 (let ((doc (get alias
'face-documentation
)))
566 (format "%s is an alias for the face `%s'.%s" face alias
567 (if doc
(format "\n%s" doc
)
569 (get face
'face-documentation
))))
572 (defun set-face-documentation (face string
)
573 "Set the documentation string for FACE to STRING."
574 ;; Perhaps the text should go in DOC.
575 (put face
'face-documentation
(purecopy string
)))
578 (defalias 'face-doc-string
'face-documentation
)
579 (defalias 'set-face-doc-string
'set-face-documentation
)
583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
584 ;; Setting face attributes.
585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
588 (defun set-face-attribute (face frame
&rest args
)
589 "Set attributes of FACE on FRAME from ARGS.
590 This function overrides the face attributes specified by FACE's
591 face spec. It is mostly intended for internal use only.
593 If FRAME is nil, set the attributes for all existing frames, as
594 well as the default for new frames. If FRAME is t, change the
595 default for new frames only.
597 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a
598 valid face attribute name. All attributes can be set to
599 `unspecified'; this fact is not further mentioned below.
601 The following attributes are recognized:
605 VALUE must be a string specifying the font family
606 \(e.g. \"Monospace\") or a fontset.
610 VALUE must be a string specifying the font foundry,
611 e.g. ``adobe''. If a font foundry is specified, wild-cards `*'
616 VALUE specifies the relative proportionate width of the font to use.
617 It must be one of the symbols `ultra-condensed', `extra-condensed',
618 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
619 `extra-expanded', or `ultra-expanded'.
623 VALUE specifies the relative or absolute height of the font. An
624 absolute height is an integer, and specifies font height in units
625 of 1/10 pt. A relative height is either a floating point number,
626 which specifies a scaling factor for the underlying face height;
627 or a function that takes a single argument (the underlying face
628 height) and returns the new height. Note that for the `default'
629 face, you must specify an absolute height (since there is nothing
630 for it to be relative to).
634 VALUE specifies the weight of the font to use. It must be one of the
635 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
636 `semi-light', `light', `extra-light', `ultra-light'.
640 VALUE specifies the slant of the font to use. It must be one of the
641 symbols `italic', `oblique', `normal', `reverse-italic', or
644 `:foreground', `:background'
646 VALUE must be a color name, a string.
650 VALUE specifies whether characters in FACE should be underlined.
651 If VALUE is t, underline with foreground color of the face.
652 If VALUE is a string, underline with that color.
653 If VALUE is nil, explicitly don't underline.
655 Otherwise, VALUE must be a property list of the form:
657 `(:color COLOR :style STYLE)'.
659 COLOR can be a either a color name string or `foreground-color'.
660 STYLE can be either `line' or `wave'.
661 If a keyword/value pair is missing from the property list, a
662 default value will be used for the value.
663 The default value of COLOR is the foreground color of the face.
664 The default value of STYLE is `line'.
668 VALUE specifies whether characters in FACE should be overlined. If
669 VALUE is t, overline with foreground color of the face. If VALUE is a
670 string, overline with that color. If VALUE is nil, explicitly don't
675 VALUE specifies whether characters in FACE should be drawn with a line
676 striking through them. If VALUE is t, use the foreground color of the
677 face. If VALUE is a string, strike-through with that color. If VALUE
678 is nil, explicitly don't strike through.
682 VALUE specifies whether characters in FACE should have a box drawn
683 around them. If VALUE is nil, explicitly don't draw boxes. If
684 VALUE is t, draw a box with lines of width 1 in the foreground color
685 of the face. If VALUE is a string, the string must be a color name,
686 and the box is drawn in that color with a line width of 1. Otherwise,
687 VALUE must be a property list of the form `(:line-width WIDTH
688 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
689 the property list, a default value will be used for the value, as
690 specified below. WIDTH specifies the width of the lines to draw; it
691 defaults to 1. If WIDTH is negative, the absolute value is the width
692 of the lines, and draw top/bottom lines inside the characters area,
693 not around it. COLOR is the name of the color to draw in, default is
694 the foreground color of the face for simple boxes, and the background
695 color of the face for 3D boxes. STYLE specifies whether a 3D box
696 should be draw. If STYLE is `released-button', draw a box looking
697 like a released 3D button. If STYLE is `pressed-button' draw a box
698 that appears like a pressed button. If STYLE is nil, the default if
699 the property list doesn't contain a style specification, draw a 2D
704 VALUE specifies whether characters in FACE should be displayed in
705 inverse video. VALUE must be one of t or nil.
709 If VALUE is a string, it must be the name of a file of pixmap data.
710 The directories listed in the `x-bitmap-file-path' variable are
711 searched. Alternatively, VALUE may be a list of the form (WIDTH
712 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
713 is a string containing the raw bits of the bitmap. VALUE nil means
714 explicitly don't use a stipple pattern.
716 For convenience, attributes `:family', `:foundry', `:width',
717 `:height', `:weight', and `:slant' may also be set in one step
722 Set font-related face attributes from VALUE. VALUE must be a
723 valid font name or font object. Setting this attribute will also
724 set the `:family', `:foundry', `:width', `:height', `:weight',
725 and `:slant' attributes.
729 VALUE is the name of a face from which to inherit attributes, or
730 a list of face names. Attributes from inherited faces are merged
731 into the face like an underlying face would be, with higher
732 priority than underlying faces.
734 For backward compatibility, the keywords `:bold' and `:italic'
735 can be used to specify weight and slant respectively. This usage
736 is considered obsolete. For these two keywords, the VALUE must
737 be either t or nil. A value of t for `:bold' is equivalent to
738 setting `:weight' to `bold', and a value of t for `:italic' is
739 equivalent to setting `:slant' to `italic'. But if `:weight' is
740 specified in the face spec, `:bold' is ignored, and if `:slant'
741 is specified, `:italic' is ignored."
742 (setq args
(purecopy args
))
743 (let ((where (if (null frame
) 0 frame
))
746 ;; If we set the new-frame defaults, this face is modified outside Custom.
747 (if (memq where
'(0 t
))
748 (put (or (get face
'face-alias
) face
) 'face-modified t
))
749 ;; If family and/or foundry are specified, set it first. Certain
750 ;; face attributes, e.g. :weight semi-condensed, are not supported
751 ;; in every font. See bug#1127.
753 (cond ((eq (car spec
) :family
)
754 (setq family
(cadr spec
)))
755 ((eq (car spec
) :foundry
)
756 (setq foundry
(cadr spec
))))
757 (setq spec
(cddr spec
)))
758 (when (or family foundry
)
759 (when (and (stringp family
)
760 (string-match "\\([^-]*\\)-\\([^-]*\\)" family
))
762 (setq foundry
(match-string 1 family
)))
763 (setq family
(match-string 2 family
)))
764 (when (or (stringp family
) (eq family
'unspecified
))
765 (internal-set-lisp-face-attribute face
:family
(purecopy family
)
767 (when (or (stringp foundry
) (eq foundry
'unspecified
))
768 (internal-set-lisp-face-attribute face
:foundry
(purecopy foundry
)
771 (unless (memq (car args
) '(:family
:foundry
))
772 (internal-set-lisp-face-attribute face
(car args
)
773 (purecopy (cadr args
))
775 (setq args
(cddr args
)))))
777 (defun make-face-bold (face &optional frame _noerror
)
778 "Make the font of FACE be bold, if possible.
779 FRAME nil or not specified means change face on all frames.
780 Argument NOERROR is ignored and retained for compatibility.
781 Use `set-face-attribute' for finer control of the font weight."
782 (interactive (list (read-face-name "Make which face bold"
784 (set-face-attribute face frame
:weight
'bold
))
787 (defun make-face-unbold (face &optional frame _noerror
)
788 "Make the font of FACE be non-bold, if possible.
789 FRAME nil or not specified means change face on all frames.
790 Argument NOERROR is ignored and retained for compatibility."
791 (interactive (list (read-face-name "Make which face non-bold"
793 (set-face-attribute face frame
:weight
'normal
))
796 (defun make-face-italic (face &optional frame _noerror
)
797 "Make the font of FACE be italic, if possible.
798 FRAME nil or not specified means change face on all frames.
799 Argument NOERROR is ignored and retained for compatibility.
800 Use `set-face-attribute' for finer control of the font slant."
801 (interactive (list (read-face-name "Make which face italic"
803 (set-face-attribute face frame
:slant
'italic
))
806 (defun make-face-unitalic (face &optional frame _noerror
)
807 "Make the font of FACE be non-italic, if possible.
808 FRAME nil or not specified means change face on all frames.
809 Argument NOERROR is ignored and retained for compatibility."
810 (interactive (list (read-face-name "Make which face non-italic"
812 (set-face-attribute face frame
:slant
'normal
))
815 (defun make-face-bold-italic (face &optional frame _noerror
)
816 "Make the font of FACE be bold and italic, if possible.
817 FRAME nil or not specified means change face on all frames.
818 Argument NOERROR is ignored and retained for compatibility.
819 Use `set-face-attribute' for finer control of font weight and slant."
820 (interactive (list (read-face-name "Make which face bold-italic"
822 (set-face-attribute face frame
:weight
'bold
:slant
'italic
))
825 (defun set-face-font (face font
&optional frame
)
826 "Change font-related attributes of FACE to those of FONT (a string).
827 FRAME nil or not specified means change face on all frames.
828 This sets the attributes `:family', `:foundry', `:width',
829 `:height', `:weight', and `:slant'. When called interactively,
830 prompt for the face and font."
831 (interactive (read-face-and-attribute :font
))
832 (set-face-attribute face frame
:font font
))
835 ;; Implementation note: Emulating gray background colors with a
836 ;; stipple pattern is now part of the face realization process, and is
837 ;; done in C depending on the frame on which the face is realized.
839 (defun set-face-background (face color
&optional frame
)
840 "Change the background color of face FACE to COLOR (a string).
841 FRAME nil or not specified means change face on all frames.
842 COLOR can be a system-defined color name (see `list-colors-display')
843 or a hex spec of the form #RRGGBB.
844 When called interactively, prompts for the face and color."
845 (interactive (read-face-and-attribute :background
))
846 (set-face-attribute face frame
:background
(or color
'unspecified
)))
849 (defun set-face-foreground (face color
&optional frame
)
850 "Change the foreground color of face FACE to COLOR (a string).
851 FRAME nil or not specified means change face on all frames.
852 COLOR can be a system-defined color name (see `list-colors-display')
853 or a hex spec of the form #RRGGBB.
854 When called interactively, prompts for the face and color."
855 (interactive (read-face-and-attribute :foreground
))
856 (set-face-attribute face frame
:foreground
(or color
'unspecified
)))
859 (defun set-face-stipple (face stipple
&optional frame
)
860 "Change the stipple pixmap of face FACE to STIPPLE.
861 FRAME nil or not specified means change face on all frames.
862 STIPPLE should be a string, the name of a file of pixmap data.
863 The directories listed in the `x-bitmap-file-path' variable are searched.
865 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
866 where WIDTH and HEIGHT are the size in pixels,
867 and DATA is a string, containing the raw bits of the bitmap."
868 (interactive (read-face-and-attribute :stipple
))
869 (set-face-attribute face frame
:stipple
(or stipple
'unspecified
)))
872 (defun set-face-underline (face underline
&optional frame
)
873 "Specify whether face FACE is underlined.
874 UNDERLINE nil means FACE explicitly doesn't underline.
875 UNDERLINE t means FACE underlines with its foreground color.
876 If UNDERLINE is a string, underline with that color.
878 UNDERLINE may also be a list of the form (:color COLOR :style STYLE),
879 where COLOR is a string or `foreground-color', and STYLE is either
880 `line' or `wave'. :color may be omitted, which means to use the
881 foreground color. :style may be omitted, which means to use a line.
883 FRAME nil or not specified means change face on all frames.
884 Use `set-face-attribute' to ``unspecify'' underlining."
885 (interactive (read-face-and-attribute :underline
))
886 (set-face-attribute face frame
:underline underline
))
888 (define-obsolete-function-alias 'set-face-underline-p
889 'set-face-underline
"24.3")
892 (defun set-face-inverse-video (face inverse-video-p
&optional frame
)
893 "Specify whether face FACE is in inverse video.
894 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
895 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
896 FRAME nil or not specified means change face on all frames.
897 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
899 (let ((list (read-face-and-attribute :inverse-video
)))
900 (list (car list
) (if (cadr list
) t
))))
901 (set-face-attribute face frame
:inverse-video inverse-video-p
))
903 (define-obsolete-function-alias 'set-face-inverse-video-p
904 'set-face-inverse-video
"24.4")
906 (defun set-face-bold (face bold-p
&optional frame
)
907 "Specify whether face FACE is bold.
908 BOLD-P non-nil means FACE should explicitly display bold.
909 BOLD-P nil means FACE should explicitly display non-bold.
910 FRAME nil or not specified means change face on all frames.
911 Use `set-face-attribute' or `modify-face' for finer control."
913 (make-face-unbold face frame
)
914 (make-face-bold face frame
)))
916 (define-obsolete-function-alias 'set-face-bold-p
'set-face-bold
"24.4")
919 (defun set-face-italic (face italic-p
&optional frame
)
920 "Specify whether face FACE is italic.
921 ITALIC-P non-nil means FACE should explicitly display italic.
922 ITALIC-P nil means FACE should explicitly display non-italic.
923 FRAME nil or not specified means change face on all frames.
924 Use `set-face-attribute' or `modify-face' for finer control."
926 (make-face-unitalic face frame
)
927 (make-face-italic face frame
)))
929 (define-obsolete-function-alias 'set-face-italic-p
'set-face-italic
"24.4")
932 (defalias 'set-face-background-pixmap
'set-face-stipple
)
935 (defun invert-face (face &optional frame
)
936 "Swap the foreground and background colors of FACE.
937 If FRAME is omitted or nil, it means change face on all frames.
938 If FACE specifies neither foreground nor background color,
939 set its foreground and background to the background and foreground
940 of the default face. Value is FACE."
941 (interactive (list (read-face-name "Invert face" (face-at-point t
))))
942 (let ((fg (face-attribute face
:foreground frame
))
943 (bg (face-attribute face
:background frame
)))
944 (if (not (and (eq fg
'unspecified
) (eq bg
'unspecified
)))
945 (set-face-attribute face frame
:foreground bg
:background fg
)
946 (set-face-attribute face frame
948 (face-attribute 'default
:background frame
)
950 (face-attribute 'default
:foreground frame
))))
954 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
955 ;;; Interactively modifying faces.
956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
958 (defvar crm-separator
) ; from crm.el
960 (defun read-face-name (prompt &optional default multiple
)
961 "Read one or more face names, prompting with PROMPT.
962 PROMPT should not end in a space or a colon.
964 Return DEFAULT if the user enters the empty string.
965 If DEFAULT is non-nil, it should be a single face or a list of face names
966 \(symbols or strings). In the latter case, return the `car' of DEFAULT
967 \(if MULTIPLE is nil, see below), or DEFAULT (if MULTIPLE is non-nil).
969 If MULTIPLE is non-nil, this function uses `completing-read-multiple'
970 to read multiple faces with \"[ \\t]*,[ \\t]*\" as the separator regexp
971 and it returns a list of face names. Otherwise, it reads and returns
973 (if (and default
(not (stringp default
)))
975 (cond ((symbolp default
)
976 (symbol-name default
))
978 (mapconcat (lambda (f) (if (symbolp f
) (symbol-name f
) f
))
980 ;; If we only want one, and the default is more than one,
981 ;; discard the unwanted ones.
982 (t (symbol-name (car default
))))))
983 (when (and default
(not multiple
))
985 ;; For compatibility with `completing-read-multiple' use `crm-separator'
986 ;; to define DEFAULT if MULTIPLE is nil.
987 (setq default
(car (split-string default crm-separator t
))))
989 (let ((prompt (if default
990 (format "%s (default `%s'): " prompt default
)
991 (format "%s: " prompt
)))
992 aliasfaces nonaliasfaces faces
)
993 ;; Build up the completion tables.
994 (mapatoms (lambda (s)
996 (if (get s
'face-alias
)
997 (push (symbol-name s
) aliasfaces
)
998 (push (symbol-name s
) nonaliasfaces
)))))
1001 (dolist (face (completing-read-multiple
1003 (completion-table-in-turn nonaliasfaces aliasfaces
)
1004 nil t nil
'face-name-history default
))
1005 ;; Ignore elements that are not faces
1006 ;; (for example, because DEFAULT was "all faces")
1007 (if (facep face
) (push (intern face
) faces
)))
1009 (let ((face (completing-read
1011 (completion-table-in-turn nonaliasfaces aliasfaces
)
1012 nil t nil
'face-name-history default
)))
1013 (if (facep face
) (intern face
))))))
1015 ;; Not defined without X, but behind window-system test.
1016 (defvar x-bitmap-file-path
)
1018 (defun face-valid-attribute-values (attribute &optional frame
)
1019 "Return valid values for face attribute ATTRIBUTE.
1020 The optional argument FRAME is used to determine available fonts
1021 and colors. If it is nil or not specified, the selected frame is used.
1022 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
1023 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1028 (if (window-system frame
)
1029 (mapcar (lambda (x) (cons x x
))
1031 ;; Only one font on TTYs.
1032 (list (cons "default" "default"))))
1036 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1039 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1042 (mapcar #'(lambda (x) (cons (symbol-name (aref x
1)) (aref x
1)))
1045 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1046 (internal-lisp-face-attribute-values attribute
)))
1047 ((or `:underline
`:overline
`:strike-through
`:box
)
1048 (if (window-system frame
)
1049 (nconc (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1050 (internal-lisp-face-attribute-values attribute
))
1051 (mapcar #'(lambda (c) (cons c c
))
1052 (defined-colors frame
)))
1053 (mapcar #'(lambda (x) (cons (symbol-name x
) x
))
1054 (internal-lisp-face-attribute-values attribute
))))
1055 ((or `:foreground
`:background
)
1056 (mapcar #'(lambda (c) (cons c c
))
1057 (defined-colors frame
)))
1061 (and (memq (window-system frame
) '(x ns
)) ; No stipple on w32
1064 (mapcar (lambda (dir)
1065 (and (file-readable-p dir
)
1066 (file-directory-p dir
)
1067 (directory-files dir
)))
1068 x-bitmap-file-path
)))))
1070 (cons '("none" . nil
)
1071 (mapcar #'(lambda (c) (cons (symbol-name c
) c
))
1074 (error "Internal error")))))
1075 (if (and (listp valid
) (not (memq attribute
'(:inherit
))))
1076 (nconc (list (cons "unspecified" 'unspecified
)) valid
)
1080 (defconst face-attribute-name-alist
1081 '((:family .
"font family")
1082 (:foundry .
"font foundry")
1083 (:width .
"character set width")
1084 (:height .
"height in 1/10 pt")
1085 (:weight .
"weight")
1087 (:underline .
"underline")
1088 (:overline .
"overline")
1089 (:strike-through .
"strike-through")
1091 (:inverse-video .
"inverse-video display")
1092 (:foreground .
"foreground color")
1093 (:background .
"background color")
1094 (:stipple .
"background stipple")
1095 (:inherit .
"inheritance"))
1096 "An alist of descriptive names for face attributes.
1097 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1098 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1099 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1102 (defun face-descriptive-attribute-name (attribute)
1103 "Return a descriptive name for ATTRIBUTE."
1104 (cdr (assq attribute face-attribute-name-alist
)))
1107 (defun face-read-string (face default name
&optional completion-alist
)
1108 "Interactively read a face attribute string value.
1109 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1110 default string to return if no new value is entered. NAME is a
1111 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1112 alist of valid values, if non-nil.
1114 Entering nothing accepts the default string DEFAULT.
1115 Value is the new attribute value."
1116 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1117 ;; each word in a string separately).
1118 (setq name
(concat (upcase (substring name
0 1)) (substring name
1)))
1119 (let* ((completion-ignore-case t
)
1120 (value (completing-read
1122 (format "%s for face `%s' (default %s): "
1124 (format "%s for face `%s': " name face
))
1125 completion-alist nil nil nil nil default
)))
1126 (if (equal value
"") default value
)))
1129 (defun face-read-integer (face default name
)
1130 "Interactively read an integer face attribute value.
1131 FACE is the face whose attribute is read. DEFAULT is the default
1132 value to return if no new value is entered. NAME is a descriptive
1133 name of the attribute for prompting. Value is the new attribute value."
1135 (face-read-string face
1136 (format "%s" default
)
1138 (list (cons "unspecified" 'unspecified
)))))
1139 (cond ((equal new-value
"unspecified")
1141 ((member new-value
'("unspecified-fg" "unspecified-bg"))
1144 (string-to-number new-value
)))))
1147 ;; FIXME this does allow you to enter the list forms of :box,
1148 ;; :stipple, or :underline, because face-valid-attribute-values does
1149 ;; not return those forms.
1150 (defun read-face-attribute (face attribute
&optional frame
)
1151 "Interactively read a new value for FACE's ATTRIBUTE.
1152 Optional argument FRAME nil or unspecified means read an attribute value
1153 of a global face. Value is the new attribute value."
1154 (let* ((old-value (face-attribute face attribute frame
))
1155 (attribute-name (face-descriptive-attribute-name attribute
))
1156 (valid (face-valid-attribute-values attribute frame
))
1158 ;; Represent complex attribute values as strings by printing them
1159 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1160 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1161 ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'.
1162 (and (memq attribute
'(:box
:stipple
:underline
))
1163 (or (consp old-value
)
1164 (vectorp old-value
))
1165 (setq old-value
(prin1-to-string old-value
)))
1166 (cond ((listp valid
)
1168 (or (car (rassoc old-value valid
))
1169 (format "%s" old-value
))))
1171 (face-read-string face default attribute-name valid
))
1172 (if (equal new-value default
)
1173 ;; Nothing changed, so don't bother with all the stuff
1174 ;; below. In particular, this avoids a non-tty color
1175 ;; from being canonicalized for a tty when the user
1176 ;; just uses the default.
1177 (setq new-value old-value
)
1178 ;; Terminal frames can support colors that don't appear
1179 ;; explicitly in VALID, using color approximation code
1180 ;; in tty-colors.el.
1181 (when (and (memq attribute
'(:foreground
:background
))
1182 (not (memq (window-system frame
) '(x w32 ns
)))
1183 (not (member new-value
1185 "unspecified-fg" "unspecified-bg"))))
1186 (setq new-value
(car (tty-color-desc new-value frame
))))
1187 (when (assoc new-value valid
)
1188 (setq new-value
(cdr (assoc new-value valid
)))))))
1189 ((eq valid
'integerp
)
1190 (setq new-value
(face-read-integer face old-value attribute-name
)))
1191 (t (error "Internal error")))
1192 ;; Convert stipple and box value text we read back to a list or
1193 ;; vector if it looks like one. This makes the assumption that a
1194 ;; pixmap file name won't start with an open-paren.
1195 (and (memq attribute
'(:stipple
:box
:underline
))
1197 (string-match-p "^[[(]" new-value
)
1198 (setq new-value
(read new-value
)))
1201 (declare-function fontset-list
"fontset.c" ())
1202 (declare-function x-list-fonts
"xfaces.c"
1203 (pattern &optional face frame maximum width
))
1205 (defun read-face-font (face &optional frame
)
1206 "Read the name of a font for FACE on FRAME.
1207 If optional argument FRAME is nil or omitted, use the selected frame."
1208 (let ((completion-ignore-case t
))
1209 (completing-read (format "Set font attributes of face `%s' from font: " face
)
1210 (append (fontset-list) (x-list-fonts "*" nil frame
)))))
1213 (defun read-all-face-attributes (face &optional frame
)
1214 "Interactively read all attributes for FACE.
1215 If optional argument FRAME is nil or omitted, use the selected frame.
1216 Value is a property list of attribute names and new values."
1218 (dolist (attribute face-attribute-name-alist result
)
1219 (setq result
(cons (car attribute
)
1220 (cons (read-face-attribute face
(car attribute
) frame
)
1223 (defun modify-face (&optional face foreground background stipple
1224 bold-p italic-p underline inverse-p frame
)
1225 "Modify attributes of faces interactively.
1226 If optional argument FRAME is nil or omitted, modify the face used
1227 for newly created frame, i.e. the global face.
1228 For non-interactive use, `set-face-attribute' is preferred.
1229 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1230 and the face and its settings are obtained by querying the user."
1233 (set-face-attribute face frame
1234 :foreground
(or foreground
'unspecified
)
1235 :background
(or background
'unspecified
)
1237 :weight
(if bold-p
'bold
'normal
)
1238 :slant
(if italic-p
'italic
'normal
)
1239 :underline underline
1240 :inverse-video inverse-p
)
1241 (setq face
(read-face-name "Modify face" (face-at-point t
)))
1242 (apply #'set-face-attribute face frame
1243 (read-all-face-attributes face frame
))))
1245 (defun read-face-and-attribute (attribute &optional frame
)
1246 "Read face name and face attribute value.
1247 ATTRIBUTE is the attribute whose new value is read.
1248 FRAME nil or unspecified means read attribute value of global face.
1249 Value is a list (FACE NEW-VALUE) where FACE is the face read
1250 \(a symbol), and NEW-VALUE is value read."
1251 (cond ((eq attribute
:font
)
1252 (let* ((prompt "Set font-related attributes of face")
1253 (face (read-face-name prompt
(face-at-point t
)))
1254 (font (read-face-font face frame
)))
1257 (let* ((attribute-name (face-descriptive-attribute-name attribute
))
1258 (prompt (format "Set %s of face" attribute-name
))
1259 (face (read-face-name prompt
(face-at-point t
)))
1260 (new-value (read-face-attribute face attribute frame
)))
1261 (list face new-value
)))))
1265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1269 (defconst list-faces-sample-text
1270 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1271 "Text string to display as the sample text for `list-faces-display'.")
1274 ;; The name list-faces would be more consistent, but let's avoid a
1275 ;; conflict with Lucid, which uses that name differently.
1277 (defvar help-xref-stack
)
1278 (defun list-faces-display (&optional regexp
)
1279 "List all faces, using the same sample text in each.
1280 The sample text is a string that comes from the variable
1281 `list-faces-sample-text'.
1283 If REGEXP is non-nil, list only those faces with names matching
1284 this regular expression. When called interactively with a prefix
1285 argument, prompt for a regular expression using `read-regexp'."
1286 (interactive (list (and current-prefix-arg
1287 (read-regexp "List faces matching regexp"))))
1288 (let ((all-faces (zerop (length regexp
)))
1289 (frame (selected-frame))
1292 disp-frame window face-name
)
1293 ;; We filter and take the max length in one pass
1297 (let ((s (symbol-name f
)))
1298 (when (or all-faces
(string-match-p regexp s
))
1299 (setq max-length
(max (length s
) max-length
))
1301 (sort (face-list) #'string-lessp
))))
1303 (error "No faces matching \"%s\"" regexp
))
1304 (setq max-length
(1+ max-length
)
1305 line-format
(format "%%-%ds" max-length
))
1306 (with-help-window "*Faces*"
1307 (with-current-buffer standard-output
1308 (setq truncate-lines t
)
1310 (substitute-command-keys
1312 "\\<help-mode-map>Use "
1313 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1314 "\\[help-follow] on a face name to customize it\n"
1315 "or on its sample text for a description of the face.\n\n")))
1316 (setq help-xref-stack nil
)
1317 (dolist (face faces
)
1318 (setq face-name
(symbol-name face
))
1319 (insert (format line-format face-name
))
1320 ;; Hyperlink to a customization buffer for the face. Using
1321 ;; the help xref mechanism may not be the best way.
1324 (search-backward face-name
)
1325 (setq help-xref-stack-item
`(list-faces-display ,regexp
))
1326 (help-xref-button 0 'help-customize-face face
)))
1328 (line-beg (line-beginning-position)))
1329 (insert list-faces-sample-text
)
1330 ;; Hyperlink to a help buffer for the face.
1333 (search-backward list-faces-sample-text
)
1334 (help-xref-button 0 'help-face face
)))
1336 (put-text-property beg
(1- (point)) 'face face
)
1337 ;; Make all face commands default to the proper face
1338 ;; anywhere in the line.
1339 (put-text-property line-beg
(1- (point)) 'read-face-name face
)
1340 ;; If the sample text has multiple lines, line up all of them.
1344 (insert-char ?\s max-length
)
1346 (goto-char (point-min))))
1347 ;; If the *Faces* buffer appears in a different frame,
1348 ;; copy all the face definitions from FRAME,
1349 ;; so that the display will reflect the frame that was selected.
1350 (setq window
(get-buffer-window (get-buffer "*Faces*") t
))
1351 (setq disp-frame
(if window
(window-frame window
)
1352 (car (frame-list))))
1353 (or (eq frame disp-frame
)
1354 (dolist (face (face-list))
1355 (copy-face face face frame disp-frame
)))))
1358 (defun describe-face (face &optional frame
)
1359 "Display the properties of face FACE on FRAME.
1360 Interactively, FACE defaults to the faces of the character after point
1361 and FRAME defaults to the selected frame.
1363 If the optional argument FRAME is given, report on face FACE in that frame.
1364 If FRAME is t, report on the defaults for face FACE (for new frames).
1365 If FRAME is omitted or nil, use the selected frame."
1366 (interactive (list (read-face-name "Describe face"
1367 (or (face-at-point t
) 'default
)
1369 (let* ((attrs '((:family .
"Family")
1370 (:foundry .
"Foundry")
1372 (:height .
"Height")
1373 (:weight .
"Weight")
1375 (:foreground .
"Foreground")
1376 (:distant-foreground .
"DistantForeground")
1377 (:background .
"Background")
1378 (:underline .
"Underline")
1379 (:overline .
"Overline")
1380 (:strike-through .
"Strike-through")
1382 (:inverse-video .
"Inverse")
1383 (:stipple .
"Stipple")
1385 (:fontset .
"Fontset")
1386 (:inherit .
"Inherit")))
1387 (max-width (apply #'max
(mapcar #'(lambda (x) (length (cdr x
)))
1389 (help-setup-xref (list #'describe-face face
)
1390 (called-interactively-p 'interactive
))
1392 (setq face
'default
))
1393 (if (not (listp face
))
1394 (setq face
(list face
)))
1395 (with-help-window (help-buffer)
1396 (with-current-buffer standard-output
1398 (if (stringp f
) (setq f
(intern f
)))
1399 ;; We may get called for anonymous faces (i.e., faces
1400 ;; expressed using prop-value plists). Those can't be
1401 ;; usefully customized, so ignore them.
1403 (insert "Face: " (symbol-name f
))
1405 (insert " undefined face.\n")
1406 (let ((customize-label "customize this face")
1408 (insert (concat " (" (propertize "sample" 'font-lock-face f
) ")"))
1409 (princ (concat " (" customize-label
")\n"))
1410 ;; FIXME not sure how much of this belongs here, and
1411 ;; how much in `face-documentation'. The latter is
1412 ;; not used much, but needs to return nil for
1413 ;; undocumented faces.
1414 (let ((alias (get f
'face-alias
))
1420 (format "\n %s is an alias for the face `%s'.\n%s"
1422 (if (setq obsolete
(get f
'obsolete-face
))
1423 (format " This face is obsolete%s; use `%s' instead.\n"
1424 (if (stringp obsolete
)
1425 (format " since %s" obsolete
)
1429 (insert "\nDocumentation:\n"
1430 (or (face-documentation face
)
1431 "Not documented as a face.")
1433 (with-current-buffer standard-output
1436 (concat "\\(" customize-label
"\\)") nil t
)
1437 (help-xref-button 1 'help-customize-face f
)))
1438 (setq file-name
(find-lisp-object-file-name f
'defface
))
1440 (princ "Defined in `")
1441 (princ (file-name-nondirectory file-name
))
1443 ;; Make a hyperlink to the library.
1445 (re-search-backward "`\\([^`']+\\)'" nil t
)
1446 (help-xref-button 1 'help-face-def f file-name
))
1451 (let ((attr (face-attribute f
(car a
) frame
)))
1452 (insert (make-string (- max-width
(length (cdr a
))) ?\s
)
1453 (cdr a
) ": " (format "%s" attr
))
1454 (if (and (eq (car a
) :inherit
)
1455 (not (eq attr
'unspecified
)))
1456 ;; Make a hyperlink to the parent face.
1458 (re-search-backward ": \\([^:]+\\)" nil t
)
1459 (help-xref-button 1 'help-face attr
)))
1464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1465 ;;; Face specifications (defface).
1466 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1468 ;; Parameter FRAME Is kept for call compatibility to with previous
1469 ;; face implementation.
1471 (defun face-attr-construct (face &optional _frame
)
1472 "Return a `defface'-style attribute list for FACE.
1473 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1474 face attributes of FACE where ATTRIBUTE is the attribute name and
1475 VALUE is the specified value of that attribute.
1476 Argument FRAME is ignored and retained for compatibility."
1478 (dolist (entry face-attribute-name-alist result
)
1479 (let* ((attribute (car entry
))
1480 (value (face-attribute face attribute
)))
1481 (unless (eq value
'unspecified
)
1482 (setq result
(nconc (list attribute value
) result
)))))))
1485 (defun face-spec-set-match-display (display frame
)
1486 "Non-nil if DISPLAY matches FRAME.
1487 DISPLAY is part of a spec such as can be used in `defface'.
1488 If FRAME is nil, the current FRAME is used."
1489 (let* ((conjuncts display
)
1490 conjunct req options
1491 ;; t means we have succeeded against all the conjuncts in
1492 ;; DISPLAY that have been tested so far.
1494 (if (eq conjuncts t
)
1495 (setq conjuncts nil
))
1496 (while (and conjuncts match
)
1497 (setq conjunct
(car conjuncts
)
1498 conjuncts
(cdr conjuncts
)
1500 options
(cdr conjunct
)
1501 match
(cond ((eq req
'type
)
1502 (or (memq (window-system frame
) options
)
1503 (and (memq 'graphic options
)
1504 (memq (window-system frame
) '(x w32 ns
)))
1505 ;; FIXME: This should be revisited to use
1506 ;; display-graphic-p, provided that the
1507 ;; color selection depends on the number
1508 ;; of supported colors, and all defface's
1509 ;; are changed to look at number of colors
1510 ;; instead of (type graphic) etc.
1511 (if (null (window-system frame
))
1513 (or (and (memq 'motif options
)
1515 (and (memq 'gtk options
)
1517 (and (memq 'lucid options
)
1518 (featurep 'x-toolkit
)
1519 (not (featurep 'motif
))
1520 (not (featurep 'gtk
)))
1521 (and (memq 'x-toolkit options
)
1522 (featurep 'x-toolkit
))))))
1523 ((eq req
'min-colors
)
1524 (>= (display-color-cells frame
) (car options
)))
1526 (memq (frame-parameter frame
'display-type
) options
))
1527 ((eq req
'background
)
1528 (memq (frame-parameter frame
'background-mode
)
1531 (display-supports-face-attributes-p options frame
))
1532 (t (error "Unknown req `%S' with options `%S'"
1537 (defun face-spec-choose (spec &optional frame no-match-retval
)
1538 "Return the proper attributes for FRAME, out of SPEC.
1540 If no match is found or SPEC is nil, return nil, unless NO-MATCH-RETVAL
1541 is given, in which case return its value instead."
1543 (setq frame
(selected-frame)))
1545 result defaults match-found
)
1547 (let* ((entry (pop tail
))
1548 (display (car entry
))
1551 ;; Get the attributes as actually specified by this alternative.
1553 (if (null (cdr attrs
)) ;; was (listp (car attrs))
1554 ;; Old-style entry, the attribute list is the
1559 ;; If the condition is `default', that sets the default
1560 ;; for following conditions.
1561 (if (eq display
'default
)
1562 (setq defaults thisval
)
1563 ;; Otherwise, if it matches, use it.
1564 (when (face-spec-set-match-display display frame
)
1565 (setq result thisval
1568 ;; If defaults have been found, it's safe to just append those to the result
1569 ;; list (which at this point will be either nil or contain actual specs) and
1570 ;; return it to the caller. Since there will most definitely be something to
1571 ;; return in this case, there's no need to know/check if a match was found.
1573 (append result defaults
)
1579 (defun face-spec-reset-face (face &optional frame
)
1580 "Reset all attributes of FACE on FRAME to unspecified."
1581 (apply 'set-face-attribute face frame
1582 (if (eq face
'default
)
1583 ;; For the default face, avoid making any attribute
1584 ;; unspecified. Instead, set attributes to default values
1585 ;; (see also realize_default_face in xfaces.c).
1587 '(:underline nil
:overline nil
:strike-through nil
1588 :box nil
:inverse-video nil
:stipple nil
:inherit nil
)
1589 ;; `display-graphic-p' is unavailable when running
1590 ;; temacs, prior to loading frame.el.
1591 (when (fboundp 'display-graphic-p
)
1592 (unless (display-graphic-p frame
)
1593 `(:family
"default" :foundry
"default" :width normal
1594 :height
1 :weight normal
:slant normal
1595 :foreground
,(if (frame-parameter nil
'reverse
)
1598 :background
,(if (frame-parameter nil
'reverse
)
1600 "unspecified-bg")))))
1601 ;; For all other faces, unspecify all attributes.
1603 (mapcar (lambda (x) (list (car x
) 'unspecified
))
1604 face-attribute-name-alist
)))))
1606 (defun face-spec-set (face spec
&optional spec-type
)
1607 "Set the face spec SPEC for FACE.
1608 See `defface' for the format of SPEC.
1610 The appearance of each face is controlled by its specs (set via
1611 this function), and by the internal frame-specific face
1612 attributes (set via `set-face-attribute').
1614 This function also defines FACE as a valid face name if it is not
1615 already one, and (re)calculates its attributes on existing
1618 The argument SPEC-TYPE determines which spec to set:
1619 nil or `face-override-spec' means the override spec (which is
1620 usually what you want if calling this function outside of
1622 `customized-face' or `saved-face' means the customized spec or
1623 the saved custom spec;
1624 `face-defface-spec' means the default spec
1625 (usually set only via `defface');
1626 `reset' means to ignore SPEC, but clear the `customized-face'
1627 and `face-override-spec' specs;
1628 Any other value means not to set any spec, but to run the
1629 function for its other effects."
1630 (if (get face
'face-alias
)
1631 (setq face
(get face
'face-alias
)))
1632 ;; Save SPEC to the relevant symbol property.
1634 (setq spec-type
'face-override-spec
))
1635 (if (memq spec-type
'(face-defface-spec face-override-spec
1636 customized-face saved-face
))
1637 (put face spec-type spec
))
1638 (if (memq spec-type
'(reset saved-face
))
1639 (put face
'customized-face nil
))
1640 ;; Setting the face spec via Custom empties out any override spec,
1641 ;; similar to how setting a variable via Custom changes its values.
1642 (if (memq spec-type
'(customized-face saved-face reset
))
1643 (put face
'face-override-spec nil
))
1644 ;; If we reset the face based on its custom spec, it is unmodified
1645 ;; as far as Custom is concerned.
1646 (unless (eq face
'face-override-spec
)
1647 (put face
'face-modified nil
))
1648 ;; Initialize the face if it does not exist, then recalculate.
1649 (make-empty-face face
)
1650 (dolist (frame (frame-list))
1651 (face-spec-recalc face frame
)))
1653 (defun face-spec-recalc (face frame
)
1654 "Reset the face attributes of FACE on FRAME according to its specs.
1655 The following sources are applied in this order:
1657 face reset to default values if it's the default face, otherwise set
1658 to unspecified (through `face-spec-reset-face')
1660 (theme and user customization)
1661 or: if none of the above exist, and none match the current frame or
1662 inherited from the defface spec instead of overwriting it
1663 entirely, the following is applied instead:
1664 (defface default spec)
1665 (X resources (if applicable))
1667 defface override spec"
1668 (while (get face
'face-alias
)
1669 (setq face
(get face
'face-alias
)))
1670 (face-spec-reset-face face frame
)
1671 ;; If FACE is customized or themed, set the custom spec from
1672 ;; `theme-face' records.
1673 (let ((theme-faces (get face
'theme-face
))
1675 spec theme-face-applied
)
1677 (dolist (elt (reverse theme-faces
))
1678 (setq spec
(face-spec-choose (cadr elt
) frame no-match-found
))
1679 (unless (eq spec no-match-found
)
1680 (face-spec-set-2 face frame spec
)
1681 (setq theme-face-applied t
))))
1682 ;; If there was a spec applicable to FRAME, that overrides the
1683 ;; defface spec entirely (rather than inheriting from it). If
1684 ;; there was no spec applicable to FRAME, apply the defface spec
1685 ;; as well as any applicable X resources.
1686 (unless theme-face-applied
1687 (setq spec
(face-spec-choose (face-default-spec face
) frame
))
1688 (face-spec-set-2 face frame spec
)
1689 (make-face-x-resource-internal face frame
))
1690 (setq spec
(face-spec-choose (get face
'face-override-spec
) frame
))
1691 (face-spec-set-2 face frame spec
)))
1693 (defun face-spec-set-2 (face frame spec
)
1694 "Set the face attributes of FACE on FRAME according to SPEC."
1697 (when (assq (car spec
) face-x-resources
)
1698 (push (car spec
) attrs
)
1699 (push (cadr spec
) attrs
))
1700 (setq spec
(cddr spec
)))
1701 (apply 'set-face-attribute face frame
(nreverse attrs
))))
1703 (defun face-attr-match-p (face attrs
&optional frame
)
1704 "Return t if attributes of FACE match values in plist ATTRS.
1705 Optional parameter FRAME is the frame whose definition of FACE
1706 is used. If nil or omitted, use the selected frame."
1708 (setq frame
(selected-frame)))
1709 (let* ((list face-attribute-name-alist
)
1711 (bold (and (plist-member attrs
:bold
)
1712 (not (plist-member attrs
:weight
))))
1713 (italic (and (plist-member attrs
:italic
)
1714 (not (plist-member attrs
:slant
))))
1715 (plist (if (or bold italic
)
1716 (copy-sequence attrs
)
1718 ;; Handle the Emacs 20 :bold and :italic properties.
1720 (plist-put plist
:weight
(if bold
'bold
'normal
)))
1722 (plist-put plist
:slant
(if italic
'italic
'normal
)))
1723 (while (and match list
)
1724 (let* ((attr (caar list
))
1726 (if (plist-member plist attr
)
1727 (plist-get plist attr
)
1729 (value-now (face-attribute face attr frame
)))
1730 (setq match
(equal specified-value value-now
))
1731 (setq list
(cdr list
))))
1734 (defsubst face-spec-match-p
(face spec
&optional frame
)
1735 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1736 (face-attr-match-p face
(face-spec-choose spec frame
) frame
))
1738 (defsubst face-default-spec
(face)
1739 "Return the default face-spec for FACE, ignoring any user customization.
1740 If there is no default for FACE, return nil."
1741 (get face
'face-defface-spec
))
1743 (defsubst face-user-default-spec
(face)
1744 "Return the user's customized face-spec for FACE, or the default if none.
1745 If there is neither a user setting nor a default for FACE, return nil."
1746 (or (get face
'customized-face
)
1747 (get face
'saved-face
)
1748 (face-default-spec face
)))
1751 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1752 ;;; Frame-type independent color support.
1753 ;;; We keep the old x-* names as aliases for back-compatibility.
1754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1756 (defun defined-colors (&optional frame
)
1757 "Return a list of colors supported for a particular frame.
1758 The argument FRAME specifies which frame to try.
1759 The value may be different for frames on different display types.
1760 If FRAME doesn't support colors, the value is nil.
1761 If FRAME is nil, that stands for the selected frame."
1762 (if (memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1763 (xw-defined-colors frame
)
1764 (mapcar 'car
(tty-color-alist frame
))))
1765 (defalias 'x-defined-colors
'defined-colors
)
1767 (declare-function xw-color-defined-p
"xfns.c" (color &optional frame
))
1769 (defun color-defined-p (color &optional frame
)
1770 "Return non-nil if COLOR is supported on frame FRAME.
1771 COLOR should be a string naming a color (e.g. \"white\"), or a
1772 string specifying a color's RGB components (e.g. \"#ff12ec\"), or
1773 the symbol `unspecified'.
1775 This function returns nil if COLOR is the symbol `unspecified',
1776 or one of the strings \"unspecified-fg\" or \"unspecified-bg\".
1778 If FRAME is omitted or nil, use the selected frame."
1779 (unless (member color
'(unspecified "unspecified-bg" "unspecified-fg"))
1780 (if (member (framep (or frame
(selected-frame))) '(x w32 ns
))
1781 (xw-color-defined-p color frame
)
1782 (numberp (tty-color-translate color frame
)))))
1783 (defalias 'x-color-defined-p
'color-defined-p
)
1785 (declare-function xw-color-values
"xfns.c" (color &optional frame
))
1787 (defun color-values (color &optional frame
)
1788 "Return a description of the color named COLOR on frame FRAME.
1789 COLOR should be a string naming a color (e.g. \"white\"), or a
1790 string specifying a color's RGB components (e.g. \"#ff12ec\").
1792 Return a list of three integers, (RED GREEN BLUE), each between 0
1793 and either 65280 or 65535 (the maximum depends on the system).
1794 Use `color-name-to-rgb' if you want RGB floating-point values
1797 If FRAME is omitted or nil, use the selected frame.
1798 If FRAME cannot display COLOR, the value is nil.
1800 COLOR can also be the symbol `unspecified' or one of the strings
1801 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1802 return value is nil."
1804 ((member color
'(unspecified "unspecified-fg" "unspecified-bg"))
1806 ((memq (framep (or frame
(selected-frame))) '(x w32 ns
))
1807 (xw-color-values color frame
))
1809 (tty-color-values color frame
))))
1811 (defalias 'x-color-values
'color-values
)
1813 (declare-function xw-display-color-p
"xfns.c" (&optional terminal
))
1815 (defun display-color-p (&optional display
)
1816 "Return t if DISPLAY supports color.
1817 The optional argument DISPLAY specifies which display to ask about.
1818 DISPLAY should be either a frame or a display name (a string).
1819 If omitted or nil, that stands for the selected frame's display."
1820 (if (memq (framep-on-display display
) '(x w32 ns
))
1821 (xw-display-color-p display
)
1822 (tty-display-color-p display
)))
1823 (defalias 'x-display-color-p
'display-color-p
)
1825 (declare-function x-display-grayscale-p
"xfns.c" (&optional terminal
))
1827 (defun display-grayscale-p (&optional display
)
1828 "Return non-nil if frames on DISPLAY can display shades of gray."
1829 (let ((frame-type (framep-on-display display
)))
1831 ((memq frame-type
'(x w32 ns
))
1832 (x-display-grayscale-p display
))
1834 (> (tty-color-gray-shades display
) 2)))))
1836 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg
)
1837 "Read a color name or RGB triplet.
1838 Completion is available for color names, but not for RGB triplets.
1840 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1841 components can have one to four digits, but all three components
1842 must have the same number of digits. Each digit is a hex value
1843 between 0 and F; either upper case or lower case for A through F
1846 In addition to standard color names and RGB hex values, the
1847 following are available as color candidates. In each case, the
1848 corresponding color is used.
1850 * `foreground at point' - foreground under the cursor
1851 * `background at point' - background under the cursor
1853 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1855 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1856 convert an input color name to an RGB hex string. Return the RGB
1859 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1860 to enter an empty color name (the empty string).
1862 Interactively, or with optional arg MSG non-nil, print the
1863 resulting color name in the echo area."
1864 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1865 (let* ((completion-ignore-case t
)
1866 (colors (or facemenu-color-alist
1867 (append '("foreground at point" "background at point")
1868 (if allow-empty-name
'(""))
1870 (color (completing-read
1871 (or prompt
"Color (name or #RGB triplet): ")
1872 ;; Completing function for reading colors, accepting
1873 ;; both color names and RGB triplets.
1874 (lambda (string pred flag
)
1876 ((null flag
) ; Try completion.
1877 (or (try-completion string colors pred
)
1878 (if (color-defined-p string
)
1880 ((eq flag t
) ; List all completions.
1881 (or (all-completions string colors pred
)
1882 (if (color-defined-p string
)
1884 ((eq flag
'lambda
) ; Test completion.
1885 (or (member string colors
)
1886 (color-defined-p string
)))))
1889 ;; Process named colors.
1890 (when (member color colors
)
1891 (cond ((string-equal color
"foreground at point")
1892 (setq color
(foreground-color-at-point)))
1893 ((string-equal color
"background at point")
1894 (setq color
(background-color-at-point))))
1895 (when (and convert-to-RGB
1896 (not (string-equal color
"")))
1897 (let ((components (x-color-values color
)))
1898 (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color
)
1899 (setq color
(format "#%04X%04X%04X"
1900 (logand 65535 (nth 0 components
))
1901 (logand 65535 (nth 1 components
))
1902 (logand 65535 (nth 2 components
))))))))
1903 (when msg
(message "Color: `%s'" color
))
1906 (defun face-at-point (&optional thing multiple
)
1907 "Return the face of the character after point.
1908 If it has more than one face, return the first one.
1909 If THING is non-nil try first to get a face name from the buffer.
1910 IF MULTIPLE is non-nil, return a list of all faces.
1911 Return nil if there is no face."
1914 ;; Try to get a face name from the buffer.
1915 (let ((face (intern-soft (thing-at-point 'symbol
))))
1917 (push face faces
))))
1918 ;; Add the named faces that the `read-face-name' or `face' property uses.
1919 (let ((faceprop (or (get-char-property (point) 'read-face-name
)
1920 (get-char-property (point) 'face
))))
1921 (cond ((facep faceprop
)
1922 (push faceprop faces
))
1923 ((and (listp faceprop
)
1924 ;; Don't treat an attribute spec as a list of faces.
1925 (not (keywordp (car faceprop
)))
1926 (not (memq (car faceprop
)
1927 '(foreground-color background-color
))))
1928 (dolist (face faceprop
)
1930 (push face faces
))))))
1931 (setq faces
(delete-dups (nreverse faces
)))
1932 (if multiple faces
(car faces
))))
1934 (defun foreground-color-at-point ()
1935 "Return the foreground color of the character after point."
1936 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1937 ;; Need also pick up any face properties that are not associated with named faces.
1938 (let ((face (or (face-at-point)
1939 (get-char-property (point) 'read-face-name
)
1940 (get-char-property (point) 'face
))))
1941 (cond ((and face
(symbolp face
))
1942 (let ((value (face-foreground face nil
'default
)))
1943 (if (member value
'("unspecified-fg" "unspecified-bg"))
1947 (cond ((memq 'foreground-color face
) (cdr (memq 'foreground-color face
)))
1948 ((memq ':foreground face
) (cadr (memq ':foreground face
)))))
1949 (t nil
)))) ; Invalid face value.
1951 (defun background-color-at-point ()
1952 "Return the background color of the character after point."
1953 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1954 ;; Need also pick up any face properties that are not associated with named faces.
1955 (let ((face (or (face-at-point)
1956 (get-char-property (point) 'read-face-name
)
1957 (get-char-property (point) 'face
))))
1958 (cond ((and face
(symbolp face
))
1959 (let ((value (face-background face nil
'default
)))
1960 (if (member value
'("unspecified-fg" "unspecified-bg"))
1964 (cond ((memq 'background-color face
) (cdr (memq 'background-color face
)))
1965 ((memq ':background face
) (cadr (memq ':background face
)))))
1966 (t nil
)))) ; Invalid face value.
1969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1971 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1973 (declare-function x-display-list
"xfns.c" ())
1974 (declare-function x-open-connection
"xfns.c"
1975 (display &optional xrm-string must-succeed
))
1976 (declare-function x-get-resource
"frame.c"
1977 (attribute class
&optional component subclass
))
1978 (declare-function x-parse-geometry
"frame.c" (string))
1979 (defvar x-display-name
)
1981 (defun x-handle-named-frame-geometry (parameters)
1982 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1983 Value is the new parameter list."
1984 ;; Note that `x-resource-name' has a global meaning.
1985 (let ((x-resource-name (cdr (assq 'name parameters
))))
1986 (when x-resource-name
1987 ;; Before checking X resources, we must have an X connection.
1990 (x-open-connection (or (cdr (assq 'display parameters
))
1992 (let (res-geometry parsed
)
1993 (and (setq res-geometry
(x-get-resource "geometry" "Geometry"))
1994 (setq parsed
(x-parse-geometry res-geometry
))
1996 (append parameters parsed
1997 ;; If the resource specifies a position,
1998 ;; take note of that.
1999 (if (or (assq 'top parsed
) (assq 'left parsed
))
2000 '((user-position . t
) (user-size . t
)))))))))
2004 (defun x-handle-reverse-video (frame parameters
)
2005 "Handle the reverse-video frame parameter and X resource.
2006 `x-create-frame' does not handle this one."
2007 (when (cdr (or (assq 'reverse parameters
)
2008 (let ((resource (x-get-resource "reverseVideo"
2011 (cons nil
(member (downcase resource
)
2012 '("on" "true")))))))
2013 (let* ((params (frame-parameters frame
))
2014 (bg (cdr (assq 'foreground-color params
)))
2015 (fg (cdr (assq 'background-color params
))))
2016 (modify-frame-parameters frame
2017 (list (cons 'foreground-color fg
)
2018 (cons 'background-color bg
)))
2019 (if (equal bg
(cdr (assq 'border-color params
)))
2020 (modify-frame-parameters frame
2021 (list (cons 'border-color fg
))))
2022 (if (equal bg
(cdr (assq 'mouse-color params
)))
2023 (modify-frame-parameters frame
2024 (list (cons 'mouse-color fg
))))
2025 (if (equal bg
(cdr (assq 'cursor-color params
)))
2026 (modify-frame-parameters frame
2027 (list (cons 'cursor-color fg
)))))))
2029 (declare-function x-create-frame
"xfns.c" (parms))
2030 (declare-function x-setup-function-keys
"term/common-win" (frame))
2032 (defun x-create-frame-with-faces (&optional parameters
)
2033 "Create and return a frame with frame parameters PARAMETERS.
2034 If PARAMETERS specify a frame name, handle X geometry resources
2035 for that name. If PARAMETERS includes a `reverse' parameter, or
2036 the X resource ``reverseVideo'' is present, handle that."
2037 (setq parameters
(x-handle-named-frame-geometry parameters
))
2038 (let* ((params (copy-tree parameters
))
2039 (visibility-spec (assq 'visibility parameters
))
2040 (delayed-params '(foreground-color background-color font
2041 border-color cursor-color mouse-color
2042 visibility scroll-bar-foreground
2043 scroll-bar-background
))
2045 (dolist (param delayed-params
)
2046 (setq params
(assq-delete-all param params
)))
2047 (setq frame
(x-create-frame `((visibility . nil
) .
,params
)))
2050 (x-setup-function-keys frame
)
2051 (x-handle-reverse-video frame parameters
)
2052 (frame-set-background-mode frame t
)
2053 (face-set-after-frame-default frame parameters
)
2054 (if (null visibility-spec
)
2055 (make-frame-visible frame
)
2056 (modify-frame-parameters frame
(list visibility-spec
)))
2059 (delete-frame frame
)))
2062 (defun face-set-after-frame-default (frame &optional parameters
)
2063 "Initialize the frame-local faces of FRAME.
2064 Calculate the face definitions using the face specs, custom theme
2065 settings, X resources, and `face-new-frame-defaults'.
2066 Finally, apply any relevant face attributes found amongst the
2067 frame parameters in PARAMETERS."
2068 ;; The `reverse' is so that `default' goes first.
2069 (dolist (face (nreverse (face-list)))
2072 ;; Initialize faces from face spec and custom theme.
2073 (face-spec-recalc face frame
)
2074 ;; Apply attributes specified by face-new-frame-defaults
2075 (internal-merge-in-global-face face frame
))
2076 ;; Don't let invalid specs prevent frame creation.
2079 ;; Apply attributes specified by frame parameters.
2080 (let ((face-params '((foreground-color default
:foreground
)
2081 (background-color default
:background
)
2082 (font default
:font
)
2083 (border-color border
:background
)
2084 (cursor-color cursor
:background
)
2085 (scroll-bar-foreground scroll-bar
:foreground
)
2086 (scroll-bar-background scroll-bar
:background
)
2087 (mouse-color mouse
:background
))))
2088 (dolist (param face-params
)
2089 (let* ((param-name (nth 0 param
))
2090 (value (cdr (assq param-name parameters
))))
2092 (set-face-attribute (nth 1 param
) frame
2093 (nth 2 param
) value
))))))
2095 (defun tty-handle-reverse-video (frame parameters
)
2096 "Handle the reverse-video frame parameter for terminal frames."
2097 (when (cdr (assq 'reverse parameters
))
2098 (let* ((params (frame-parameters frame
))
2099 (bg (cdr (assq 'foreground-color params
)))
2100 (fg (cdr (assq 'background-color params
))))
2101 (modify-frame-parameters frame
2102 (list (cons 'foreground-color fg
)
2103 (cons 'background-color bg
)))
2104 (if (equal bg
(cdr (assq 'mouse-color params
)))
2105 (modify-frame-parameters frame
2106 (list (cons 'mouse-color fg
))))
2107 (if (equal bg
(cdr (assq 'cursor-color params
)))
2108 (modify-frame-parameters frame
2109 (list (cons 'cursor-color fg
)))))))
2112 (defun tty-create-frame-with-faces (&optional parameters
)
2113 "Create and return a frame from optional frame parameters PARAMETERS.
2114 If PARAMETERS contains a `reverse' parameter, handle that."
2115 (let ((frame (make-terminal-frame parameters
))
2118 (with-selected-frame frame
2119 (tty-handle-reverse-video frame
(frame-parameters frame
))
2121 (unless (terminal-parameter frame
'terminal-initted
)
2122 (set-terminal-parameter frame
'terminal-initted t
)
2123 (set-locale-environment nil frame
)
2124 (tty-run-terminal-initialization frame nil t
))
2125 (frame-set-background-mode frame t
)
2126 (face-set-after-frame-default frame parameters
)
2129 (delete-frame frame
)))
2132 (defun tty-find-type (pred type
)
2133 "Return the longest prefix of TYPE to which PRED returns non-nil.
2134 TYPE should be a tty type name such as \"xterm-16color\".
2136 The function tries only those prefixes that are followed by a
2137 dash or underscore in the original type name, like \"xterm\" in
2141 (not (funcall pred type
)))
2142 ;; Strip off last hyphen and what follows, then try again
2144 (if (setq hyphend
(string-match-p "[-_][^-_]+$" type
))
2145 (substring type
0 hyphend
)
2149 (defvar tty-setup-hook nil
2150 "Hook run after running the initialization function of a new text terminal.
2151 Specifically, `tty-run-terminal-initialization' runs this.
2152 This can be used to fine tune the `input-decode-map', for example.")
2154 (defun tty-run-terminal-initialization (frame &optional type run-hook
)
2155 "Run the special initialization code for the terminal type of FRAME.
2156 The optional TYPE parameter may be used to override the autodetected
2157 terminal type to a different value.
2159 This consults `term-file-aliases' to map terminal types to their aliases.
2161 If optional argument RUN-HOOK is non-nil, then as a final step,
2162 this runs the hook `tty-setup-hook'.
2164 If you set `term-file-prefix' to nil, this function does nothing."
2165 (setq type
(or type
(tty-type frame
)))
2166 (let ((alias (tty-find-type
2167 (lambda (typ) (assoc typ term-file-aliases
)) type
)))
2168 (if alias
(setq type
(cdr (assoc alias term-file-aliases
)))))
2169 ;; Load library for our terminal type.
2170 ;; User init file can set term-file-prefix to nil to prevent this.
2171 (with-selected-frame frame
2172 (unless (null term-file-prefix
)
2173 (let* (term-init-func)
2174 ;; First, load the terminal initialization file, if it is
2175 ;; available and it hasn't been loaded already.
2176 (tty-find-type #'(lambda (type)
2177 (let ((file (locate-library (concat term-file-prefix type
))))
2179 (or (assoc file load-history
)
2182 ;; Next, try to find a matching initialization function, and call it.
2183 (tty-find-type #'(lambda (type)
2184 (fboundp (setq term-init-func
2185 (intern (concat "terminal-init-" type
)))))
2187 (when (fboundp term-init-func
)
2188 (funcall term-init-func
))
2189 (set-terminal-parameter frame
'terminal-initted term-init-func
)
2190 (if run-hook
(run-hooks 'tty-setup-hook
))))))
2192 ;; Called from C function init_display to initialize faces of the
2193 ;; dumped terminal frame on startup.
2195 (defun tty-set-up-initial-frame-faces ()
2196 (let ((frame (selected-frame)))
2197 (frame-set-background-mode frame t
)
2198 (face-set-after-frame-default frame
)))
2201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2205 (defgroup basic-faces nil
2206 "The standard faces of Emacs."
2210 '((t nil
)) ; If this were nil, face-defface-spec would not be set.
2211 "Basic default face."
2212 :group
'basic-faces
)
2217 :group
'basic-faces
)
2220 '((((supports :slant italic
))
2222 (((supports :underline t
))
2225 ;; Default to italic, even if it doesn't appear to be supported,
2226 ;; because in some cases the display engine will do its own
2227 ;; workaround (to `dim' on ttys).
2229 "Basic italic face."
2230 :group
'basic-faces
)
2232 (defface bold-italic
2233 '((t :weight bold
:slant italic
))
2234 "Basic bold-italic face."
2235 :group
'basic-faces
)
2238 '((((supports :underline t
))
2240 (((supports :weight bold
))
2243 "Basic underlined face."
2244 :group
'basic-faces
)
2246 (defface fixed-pitch
2247 '((t :family
"Monospace"))
2248 "The basic fixed-pitch face."
2249 :group
'basic-faces
)
2251 (defface variable-pitch
2252 '((t :family
"Sans Serif"))
2253 "The basic variable-pitch face."
2254 :group
'basic-faces
)
2257 '((((class color grayscale
) (min-colors 88) (background light
))
2258 :foreground
"grey50")
2259 (((class color grayscale
) (min-colors 88) (background dark
))
2260 :foreground
"grey70")
2261 (((class color
) (min-colors 8) (background light
))
2262 :foreground
"green")
2263 (((class color
) (min-colors 8) (background dark
))
2264 :foreground
"yellow"))
2265 "Basic face for shadowed text."
2270 '((((class color
) (min-colors 88) (background light
))
2271 :foreground
"RoyalBlue3" :underline t
)
2272 (((class color
) (background light
))
2273 :foreground
"blue" :underline t
)
2274 (((class color
) (min-colors 88) (background dark
))
2275 :foreground
"cyan1" :underline t
)
2276 (((class color
) (background dark
))
2277 :foreground
"cyan" :underline t
)
2278 (t :inherit underline
))
2279 "Basic face for unvisited links."
2283 (defface link-visited
2284 '((default :inherit link
)
2285 (((class color
) (background light
)) :foreground
"magenta4")
2286 (((class color
) (background dark
)) :foreground
"violet"))
2287 "Basic face for visited links."
2292 '((((class color
) (min-colors 88) (background light
))
2293 :background
"darkseagreen2")
2294 (((class color
) (min-colors 88) (background dark
))
2295 :background
"darkolivegreen")
2296 (((class color
) (min-colors 16) (background light
))
2297 :background
"darkseagreen2")
2298 (((class color
) (min-colors 16) (background dark
))
2299 :background
"darkolivegreen")
2300 (((class color
) (min-colors 8))
2301 :background
"green" :foreground
"black")
2302 (t :inverse-video t
))
2303 "Basic face for highlighting."
2304 :group
'basic-faces
)
2306 ;; Region face: under NS, default to the system-defined selection
2307 ;; color (optimized for the fixed white background of other apps),
2308 ;; if background is light.
2310 '((((class color
) (min-colors 88) (background dark
))
2311 :background
"blue3")
2312 (((class color
) (min-colors 88) (background light
) (type gtk
))
2313 :distant-foreground
"gtk_selection_fg_color"
2314 :background
"gtk_selection_bg_color")
2315 (((class color
) (min-colors 88) (background light
) (type ns
))
2316 :distant-foreground
"ns_selection_fg_color"
2317 :background
"ns_selection_bg_color")
2318 (((class color
) (min-colors 88) (background light
))
2319 :background
"lightgoldenrod2")
2320 (((class color
) (min-colors 16) (background dark
))
2321 :background
"blue3")
2322 (((class color
) (min-colors 16) (background light
))
2323 :background
"lightgoldenrod2")
2324 (((class color
) (min-colors 8))
2325 :background
"blue" :foreground
"white")
2326 (((type tty
) (class mono
))
2328 (t :background
"gray"))
2329 "Basic face for highlighting the region."
2331 :group
'basic-faces
)
2333 (defface secondary-selection
2334 '((((class color
) (min-colors 88) (background light
))
2335 :background
"yellow1")
2336 (((class color
) (min-colors 88) (background dark
))
2337 :background
"SkyBlue4")
2338 (((class color
) (min-colors 16) (background light
))
2339 :background
"yellow")
2340 (((class color
) (min-colors 16) (background dark
))
2341 :background
"SkyBlue4")
2342 (((class color
) (min-colors 8))
2343 :background
"cyan" :foreground
"black")
2344 (t :inverse-video t
))
2345 "Basic face for displaying the secondary selection."
2346 :group
'basic-faces
)
2348 (defface trailing-whitespace
2349 '((((class color
) (background light
))
2351 (((class color
) (background dark
))
2353 (t :inverse-video t
))
2354 "Basic face for highlighting trailing whitespace."
2356 :group
'basic-faces
)
2358 (defface escape-glyph
2359 '((((background dark
)) :foreground
"cyan")
2360 ;; See the comment in minibuffer-prompt for
2361 ;; the reason not to use blue on MS-DOS.
2362 (((type pc
)) :foreground
"magenta")
2363 ;; red4 is too dark, but some say blue is too loud.
2364 ;; brown seems to work ok. -- rms.
2365 (t :foreground
"brown"))
2366 "Face for characters displayed as sequences using `^' or `\\'."
2370 (defface nobreak-space
2371 '((((class color
) (min-colors 88)) :inherit escape-glyph
:underline t
)
2372 (((class color
) (min-colors 8)) :background
"magenta")
2373 (t :inverse-video t
))
2374 "Face for displaying nobreak space."
2378 (defgroup mode-line-faces nil
2379 "Faces used in the mode line."
2385 '((((class color
) (min-colors 88))
2386 :box
(:line-width -
1 :style released-button
)
2387 :background
"grey75" :foreground
"black")
2390 "Basic mode line face for selected window."
2392 :group
'mode-line-faces
2393 :group
'basic-faces
)
2395 (defface mode-line-inactive
2398 (((class color
) (min-colors 88) (background light
))
2400 :box
(:line-width -
1 :color
"grey75" :style nil
)
2401 :foreground
"grey20" :background
"grey90")
2402 (((class color
) (min-colors 88) (background dark
) )
2404 :box
(:line-width -
1 :color
"grey40" :style nil
)
2405 :foreground
"grey80" :background
"grey30"))
2406 "Basic mode line face for non-selected windows."
2408 :group
'mode-line-faces
2409 :group
'basic-faces
)
2410 (define-obsolete-face-alias 'modeline-inactive
'mode-line-inactive
"22.1")
2412 (defface mode-line-highlight
2413 '((((class color
) (min-colors 88))
2414 :box
(:line-width
2 :color
"grey40" :style released-button
))
2416 :inherit highlight
))
2417 "Basic mode line face for highlighting."
2419 :group
'mode-line-faces
2420 :group
'basic-faces
)
2421 (define-obsolete-face-alias 'modeline-highlight
'mode-line-highlight
"22.1")
2423 (defface mode-line-emphasis
2424 '((t (:weight bold
)))
2425 "Face used to emphasize certain mode line features.
2426 Use the face `mode-line-highlight' for features that can be selected."
2428 :group
'mode-line-faces
2429 :group
'basic-faces
)
2431 (defface mode-line-buffer-id
2432 '((t (:weight bold
)))
2433 "Face used for buffer identification parts of the mode line."
2435 :group
'mode-line-faces
2436 :group
'basic-faces
)
2437 (define-obsolete-face-alias 'modeline-buffer-id
'mode-line-buffer-id
"22.1")
2439 (defface header-line
2443 ;; This used to be `:inverse-video t', but that doesn't look very
2444 ;; good when combined with inverse-video mode-lines and multiple
2445 ;; windows. Underlining looks better, and is more consistent with
2446 ;; the window-system face variants, which deemphasize the
2447 ;; header-line in relation to the mode-line face. If a terminal
2448 ;; can't underline, then the header-line will end up without any
2449 ;; highlighting; this may be too confusing in general, although it
2450 ;; happens to look good with the only current use of header-lines,
2451 ;; the info browser. XXX
2452 :inverse-video nil
;Override the value inherited from mode-line.
2454 (((class color grayscale
) (background light
))
2455 :background
"grey90" :foreground
"grey20"
2457 (((class color grayscale
) (background dark
))
2458 :background
"grey20" :foreground
"grey90"
2460 (((class mono
) (background light
))
2461 :background
"white" :foreground
"black"
2465 (((class mono
) (background dark
))
2466 :background
"black" :foreground
"white"
2470 "Basic header-line face."
2472 :group
'basic-faces
)
2474 (defface vertical-border
2475 '((((type tty
)) :inherit mode-line-inactive
))
2476 "Face used for vertical window dividers on ttys."
2478 :group
'basic-faces
)
2480 (defface window-divider
'((t :foreground
"gray60"))
2481 "Basic face for window dividers.
2482 When a divider is less than 3 pixels wide, it is drawn solidly
2483 with the foreground of this face. For larger dividers this face
2484 is used for the inner part while the first pixel line/column is
2485 drawn with the `window-divider-first-pixel' face and the last
2486 pixel line/column with the `window-divider-last-pixel' face."
2489 :group
'basic-faces
)
2491 (defface window-divider-first-pixel
2492 '((t :foreground
"gray80"))
2493 "Basic face for first pixel line/column of window dividers.
2494 When a divider is at least 3 pixels wide, its first pixel
2495 line/column is drawn with the foreground of this face. If you do
2496 not want to accentuate the first pixel line/column, set this to
2497 the same as `window-divider' face."
2500 :group
'basic-faces
)
2502 (defface window-divider-last-pixel
2503 '((t :foreground
"gray40"))
2504 "Basic face for last pixel line/column of window dividers.
2505 When a divider is at least 3 pixels wide, its last pixel
2506 line/column is drawn with the foreground of this face. If you do
2507 not want to accentuate the last pixel line/column, set this to
2508 the same as `window-divider' face."
2511 :group
'basic-faces
)
2513 (defface minibuffer-prompt
2514 '((((background dark
)) :foreground
"cyan")
2515 ;; Don't use blue because many users of the MS-DOS port customize
2516 ;; their foreground color to be blue.
2517 (((type pc
)) :foreground
"magenta")
2518 (t :foreground
"medium blue"))
2519 "Face for minibuffer prompts.
2520 By default, Emacs automatically adds this face to the value of
2521 `minibuffer-prompt-properties', which is a list of text properties
2522 used to display the prompt text."
2524 :group
'basic-faces
)
2526 (setq minibuffer-prompt-properties
2527 (append minibuffer-prompt-properties
(list 'face
'minibuffer-prompt
)))
2530 '((((class color
) (background light
))
2531 :background
"grey95")
2532 (((class color
) (background dark
))
2533 :background
"grey10")
2535 :background
"gray"))
2536 "Basic face for the fringes to the left and right of windows under X."
2539 :group
'basic-faces
)
2541 (defface scroll-bar
'((t nil
))
2542 "Basic face for the scroll bar colors under X."
2545 :group
'basic-faces
)
2547 (defface border
'((t nil
))
2548 "Basic face for the frame border under X."
2551 :group
'basic-faces
)
2554 '((((background light
)) :background
"black")
2555 (((background dark
)) :background
"white"))
2556 "Basic face for the cursor color under X.
2557 Currently, only the `:background' attribute is meaningful; all
2558 other attributes are ignored. The cursor foreground color is
2559 taken from the background color of the underlying text.
2561 Note: Other faces cannot inherit from the cursor face."
2564 :group
'basic-faces
)
2566 (put 'cursor
'face-no-inherit t
)
2568 (defface mouse
'((t nil
))
2569 "Basic face for the mouse color under X."
2572 :group
'basic-faces
)
2576 :box
(:line-width
1 :style released-button
)
2577 :foreground
"black")
2578 (((type x w32 ns
) (class color
))
2579 :background
"grey75")
2580 (((type x
) (class mono
))
2581 :background
"grey"))
2582 "Basic tool-bar face."
2584 :group
'basic-faces
)
2593 "Basic face for the font and colors of the menu bar and popup menus."
2596 :group
'basic-faces
)
2598 (defface help-argument-name
'((t :inherit italic
))
2599 "Face to highlight argument names in *Help* buffers."
2602 (defface glyphless-char
2603 '((((type tty
)) :inherit underline
)
2604 (((type pc
)) :inherit escape-glyph
)
2606 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2607 It is used for characters of no fonts too."
2609 :group
'basic-faces
)
2612 '((default :weight bold
)
2613 (((class color
) (min-colors 88) (background light
)) :foreground
"Red1")
2614 (((class color
) (min-colors 88) (background dark
)) :foreground
"Pink")
2615 (((class color
) (min-colors 16) (background light
)) :foreground
"Red1")
2616 (((class color
) (min-colors 16) (background dark
)) :foreground
"Pink")
2617 (((class color
) (min-colors 8)) :foreground
"red")
2618 (t :inverse-video t
))
2619 "Basic face used to highlight errors and to denote failure."
2621 :group
'basic-faces
)
2624 '((default :weight bold
)
2625 (((class color
) (min-colors 16)) :foreground
"DarkOrange")
2626 (((class color
)) :foreground
"yellow"))
2627 "Basic face used to highlight warnings."
2629 :group
'basic-faces
)
2632 '((default :weight bold
)
2633 (((class color
) (min-colors 16) (background light
)) :foreground
"ForestGreen")
2634 (((class color
) (min-colors 88) (background dark
)) :foreground
"Green1")
2635 (((class color
) (min-colors 16) (background dark
)) :foreground
"Green")
2636 (((class color
)) :foreground
"green"))
2637 "Basic face used to indicate successful operation."
2639 :group
'basic-faces
)
2641 ;; Faces for TTY menus.
2642 (defface tty-menu-enabled-face
2644 :foreground
"yellow" :background
"blue" :weight bold
))
2645 "Face for displaying enabled items in TTY menus."
2646 :group
'basic-faces
)
2648 (defface tty-menu-disabled-face
2649 '((((class color
) (min-colors 16))
2650 :foreground
"lightgray" :background
"blue")
2652 :foreground
"white" :background
"blue"))
2653 "Face for displaying disabled items in TTY menus."
2654 :group
'basic-faces
)
2656 (defface tty-menu-selected-face
2657 '((t :background
"red"))
2658 "Face for displaying the currently selected item in TTY menus."
2659 :group
'basic-faces
)
2661 (defgroup paren-showing-faces nil
2662 "Faces used to highlight paren matches."
2663 :group
'paren-showing
2667 (defface show-paren-match
2668 '((((class color
) (background light
))
2669 :background
"turquoise") ; looks OK on tty (becomes cyan)
2670 (((class color
) (background dark
))
2671 :background
"steelblue3") ; looks OK on tty (becomes blue)
2672 (((background dark
))
2673 :background
"grey50")
2675 :background
"gray"))
2676 "Face used for a matching paren."
2677 :group
'paren-showing-faces
)
2679 (defface show-paren-mismatch
2680 '((((class color
)) (:foreground
"white" :background
"purple"))
2681 (t (:inverse-video t
)))
2682 "Face used for a mismatching paren."
2683 :group
'paren-showing-faces
)
2686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2687 ;;; Manipulating font names.
2688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2690 ;; This is here for compatibility with Emacs 20.2. For example,
2691 ;; international/fontset.el uses x-resolve-font-name. The following
2692 ;; functions are not used in the face implementation itself.
2694 (defvar x-font-regexp nil
)
2695 (defvar x-font-regexp-head nil
)
2696 (defvar x-font-regexp-weight nil
)
2697 (defvar x-font-regexp-slant nil
)
2699 (defconst x-font-regexp-weight-subnum
1)
2700 (defconst x-font-regexp-slant-subnum
2)
2701 (defconst x-font-regexp-swidth-subnum
3)
2702 (defconst x-font-regexp-adstyle-subnum
4)
2704 ;;; Regexps matching font names in "Host Portable Character Representation."
2709 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2710 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2711 (weight\? "\\([^-]*\\)") ; 1
2712 (slant "\\([ior]\\)") ; 2
2713 ; (slant\? "\\([ior?*]?\\)") ; 2
2714 (slant\? "\\([^-]?\\)") ; 2
2715 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2716 (swidth "\\([^-]*\\)") ; 3
2717 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2718 (adstyle "\\([^-]*\\)") ; 4
2719 (pixelsize "[0-9]+")
2720 (pointsize "[0-9][0-9]+")
2721 (resx "[0-9][0-9]+")
2722 (resy "[0-9][0-9]+")
2729 (purecopy (concat "\\`\\*?[-?*]"
2730 foundry - family - weight
\? - slant
\? - swidth - adstyle -
2731 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2732 registry - encoding
"\\*?\\'"
2734 (setq x-font-regexp-head
2735 (purecopy (concat "\\`[-?*]" foundry - family - weight
\? - slant
\?
2736 "\\([-*?]\\|\\'\\)")))
2737 (setq x-font-regexp-slant
(purecopy (concat - slant -
)))
2738 (setq x-font-regexp-weight
(purecopy (concat - weight -
)))
2742 (defun x-resolve-font-name (pattern &optional face frame
)
2743 "Return a font name matching PATTERN.
2744 All wildcards in PATTERN are instantiated.
2745 If PATTERN is nil, return the name of the frame's base font, which never
2747 Given optional arguments FACE and FRAME, return a font which is
2748 also the same size as FACE on FRAME, or fail."
2752 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2753 (let ((fonts (x-list-fonts pattern face frame
1)))
2756 (if (string-match-p "\\*" pattern
)
2757 (if (null (face-font face
))
2758 (error "No matching fonts are the same height as the frame default font")
2759 (error "No matching fonts are the same height as face `%s'" face
))
2760 (if (null (face-font face
))
2761 (error "Height of font `%s' doesn't match the frame default font"
2763 (error "Height of font `%s' doesn't match face `%s'"
2765 (error "No fonts match `%s'" pattern
)))
2767 (cdr (assq 'font
(frame-parameters (selected-frame))))))
2769 (defcustom font-list-limit
100
2770 "This variable is obsolete and has no effect."
2773 (make-obsolete-variable 'font-list-limit nil
"24.3")
2777 ;;; faces.el ends here