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