Merge from origin/emacs-25
[emacs.git] / lisp / faces.el
blobe62561a63a5e8e6fc61a4853f98f6525d7f49c7c
1 ;;; faces.el --- Lisp faces -*- lexical-binding: t -*-
3 ;; Copyright (C) 1992-1996, 1998-2017 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
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 (defcustom term-file-aliases
39 '(("apollo" . "vt100")
40 ("vt102" . "vt100")
41 ("vt125" . "vt100")
42 ("vt201" . "vt200")
43 ("vt220" . "vt200")
44 ("vt240" . "vt200")
45 ("vt300" . "vt200")
46 ("vt320" . "vt200")
47 ("vt400" . "vt200")
48 ("vt420" . "vt200")
50 "Alist of terminal type aliases.
51 Entries are of the form (TYPE . ALIAS), where both elements are strings.
52 This means to treat a terminal of type TYPE as if it were of type ALIAS."
53 :type '(alist :key-type (string :tag "Terminal")
54 :value-type (string :tag "Alias"))
55 :group 'terminals
56 :version "25.1")
58 (declare-function xw-defined-colors "term/common-win" (&optional frame))
60 (defvar help-xref-stack-item)
62 (defvar face-name-history nil
63 "History list for some commands that read face names.
64 Maximum length of the history list is determined by the value
65 of `history-length', which see.")
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69 ;;; Font selection.
70 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72 (defgroup font-selection nil
73 "Influencing face font selection."
74 :group 'faces)
77 (defcustom face-font-selection-order
78 '(:width :height :weight :slant)
79 "A list specifying how face font selection chooses fonts.
80 Each of the four symbols `:width', `:height', `:weight', and `:slant'
81 must appear once in the list, and the list must not contain any other
82 elements. Font selection first tries to find a best matching font
83 for those face attributes that appear before in the list. For
84 example, if `:slant' appears before `:height', font selection first
85 tries to find a font with a suitable slant, even if this results in
86 a font height that isn't optimal."
87 :tag "Font selection order"
88 :type '(list symbol symbol symbol symbol)
89 :group 'font-selection
90 :set #'(lambda (symbol value)
91 (set-default symbol value)
92 (internal-set-font-selection-order value)))
95 ;; In the absence of Fontconfig support, Monospace and Sans Serif are
96 ;; unavailable, and we fall back on the courier and helv families,
97 ;; which are generally available.
98 (defcustom face-font-family-alternatives
99 (mapcar (lambda (arg) (mapcar 'purecopy arg))
100 '(("Monospace" "courier" "fixed")
102 ;; Monospace Serif is an Emacs invention, intended to work around
103 ;; portability problems when using Courier. It should work well
104 ;; when combined with Monospaced and with other standard fonts.
105 ("Monospace Serif"
107 ;; This looks good on GNU/Linux.
108 "Courier 10 Pitch"
109 ;; This looks good on MS-Windows and OS X.
110 "Consolas"
111 ;; This looks good on macOS. "Courier" looks good too, but is
112 ;; jagged on GNU/Linux and so is listed later as "courier".
113 "Courier Std"
114 ;; Although these are anti-aliased, they are a bit faint compared
115 ;; to the above.
116 "FreeMono" "Nimbus Mono L"
117 ;; These are aliased and look jagged.
118 "courier" "fixed"
119 ;; Omit Courier New, as it is the default MS-Windows font and so
120 ;; would look no different, and is pretty faint on other platforms.
123 ;; This is present for backward compatibility.
124 ("courier" "CMU Typewriter Text" "fixed")
126 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
127 ("helv" "helvetica" "arial" "fixed")))
128 "Alist of alternative font family names.
129 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
130 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
131 ALTERNATIVE2 etc."
132 :tag "Alternative font families to try"
133 :type '(repeat (repeat string))
134 :group 'font-selection
135 :set #'(lambda (symbol value)
136 (set-default symbol value)
137 (internal-set-alternative-font-family-alist value)))
140 ;; This is defined originally in xfaces.c.
141 (defcustom face-font-registry-alternatives
142 (mapcar (lambda (arg) (mapcar 'purecopy arg))
143 (if (featurep 'w32)
144 '(("iso8859-1" "ms-oemlatin")
145 ("gb2312.1980" "gb2312" "gbk" "gb18030")
146 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
147 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
148 ("muletibetan-2" "muletibetan-0"))
149 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
150 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
151 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
152 ("muletibetan-2" "muletibetan-0"))))
153 "Alist of alternative font registry names.
154 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
155 If fonts of registry REGISTRY can be loaded, font selection
156 tries to find a best matching font among all fonts of registry
157 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
158 :tag "Alternative font registries to try"
159 :type '(repeat (repeat string))
160 :version "21.1"
161 :group 'font-selection
162 :set #'(lambda (symbol value)
163 (set-default symbol value)
164 (internal-set-alternative-font-registry-alist value)))
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 ;;; Creation, copying.
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 (defun face-list ()
173 "Return a list of all defined faces."
174 (mapcar #'car face-new-frame-defaults))
176 (defun make-face (face)
177 "Define a new face with name FACE, a symbol.
178 Do not call this directly from Lisp code; use `defface' instead.
180 If FACE is already known as a face, leave it unmodified. Return FACE."
181 (interactive (list (read-from-minibuffer
182 "Make face: " nil nil t 'face-name-history)))
183 (unless (facep face)
184 ;; Make frame-local faces (this also makes the global one).
185 (dolist (frame (frame-list))
186 (internal-make-lisp-face face frame))
187 ;; Add the face to the face menu.
188 (when (fboundp 'facemenu-add-new-face)
189 (facemenu-add-new-face face))
190 ;; Define frame-local faces for all frames from X resources.
191 (make-face-x-resource-internal face))
192 face)
194 (defun make-empty-face (face)
195 "Define a new, empty face with name FACE.
196 Do not call this directly from Lisp code; use `defface' instead."
197 (interactive (list (read-from-minibuffer
198 "Make empty face: " nil nil t 'face-name-history)))
199 (make-face face))
201 (defun copy-face (old-face new-face &optional frame new-frame)
202 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
203 This function does not copy face customization data, so NEW-FACE
204 will not be made customizable. Most Lisp code should not call
205 this function; use `defface' with :inherit instead.
207 If NEW-FACE already exists as a face, modify it to be like
208 OLD-FACE. If NEW-FACE doesn't already exist, create it.
210 If the optional argument FRAME is a frame, change NEW-FACE on
211 FRAME only. If FRAME is t, copy the frame-independent default
212 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
213 the defaults as well as the faces on each existing frame.
215 If the optional fourth argument NEW-FRAME is given, copy the
216 information from face OLD-FACE on frame FRAME to NEW-FACE on
217 frame NEW-FRAME. In this case, FRAME must not be nil."
218 (let ((inhibit-quit t))
219 (if (null frame)
220 (progn
221 (when new-frame
222 (error "Copying face %s from all frames to one frame"
223 old-face))
224 (make-empty-face new-face)
225 (dolist (frame (frame-list))
226 (copy-face old-face new-face frame))
227 (copy-face old-face new-face t))
228 (make-empty-face new-face)
229 (internal-copy-lisp-face old-face new-face frame new-frame))
230 new-face))
233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
234 ;;; Predicates, type checks.
235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
237 (defun facep (face)
238 "Return non-nil if FACE is a face name; nil otherwise.
239 A face name can be a string or a symbol."
240 (internal-lisp-face-p face))
243 (defun check-face (face)
244 "Signal an error if FACE doesn't name a face.
245 Value is FACE."
246 (unless (facep face)
247 (error "Not a face: %s" face))
248 face)
251 ;; The ID returned is not to be confused with the internally used IDs
252 ;; of realized faces. The ID assigned to Lisp faces is used to
253 ;; support faces in display table entries.
255 (defun face-id (face &optional _frame)
256 "Return the internal ID of face with name FACE.
257 If FACE is a face-alias, return the ID of the target face.
258 The optional argument FRAME is ignored, since the internal face ID
259 of a face name is the same for all frames."
260 (check-face face)
261 (or (get face 'face)
262 (face-id (get face 'face-alias))))
264 (defun face-equal (face1 face2 &optional frame)
265 "Non-nil if faces FACE1 and FACE2 are equal.
266 Faces are considered equal if all their attributes are equal.
267 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
268 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
269 If FRAME is omitted or nil, use the selected frame."
270 (internal-lisp-face-equal-p face1 face2 frame))
273 (defun face-differs-from-default-p (face &optional frame)
274 "Return non-nil if FACE displays differently from the default face.
275 If the optional argument FRAME is given, report on face FACE in that frame.
276 If FRAME is t, report on the defaults for face FACE (for new frames).
277 If FRAME is omitted or nil, use the selected frame."
278 (let ((attrs
279 (delq :inherit (mapcar 'car face-attribute-name-alist)))
280 (differs nil))
281 (while (and attrs (not differs))
282 (let* ((attr (pop attrs))
283 (attr-val (face-attribute face attr frame t)))
284 (when (and
285 (not (eq attr-val 'unspecified))
286 (display-supports-face-attributes-p (list attr attr-val)
287 frame))
288 (setq differs attr))))
289 differs))
292 (defun face-nontrivial-p (face &optional frame)
293 "True if face FACE has some non-nil attribute.
294 If the optional argument FRAME is given, report on face FACE in that frame.
295 If FRAME is t, report on the defaults for face FACE (for new frames).
296 If FRAME is omitted or nil, use the selected frame."
297 (not (internal-lisp-face-empty-p face frame)))
300 (defun face-list-p (face-or-list)
301 "True if FACE-OR-LIST is a list of faces.
302 Return nil if FACE-OR-LIST is a non-nil atom, or a cons cell whose car
303 is either `foreground-color', `background-color', or a keyword."
304 ;; The logic of merge_face_ref (xfaces.c) is recreated here.
305 (and (listp face-or-list)
306 (not (memq (car face-or-list)
307 '(foreground-color background-color)))
308 (not (keywordp (car face-or-list)))))
312 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
313 ;;; Setting face attributes from X resources.
314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
316 (defcustom face-x-resources
317 (mapcar
318 (lambda (arg)
319 ;; FIXME; can we purecopy some of the conses too?
320 (cons (car arg)
321 (cons (purecopy (car (cdr arg))) (purecopy (cdr (cdr arg))))))
322 '((:family (".attributeFamily" . "Face.AttributeFamily"))
323 (:foundry (".attributeFoundry" . "Face.AttributeFoundry"))
324 (:width (".attributeWidth" . "Face.AttributeWidth"))
325 (:height (".attributeHeight" . "Face.AttributeHeight"))
326 (:weight (".attributeWeight" . "Face.AttributeWeight"))
327 (:slant (".attributeSlant" . "Face.AttributeSlant"))
328 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
329 (:distant-foreground
330 (".attributeDistantForeground" . "Face.AttributeDistantForeground"))
331 (:background (".attributeBackground" . "Face.AttributeBackground"))
332 (:overline (".attributeOverline" . "Face.AttributeOverline"))
333 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
334 (:box (".attributeBox" . "Face.AttributeBox"))
335 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
336 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
337 (:stipple
338 (".attributeStipple" . "Face.AttributeStipple")
339 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
340 (:bold (".attributeBold" . "Face.AttributeBold"))
341 (:italic (".attributeItalic" . "Face.AttributeItalic"))
342 (:font (".attributeFont" . "Face.AttributeFont"))
343 (:inherit (".attributeInherit" . "Face.AttributeInherit"))))
344 "List of X resources and classes for face attributes.
345 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
346 the name of a face attribute, and each ENTRY is a cons of the form
347 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
348 X resource class for the attribute."
349 :type '(repeat (cons symbol (repeat (cons string string))))
350 :group 'faces)
353 (declare-function internal-face-x-get-resource "xfaces.c"
354 (resource class &optional frame))
356 (declare-function internal-set-lisp-face-attribute-from-resource "xfaces.c"
357 (face attr value &optional frame))
359 (defun set-face-attribute-from-resource (face attribute resource class frame)
360 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
361 Value is the attribute value specified by the resource, or nil
362 if not present. This function displays a message if the resource
363 specifies an invalid attribute."
364 (let* ((face-name (face-name face))
365 (value (internal-face-x-get-resource (concat face-name resource)
366 class frame)))
367 (when value
368 (condition-case ()
369 (internal-set-lisp-face-attribute-from-resource
370 face attribute (downcase value) frame)
371 (error
372 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
373 face-name frame attribute value))))
374 value))
377 (defun set-face-attributes-from-resources (face frame)
378 "Set attributes of FACE from X resources for FRAME."
379 (when (memq (framep frame) '(x w32))
380 (dolist (definition face-x-resources)
381 (let ((attribute (car definition)))
382 (dolist (entry (cdr definition))
383 (set-face-attribute-from-resource face attribute (car entry)
384 (cdr entry) frame))))))
387 (defun make-face-x-resource-internal (face &optional frame)
388 "Fill frame-local FACE on FRAME from X resources.
389 FRAME nil or not specified means do it for all frames.
391 If `inhibit-x-resources' is non-nil, this function does nothing."
392 (unless inhibit-x-resources
393 (dolist (frame (if (null frame) (frame-list) (list frame)))
394 ;; `x-create-frame' already took care of correctly handling
395 ;; the reverse video case-- do _not_ touch the default face
396 (unless (and (eq face 'default)
397 (frame-parameter frame 'reverse))
398 (set-face-attributes-from-resources face frame)))))
402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
403 ;;; Retrieving face attributes.
404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
406 (defun face-name (face)
407 "Return the name of face FACE."
408 (symbol-name (check-face face)))
411 (defun face-all-attributes (face &optional frame)
412 "Return an alist stating the attributes of FACE.
413 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
414 If FRAME is omitted or nil the value describes the default attributes,
415 but if you specify FRAME, the value describes the attributes
416 of FACE on FRAME."
417 (mapcar (lambda (pair)
418 (let ((attr (car pair)))
419 (cons attr (face-attribute face attr (or frame t)))))
420 face-attribute-name-alist))
422 (defun face-attribute (face attribute &optional frame inherit)
423 "Return the value of FACE's ATTRIBUTE on FRAME.
424 If the optional argument FRAME is given, report on face FACE in that frame.
425 If FRAME is t, report on the defaults for face FACE (for new frames).
426 If FRAME is omitted or nil, use the selected frame.
428 If INHERIT is nil, only attributes directly defined by FACE are considered,
429 so the return value may be `unspecified', or a relative value.
430 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
431 faces specified by its `:inherit' attribute; however the return value
432 may still be `unspecified' or relative.
433 If INHERIT is a face or a list of faces, then the result is further merged
434 with that face (or faces), until it becomes specified and absolute.
436 To ensure that the return value is always specified and absolute, use a
437 value of `default' for INHERIT; this will resolve any unspecified or
438 relative values by merging with the `default' face (which is always
439 completely specified)."
440 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
441 (when (and inherit (face-attribute-relative-p attribute value))
442 ;; VALUE is relative, so merge with inherited faces
443 (let ((inh-from (face-attribute face :inherit frame)))
444 (unless (or (null inh-from) (eq inh-from 'unspecified))
445 (condition-case nil
446 (setq value
447 (face-attribute-merged-with attribute value inh-from frame))
448 ;; The `inherit' attribute may point to non existent faces.
449 (error nil)))))
450 (when (and inherit
451 (not (eq inherit t))
452 (face-attribute-relative-p attribute value))
453 ;; We should merge with INHERIT as well
454 (setq value (face-attribute-merged-with attribute value inherit frame)))
455 value))
457 (defun face-attribute-merged-with (attribute value faces &optional frame)
458 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
459 FACES may be either a single face or a list of faces.
460 [This is an internal function.]"
461 (cond ((not (face-attribute-relative-p attribute value))
462 value)
463 ((null faces)
464 value)
465 ((consp faces)
466 (face-attribute-merged-with
467 attribute
468 (face-attribute-merged-with attribute value (car faces) frame)
469 (cdr faces)
470 frame))
472 (merge-face-attribute attribute
473 value
474 (face-attribute faces attribute frame t)))))
477 (defmacro face-attribute-specified-or (value &rest body)
478 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
479 (let ((temp (make-symbol "value")))
480 `(let ((,temp ,value))
481 (if (not (eq ,temp 'unspecified))
482 ,temp
483 ,@body))))
485 (defun face-foreground (face &optional frame inherit)
486 "Return the foreground color name of FACE, or nil if unspecified.
487 If the optional argument FRAME is given, report on face FACE in that frame.
488 If FRAME is t, report on the defaults for face FACE (for new frames).
489 If FRAME is omitted or nil, use the selected frame.
491 If INHERIT is nil, only a foreground color directly defined by FACE is
492 considered, so the return value may be nil.
493 If INHERIT is t, and FACE doesn't define a foreground color, then any
494 foreground color that FACE inherits through its `:inherit' attribute
495 is considered as well; however the return value may still be nil.
496 If INHERIT is a face or a list of faces, then it is used to try to
497 resolve an unspecified foreground color.
499 To ensure that a valid color is always returned, use a value of
500 `default' for INHERIT; this will resolve any unspecified values by
501 merging with the `default' face (which is always completely specified)."
502 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
503 nil))
505 (defun face-background (face &optional frame inherit)
506 "Return the background color name of FACE, or nil if unspecified.
507 If the optional argument FRAME is given, report on face FACE in that frame.
508 If FRAME is t, report on the defaults for face FACE (for new frames).
509 If FRAME is omitted or nil, use the selected frame.
511 If INHERIT is nil, only a background color directly defined by FACE is
512 considered, so the return value may be nil.
513 If INHERIT is t, and FACE doesn't define a background color, then any
514 background color that FACE inherits through its `:inherit' attribute
515 is considered as well; however the return value may still be nil.
516 If INHERIT is a face or a list of faces, then it is used to try to
517 resolve an unspecified background color.
519 To ensure that a valid color is always returned, use a value of
520 `default' for INHERIT; this will resolve any unspecified values by
521 merging with the `default' face (which is always completely specified)."
522 (face-attribute-specified-or (face-attribute face :background frame inherit)
523 nil))
525 (defun face-stipple (face &optional frame inherit)
526 "Return the stipple pixmap name of FACE, or nil if unspecified.
527 If the optional argument FRAME is given, report on face FACE in that frame.
528 If FRAME is t, report on the defaults for face FACE (for new frames).
529 If FRAME is omitted or nil, use the selected frame.
531 If INHERIT is nil, only a stipple directly defined by FACE is
532 considered, so the return value may be nil.
533 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
534 that FACE inherits through its `:inherit' attribute is considered as
535 well; however the return value may still be nil.
536 If INHERIT is a face or a list of faces, then it is used to try to
537 resolve an unspecified stipple.
539 To ensure that a valid stipple or nil is always returned, use a value of
540 `default' for INHERIT; this will resolve any unspecified values by merging
541 with the `default' face (which is always completely specified)."
542 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
543 nil))
546 (defalias 'face-background-pixmap 'face-stipple)
549 (defun face-underline-p (face &optional frame inherit)
550 "Return non-nil if FACE specifies a non-nil underlining.
551 If the optional argument FRAME is given, report on face FACE in that frame.
552 If FRAME is t, report on the defaults for face FACE (for new frames).
553 If FRAME is omitted or nil, use the selected frame.
554 Optional argument INHERIT is passed to `face-attribute'."
555 (face-attribute-specified-or
556 (face-attribute face :underline frame inherit) nil))
559 (defun face-inverse-video-p (face &optional frame inherit)
560 "Return non-nil if FACE specifies a non-nil inverse-video.
561 If the optional argument FRAME is given, report on face FACE in that frame.
562 If FRAME is t, report on the defaults for face FACE (for new frames).
563 If FRAME is omitted or nil, use the selected frame.
564 Optional argument INHERIT is passed to `face-attribute'."
565 (eq (face-attribute face :inverse-video frame inherit) t))
568 (defun face-bold-p (face &optional frame inherit)
569 "Return non-nil if the font of FACE is bold on FRAME.
570 If the optional argument FRAME is given, report on face FACE in that frame.
571 If FRAME is t, report on the defaults for face FACE (for new frames).
572 If FRAME is omitted or nil, use the selected frame.
573 Optional argument INHERIT is passed to `face-attribute'.
574 Use `face-attribute' for finer control."
575 (let ((bold (face-attribute face :weight frame inherit)))
576 (memq bold '(semi-bold bold extra-bold ultra-bold))))
579 (defun face-italic-p (face &optional frame inherit)
580 "Return non-nil if the font of FACE is italic on FRAME.
581 If the optional argument FRAME is given, report on face FACE in that frame.
582 If FRAME is t, report on the defaults for face FACE (for new frames).
583 If FRAME is omitted or nil, use the selected frame.
584 Optional argument INHERIT is passed to `face-attribute'.
585 Use `face-attribute' for finer control."
586 (let ((italic (face-attribute face :slant frame inherit)))
587 (memq italic '(italic oblique))))
591 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
592 ;;; Face documentation.
593 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
595 (defun face-documentation (face)
596 "Get the documentation string for FACE.
597 If FACE is a face-alias, get the documentation for the target face."
598 (let ((alias (get face 'face-alias)))
599 (if alias
600 (let ((doc (get alias 'face-documentation)))
601 (format "%s is an alias for the face `%s'.%s" face alias
602 (if doc (format "\n%s" doc)
603 "")))
604 (get face 'face-documentation))))
607 (defun set-face-documentation (face string)
608 "Set the documentation string for FACE to STRING."
609 ;; Perhaps the text should go in DOC.
610 (put face 'face-documentation (purecopy string)))
613 (defalias 'face-doc-string 'face-documentation)
614 (defalias 'set-face-doc-string 'set-face-documentation)
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
619 ;; Setting face attributes.
620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
623 (defun set-face-attribute (face frame &rest args)
624 "Set attributes of FACE on FRAME from ARGS.
625 This function overrides the face attributes specified by FACE's
626 face spec. It is mostly intended for internal use only.
628 If FRAME is nil, set the attributes for all existing frames, as
629 well as the default for new frames. If FRAME is t, change the
630 default for new frames only.
632 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a
633 valid face attribute name. All attributes can be set to
634 `unspecified'; this fact is not further mentioned below.
636 The following attributes are recognized:
638 `:family'
640 VALUE must be a string specifying the font family
641 \(e.g. \"Monospace\") or a fontset.
643 `:foundry'
645 VALUE must be a string specifying the font foundry,
646 e.g., \"adobe\". If a font foundry is specified, wild-cards `*'
647 and `?' are allowed.
649 `:width'
651 VALUE specifies the relative proportionate width of the font to use.
652 It must be one of the symbols `ultra-condensed', `extra-condensed',
653 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
654 `extra-expanded', or `ultra-expanded'.
656 `:height'
658 VALUE specifies the relative or absolute height of the font. An
659 absolute height is an integer, and specifies font height in units
660 of 1/10 pt. A relative height is either a floating point number,
661 which specifies a scaling factor for the underlying face height;
662 or a function that takes a single argument (the underlying face
663 height) and returns the new height. Note that for the `default'
664 face, you must specify an absolute height (since there is nothing
665 for it to be relative to).
667 `:weight'
669 VALUE specifies the weight of the font to use. It must be one of the
670 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
671 `semi-light', `light', `extra-light', `ultra-light'.
673 `:slant'
675 VALUE specifies the slant of the font to use. It must be one of the
676 symbols `italic', `oblique', `normal', `reverse-italic', or
677 `reverse-oblique'.
679 `:foreground', `:background'
681 VALUE must be a color name, a string.
683 `:underline'
685 VALUE specifies whether characters in FACE should be underlined.
686 If VALUE is t, underline with foreground color of the face.
687 If VALUE is a string, underline with that color.
688 If VALUE is nil, explicitly don't underline.
690 Otherwise, VALUE must be a property list of the form:
692 `(:color COLOR :style STYLE)'.
694 COLOR can be a either a color name string or `foreground-color'.
695 STYLE can be either `line' or `wave'.
696 If a keyword/value pair is missing from the property list, a
697 default value will be used for the value.
698 The default value of COLOR is the foreground color of the face.
699 The default value of STYLE is `line'.
701 `:overline'
703 VALUE specifies whether characters in FACE should be overlined. If
704 VALUE is t, overline with foreground color of the face. If VALUE is a
705 string, overline with that color. If VALUE is nil, explicitly don't
706 overline.
708 `:strike-through'
710 VALUE specifies whether characters in FACE should be drawn with a line
711 striking through them. If VALUE is t, use the foreground color of the
712 face. If VALUE is a string, strike-through with that color. If VALUE
713 is nil, explicitly don't strike through.
715 `:box'
717 VALUE specifies whether characters in FACE should have a box drawn
718 around them. If VALUE is nil, explicitly don't draw boxes. If
719 VALUE is t, draw a box with lines of width 1 in the foreground color
720 of the face. If VALUE is a string, the string must be a color name,
721 and the box is drawn in that color with a line width of 1. Otherwise,
722 VALUE must be a property list of the form `(:line-width WIDTH
723 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
724 the property list, a default value will be used for the value, as
725 specified below. WIDTH specifies the width of the lines to draw; it
726 defaults to 1. If WIDTH is negative, the absolute value is the width
727 of the lines, and draw top/bottom lines inside the characters area,
728 not around it. COLOR is the name of the color to draw in, default is
729 the foreground color of the face for simple boxes, and the background
730 color of the face for 3D boxes. STYLE specifies whether a 3D box
731 should be draw. If STYLE is `released-button', draw a box looking
732 like a released 3D button. If STYLE is `pressed-button' draw a box
733 that appears like a pressed button. If STYLE is nil, the default if
734 the property list doesn't contain a style specification, draw a 2D
735 box.
737 `:inverse-video'
739 VALUE specifies whether characters in FACE should be displayed in
740 inverse video. VALUE must be one of t or nil.
742 `:stipple'
744 If VALUE is a string, it must be the name of a file of pixmap data.
745 The directories listed in the `x-bitmap-file-path' variable are
746 searched. Alternatively, VALUE may be a list of the form (WIDTH
747 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
748 is a string containing the raw bits of the bitmap. VALUE nil means
749 explicitly don't use a stipple pattern.
751 For convenience, attributes `:family', `:foundry', `:width',
752 `:height', `:weight', and `:slant' may also be set in one step
753 from an X font name:
755 `:font'
757 Set font-related face attributes from VALUE. VALUE must be a
758 valid font name or font object. Setting this attribute will also
759 set the `:family', `:foundry', `:width', `:height', `:weight',
760 and `:slant' attributes.
762 `:inherit'
764 VALUE is the name of a face from which to inherit attributes, or
765 a list of face names. Attributes from inherited faces are merged
766 into the face like an underlying face would be, with higher
767 priority than underlying faces.
769 For backward compatibility, the keywords `:bold' and `:italic'
770 can be used to specify weight and slant respectively. This usage
771 is considered obsolete. For these two keywords, the VALUE must
772 be either t or nil. A value of t for `:bold' is equivalent to
773 setting `:weight' to `bold', and a value of t for `:italic' is
774 equivalent to setting `:slant' to `italic'. But if `:weight' is
775 specified in the face spec, `:bold' is ignored, and if `:slant'
776 is specified, `:italic' is ignored."
777 (setq args (purecopy args))
778 (let ((where (if (null frame) 0 frame))
779 (spec args)
780 family foundry orig-family orig-foundry)
781 ;; If we set the new-frame defaults, this face is modified outside Custom.
782 (if (memq where '(0 t))
783 (put (or (get face 'face-alias) face) 'face-modified t))
784 ;; If family and/or foundry are specified, set it first. Certain
785 ;; face attributes, e.g. :weight semi-condensed, are not supported
786 ;; in every font. See bug#1127.
787 (while spec
788 (cond ((eq (car spec) :family)
789 (setq family (cadr spec)))
790 ((eq (car spec) :foundry)
791 (setq foundry (cadr spec))))
792 (setq spec (cddr spec)))
793 (when (or family foundry)
794 (when (and (stringp family)
795 (string-match "\\([^-]*\\)-\\([^-]*\\)" family))
796 (setq orig-foundry foundry
797 orig-family family)
798 (unless foundry
799 (setq foundry (match-string 1 family)))
800 (setq family (match-string 2 family))
801 ;; Reject bogus "families" that are all-digits -- those are some
802 ;; weird font names, like Foobar-12, that end in a number.
803 (when (string-match "\\`[0-9]*\\'" family)
804 (setq family orig-family)
805 (setq foundry orig-foundry)))
806 (when (or (stringp family) (eq family 'unspecified))
807 (internal-set-lisp-face-attribute face :family (purecopy family)
808 where))
809 (when (or (stringp foundry) (eq foundry 'unspecified))
810 (internal-set-lisp-face-attribute face :foundry (purecopy foundry)
811 where)))
812 (while args
813 (unless (memq (car args) '(:family :foundry))
814 (internal-set-lisp-face-attribute face (car args)
815 (purecopy (cadr args))
816 where))
817 (setq args (cddr args)))))
819 (defun make-face-bold (face &optional frame _noerror)
820 "Make the font of FACE be bold, if possible.
821 FRAME nil or not specified means change face on all frames.
822 Argument NOERROR is ignored and retained for compatibility.
823 Use `set-face-attribute' for finer control of the font weight."
824 (interactive (list (read-face-name "Make which face bold"
825 (face-at-point t))))
826 (set-face-attribute face frame :weight 'bold))
829 (defun make-face-unbold (face &optional frame _noerror)
830 "Make the font of FACE be non-bold, if possible.
831 FRAME nil or not specified means change face on all frames.
832 Argument NOERROR is ignored and retained for compatibility."
833 (interactive (list (read-face-name "Make which face non-bold"
834 (face-at-point t))))
835 (set-face-attribute face frame :weight 'normal))
838 (defun make-face-italic (face &optional frame _noerror)
839 "Make the font of FACE be italic, if possible.
840 FRAME nil or not specified means change face on all frames.
841 Argument NOERROR is ignored and retained for compatibility.
842 Use `set-face-attribute' for finer control of the font slant."
843 (interactive (list (read-face-name "Make which face italic"
844 (face-at-point t))))
845 (set-face-attribute face frame :slant 'italic))
848 (defun make-face-unitalic (face &optional frame _noerror)
849 "Make the font of FACE be non-italic, if possible.
850 FRAME nil or not specified means change face on all frames.
851 Argument NOERROR is ignored and retained for compatibility."
852 (interactive (list (read-face-name "Make which face non-italic"
853 (face-at-point t))))
854 (set-face-attribute face frame :slant 'normal))
857 (defun make-face-bold-italic (face &optional frame _noerror)
858 "Make the font of FACE be bold and italic, if possible.
859 FRAME nil or not specified means change face on all frames.
860 Argument NOERROR is ignored and retained for compatibility.
861 Use `set-face-attribute' for finer control of font weight and slant."
862 (interactive (list (read-face-name "Make which face bold-italic"
863 (face-at-point t))))
864 (set-face-attribute face frame :weight 'bold :slant 'italic))
867 (defun set-face-font (face font &optional frame)
868 "Change font-related attributes of FACE to those of FONT (a string).
869 FRAME nil or not specified means change face on all frames.
870 This sets the attributes `:family', `:foundry', `:width',
871 `:height', `:weight', and `:slant'. When called interactively,
872 prompt for the face and font."
873 (interactive (read-face-and-attribute :font))
874 (set-face-attribute face frame :font font))
877 ;; Implementation note: Emulating gray background colors with a
878 ;; stipple pattern is now part of the face realization process, and is
879 ;; done in C depending on the frame on which the face is realized.
881 (defun set-face-background (face color &optional frame)
882 "Change the background color of face FACE to COLOR (a string).
883 FRAME nil or not specified means change face on all frames.
884 COLOR can be a system-defined color name (see `list-colors-display')
885 or a hex spec of the form #RRGGBB.
886 When called interactively, prompts for the face and color."
887 (interactive (read-face-and-attribute :background))
888 (set-face-attribute face frame :background (or color 'unspecified)))
891 (defun set-face-foreground (face color &optional frame)
892 "Change the foreground color of face FACE to COLOR (a string).
893 FRAME nil or not specified means change face on all frames.
894 COLOR can be a system-defined color name (see `list-colors-display')
895 or a hex spec of the form #RRGGBB.
896 When called interactively, prompts for the face and color."
897 (interactive (read-face-and-attribute :foreground))
898 (set-face-attribute face frame :foreground (or color 'unspecified)))
901 (defun set-face-stipple (face stipple &optional frame)
902 "Change the stipple pixmap of face FACE to STIPPLE.
903 FRAME nil or not specified means change face on all frames.
904 STIPPLE should be a string, the name of a file of pixmap data.
905 The directories listed in the `x-bitmap-file-path' variable are searched.
907 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
908 where WIDTH and HEIGHT are the size in pixels,
909 and DATA is a string, containing the raw bits of the bitmap."
910 (interactive (read-face-and-attribute :stipple))
911 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
914 (defun set-face-underline (face underline &optional frame)
915 "Specify whether face FACE is underlined.
916 UNDERLINE nil means FACE explicitly doesn't underline.
917 UNDERLINE t means FACE underlines with its foreground color.
918 If UNDERLINE is a string, underline with that color.
920 UNDERLINE may also be a list of the form (:color COLOR :style STYLE),
921 where COLOR is a string or `foreground-color', and STYLE is either
922 `line' or `wave'. :color may be omitted, which means to use the
923 foreground color. :style may be omitted, which means to use a line.
925 FRAME nil or not specified means change face on all frames.
926 Use `set-face-attribute' to \"unspecify\" underlining."
927 (interactive (read-face-and-attribute :underline))
928 (set-face-attribute face frame :underline underline))
930 (define-obsolete-function-alias 'set-face-underline-p
931 'set-face-underline "24.3")
934 (defun set-face-inverse-video (face inverse-video-p &optional frame)
935 "Specify whether face FACE is in inverse video.
936 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
937 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
938 FRAME nil or not specified means change face on all frames.
939 Use `set-face-attribute' to \"unspecify\" the inverse video attribute."
940 (interactive
941 (let ((list (read-face-and-attribute :inverse-video)))
942 (list (car list) (if (cadr list) t))))
943 (set-face-attribute face frame :inverse-video inverse-video-p))
945 (define-obsolete-function-alias 'set-face-inverse-video-p
946 'set-face-inverse-video "24.4")
948 (defun set-face-bold (face bold-p &optional frame)
949 "Specify whether face FACE is bold.
950 BOLD-P non-nil means FACE should explicitly display bold.
951 BOLD-P nil means FACE should explicitly display non-bold.
952 FRAME nil or not specified means change face on all frames.
953 Use `set-face-attribute' or `modify-face' for finer control."
954 (if (null bold-p)
955 (make-face-unbold face frame)
956 (make-face-bold face frame)))
958 (define-obsolete-function-alias 'set-face-bold-p 'set-face-bold "24.4")
961 (defun set-face-italic (face italic-p &optional frame)
962 "Specify whether face FACE is italic.
963 ITALIC-P non-nil means FACE should explicitly display italic.
964 ITALIC-P nil means FACE should explicitly display non-italic.
965 FRAME nil or not specified means change face on all frames.
966 Use `set-face-attribute' or `modify-face' for finer control."
967 (if (null italic-p)
968 (make-face-unitalic face frame)
969 (make-face-italic face frame)))
971 (define-obsolete-function-alias 'set-face-italic-p 'set-face-italic "24.4")
974 (defalias 'set-face-background-pixmap 'set-face-stipple)
977 (defun invert-face (face &optional frame)
978 "Swap the foreground and background colors of FACE.
979 If FRAME is omitted or nil, it means change face on all frames.
980 If FACE specifies neither foreground nor background color,
981 set its foreground and background to the background and foreground
982 of the default face. Value is FACE."
983 (interactive (list (read-face-name "Invert face" (face-at-point t))))
984 (let ((fg (face-attribute face :foreground frame))
985 (bg (face-attribute face :background frame)))
986 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
987 (set-face-attribute face frame :foreground bg :background fg)
988 (set-face-attribute face frame
989 :foreground
990 (face-attribute 'default :background frame)
991 :background
992 (face-attribute 'default :foreground frame))))
993 face)
996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
997 ;;; Interactively modifying faces.
998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1000 (defvar crm-separator) ; from crm.el
1002 (defun read-face-name (prompt &optional default multiple)
1003 "Read one or more face names, prompting with PROMPT.
1004 PROMPT should not end in a space or a colon.
1006 If DEFAULT is non-nil, it should be a face (a symbol) or a face
1007 name (a string). It can also be a list of faces or face names.
1009 If MULTIPLE is non-nil, the return value from this function is a
1010 list of faces. Otherwise a single face is returned.
1012 If the user enter the empty string at the prompt, DEFAULT is
1013 returned after a possible transformation according to MULTIPLE.
1014 That is, if DEFAULT is a list and MULTIPLE is nil, the first
1015 element of DEFAULT is returned. If DEFAULT isn't a list, but
1016 MULTIPLE is non-nil, a one-element list containing DEFAULT is
1017 returned. Otherwise, DEFAULT is returned verbatim."
1018 (unless (listp default)
1019 (setq default (list default)))
1020 (when default
1021 (setq default
1022 (if multiple
1023 (mapconcat (lambda (f) (if (symbolp f) (symbol-name f) f))
1024 default ", ")
1025 ;; If we only want one, and the default is more than one,
1026 ;; discard the unwanted ones.
1027 (setq default (car default))
1028 (if (symbolp default)
1029 (symbol-name default)
1030 default))))
1031 (when (and default (not multiple))
1032 (require 'crm)
1033 ;; For compatibility with `completing-read-multiple' use `crm-separator'
1034 ;; to define DEFAULT if MULTIPLE is nil.
1035 (setq default (car (split-string default crm-separator t))))
1037 ;; Older versions of `read-face-name' did not append ": " to the
1038 ;; prompt, so there are third party libraries that have that in the
1039 ;; prompt. If so, remove it.
1040 (setq prompt (replace-regexp-in-string ": ?\\'" "" prompt))
1041 (let ((prompt (if default
1042 (format-message "%s (default `%s'): " prompt default)
1043 (format "%s: " prompt)))
1044 aliasfaces nonaliasfaces faces)
1045 ;; Build up the completion tables.
1046 (mapatoms (lambda (s)
1047 (if (facep s)
1048 (if (get s 'face-alias)
1049 (push (symbol-name s) aliasfaces)
1050 (push (symbol-name s) nonaliasfaces)))))
1051 (if multiple
1052 (progn
1053 (dolist (face (completing-read-multiple
1054 prompt
1055 (completion-table-in-turn nonaliasfaces aliasfaces)
1056 nil t nil 'face-name-history default))
1057 ;; Ignore elements that are not faces
1058 ;; (for example, because DEFAULT was "all faces")
1059 (if (facep face) (push (intern face) faces)))
1060 (nreverse faces))
1061 (let ((face (completing-read
1062 prompt
1063 (completion-table-in-turn nonaliasfaces aliasfaces)
1064 nil t nil 'face-name-history default)))
1065 (if (facep face) (intern face))))))
1067 ;; Not defined without X, but behind window-system test.
1068 (defvar x-bitmap-file-path)
1070 (defun face-valid-attribute-values (attribute &optional frame)
1071 "Return valid values for face attribute ATTRIBUTE.
1072 The optional argument FRAME is used to determine available fonts
1073 and colors. If it is nil or not specified, the selected frame is used.
1074 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
1075 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1076 an integer value."
1077 (let ((valid
1078 (pcase attribute
1079 (`:family
1080 (if (window-system frame)
1081 (mapcar (lambda (x) (cons x x))
1082 (font-family-list))
1083 ;; Only one font on TTYs.
1084 (list (cons "default" "default"))))
1085 (`:foundry
1086 (list nil))
1087 (`:width
1088 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1089 font-width-table))
1090 (`:weight
1091 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1092 font-weight-table))
1093 (`:slant
1094 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1095 font-slant-table))
1096 (`:inverse-video
1097 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1098 (internal-lisp-face-attribute-values attribute)))
1099 ((or `:underline `:overline `:strike-through `:box)
1100 (if (window-system frame)
1101 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
1102 (internal-lisp-face-attribute-values attribute))
1103 (mapcar #'(lambda (c) (cons c c))
1104 (defined-colors frame)))
1105 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1106 (internal-lisp-face-attribute-values attribute))))
1107 ((or `:foreground `:background)
1108 (mapcar #'(lambda (c) (cons c c))
1109 (defined-colors frame)))
1110 (`:height
1111 'integerp)
1112 (`:stipple
1113 (and (memq (window-system frame) '(x ns)) ; No stipple on w32
1114 (mapcar #'list
1115 (apply #'nconc
1116 (mapcar (lambda (dir)
1117 (and (file-readable-p dir)
1118 (file-directory-p dir)
1119 (directory-files dir)))
1120 x-bitmap-file-path)))))
1121 (`:inherit
1122 (cons '("none" . nil)
1123 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1124 (face-list))))
1126 (error "Internal error")))))
1127 (if (and (listp valid) (not (memq attribute '(:inherit))))
1128 (nconc (list (cons "unspecified" 'unspecified)) valid)
1129 valid)))
1132 (defconst face-attribute-name-alist
1133 '((:family . "font family")
1134 (:foundry . "font foundry")
1135 (:width . "character set width")
1136 (:height . "height in 1/10 pt")
1137 (:weight . "weight")
1138 (:slant . "slant")
1139 (:underline . "underline")
1140 (:overline . "overline")
1141 (:strike-through . "strike-through")
1142 (:box . "box")
1143 (:inverse-video . "inverse-video display")
1144 (:foreground . "foreground color")
1145 (:background . "background color")
1146 (:stipple . "background stipple")
1147 (:inherit . "inheritance"))
1148 "An alist of descriptive names for face attributes.
1149 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1150 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1151 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1154 (defun face-descriptive-attribute-name (attribute)
1155 "Return a descriptive name for ATTRIBUTE."
1156 (cdr (assq attribute face-attribute-name-alist)))
1159 (defun face-read-string (face default name &optional completion-alist)
1160 "Interactively read a face attribute string value.
1161 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1162 default string to return if no new value is entered. NAME is a
1163 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1164 alist of valid values, if non-nil.
1166 Entering nothing accepts the default string DEFAULT.
1167 Value is the new attribute value."
1168 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1169 ;; each word in a string separately).
1170 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1171 (let* ((completion-ignore-case t)
1172 (value (completing-read
1173 (format-message (if default
1174 "%s for face `%s' (default %s): "
1175 "%s for face `%s': ")
1176 name face default)
1177 completion-alist nil nil nil nil default)))
1178 (if (equal value "") default value)))
1181 (defun face-read-integer (face default name)
1182 "Interactively read an integer face attribute value.
1183 FACE is the face whose attribute is read. DEFAULT is the default
1184 value to return if no new value is entered. NAME is a descriptive
1185 name of the attribute for prompting. Value is the new attribute value."
1186 (let ((new-value
1187 (face-read-string face
1188 (format "%s" default)
1189 name
1190 (list (cons "unspecified" 'unspecified)))))
1191 (cond ((equal new-value "unspecified")
1192 'unspecified)
1193 ((member new-value '("unspecified-fg" "unspecified-bg"))
1194 new-value)
1196 (string-to-number new-value)))))
1199 ;; FIXME this does allow you to enter the list forms of :box,
1200 ;; :stipple, or :underline, because face-valid-attribute-values does
1201 ;; not return those forms.
1202 (defun read-face-attribute (face attribute &optional frame)
1203 "Interactively read a new value for FACE's ATTRIBUTE.
1204 Optional argument FRAME nil or unspecified means read an attribute value
1205 of a global face. Value is the new attribute value."
1206 (let* ((old-value (face-attribute face attribute frame))
1207 (attribute-name (face-descriptive-attribute-name attribute))
1208 (valid (face-valid-attribute-values attribute frame))
1209 new-value)
1210 ;; Represent complex attribute values as strings by printing them
1211 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1212 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1213 ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'.
1214 (and (memq attribute '(:box :stipple :underline))
1215 (or (consp old-value)
1216 (vectorp old-value))
1217 (setq old-value (prin1-to-string old-value)))
1218 (cond ((listp valid)
1219 (let ((default
1220 (or (car (rassoc old-value valid))
1221 (format "%s" old-value))))
1222 (setq new-value
1223 (face-read-string face default attribute-name valid))
1224 (if (equal new-value default)
1225 ;; Nothing changed, so don't bother with all the stuff
1226 ;; below. In particular, this avoids a non-tty color
1227 ;; from being canonicalized for a tty when the user
1228 ;; just uses the default.
1229 (setq new-value old-value)
1230 ;; Terminal frames can support colors that don't appear
1231 ;; explicitly in VALID, using color approximation code
1232 ;; in tty-colors.el.
1233 (when (and (memq attribute '(:foreground :background))
1234 (not (memq (window-system frame) '(x w32 ns)))
1235 (not (member new-value
1236 '("unspecified"
1237 "unspecified-fg" "unspecified-bg"))))
1238 (setq new-value (car (tty-color-desc new-value frame))))
1239 (when (assoc new-value valid)
1240 (setq new-value (cdr (assoc new-value valid)))))))
1241 ((eq valid 'integerp)
1242 (setq new-value (face-read-integer face old-value attribute-name)))
1243 (t (error "Internal error")))
1244 ;; Convert stipple and box value text we read back to a list or
1245 ;; vector if it looks like one. This makes the assumption that a
1246 ;; pixmap file name won't start with an open-paren.
1247 (and (memq attribute '(:stipple :box :underline))
1248 (stringp new-value)
1249 (string-match-p "^[[(]" new-value)
1250 (setq new-value (read new-value)))
1251 new-value))
1253 (declare-function fontset-list "fontset.c" ())
1254 (declare-function x-list-fonts "xfaces.c"
1255 (pattern &optional face frame maximum width))
1257 (defun read-face-font (face &optional frame)
1258 "Read the name of a font for FACE on FRAME.
1259 If optional argument FRAME is nil or omitted, use the selected frame."
1260 (let ((completion-ignore-case t))
1261 (completing-read (format-message
1262 "Set font attributes of face `%s' from font: " face)
1263 (append (fontset-list) (x-list-fonts "*" nil frame)))))
1266 (defun read-all-face-attributes (face &optional frame)
1267 "Interactively read all attributes for FACE.
1268 If optional argument FRAME is nil or omitted, use the selected frame.
1269 Value is a property list of attribute names and new values."
1270 (let (result)
1271 (dolist (attribute face-attribute-name-alist result)
1272 (setq result (cons (car attribute)
1273 (cons (read-face-attribute face (car attribute) frame)
1274 result))))))
1276 (defun modify-face (&optional face foreground background stipple
1277 bold-p italic-p underline inverse-p frame)
1278 "Modify attributes of faces interactively.
1279 If optional argument FRAME is nil or omitted, modify the face used
1280 for newly created frame, i.e. the global face.
1281 For non-interactive use, `set-face-attribute' is preferred.
1282 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1283 and the face and its settings are obtained by querying the user."
1284 (interactive)
1285 (if face
1286 (set-face-attribute face frame
1287 :foreground (or foreground 'unspecified)
1288 :background (or background 'unspecified)
1289 :stipple stipple
1290 :weight (if bold-p 'bold 'normal)
1291 :slant (if italic-p 'italic 'normal)
1292 :underline underline
1293 :inverse-video inverse-p)
1294 (setq face (read-face-name "Modify face" (face-at-point t)))
1295 (apply #'set-face-attribute face frame
1296 (read-all-face-attributes face frame))))
1298 (defun read-face-and-attribute (attribute &optional frame)
1299 "Read face name and face attribute value.
1300 ATTRIBUTE is the attribute whose new value is read.
1301 FRAME nil or unspecified means read attribute value of global face.
1302 Value is a list (FACE NEW-VALUE) where FACE is the face read
1303 \(a symbol), and NEW-VALUE is value read."
1304 (cond ((eq attribute :font)
1305 (let* ((prompt "Set font-related attributes of face")
1306 (face (read-face-name prompt (face-at-point t)))
1307 (font (read-face-font face frame)))
1308 (list face font)))
1310 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1311 (prompt (format "Set %s of face" attribute-name))
1312 (face (read-face-name prompt (face-at-point t)))
1313 (new-value (read-face-attribute face attribute frame)))
1314 (list face new-value)))))
1318 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1319 ;;; Listing faces.
1320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1322 (defconst list-faces-sample-text
1323 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1324 "Text string to display as the sample text for `list-faces-display'.")
1327 ;; The name list-faces would be more consistent, but let's avoid a
1328 ;; conflict with Lucid, which uses that name differently.
1330 (defvar help-xref-stack)
1331 (defun list-faces-display (&optional regexp)
1332 "List all faces, using the same sample text in each.
1333 The sample text is a string that comes from the variable
1334 `list-faces-sample-text'.
1336 If REGEXP is non-nil, list only those faces with names matching
1337 this regular expression. When called interactively with a prefix
1338 argument, prompt for a regular expression using `read-regexp'."
1339 (interactive (list (and current-prefix-arg
1340 (read-regexp "List faces matching regexp"))))
1341 (let ((all-faces (zerop (length regexp)))
1342 (frame (selected-frame))
1343 (max-length 0)
1344 faces line-format
1345 disp-frame window face-name)
1346 ;; We filter and take the max length in one pass
1347 (setq faces
1348 (delq nil
1349 (mapcar (lambda (f)
1350 (let ((s (symbol-name f)))
1351 (when (or all-faces (string-match-p regexp s))
1352 (setq max-length (max (length s) max-length))
1353 f)))
1354 (sort (face-list) #'string-lessp))))
1355 (unless faces
1356 (error "No faces matching \"%s\"" regexp))
1357 (setq max-length (1+ max-length)
1358 line-format (format "%%-%ds" max-length))
1359 (with-help-window "*Faces*"
1360 (with-current-buffer standard-output
1361 (setq truncate-lines t)
1362 (insert
1363 (substitute-command-keys
1364 (concat
1365 "\\<help-mode-map>Use "
1366 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1367 "\\[help-follow] on a face name to customize it\n"
1368 "or on its sample text for a description of the face.\n\n")))
1369 (setq help-xref-stack nil)
1370 (dolist (face faces)
1371 (setq face-name (symbol-name face))
1372 (insert (format line-format face-name))
1373 ;; Hyperlink to a customization buffer for the face. Using
1374 ;; the help xref mechanism may not be the best way.
1375 (save-excursion
1376 (save-match-data
1377 (search-backward face-name)
1378 (setq help-xref-stack-item `(list-faces-display ,regexp))
1379 (help-xref-button 0 'help-customize-face face)))
1380 (let ((beg (point))
1381 (line-beg (line-beginning-position)))
1382 (insert list-faces-sample-text)
1383 ;; Hyperlink to a help buffer for the face.
1384 (save-excursion
1385 (save-match-data
1386 (search-backward list-faces-sample-text)
1387 (help-xref-button 0 'help-face face)))
1388 (insert "\n")
1389 (put-text-property beg (1- (point)) 'face face)
1390 ;; Make all face commands default to the proper face
1391 ;; anywhere in the line.
1392 (put-text-property line-beg (1- (point)) 'read-face-name face)
1393 ;; If the sample text has multiple lines, line up all of them.
1394 (goto-char beg)
1395 (forward-line 1)
1396 (while (not (eobp))
1397 (insert-char ?\s max-length)
1398 (forward-line 1))))
1399 (goto-char (point-min))))
1400 ;; If the *Faces* buffer appears in a different frame,
1401 ;; copy all the face definitions from FRAME,
1402 ;; so that the display will reflect the frame that was selected.
1403 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1404 (setq disp-frame (if window (window-frame window)
1405 (car (frame-list))))
1406 (or (eq frame disp-frame)
1407 (dolist (face (face-list))
1408 (copy-face face face frame disp-frame)))))
1411 (defun describe-face (face &optional frame)
1412 "Display the properties of face FACE on FRAME.
1413 Interactively, FACE defaults to the faces of the character after point
1414 and FRAME defaults to the selected frame.
1416 If the optional argument FRAME is given, report on face FACE in that frame.
1417 If FRAME is t, report on the defaults for face FACE (for new frames).
1418 If FRAME is omitted or nil, use the selected frame."
1419 (interactive (list (read-face-name "Describe face"
1420 (or (face-at-point t) 'default)
1421 t)))
1422 (let* ((attrs '((:family . "Family")
1423 (:foundry . "Foundry")
1424 (:width . "Width")
1425 (:height . "Height")
1426 (:weight . "Weight")
1427 (:slant . "Slant")
1428 (:foreground . "Foreground")
1429 (:distant-foreground . "DistantForeground")
1430 (:background . "Background")
1431 (:underline . "Underline")
1432 (:overline . "Overline")
1433 (:strike-through . "Strike-through")
1434 (:box . "Box")
1435 (:inverse-video . "Inverse")
1436 (:stipple . "Stipple")
1437 (:font . "Font")
1438 (:fontset . "Fontset")
1439 (:inherit . "Inherit")))
1440 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1441 attrs))))
1442 (help-setup-xref (list #'describe-face face)
1443 (called-interactively-p 'interactive))
1444 (unless face
1445 (setq face 'default))
1446 (if (not (listp face))
1447 (setq face (list face)))
1448 (with-help-window (help-buffer)
1449 (with-current-buffer standard-output
1450 (dolist (f face)
1451 (if (stringp f) (setq f (intern f)))
1452 ;; We may get called for anonymous faces (i.e., faces
1453 ;; expressed using prop-value plists). Those can't be
1454 ;; usefully customized, so ignore them.
1455 (when (symbolp f)
1456 (insert "Face: " (symbol-name f))
1457 (if (not (facep f))
1458 (insert " undefined face.\n")
1459 (let ((customize-label "customize this face")
1460 file-name)
1461 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1462 (princ (concat " (" customize-label ")\n"))
1463 ;; FIXME not sure how much of this belongs here, and
1464 ;; how much in `face-documentation'. The latter is
1465 ;; not used much, but needs to return nil for
1466 ;; undocumented faces.
1467 (let ((alias (get f 'face-alias))
1468 (face f)
1469 obsolete)
1470 (when alias
1471 (setq face alias)
1472 (insert
1473 (format-message
1474 "\n %s is an alias for the face `%s'.\n%s"
1475 f alias
1476 (if (setq obsolete (get f 'obsolete-face))
1477 (format-message
1478 " This face is obsolete%s; use `%s' instead.\n"
1479 (if (stringp obsolete)
1480 (format " since %s" obsolete)
1482 alias)
1483 ""))))
1484 (insert "\nDocumentation:\n"
1485 (substitute-command-keys
1486 (or (face-documentation face)
1487 "Not documented as a face."))
1488 "\n\n"))
1489 (with-current-buffer standard-output
1490 (save-excursion
1491 (re-search-backward
1492 (concat "\\(" customize-label "\\)") nil t)
1493 (help-xref-button 1 'help-customize-face f)))
1494 (setq file-name (find-lisp-object-file-name f 'defface))
1495 (when file-name
1496 (princ (substitute-command-keys "Defined in `"))
1497 (princ (file-name-nondirectory file-name))
1498 (princ (substitute-command-keys "'"))
1499 ;; Make a hyperlink to the library.
1500 (save-excursion
1501 (re-search-backward
1502 (substitute-command-keys "`\\([^`']+\\)'") nil t)
1503 (help-xref-button 1 'help-face-def f file-name))
1504 (princ ".")
1505 (terpri)
1506 (terpri))
1507 (dolist (a attrs)
1508 (let ((attr (face-attribute f (car a) frame)))
1509 (insert (make-string (- max-width (length (cdr a))) ?\s)
1510 (cdr a) ": " (format "%s" attr))
1511 (if (and (eq (car a) :inherit)
1512 (not (eq attr 'unspecified)))
1513 ;; Make a hyperlink to the parent face.
1514 (save-excursion
1515 (re-search-backward ": \\([^:]+\\)" nil t)
1516 (help-xref-button 1 'help-face attr)))
1517 (insert "\n")))))
1518 (terpri)))))))
1521 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1522 ;;; Face specifications (defface).
1523 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1525 ;; Parameter FRAME Is kept for call compatibility to with previous
1526 ;; face implementation.
1528 (defun face-attr-construct (face &optional _frame)
1529 "Return a `defface'-style attribute list for FACE.
1530 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1531 face attributes of FACE where ATTRIBUTE is the attribute name and
1532 VALUE is the specified value of that attribute.
1533 Argument FRAME is ignored and retained for compatibility."
1534 (let (result)
1535 (dolist (entry face-attribute-name-alist result)
1536 (let* ((attribute (car entry))
1537 (value (face-attribute face attribute)))
1538 (unless (eq value 'unspecified)
1539 (setq result (nconc (list attribute value) result)))))))
1542 (defun face-spec-set-match-display (display frame)
1543 "Non-nil if DISPLAY matches FRAME.
1544 DISPLAY is part of a spec such as can be used in `defface'.
1545 If FRAME is nil, the current FRAME is used."
1546 (let* ((conjuncts display)
1547 conjunct req options
1548 ;; t means we have succeeded against all the conjuncts in
1549 ;; DISPLAY that have been tested so far.
1550 (match t))
1551 (if (eq conjuncts t)
1552 (setq conjuncts nil))
1553 (while (and conjuncts match)
1554 (setq conjunct (car conjuncts)
1555 conjuncts (cdr conjuncts)
1556 req (car conjunct)
1557 options (cdr conjunct)
1558 match (cond ((eq req 'type)
1559 (or (memq (window-system frame) options)
1560 (and (memq 'graphic options)
1561 (memq (window-system frame) '(x w32 ns)))
1562 ;; FIXME: This should be revisited to use
1563 ;; display-graphic-p, provided that the
1564 ;; color selection depends on the number
1565 ;; of supported colors, and all defface's
1566 ;; are changed to look at number of colors
1567 ;; instead of (type graphic) etc.
1568 (if (null (window-system frame))
1569 (memq 'tty options)
1570 (or (and (memq 'motif options)
1571 (featurep 'motif))
1572 (and (memq 'gtk options)
1573 (featurep 'gtk))
1574 (and (memq 'lucid options)
1575 (featurep 'x-toolkit)
1576 (not (featurep 'motif))
1577 (not (featurep 'gtk)))
1578 (and (memq 'x-toolkit options)
1579 (featurep 'x-toolkit))))))
1580 ((eq req 'min-colors)
1581 (>= (display-color-cells frame) (car options)))
1582 ((eq req 'class)
1583 (memq (frame-parameter frame 'display-type) options))
1584 ((eq req 'background)
1585 (memq (frame-parameter frame 'background-mode)
1586 options))
1587 ((eq req 'supports)
1588 (display-supports-face-attributes-p options frame))
1589 (t (error "Unknown req `%S' with options `%S'"
1590 req options)))))
1591 match))
1594 (defun face-spec-choose (spec &optional frame no-match-retval)
1595 "Return the proper attributes for FRAME, out of SPEC.
1597 If no match is found or SPEC is nil, return nil, unless NO-MATCH-RETVAL
1598 is given, in which case return its value instead."
1599 (unless frame
1600 (setq frame (selected-frame)))
1601 (let ((tail spec)
1602 result defaults match-found)
1603 (while tail
1604 (let* ((entry (pop tail))
1605 (display (car entry))
1606 (attrs (cdr entry))
1607 thisval)
1608 ;; Get the attributes as actually specified by this alternative.
1609 (setq thisval
1610 (if (null (cdr attrs)) ;; was (listp (car attrs))
1611 ;; Old-style entry, the attribute list is the
1612 ;; first element.
1613 (car attrs)
1614 attrs))
1616 ;; If the condition is `default', that sets the default
1617 ;; for following conditions.
1618 (if (eq display 'default)
1619 (setq defaults thisval)
1620 ;; Otherwise, if it matches, use it.
1621 (when (face-spec-set-match-display display frame)
1622 (setq result thisval
1623 tail nil
1624 match-found t)))))
1625 ;; If defaults have been found, it's safe to just append those to the result
1626 ;; list (which at this point will be either nil or contain actual specs) and
1627 ;; return it to the caller. Since there will most definitely be something to
1628 ;; return in this case, there's no need to know/check if a match was found.
1629 (if defaults
1630 (append result defaults)
1631 (if match-found
1632 result
1633 no-match-retval))))
1635 ;; When over 80 faces get processed at frame creation time, all but
1636 ;; one specifying all attributes as "unspecified", generating this
1637 ;; list every time means a lot of consing.
1638 (defconst face--attributes-unspecified
1639 (apply 'append
1640 (mapcar (lambda (x) (list (car x) 'unspecified))
1641 face-attribute-name-alist)))
1643 (defun face-spec-reset-face (face &optional frame)
1644 "Reset all attributes of FACE on FRAME to unspecified."
1645 (apply 'set-face-attribute face frame
1646 (if (eq face 'default)
1647 ;; For the default face, avoid making any attribute
1648 ;; unspecified. Instead, set attributes to default values
1649 ;; (see also realize_default_face in xfaces.c).
1650 (append
1651 '(:underline nil :overline nil :strike-through nil
1652 :box nil :inverse-video nil :stipple nil :inherit nil)
1653 ;; `display-graphic-p' is unavailable when running
1654 ;; temacs, prior to loading frame.el.
1655 (when (fboundp 'display-graphic-p)
1656 (unless (display-graphic-p frame)
1657 `(:family "default" :foundry "default" :width normal
1658 :height 1 :weight normal :slant normal
1659 :foreground ,(if (frame-parameter nil 'reverse)
1660 "unspecified-bg"
1661 "unspecified-fg")
1662 :background ,(if (frame-parameter nil 'reverse)
1663 "unspecified-fg"
1664 "unspecified-bg")))))
1665 ;; For all other faces, unspecify all attributes.
1666 face--attributes-unspecified)))
1668 (defun face-spec-set (face spec &optional spec-type)
1669 "Set the face spec SPEC for FACE.
1670 See `defface' for the format of SPEC.
1672 The appearance of each face is controlled by its specs (set via
1673 this function), and by the internal frame-specific face
1674 attributes (set via `set-face-attribute').
1676 This function also defines FACE as a valid face name if it is not
1677 already one, and (re)calculates its attributes on existing
1678 frames.
1680 The argument SPEC-TYPE determines which spec to set:
1681 nil or `face-override-spec' means the override spec (which is
1682 usually what you want if calling this function outside of
1683 Custom code);
1684 `customized-face' or `saved-face' means the customized spec or
1685 the saved custom spec;
1686 `face-defface-spec' means the default spec
1687 (usually set only via `defface');
1688 `reset' means to ignore SPEC, but clear the `customized-face'
1689 and `face-override-spec' specs;
1690 Any other value means not to set any spec, but to run the
1691 function for its other effects."
1692 (if (get face 'face-alias)
1693 (setq face (get face 'face-alias)))
1694 ;; Save SPEC to the relevant symbol property.
1695 (unless spec-type
1696 (setq spec-type 'face-override-spec))
1697 (if (memq spec-type '(face-defface-spec face-override-spec
1698 customized-face saved-face))
1699 (put face spec-type spec))
1700 (if (memq spec-type '(reset saved-face))
1701 (put face 'customized-face nil))
1702 ;; Setting the face spec via Custom empties out any override spec,
1703 ;; similar to how setting a variable via Custom changes its values.
1704 (if (memq spec-type '(customized-face saved-face reset))
1705 (put face 'face-override-spec nil))
1706 ;; If we reset the face based on its custom spec, it is unmodified
1707 ;; as far as Custom is concerned.
1708 (unless (eq face 'face-override-spec)
1709 (put face 'face-modified nil))
1710 ;; Initialize the face if it does not exist, then recalculate.
1711 (make-empty-face face)
1712 (dolist (frame (frame-list))
1713 (face-spec-recalc face frame)))
1715 (defun face-spec-recalc (face frame)
1716 "Reset the face attributes of FACE on FRAME according to its specs.
1717 The following sources are applied in this order:
1719 face reset to default values if it's the default face, otherwise set
1720 to unspecified (through `face-spec-reset-face')
1722 (theme and user customization)
1723 or: if none of the above exist, and none match the current frame or
1724 inherited from the defface spec instead of overwriting it
1725 entirely, the following is applied instead:
1726 (defface default spec)
1727 (X resources (if applicable))
1729 defface override spec"
1730 (while (get face 'face-alias)
1731 (setq face (get face 'face-alias)))
1732 (face-spec-reset-face face frame)
1733 ;; If FACE is customized or themed, set the custom spec from
1734 ;; `theme-face' records.
1735 (let ((theme-faces (get face 'theme-face))
1736 (no-match-found 0)
1737 spec theme-face-applied)
1738 (if theme-faces
1739 (dolist (elt (reverse theme-faces))
1740 (setq spec (face-spec-choose (cadr elt) frame no-match-found))
1741 (unless (eq spec no-match-found)
1742 (face-spec-set-2 face frame spec)
1743 (setq theme-face-applied t))))
1744 ;; If there was a spec applicable to FRAME, that overrides the
1745 ;; defface spec entirely (rather than inheriting from it). If
1746 ;; there was no spec applicable to FRAME, apply the defface spec
1747 ;; as well as any applicable X resources.
1748 (unless theme-face-applied
1749 (setq spec (face-spec-choose (face-default-spec face) frame))
1750 (face-spec-set-2 face frame spec)
1751 (make-face-x-resource-internal face frame))
1752 (setq spec (face-spec-choose (get face 'face-override-spec) frame))
1753 (face-spec-set-2 face frame spec)))
1755 (defun face-spec-set-2 (face frame spec)
1756 "Set the face attributes of FACE on FRAME according to SPEC."
1757 (let (attrs)
1758 (while spec
1759 (when (assq (car spec) face-x-resources)
1760 (push (car spec) attrs)
1761 (push (cadr spec) attrs))
1762 (setq spec (cddr spec)))
1763 (apply 'set-face-attribute face frame (nreverse attrs))))
1765 (defun face-attr-match-p (face attrs &optional frame)
1766 "Return t if attributes of FACE match values in plist ATTRS.
1767 Optional parameter FRAME is the frame whose definition of FACE
1768 is used. If nil or omitted, use the selected frame."
1769 (unless frame
1770 (setq frame (selected-frame)))
1771 (let* ((list face-attribute-name-alist)
1772 (match t)
1773 (bold (and (plist-member attrs :bold)
1774 (not (plist-member attrs :weight))))
1775 (italic (and (plist-member attrs :italic)
1776 (not (plist-member attrs :slant))))
1777 (plist (if (or bold italic)
1778 (copy-sequence attrs)
1779 attrs)))
1780 ;; Handle the Emacs 20 :bold and :italic properties.
1781 (if bold
1782 (plist-put plist :weight (if bold 'bold 'normal)))
1783 (if italic
1784 (plist-put plist :slant (if italic 'italic 'normal)))
1785 (while (and match list)
1786 (let* ((attr (caar list))
1787 (specified-value
1788 (if (plist-member plist attr)
1789 (plist-get plist attr)
1790 'unspecified))
1791 (value-now (face-attribute face attr frame)))
1792 (setq match (equal specified-value value-now))
1793 (setq list (cdr list))))
1794 match))
1796 (defsubst face-spec-match-p (face spec &optional frame)
1797 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1798 (face-attr-match-p face (face-spec-choose spec frame) frame))
1800 (defsubst face-default-spec (face)
1801 "Return the default face-spec for FACE, ignoring any user customization.
1802 If there is no default for FACE, return nil."
1803 (get face 'face-defface-spec))
1805 (defsubst face-user-default-spec (face)
1806 "Return the user's customized face-spec for FACE, or the default if none.
1807 If there is neither a user setting nor a default for FACE, return nil."
1808 (or (get face 'customized-face)
1809 (get face 'saved-face)
1810 (face-default-spec face)))
1813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1814 ;;; Frame-type independent color support.
1815 ;;; We keep the old x-* names as aliases for back-compatibility.
1816 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1818 (defun defined-colors (&optional frame)
1819 "Return a list of colors supported for a particular frame.
1820 The argument FRAME specifies which frame to try.
1821 The value may be different for frames on different display types.
1822 If FRAME doesn't support colors, the value is nil.
1823 If FRAME is nil, that stands for the selected frame."
1824 (if (memq (framep (or frame (selected-frame))) '(x w32 ns))
1825 (xw-defined-colors frame)
1826 (mapcar 'car (tty-color-alist frame))))
1827 (defalias 'x-defined-colors 'defined-colors)
1829 (defun defined-colors-with-face-attributes (&optional frame)
1830 "Return a list of colors supported for a particular frame.
1831 See `defined-colors' for arguments and return value. In contrast
1832 to `define-colors' the elements of the returned list are color
1833 strings with text properties, that make the color names render
1834 with the color they represent as background color."
1835 (mapcar
1836 (lambda (color-name)
1837 (let ((foreground (readable-foreground-color color-name))
1838 (color (copy-sequence color-name)))
1839 (propertize color 'face (list :foreground foreground
1840 :background color))))
1841 (defined-colors frame)))
1843 (defun readable-foreground-color (color)
1844 "Return a readable foreground color for background COLOR."
1845 (let* ((rgb (color-values color))
1846 (max (apply #'max rgb))
1847 (black (car (color-values "black")))
1848 (white (car (color-values "white"))))
1849 ;; Select black or white depending on which one is less similar to
1850 ;; the brightest component.
1851 (if (> (abs (- max black)) (abs (- max white)))
1852 "black"
1853 "white")))
1855 (declare-function xw-color-defined-p "xfns.c" (color &optional frame))
1857 (defun color-defined-p (color &optional frame)
1858 "Return non-nil if COLOR is supported on frame FRAME.
1859 COLOR should be a string naming a color (e.g. \"white\"), or a
1860 string specifying a color's RGB components (e.g. \"#ff12ec\"), or
1861 the symbol `unspecified'.
1863 This function returns nil if COLOR is the symbol `unspecified',
1864 or one of the strings \"unspecified-fg\" or \"unspecified-bg\".
1866 If FRAME is omitted or nil, use the selected frame."
1867 (unless (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1868 (if (member (framep (or frame (selected-frame))) '(x w32 ns))
1869 (xw-color-defined-p color frame)
1870 (numberp (tty-color-translate color frame)))))
1871 (defalias 'x-color-defined-p 'color-defined-p)
1873 (declare-function xw-color-values "xfns.c" (color &optional frame))
1875 (defun color-values (color &optional frame)
1876 "Return a description of the color named COLOR on frame FRAME.
1877 COLOR should be a string naming a color (e.g. \"white\"), or a
1878 string specifying a color's RGB components (e.g. \"#ff12ec\").
1880 Return a list of three integers, (RED GREEN BLUE), each between 0
1881 and either 65280 or 65535 (the maximum depends on the system).
1882 Use `color-name-to-rgb' if you want RGB floating-point values
1883 normalized to 1.0.
1885 If FRAME is omitted or nil, use the selected frame.
1886 If FRAME cannot display COLOR, the value is nil.
1888 COLOR can also be the symbol `unspecified' or one of the strings
1889 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1890 return value is nil."
1891 (cond
1892 ((member color '(unspecified "unspecified-fg" "unspecified-bg"))
1893 nil)
1894 ((memq (framep (or frame (selected-frame))) '(x w32 ns))
1895 (xw-color-values color frame))
1897 (tty-color-values color frame))))
1899 (defalias 'x-color-values 'color-values)
1901 (declare-function xw-display-color-p "xfns.c" (&optional terminal))
1903 (defun display-color-p (&optional display)
1904 "Return t if DISPLAY supports color.
1905 The optional argument DISPLAY specifies which display to ask about.
1906 DISPLAY should be either a frame or a display name (a string).
1907 If omitted or nil, that stands for the selected frame's display."
1908 (if (memq (framep-on-display display) '(x w32 ns))
1909 (xw-display-color-p display)
1910 (tty-display-color-p display)))
1911 (defalias 'x-display-color-p 'display-color-p)
1913 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
1915 (defun display-grayscale-p (&optional display)
1916 "Return non-nil if frames on DISPLAY can display shades of gray.
1917 DISPLAY should be either a frame or a display name (a string).
1918 If omitted or nil, that stands for the selected frame's display."
1919 (let ((frame-type (framep-on-display display)))
1920 (cond
1921 ((memq frame-type '(x w32 ns))
1922 (x-display-grayscale-p display))
1924 (> (tty-color-gray-shades display) 2)))))
1926 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg)
1927 "Read a color name or RGB triplet.
1928 Completion is available for color names, but not for RGB triplets.
1930 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1931 components can have one to four digits, but all three components
1932 must have the same number of digits. Each digit is a hex value
1933 between 0 and F; either upper case or lower case for A through F
1934 are acceptable.
1936 In addition to standard color names and RGB hex values, the
1937 following are available as color candidates. In each case, the
1938 corresponding color is used.
1940 * `foreground at point' - foreground under the cursor
1941 * `background at point' - background under the cursor
1943 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1945 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1946 convert an input color name to an RGB hex string. Return the RGB
1947 hex string.
1949 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1950 to enter an empty color name (the empty string).
1952 Interactively, or with optional arg MSG non-nil, print the
1953 resulting color name in the echo area."
1954 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1955 (let* ((completion-ignore-case t)
1956 (colors (or facemenu-color-alist
1957 (append '("foreground at point" "background at point")
1958 (if allow-empty-name '(""))
1959 (if (display-color-p)
1960 (defined-colors-with-face-attributes)
1961 (defined-colors)))))
1962 (color (completing-read
1963 (or prompt "Color (name or #RGB triplet): ")
1964 ;; Completing function for reading colors, accepting
1965 ;; both color names and RGB triplets.
1966 (lambda (string pred flag)
1967 (cond
1968 ((null flag) ; Try completion.
1969 (or (try-completion string colors pred)
1970 (if (color-defined-p string)
1971 string)))
1972 ((eq flag t) ; List all completions.
1973 (or (all-completions string colors pred)
1974 (if (color-defined-p string)
1975 (list string))))
1976 ((eq flag 'lambda) ; Test completion.
1977 (or (member string colors)
1978 (color-defined-p string)))))
1979 nil t)))
1981 ;; Process named colors.
1982 (when (member color colors)
1983 (cond ((string-equal color "foreground at point")
1984 (setq color (foreground-color-at-point)))
1985 ((string-equal color "background at point")
1986 (setq color (background-color-at-point))))
1987 (when (and convert-to-RGB
1988 (not (string-equal color "")))
1989 (let ((components (x-color-values color)))
1990 (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1991 (setq color (format "#%04X%04X%04X"
1992 (logand 65535 (nth 0 components))
1993 (logand 65535 (nth 1 components))
1994 (logand 65535 (nth 2 components))))))))
1995 (when msg (message "Color: `%s'" color))
1996 color))
1998 (defun face-at-point (&optional thing multiple)
1999 "Return the face of the character after point.
2000 If it has more than one face, return the first one.
2001 If THING is non-nil try first to get a face name from the buffer.
2002 IF MULTIPLE is non-nil, return a list of all faces.
2003 Return nil if there is no face."
2004 (let (faces)
2005 (if thing
2006 ;; Try to get a face name from the buffer.
2007 (let ((face (intern-soft (thing-at-point 'symbol))))
2008 (if (facep face)
2009 (push face faces))))
2010 ;; Add the named faces that the `read-face-name' or `face' property uses.
2011 (let ((faceprop (or (get-char-property (point) 'read-face-name)
2012 (get-char-property (point) 'face))))
2013 (cond ((facep faceprop)
2014 (push faceprop faces))
2015 ((face-list-p faceprop)
2016 (dolist (face faceprop)
2017 (if (facep face)
2018 (push face faces))))))
2019 (if multiple
2020 (delete-dups (nreverse faces))
2021 (car (last faces)))))
2023 (defun faces--attribute-at-point (attribute &optional attribute-unnamed)
2024 "Return the face ATTRIBUTE at point.
2025 ATTRIBUTE is a keyword.
2026 If ATTRIBUTE-UNNAMED is non-nil, it is a symbol to look for in
2027 unnamed faces (e.g, `foreground-color')."
2028 ;; `face-at-point' alone is not sufficient. It only gets named faces.
2029 ;; Need also pick up any face properties that are not associated with named faces.
2030 (let ((faces (or (get-char-property (point) 'read-face-name)
2031 ;; If `font-lock-mode' is on, `font-lock-face' takes precedence.
2032 (and font-lock-mode
2033 (get-char-property (point) 'font-lock-face))
2034 (get-char-property (point) 'face)))
2035 (found nil))
2036 (dolist (face (if (face-list-p faces)
2037 faces
2038 (list faces)))
2039 (cond (found)
2040 ((and face (symbolp face))
2041 (let ((value (face-attribute-specified-or
2042 (face-attribute face attribute nil t)
2043 nil)))
2044 (unless (member value '(nil "unspecified-fg" "unspecified-bg"))
2045 (setq found value))))
2046 ((consp face)
2047 (setq found (cond ((and attribute-unnamed
2048 (memq attribute-unnamed face))
2049 (cdr (memq attribute-unnamed face)))
2050 ((memq attribute face) (cadr (memq attribute face))))))))
2051 (or found
2052 (face-attribute 'default attribute))))
2054 (defun foreground-color-at-point ()
2055 "Return the foreground color of the character after point."
2056 (faces--attribute-at-point :foreground 'foreground-color))
2058 (defun background-color-at-point ()
2059 "Return the background color of the character after point."
2060 (faces--attribute-at-point :background 'background-color))
2063 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2064 ;;; Frame creation.
2065 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2067 (declare-function x-display-list "xfns.c" ())
2068 (declare-function x-open-connection "xfns.c"
2069 (display &optional xrm-string must-succeed))
2070 (declare-function x-get-resource "frame.c"
2071 (attribute class &optional component subclass))
2072 (declare-function x-parse-geometry "frame.c" (string))
2073 (defvar x-display-name)
2075 (defun x-handle-named-frame-geometry (parameters)
2076 "Add geometry parameters for a named frame to parameter list PARAMETERS.
2077 Value is the new parameter list."
2078 ;; Note that `x-resource-name' has a global meaning.
2079 (let ((x-resource-name (cdr (assq 'name parameters))))
2080 (when x-resource-name
2081 ;; Before checking X resources, we must have an X connection.
2082 (or (window-system)
2083 (x-display-list)
2084 (x-open-connection (or (cdr (assq 'display parameters))
2085 x-display-name)))
2086 (let (res-geometry parsed)
2087 (and (setq res-geometry (x-get-resource "geometry" "Geometry"))
2088 (setq parsed (x-parse-geometry res-geometry))
2089 (setq parameters
2090 (append parameters parsed
2091 ;; If the resource specifies a position,
2092 ;; take note of that.
2093 (if (or (assq 'top parsed) (assq 'left parsed))
2094 '((user-position . t) (user-size . t)))))))))
2095 parameters)
2098 (defun x-handle-reverse-video (frame parameters)
2099 "Handle the reverse-video frame parameter and X resource.
2100 `x-create-frame' does not handle this one."
2101 (when (cdr (or (assq 'reverse parameters)
2102 (let ((resource (x-get-resource "reverseVideo"
2103 "ReverseVideo")))
2104 (if resource
2105 (cons nil (member (downcase resource)
2106 '("on" "true")))))))
2107 (let* ((params (frame-parameters frame))
2108 (bg (cdr (assq 'foreground-color params)))
2109 (fg (cdr (assq 'background-color params))))
2110 (modify-frame-parameters frame
2111 (list (cons 'foreground-color fg)
2112 (cons 'background-color bg)))
2113 (if (equal bg (cdr (assq 'border-color params)))
2114 (modify-frame-parameters frame
2115 (list (cons 'border-color fg))))
2116 (if (equal bg (cdr (assq 'mouse-color params)))
2117 (modify-frame-parameters frame
2118 (list (cons 'mouse-color fg))))
2119 (if (equal bg (cdr (assq 'cursor-color params)))
2120 (modify-frame-parameters frame
2121 (list (cons 'cursor-color fg)))))))
2123 (declare-function x-create-frame "xfns.c" (parms))
2124 (declare-function x-setup-function-keys "term/common-win" (frame))
2126 (defun x-create-frame-with-faces (&optional parameters)
2127 "Create and return a frame with frame parameters PARAMETERS.
2128 If PARAMETERS specify a frame name, handle X geometry resources
2129 for that name. If PARAMETERS includes a `reverse' parameter, or
2130 the X resource \"reverseVideo\" is present, handle that."
2131 (setq parameters (x-handle-named-frame-geometry parameters))
2132 (let* ((params (copy-tree parameters))
2133 (visibility-spec (assq 'visibility parameters))
2134 (delayed-params '(foreground-color background-color font
2135 border-color cursor-color mouse-color
2136 visibility scroll-bar-foreground
2137 scroll-bar-background))
2138 frame success)
2139 (dolist (param delayed-params)
2140 (setq params (assq-delete-all param params)))
2141 (setq frame (x-create-frame `((visibility . nil) . ,params)))
2142 (unwind-protect
2143 (progn
2144 (x-setup-function-keys frame)
2145 (x-handle-reverse-video frame parameters)
2146 (frame-set-background-mode frame t)
2147 (face-set-after-frame-default frame parameters)
2148 (if (null visibility-spec)
2149 (make-frame-visible frame)
2150 (modify-frame-parameters frame (list visibility-spec)))
2151 (setq success t))
2152 (unless success
2153 (delete-frame frame)))
2154 frame))
2156 (defun face-set-after-frame-default (frame &optional parameters)
2157 "Initialize the frame-local faces of FRAME.
2158 Calculate the face definitions using the face specs, custom theme
2159 settings, X resources, and `face-new-frame-defaults'.
2160 Finally, apply any relevant face attributes found amongst the
2161 frame parameters in PARAMETERS."
2162 ;; The `reverse' is so that `default' goes first.
2163 (dolist (face (nreverse (face-list)))
2164 (condition-case ()
2165 (progn
2166 ;; Initialize faces from face spec and custom theme.
2167 (face-spec-recalc face frame)
2168 ;; Apply attributes specified by face-new-frame-defaults
2169 (internal-merge-in-global-face face frame))
2170 ;; Don't let invalid specs prevent frame creation.
2171 (error nil)))
2173 ;; Apply attributes specified by frame parameters.
2174 (let ((face-params '((foreground-color default :foreground)
2175 (background-color default :background)
2176 (font default :font)
2177 (border-color border :background)
2178 (cursor-color cursor :background)
2179 (scroll-bar-foreground scroll-bar :foreground)
2180 (scroll-bar-background scroll-bar :background)
2181 (mouse-color mouse :background))))
2182 (dolist (param face-params)
2183 (let* ((param-name (nth 0 param))
2184 (value (cdr (assq param-name parameters))))
2185 (if value
2186 (set-face-attribute (nth 1 param) frame
2187 (nth 2 param) value))))))
2189 (defun tty-handle-reverse-video (frame parameters)
2190 "Handle the reverse-video frame parameter for terminal frames."
2191 (when (cdr (assq 'reverse parameters))
2192 (let* ((params (frame-parameters frame))
2193 (bg (cdr (assq 'foreground-color params)))
2194 (fg (cdr (assq 'background-color params))))
2195 (modify-frame-parameters frame
2196 (list (cons 'foreground-color fg)
2197 (cons 'background-color bg)))
2198 (if (equal bg (cdr (assq 'mouse-color params)))
2199 (modify-frame-parameters frame
2200 (list (cons 'mouse-color fg))))
2201 (if (equal bg (cdr (assq 'cursor-color params)))
2202 (modify-frame-parameters frame
2203 (list (cons 'cursor-color fg)))))))
2206 (defun tty-create-frame-with-faces (&optional parameters)
2207 "Create and return a frame from optional frame parameters PARAMETERS.
2208 If PARAMETERS contains a `reverse' parameter, handle that."
2209 (let ((frame (make-terminal-frame parameters))
2210 success)
2211 (unwind-protect
2212 (with-selected-frame frame
2213 (tty-handle-reverse-video frame (frame-parameters frame))
2215 (unless (terminal-parameter frame 'terminal-initted)
2216 (set-terminal-parameter frame 'terminal-initted t)
2217 (set-locale-environment nil frame)
2218 (tty-run-terminal-initialization frame nil t))
2219 (frame-set-background-mode frame t)
2220 (face-set-after-frame-default frame parameters)
2221 (setq success t))
2222 (unless success
2223 (delete-frame frame)))
2224 frame))
2226 (defun tty-find-type (pred type)
2227 "Return the longest prefix of TYPE to which PRED returns non-nil.
2228 TYPE should be a tty type name such as \"xterm-16color\".
2230 The function tries only those prefixes that are followed by a
2231 dash or underscore in the original type name, like \"xterm\" in
2232 the above example."
2233 (let (hyphend)
2234 (while (and type
2235 (not (funcall pred type)))
2236 ;; Strip off last hyphen and what follows, then try again
2237 (setq type
2238 (if (setq hyphend (string-match-p "[-_][^-_]+$" type))
2239 (substring type 0 hyphend)
2240 nil))))
2241 type)
2243 (defvar tty-setup-hook nil
2244 "Hook run after running the initialization function of a new text terminal.
2245 Specifically, `tty-run-terminal-initialization' runs this.
2246 This can be used to fine tune the `input-decode-map', for example.")
2248 (defun tty-run-terminal-initialization (frame &optional type run-hook)
2249 "Run the special initialization code for the terminal type of FRAME.
2250 The optional TYPE parameter may be used to override the autodetected
2251 terminal type to a different value.
2253 This consults `term-file-aliases' to map terminal types to their aliases.
2255 If optional argument RUN-HOOK is non-nil, then as a final step,
2256 this runs the hook `tty-setup-hook'.
2258 If you set `term-file-prefix' to nil, this function does nothing."
2259 (setq type (or type (tty-type frame)))
2260 (let ((alias (tty-find-type
2261 (lambda (typ) (assoc typ term-file-aliases)) type)))
2262 (if alias (setq type (cdr (assoc alias term-file-aliases)))))
2263 ;; Load library for our terminal type.
2264 ;; User init file can set term-file-prefix to nil to prevent this.
2265 (with-selected-frame frame
2266 (unless (null term-file-prefix)
2267 (let* (term-init-func)
2268 ;; First, load the terminal initialization file, if it is
2269 ;; available and it hasn't been loaded already.
2270 (tty-find-type #'(lambda (type)
2271 (let ((file (locate-library (concat term-file-prefix type))))
2272 (and file
2273 (or (assoc file load-history)
2274 (load file t t)))))
2275 type)
2276 ;; Next, try to find a matching initialization function, and call it.
2277 (tty-find-type #'(lambda (type)
2278 (fboundp (setq term-init-func
2279 (intern (concat "terminal-init-" type)))))
2280 type)
2281 (when (fboundp term-init-func)
2282 (funcall term-init-func))
2283 (set-terminal-parameter frame 'terminal-initted term-init-func)
2284 (if run-hook (run-hooks 'tty-setup-hook))))))
2286 ;; Called from C function init_display to initialize faces of the
2287 ;; dumped terminal frame on startup.
2289 (defun tty-set-up-initial-frame-faces ()
2290 (let ((frame (selected-frame)))
2291 (frame-set-background-mode frame t)
2292 (face-set-after-frame-default frame)))
2295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2296 ;;; Standard faces.
2297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2299 (defgroup basic-faces nil
2300 "The standard faces of Emacs."
2301 :group 'faces)
2303 (defface default
2304 '((t nil)) ; If this were nil, face-defface-spec would not be set.
2305 "Basic default face."
2306 :group 'basic-faces)
2308 (defface bold
2309 '((t :weight bold))
2310 "Basic bold face."
2311 :group 'basic-faces)
2313 (defface italic
2314 '((((supports :slant italic))
2315 :slant italic)
2316 (((supports :underline t))
2317 :underline t)
2319 ;; Default to italic, even if it doesn't appear to be supported,
2320 ;; because in some cases the display engine will do its own
2321 ;; workaround (to `dim' on ttys).
2322 :slant italic))
2323 "Basic italic face."
2324 :group 'basic-faces)
2326 (defface bold-italic
2327 '((t :weight bold :slant italic))
2328 "Basic bold-italic face."
2329 :group 'basic-faces)
2331 (defface underline
2332 '((((supports :underline t))
2333 :underline t)
2334 (((supports :weight bold))
2335 :weight bold)
2336 (t :underline t))
2337 "Basic underlined face."
2338 :group 'basic-faces)
2340 (defface fixed-pitch
2341 '((t :family "Monospace"))
2342 "The basic fixed-pitch face."
2343 :group 'basic-faces)
2345 (defface fixed-pitch-serif
2346 '((t :family "Monospace Serif"))
2347 "The basic fixed-pitch face with serifs."
2348 :group 'basic-faces)
2350 (defface variable-pitch
2351 '((((type w32))
2352 ;; This is a workaround for an issue discussed in
2353 ;; http://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00746.html.
2354 ;; We need (a) the splash screen not to pick up bold-italics variant of
2355 ;; the font, and (b) still be able to request bold/italic/larger size
2356 ;; variants in the likes of EWW.
2357 :family "Arial" :foundry "outline")
2358 (t :family "Sans Serif"))
2359 "The basic variable-pitch face."
2360 :group 'basic-faces)
2362 (defface shadow
2363 '((((class color grayscale) (min-colors 88) (background light))
2364 :foreground "grey50")
2365 (((class color grayscale) (min-colors 88) (background dark))
2366 :foreground "grey70")
2367 (((class color) (min-colors 8) (background light))
2368 :foreground "green")
2369 (((class color) (min-colors 8) (background dark))
2370 :foreground "yellow"))
2371 "Basic face for shadowed text."
2372 :group 'basic-faces
2373 :version "22.1")
2375 (defface link
2376 '((((class color) (min-colors 88) (background light))
2377 :foreground "RoyalBlue3" :underline t)
2378 (((class color) (background light))
2379 :foreground "blue" :underline t)
2380 (((class color) (min-colors 88) (background dark))
2381 :foreground "cyan1" :underline t)
2382 (((class color) (background dark))
2383 :foreground "cyan" :underline t)
2384 (t :inherit underline))
2385 "Basic face for unvisited links."
2386 :group 'basic-faces
2387 :version "22.1")
2389 (defface link-visited
2390 '((default :inherit link)
2391 (((class color) (background light)) :foreground "magenta4")
2392 (((class color) (background dark)) :foreground "violet"))
2393 "Basic face for visited links."
2394 :group 'basic-faces
2395 :version "22.1")
2397 (defface highlight
2398 '((((class color) (min-colors 88) (background light))
2399 :background "darkseagreen2")
2400 (((class color) (min-colors 88) (background dark))
2401 :background "darkolivegreen")
2402 (((class color) (min-colors 16) (background light))
2403 :background "darkseagreen2")
2404 (((class color) (min-colors 16) (background dark))
2405 :background "darkolivegreen")
2406 (((class color) (min-colors 8))
2407 :background "green" :foreground "black")
2408 (t :inverse-video t))
2409 "Basic face for highlighting."
2410 :group 'basic-faces)
2412 ;; Region face: under NS, default to the system-defined selection
2413 ;; color (optimized for the fixed white background of other apps),
2414 ;; if background is light.
2415 (defface region
2416 '((((class color) (min-colors 88) (background dark))
2417 :background "blue3")
2418 (((class color) (min-colors 88) (background light) (type gtk))
2419 :distant-foreground "gtk_selection_fg_color"
2420 :background "gtk_selection_bg_color")
2421 (((class color) (min-colors 88) (background light) (type ns))
2422 :distant-foreground "ns_selection_fg_color"
2423 :background "ns_selection_bg_color")
2424 (((class color) (min-colors 88) (background light))
2425 :background "lightgoldenrod2")
2426 (((class color) (min-colors 16) (background dark))
2427 :background "blue3")
2428 (((class color) (min-colors 16) (background light))
2429 :background "lightgoldenrod2")
2430 (((class color) (min-colors 8))
2431 :background "blue" :foreground "white")
2432 (((type tty) (class mono))
2433 :inverse-video t)
2434 (t :background "gray"))
2435 "Basic face for highlighting the region."
2436 :version "21.1"
2437 :group 'basic-faces)
2439 (defface secondary-selection
2440 '((((class color) (min-colors 88) (background light))
2441 :background "yellow1")
2442 (((class color) (min-colors 88) (background dark))
2443 :background "SkyBlue4")
2444 (((class color) (min-colors 16) (background light))
2445 :background "yellow")
2446 (((class color) (min-colors 16) (background dark))
2447 :background "SkyBlue4")
2448 (((class color) (min-colors 8))
2449 :background "cyan" :foreground "black")
2450 (t :inverse-video t))
2451 "Basic face for displaying the secondary selection."
2452 :group 'basic-faces)
2454 (defface trailing-whitespace
2455 '((((class color) (background light))
2456 :background "red1")
2457 (((class color) (background dark))
2458 :background "red1")
2459 (t :inverse-video t))
2460 "Basic face for highlighting trailing whitespace."
2461 :version "21.1"
2462 :group 'basic-faces)
2464 (defface escape-glyph
2465 '((((background dark)) :foreground "cyan")
2466 ;; See the comment in minibuffer-prompt for
2467 ;; the reason not to use blue on MS-DOS.
2468 (((type pc)) :foreground "magenta")
2469 ;; red4 is too dark, but some say blue is too loud.
2470 ;; brown seems to work ok. -- rms.
2471 (t :foreground "brown"))
2472 "Face for characters displayed as sequences using `^' or `\\'."
2473 :group 'basic-faces
2474 :version "22.1")
2476 (defface homoglyph
2477 '((((background dark)) :foreground "cyan")
2478 (((type pc)) :foreground "magenta")
2479 (t :foreground "brown"))
2480 "Face for lookalike characters."
2481 :group 'basic-faces
2482 :version "26.1")
2484 (defface nobreak-space
2485 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2486 (((class color) (min-colors 8)) :background "magenta")
2487 (t :inverse-video t))
2488 "Face for displaying nobreak space."
2489 :group 'basic-faces
2490 :version "22.1")
2492 (defface nobreak-hyphen
2493 '((((background dark)) :foreground "cyan")
2494 (((type pc)) :foreground "magenta")
2495 (t :foreground "brown"))
2496 "Face for displaying nobreak hyphens."
2497 :group 'basic-faces
2498 :version "26.1")
2500 (defgroup mode-line-faces nil
2501 "Faces used in the mode line."
2502 :group 'mode-line
2503 :group 'faces
2504 :version "22.1")
2506 (defface mode-line
2507 '((((class color) (min-colors 88))
2508 :box (:line-width -1 :style released-button)
2509 :background "grey75" :foreground "black")
2511 :inverse-video t))
2512 "Basic mode line face for selected window."
2513 :version "21.1"
2514 :group 'mode-line-faces
2515 :group 'basic-faces)
2517 (defface mode-line-inactive
2518 '((default
2519 :inherit mode-line)
2520 (((class color) (min-colors 88) (background light))
2521 :weight light
2522 :box (:line-width -1 :color "grey75" :style nil)
2523 :foreground "grey20" :background "grey90")
2524 (((class color) (min-colors 88) (background dark) )
2525 :weight light
2526 :box (:line-width -1 :color "grey40" :style nil)
2527 :foreground "grey80" :background "grey30"))
2528 "Basic mode line face for non-selected windows."
2529 :version "22.1"
2530 :group 'mode-line-faces
2531 :group 'basic-faces)
2533 (defface mode-line-highlight
2534 '((((class color) (min-colors 88))
2535 :box (:line-width 2 :color "grey40" :style released-button))
2537 :inherit highlight))
2538 "Basic mode line face for highlighting."
2539 :version "22.1"
2540 :group 'mode-line-faces
2541 :group 'basic-faces)
2543 (defface mode-line-emphasis
2544 '((t (:weight bold)))
2545 "Face used to emphasize certain mode line features.
2546 Use the face `mode-line-highlight' for features that can be selected."
2547 :version "23.1"
2548 :group 'mode-line-faces
2549 :group 'basic-faces)
2551 (defface mode-line-buffer-id
2552 '((t (:weight bold)))
2553 "Face used for buffer identification parts of the mode line."
2554 :version "22.1"
2555 :group 'mode-line-faces
2556 :group 'basic-faces)
2558 (defface header-line
2559 '((default
2560 :inherit mode-line)
2561 (((type tty))
2562 ;; This used to be `:inverse-video t', but that doesn't look very
2563 ;; good when combined with inverse-video mode-lines and multiple
2564 ;; windows. Underlining looks better, and is more consistent with
2565 ;; the window-system face variants, which deemphasize the
2566 ;; header-line in relation to the mode-line face. If a terminal
2567 ;; can't underline, then the header-line will end up without any
2568 ;; highlighting; this may be too confusing in general, although it
2569 ;; happens to look good with the only current use of header-lines,
2570 ;; the info browser. XXX
2571 :inverse-video nil ;Override the value inherited from mode-line.
2572 :underline t)
2573 (((class color grayscale) (background light))
2574 :background "grey90" :foreground "grey20"
2575 :box nil)
2576 (((class color grayscale) (background dark))
2577 :background "grey20" :foreground "grey90"
2578 :box nil)
2579 (((class mono) (background light))
2580 :background "white" :foreground "black"
2581 :inverse-video nil
2582 :box nil
2583 :underline t)
2584 (((class mono) (background dark))
2585 :background "black" :foreground "white"
2586 :inverse-video nil
2587 :box nil
2588 :underline t))
2589 "Basic header-line face."
2590 :version "21.1"
2591 :group 'basic-faces)
2593 (defface vertical-border
2594 '((((type tty)) :inherit mode-line-inactive))
2595 "Face used for vertical window dividers on ttys."
2596 :version "22.1"
2597 :group 'basic-faces)
2599 (defface window-divider '((t :foreground "gray60"))
2600 "Basic face for window dividers.
2601 When a divider is less than 3 pixels wide, it is drawn solidly
2602 with the foreground of this face. For larger dividers this face
2603 is used for the inner part while the first pixel line/column is
2604 drawn with the `window-divider-first-pixel' face and the last
2605 pixel line/column with the `window-divider-last-pixel' face."
2606 :version "24.4"
2607 :group 'window-divider
2608 :group 'basic-faces)
2610 (defface window-divider-first-pixel
2611 '((t :foreground "gray80"))
2612 "Basic face for first pixel line/column of window dividers.
2613 When a divider is at least 3 pixels wide, its first pixel
2614 line/column is drawn with the foreground of this face. If you do
2615 not want to accentuate the first pixel line/column, set this to
2616 the same as `window-divider' face."
2617 :version "24.4"
2618 :group 'window-divider
2619 :group 'basic-faces)
2621 (defface window-divider-last-pixel
2622 '((t :foreground "gray40"))
2623 "Basic face for last pixel line/column of window dividers.
2624 When a divider is at least 3 pixels wide, its last pixel
2625 line/column is drawn with the foreground of this face. If you do
2626 not want to accentuate the last pixel line/column, set this to
2627 the same as `window-divider' face."
2628 :version "24.4"
2629 :group 'window-divider
2630 :group 'basic-faces)
2632 (defface minibuffer-prompt
2633 '((((background dark)) :foreground "cyan")
2634 ;; Don't use blue because many users of the MS-DOS port customize
2635 ;; their foreground color to be blue.
2636 (((type pc)) :foreground "magenta")
2637 (t :foreground "medium blue"))
2638 "Face for minibuffer prompts.
2639 By default, Emacs automatically adds this face to the value of
2640 `minibuffer-prompt-properties', which is a list of text properties
2641 used to display the prompt text."
2642 :version "22.1"
2643 :group 'basic-faces)
2645 (setq minibuffer-prompt-properties
2646 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2648 (defface fringe
2649 '((((class color) (background light))
2650 :background "grey95")
2651 (((class color) (background dark))
2652 :background "grey10")
2654 :background "gray"))
2655 "Basic face for the fringes to the left and right of windows under X."
2656 :version "21.1"
2657 :group 'frames
2658 :group 'basic-faces)
2660 (defface scroll-bar '((t nil))
2661 "Basic face for the scroll bar colors under X."
2662 :version "21.1"
2663 :group 'frames
2664 :group 'basic-faces)
2666 (defface border '((t nil))
2667 "Basic face for the frame border under X."
2668 :version "21.1"
2669 :group 'frames
2670 :group 'basic-faces)
2672 (defface cursor
2673 '((((background light)) :background "black")
2674 (((background dark)) :background "white"))
2675 "Basic face for the cursor color under X.
2676 Currently, only the `:background' attribute is meaningful; all
2677 other attributes are ignored. The cursor foreground color is
2678 taken from the background color of the underlying text.
2680 Note: Other faces cannot inherit from the cursor face."
2681 :version "21.1"
2682 :group 'cursor
2683 :group 'basic-faces)
2685 (put 'cursor 'face-no-inherit t)
2687 (defface mouse '((t nil))
2688 "Basic face for the mouse color under X."
2689 :version "21.1"
2690 :group 'mouse
2691 :group 'basic-faces)
2693 (defface tool-bar
2694 '((default
2695 :box (:line-width 1 :style released-button)
2696 :foreground "black")
2697 (((type x w32 ns) (class color))
2698 :background "grey75")
2699 (((type x) (class mono))
2700 :background "grey"))
2701 "Basic tool-bar face."
2702 :version "21.1"
2703 :group 'basic-faces)
2705 (defface menu
2706 '((((type tty))
2707 :inverse-video t)
2708 (((type x-toolkit))
2711 :inverse-video t))
2712 "Basic face for the font and colors of the menu bar and popup menus."
2713 :version "21.1"
2714 :group 'menu
2715 :group 'basic-faces)
2717 (defface help-argument-name '((t :inherit italic))
2718 "Face to highlight argument names in *Help* buffers."
2719 :group 'help)
2721 (defface glyphless-char
2722 '((((type tty)) :inherit underline)
2723 (((type pc)) :inherit escape-glyph)
2724 (t :height 0.6))
2725 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2726 It is used for characters of no fonts too."
2727 :version "24.1"
2728 :group 'basic-faces)
2730 (defface error
2731 '((default :weight bold)
2732 (((class color) (min-colors 88) (background light)) :foreground "Red1")
2733 (((class color) (min-colors 88) (background dark)) :foreground "Pink")
2734 (((class color) (min-colors 16) (background light)) :foreground "Red1")
2735 (((class color) (min-colors 16) (background dark)) :foreground "Pink")
2736 (((class color) (min-colors 8)) :foreground "red")
2737 (t :inverse-video t))
2738 "Basic face used to highlight errors and to denote failure."
2739 :version "24.1"
2740 :group 'basic-faces)
2742 (defface warning
2743 '((default :weight bold)
2744 (((class color) (min-colors 16)) :foreground "DarkOrange")
2745 (((class color)) :foreground "yellow"))
2746 "Basic face used to highlight warnings."
2747 :version "24.1"
2748 :group 'basic-faces)
2750 (defface success
2751 '((default :weight bold)
2752 (((class color) (min-colors 16) (background light)) :foreground "ForestGreen")
2753 (((class color) (min-colors 88) (background dark)) :foreground "Green1")
2754 (((class color) (min-colors 16) (background dark)) :foreground "Green")
2755 (((class color)) :foreground "green"))
2756 "Basic face used to indicate successful operation."
2757 :version "24.1"
2758 :group 'basic-faces)
2760 (defface read-multiple-choice-face
2761 '((t (:inherit underline
2762 :weight bold)))
2763 "Face for the symbol name in `read-multiple-choice' output."
2764 :group 'basic-faces
2765 :version "26.1")
2767 ;; Faces for TTY menus.
2768 (defface tty-menu-enabled-face
2769 '((t
2770 :foreground "yellow" :background "blue" :weight bold))
2771 "Face for displaying enabled items in TTY menus."
2772 :group 'basic-faces)
2774 (defface tty-menu-disabled-face
2775 '((((class color) (min-colors 16))
2776 :foreground "lightgray" :background "blue")
2778 :foreground "white" :background "blue"))
2779 "Face for displaying disabled items in TTY menus."
2780 :group 'basic-faces)
2782 (defface tty-menu-selected-face
2783 '((t :background "red"))
2784 "Face for displaying the currently selected item in TTY menus."
2785 :group 'basic-faces)
2787 (defgroup paren-showing-faces nil
2788 "Faces used to highlight paren matches."
2789 :group 'paren-showing
2790 :group 'faces
2791 :version "22.1")
2793 (defface show-paren-match
2794 '((((class color) (background light))
2795 :background "turquoise") ; looks OK on tty (becomes cyan)
2796 (((class color) (background dark))
2797 :background "steelblue3") ; looks OK on tty (becomes blue)
2798 (((background dark) (min-colors 4))
2799 :background "grey50")
2800 (((background light) (min-colors 4))
2801 :background "gray")
2803 :inherit underline))
2804 "Face used for a matching paren."
2805 :group 'paren-showing-faces)
2807 (defface show-paren-mismatch
2808 '((((class color)) (:foreground "white" :background "purple"))
2809 (t (:inverse-video t)))
2810 "Face used for a mismatching paren."
2811 :group 'paren-showing-faces)
2814 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2815 ;;; Manipulating font names.
2816 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2818 ;; This is here for compatibility with Emacs 20.2. For example,
2819 ;; international/fontset.el uses x-resolve-font-name. The following
2820 ;; functions are not used in the face implementation itself.
2822 (defvar x-font-regexp nil)
2823 (defvar x-font-regexp-head nil)
2824 (defvar x-font-regexp-weight nil)
2825 (defvar x-font-regexp-slant nil)
2827 (defconst x-font-regexp-weight-subnum 1)
2828 (defconst x-font-regexp-slant-subnum 2)
2829 (defconst x-font-regexp-swidth-subnum 3)
2830 (defconst x-font-regexp-adstyle-subnum 4)
2832 ;;; Regexps matching font names in "Host Portable Character Representation."
2834 (let ((- "[-?]")
2835 (foundry "[^-]+")
2836 (family "[^-]+")
2837 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2838 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2839 (weight\? "\\([^-]*\\)") ; 1
2840 (slant "\\([ior]\\)") ; 2
2841 ; (slant\? "\\([ior?*]?\\)") ; 2
2842 (slant\? "\\([^-]?\\)") ; 2
2843 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2844 (swidth "\\([^-]*\\)") ; 3
2845 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2846 (adstyle "\\([^-]*\\)") ; 4
2847 (pixelsize "[0-9]+")
2848 (pointsize "[0-9][0-9]+")
2849 (resx "[0-9][0-9]+")
2850 (resy "[0-9][0-9]+")
2851 (spacing "[cmp?*]")
2852 (avgwidth "[0-9]+")
2853 (registry "[^-]+")
2854 (encoding "[^-]+")
2856 (setq x-font-regexp
2857 (purecopy (concat "\\`\\*?[-?*]"
2858 foundry - family - weight\? - slant\? - swidth - adstyle -
2859 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2860 registry - encoding "\\*?\\'"
2862 (setq x-font-regexp-head
2863 (purecopy (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2864 "\\([-*?]\\|\\'\\)")))
2865 (setq x-font-regexp-slant (purecopy (concat - slant -)))
2866 (setq x-font-regexp-weight (purecopy (concat - weight -)))
2867 nil)
2870 (defun x-resolve-font-name (pattern &optional face frame)
2871 "Return a font name matching PATTERN.
2872 All wildcards in PATTERN are instantiated.
2873 If PATTERN is nil, return the name of the frame's base font, which never
2874 contains wildcards.
2875 Given optional arguments FACE and FRAME, return a font which is
2876 also the same size as FACE on FRAME, or fail."
2877 (and (eq frame t)
2878 (setq frame nil))
2879 (if pattern
2880 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2881 (let ((fonts (x-list-fonts pattern face frame 1)))
2882 (or fonts
2883 (if face
2884 (if (string-match-p "\\*" pattern)
2885 (if (null (face-font face))
2886 (error "No matching fonts are the same height as the frame default font")
2887 (error "No matching fonts are the same height as face `%s'" face))
2888 (if (null (face-font face))
2889 (error "Height of font `%s' doesn't match the frame default font"
2890 pattern)
2891 (error "Height of font `%s' doesn't match face `%s'"
2892 pattern face)))
2893 (error "No fonts match `%s'" pattern)))
2894 (car fonts))
2895 (frame-parameter nil 'font)))
2897 (defcustom font-list-limit 100
2898 "This variable is obsolete and has no effect."
2899 :type 'integer
2900 :group 'display)
2901 (make-obsolete-variable 'font-list-limit nil "24.3")
2903 (provide 'faces)
2905 ;;; faces.el ends here