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