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