(frame-parameter) <defsetf>: Make it return the assigned value.
[emacs.git] / lisp / faces.el
blob08b0bb89021c892b60585b97fdf7256934e8be6b
1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 ;; 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: internal
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, or (at your option)
14 ;; 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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;;; Code:
30 (eval-when-compile
31 (require 'cl))
33 (declare-function xw-defined-colors "term/x-win" (&optional frame))
35 (defvar help-xref-stack-item)
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Font selection.
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 (defgroup font-selection nil
42 "Influencing face font selection."
43 :group 'faces)
46 (defcustom face-font-selection-order
47 '(:width :height :weight :slant)
48 "*A list specifying how face font selection chooses fonts.
49 Each of the four symbols `:width', `:height', `:weight', and `:slant'
50 must appear once in the list, and the list must not contain any other
51 elements. Font selection first tries to find a best matching font
52 for those face attributes that appear before in the list. For
53 example, if `:slant' appears before `:height', font selection first
54 tries to find a font with a suitable slant, even if this results in
55 a font height that isn't optimal."
56 :tag "Font selection order"
57 :type '(list symbol symbol symbol symbol)
58 :group 'font-selection
59 :set #'(lambda (symbol value)
60 (set-default symbol value)
61 (internal-set-font-selection-order value)))
64 ;; This is defined originally in xfaces.c.
65 (defcustom face-font-family-alternatives
66 '(("courier" "fixed")
67 ("helv" "helvetica" "arial" "fixed"))
68 "*Alist of alternative font family names.
69 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
70 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
71 ALTERNATIVE2 etc."
72 :tag "Alternative font families to try"
73 :type '(repeat (repeat string))
74 :group 'font-selection
75 :set #'(lambda (symbol value)
76 (set-default symbol value)
77 (internal-set-alternative-font-family-alist value)))
80 ;; This is defined originally in xfaces.c.
81 (defcustom face-font-registry-alternatives
82 (if (eq system-type 'windows-nt)
83 '(("iso8859-1" "ms-oemlatin")
84 ("gb2312.1980" "gb2312" "gbk" "gb18030")
85 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
86 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
87 ("muletibetan-2" "muletibetan-0"))
88 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
89 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
90 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
91 ("muletibetan-2" "muletibetan-0")))
92 "*Alist of alternative font registry names.
93 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
94 If fonts of registry REGISTRY can be loaded, font selection
95 tries to find a best matching font among all fonts of registry
96 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
97 :tag "Alternative font registries to try"
98 :type '(repeat (repeat string))
99 :version "21.1"
100 :group 'font-selection
101 :set #'(lambda (symbol value)
102 (set-default symbol value)
103 (internal-set-alternative-font-registry-alist value)))
106 (defcustom font-weight-table
107 (if (eq system-type 'windows-nt)
108 '((thin . 100)
109 (ultralight . 199) (ultra-light . 200) (extra-light . 201)
110 (light . 300)
111 (semilight . 330) (semi-light . 331)
112 (book . 350)
113 (normal . 400) (regular . 401)
114 (medium . 500)
115 (semibold . 599) (semi-bold . 600) (demibold . 601) (demi . 602)
116 (bold . 700)
117 (extrabold . 799) (extra-bold . 800)
118 (ultrabold . 801) (ultra-bold . 802)
119 (black . 900) (heavy . 901))
120 '((thin . 0)
121 (ultralight . 39) (ultra-light . 40) (extra-light . 41)
122 (light . 50)
123 (semilight . 65) (semi-light . 66)
124 (book . 75)
125 (medium . 99) (regular . 100) (normal . 101)
126 (semibold . 179) (semi-bold . 180) (demibold . 181) (demi . 182)
127 (bold . 200)
128 (extrabold . 204) (extra-bold . 205)
129 (ultrabold . 206) (ultra-bold . 207)
130 (black . 210) (heavy . 211)))
131 "*Alist of font weight symbols vs the corresponding numeric values."
132 :tag "Font weight table"
133 :version "23.1"
134 :group 'font-selection
135 :type '(repeat (cons symbol integer))
136 :set #'(lambda (symbol value)
137 (set-default symbol value)
138 (if (fboundp 'internal-set-font-style-table)
139 (internal-set-font-style-table :weight value))))
141 (defcustom font-slant-table
142 '((ro . 0)
143 (ri . 10)
144 (r . 99) (roman . 100) (normal . 101)
145 (i . 199) (italic . 200) (ot . 201)
146 (o . 210) (oblique . 211))
147 "*Alist of font slant symbols vs the corresponding numeric values."
148 :tag "Font slant table"
149 :version "23.1"
150 :group 'font-selection
151 :type '(repeat (cons symbol integer))
152 :set #'(lambda (symbol value)
153 (set-default symbol value)
154 (if (fboundp 'internal-set-font-style-table)
155 (internal-set-font-style-table :slant value))))
157 (defcustom font-swidth-table
158 '((ultracondensed . 50) (ultra-condensed . 51)
159 (extracondensed . 63) (extra-condensed . 64)
160 (narrow . 74) (compressed . 75) (condensed . 76)
161 (semi-condensed . 87) (semicondensed . 88)
162 (medium . 99) (normal . 100) (regular . 101)
163 (semiexpanded . 112) (semi-expanded . 113) (demiexpanded . 114)
164 (expanded . 125)
165 (extraexpanded . 150) (extra-expanded . 151)
166 (ultraexpanded . 199) (ultra-expanded . 200) (wide . 201))
167 "*Alist of font swidth symbols vs the corresponding numeric values."
168 :tag "Font swidth table"
169 :version "23.1"
170 :group 'font-selection
171 :type '(repeat (cons symbol integer))
172 :set #'(lambda (symbol value)
173 (set-default symbol value)
174 (if (fboundp 'internal-set-font-style-table)
175 (internal-set-font-style-table :width value))))
177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 ;;; Creation, copying.
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 (defun face-list ()
183 "Return a list of all defined face names."
184 (mapcar #'car face-new-frame-defaults))
187 ;;; ### If not frame-local initialize by what X resources?
189 (defun make-face (face &optional no-init-from-resources)
190 "Define a new face with name FACE, a symbol.
191 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
192 variants of FACE from X resources. (X resources recognized are found
193 in the global variable `face-x-resources'.) If FACE is already known
194 as a face, leave it unmodified. Value is FACE."
195 (interactive "SMake face: ")
196 (unless (facep face)
197 ;; Make frame-local faces (this also makes the global one).
198 (dolist (frame (frame-list))
199 (internal-make-lisp-face face frame))
200 ;; Add the face to the face menu.
201 (when (fboundp 'facemenu-add-new-face)
202 (facemenu-add-new-face face))
203 ;; Define frame-local faces for all frames from X resources.
204 (unless no-init-from-resources
205 (make-face-x-resource-internal face)))
206 face)
209 (defun make-empty-face (face)
210 "Define a new, empty face with name FACE.
211 If the face already exists, it is left unmodified. Value is FACE."
212 (interactive "SMake empty face: ")
213 (make-face face 'no-init-from-resources))
216 (defun copy-face (old-face new-face &optional frame new-frame)
217 "Define a face just like OLD-FACE, with name NEW-FACE.
219 If NEW-FACE already exists as a face, it is modified to be like
220 OLD-FACE. If it doesn't already exist, it is created.
222 If the optional argument FRAME is given as a frame, NEW-FACE is
223 changed on FRAME only.
224 If FRAME is t, the frame-independent default specification for OLD-FACE
225 is copied to NEW-FACE.
226 If FRAME is nil, copying is done for the frame-independent defaults
227 and for each existing frame.
229 If the optional fourth argument NEW-FRAME is given,
230 copy the information from face OLD-FACE on frame FRAME
231 to NEW-FACE on frame NEW-FRAME. In this case, FRAME may not be nil."
232 (let ((inhibit-quit t))
233 (if (null frame)
234 (progn
235 (when new-frame
236 (error "Copying face %s from all frames to one frame"
237 old-face))
238 (make-empty-face new-face)
239 (dolist (frame (frame-list))
240 (copy-face old-face new-face frame))
241 (copy-face old-face new-face t))
242 (make-empty-face new-face)
243 (internal-copy-lisp-face old-face new-face frame new-frame))
244 new-face))
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249 ;;; Obsolete functions
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 ;; The functions in this section are defined because Lisp packages use
253 ;; them, despite the prefix `internal-' suggesting that they are
254 ;; private to the face implementation.
256 (defun internal-find-face (name &optional frame)
257 "Retrieve the face named NAME.
258 Return nil if there is no such face.
259 If NAME is already a face, it is simply returned.
260 The optional argument FRAME is ignored."
261 (facep name))
262 (make-obsolete 'internal-find-face 'facep "21.1")
265 (defun internal-get-face (name &optional frame)
266 "Retrieve the face named NAME; error if there is none.
267 If NAME is already a face, it is simply returned.
268 The optional argument FRAME is ignored."
269 (or (facep name)
270 (check-face name)))
271 (make-obsolete 'internal-get-face "see `facep' and `check-face'." "21.1")
274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
275 ;;; Predicates, type checks.
276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278 (defun facep (face)
279 "Return non-nil if FACE is a face name; nil otherwise.
280 A face name can be a string or a symbol."
281 (internal-lisp-face-p face))
284 (defun check-face (face)
285 "Signal an error if FACE doesn't name a face.
286 Value is FACE."
287 (unless (facep face)
288 (error "Not a face: %s" face))
289 face)
292 ;; The ID returned is not to be confused with the internally used IDs
293 ;; of realized faces. The ID assigned to Lisp faces is used to
294 ;; support faces in display table entries.
296 (defun face-id (face &optional frame)
297 "Return the internal ID of face with name FACE.
298 If FACE is a face-alias, return the ID of the target face.
299 The optional argument FRAME is ignored, since the internal face ID
300 of a face name is the same for all frames."
301 (check-face face)
302 (or (get face 'face)
303 (face-id (get face 'face-alias))))
305 (defun face-equal (face1 face2 &optional frame)
306 "Non-nil if faces FACE1 and FACE2 are equal.
307 Faces are considered equal if all their attributes are equal.
308 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
309 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
310 If FRAME is omitted or nil, use the selected frame."
311 (internal-lisp-face-equal-p face1 face2 frame))
314 (defun face-differs-from-default-p (face &optional frame)
315 "Return non-nil if FACE displays differently from the default face.
316 If the optional argument FRAME is given, report on face FACE in that frame.
317 If FRAME is t, report on the defaults for face FACE (for new frames).
318 If FRAME is omitted or nil, use the selected frame."
319 (let ((attrs
320 (delq :inherit (mapcar 'car face-attribute-name-alist)))
321 (differs nil))
322 (while (and attrs (not differs))
323 (let* ((attr (pop attrs))
324 (attr-val (face-attribute face attr frame t)))
325 (when (and
326 (not (eq attr-val 'unspecified))
327 (display-supports-face-attributes-p (list attr attr-val)
328 frame))
329 (setq differs attr))))
330 differs))
333 (defun face-nontrivial-p (face &optional frame)
334 "True if face FACE has some non-nil attribute.
335 If the optional argument FRAME is given, report on face FACE in that frame.
336 If FRAME is t, report on the defaults for face FACE (for new frames).
337 If FRAME is omitted or nil, use the selected frame."
338 (not (internal-lisp-face-empty-p face frame)))
342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
343 ;;; Setting face attributes from X resources.
344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
346 (defcustom face-x-resources
347 '((:family (".attributeFamily" . "Face.AttributeFamily"))
348 (:width (".attributeWidth" . "Face.AttributeWidth"))
349 (:height (".attributeHeight" . "Face.AttributeHeight"))
350 (:weight (".attributeWeight" . "Face.AttributeWeight"))
351 (:slant (".attributeSlant" . "Face.AttributeSlant"))
352 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
353 (:background (".attributeBackground" . "Face.AttributeBackground"))
354 (:overline (".attributeOverline" . "Face.AttributeOverline"))
355 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
356 (:box (".attributeBox" . "Face.AttributeBox"))
357 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
358 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
359 (:stipple
360 (".attributeStipple" . "Face.AttributeStipple")
361 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
362 (:bold (".attributeBold" . "Face.AttributeBold"))
363 (:italic (".attributeItalic" . "Face.AttributeItalic"))
364 (:font (".attributeFont" . "Face.AttributeFont"))
365 (:inherit (".attributeInherit" . "Face.AttributeInherit")))
366 "*List of X resources and classes for face attributes.
367 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
368 the name of a face attribute, and each ENTRY is a cons of the form
369 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
370 X resource class for the attribute."
371 :type '(repeat (cons symbol (repeat (cons string string))))
372 :group 'faces)
375 (defun set-face-attribute-from-resource (face attribute resource class frame)
376 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
377 Value is the attribute value specified by the resource, or nil
378 if not present. This function displays a message if the resource
379 specifies an invalid attribute."
380 (let* ((face-name (face-name face))
381 (value (internal-face-x-get-resource (concat face-name resource)
382 class frame)))
383 (when value
384 (condition-case ()
385 (internal-set-lisp-face-attribute-from-resource
386 face attribute (downcase value) frame)
387 (error
388 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
389 face-name frame attribute value))))
390 value))
393 (defun set-face-attributes-from-resources (face frame)
394 "Set attributes of FACE from X resources for FRAME."
395 (when (memq (framep frame) '(x w32 mac))
396 (dolist (definition face-x-resources)
397 (let ((attribute (car definition)))
398 (dolist (entry (cdr definition))
399 (set-face-attribute-from-resource face attribute (car entry)
400 (cdr entry) frame))))))
403 (defun make-face-x-resource-internal (face &optional frame)
404 "Fill frame-local FACE on FRAME from X resources.
405 FRAME nil or not specified means do it for all frames."
406 (if (null frame)
407 (dolist (frame (frame-list))
408 (set-face-attributes-from-resources face frame))
409 (set-face-attributes-from-resources face frame)))
413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
414 ;;; Retrieving face attributes.
415 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
417 (defun face-name (face)
418 "Return the name of face FACE."
419 (symbol-name (check-face face)))
422 (defun face-all-attributes (face &optional frame)
423 "Return an alist stating the attributes of FACE.
424 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
425 Normally the value describes the default attributes,
426 but if you specify FRAME, the value describes the attributes
427 of FACE on FRAME."
428 (mapcar (lambda (pair)
429 (let ((attr (car pair)))
430 (cons attr (face-attribute face attr (or frame t)))))
431 face-attribute-name-alist))
433 (defun face-attribute (face attribute &optional frame inherit)
434 "Return the value of FACE's ATTRIBUTE on FRAME.
435 If the optional argument FRAME is given, report on face FACE in that frame.
436 If FRAME is t, report on the defaults for face FACE (for new frames).
437 If FRAME is omitted or nil, use the selected frame.
439 If INHERIT is nil, only attributes directly defined by FACE are considered,
440 so the return value may be `unspecified', or a relative value.
441 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
442 faces specified by its `:inherit' attribute; however the return value
443 may still be `unspecified' or relative.
444 If INHERIT is a face or a list of faces, then the result is further merged
445 with that face (or faces), until it becomes specified and absolute.
447 To ensure that the return value is always specified and absolute, use a
448 value of `default' for INHERIT; this will resolve any unspecified or
449 relative values by merging with the `default' face (which is always
450 completely specified)."
451 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
452 (when (and inherit (face-attribute-relative-p attribute value))
453 ;; VALUE is relative, so merge with inherited faces
454 (let ((inh-from (face-attribute face :inherit frame)))
455 (unless (or (null inh-from) (eq inh-from 'unspecified))
456 (condition-case nil
457 (setq value
458 (face-attribute-merged-with attribute value inh-from frame))
459 ;; The `inherit' attribute may point to non existent faces.
460 (error nil)))))
461 (when (and inherit
462 (not (eq inherit t))
463 (face-attribute-relative-p attribute value))
464 ;; We should merge with INHERIT as well
465 (setq value (face-attribute-merged-with attribute value inherit frame)))
466 value))
468 (defun face-attribute-merged-with (attribute value faces &optional frame)
469 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
470 FACES may be either a single face or a list of faces.
471 \[This is an internal function.]"
472 (cond ((not (face-attribute-relative-p attribute value))
473 value)
474 ((null faces)
475 value)
476 ((consp faces)
477 (face-attribute-merged-with
478 attribute
479 (face-attribute-merged-with attribute value (car faces) frame)
480 (cdr faces)
481 frame))
483 (merge-face-attribute attribute
484 value
485 (face-attribute faces attribute frame t)))))
488 (defmacro face-attribute-specified-or (value &rest body)
489 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
490 (let ((temp (make-symbol "value")))
491 `(let ((,temp ,value))
492 (if (not (eq ,temp 'unspecified))
493 ,temp
494 ,@body))))
496 (defun face-foreground (face &optional frame inherit)
497 "Return the foreground color name of FACE, or nil if unspecified.
498 If the optional argument FRAME is given, report on face FACE in that frame.
499 If FRAME is t, report on the defaults for face FACE (for new frames).
500 If FRAME is omitted or nil, use the selected frame.
502 If INHERIT is nil, only a foreground color directly defined by FACE is
503 considered, so the return value may be nil.
504 If INHERIT is t, and FACE doesn't define a foreground color, then any
505 foreground color that FACE inherits through its `:inherit' attribute
506 is considered as well; however the return value may still be nil.
507 If INHERIT is a face or a list of faces, then it is used to try to
508 resolve an unspecified foreground color.
510 To ensure that a valid color is always returned, use a value of
511 `default' for INHERIT; this will resolve any unspecified values by
512 merging with the `default' face (which is always completely specified)."
513 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
514 nil))
516 (defun face-background (face &optional frame inherit)
517 "Return the background color name of FACE, or nil if unspecified.
518 If the optional argument FRAME is given, report on face FACE in that frame.
519 If FRAME is t, report on the defaults for face FACE (for new frames).
520 If FRAME is omitted or nil, use the selected frame.
522 If INHERIT is nil, only a background color directly defined by FACE is
523 considered, so the return value may be nil.
524 If INHERIT is t, and FACE doesn't define a background color, then any
525 background color that FACE inherits through its `:inherit' attribute
526 is considered as well; however the return value may still be nil.
527 If INHERIT is a face or a list of faces, then it is used to try to
528 resolve an unspecified background color.
530 To ensure that a valid color is always returned, use a value of
531 `default' for INHERIT; this will resolve any unspecified values by
532 merging with the `default' face (which is always completely specified)."
533 (face-attribute-specified-or (face-attribute face :background frame inherit)
534 nil))
536 (defun face-stipple (face &optional frame inherit)
537 "Return the stipple pixmap name of FACE, or nil if unspecified.
538 If the optional argument FRAME is given, report on face FACE in that frame.
539 If FRAME is t, report on the defaults for face FACE (for new frames).
540 If FRAME is omitted or nil, use the selected frame.
542 If INHERIT is nil, only a stipple directly defined by FACE is
543 considered, so the return value may be nil.
544 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
545 that FACE inherits through its `:inherit' attribute is considered as
546 well; however the return value may still be nil.
547 If INHERIT is a face or a list of faces, then it is used to try to
548 resolve an unspecified stipple.
550 To ensure that a valid stipple or nil is always returned, use a value of
551 `default' for INHERIT; this will resolve any unspecified values by merging
552 with the `default' face (which is always completely specified)."
553 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
554 nil))
557 (defalias 'face-background-pixmap 'face-stipple)
560 (defun face-underline-p (face &optional frame)
561 "Return non-nil if FACE is underlined.
562 If the optional argument FRAME is given, report on face FACE in that frame.
563 If FRAME is t, report on the defaults for face FACE (for new frames).
564 If FRAME is omitted or nil, use the selected frame."
565 (eq (face-attribute face :underline frame) t))
568 (defun face-inverse-video-p (face &optional frame)
569 "Return non-nil if FACE is in inverse video on FRAME.
570 If the optional argument FRAME is given, report on face FACE in that frame.
571 If FRAME is t, report on the defaults for face FACE (for new frames).
572 If FRAME is omitted or nil, use the selected frame."
573 (eq (face-attribute face :inverse-video frame) t))
576 (defun face-bold-p (face &optional frame)
577 "Return non-nil if the font of FACE is bold on FRAME.
578 If the optional argument FRAME is given, report on face FACE in that frame.
579 If FRAME is t, report on the defaults for face FACE (for new frames).
580 If FRAME is omitted or nil, use the selected frame.
581 Use `face-attribute' for finer control."
582 (let ((bold (face-attribute face :weight frame)))
583 (memq bold '(semi-bold bold extra-bold ultra-bold))))
586 (defun face-italic-p (face &optional frame)
587 "Return non-nil if the font of FACE is italic on FRAME.
588 If the optional argument FRAME is given, report on face FACE in that frame.
589 If FRAME is t, report on the defaults for face FACE (for new frames).
590 If FRAME is omitted or nil, use the selected frame.
591 Use `face-attribute' for finer control."
592 (let ((italic (face-attribute face :slant frame)))
593 (memq italic '(italic oblique))))
597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
598 ;;; Face documentation.
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
601 (defun face-documentation (face)
602 "Get the documentation string for FACE.
603 If FACE is a face-alias, get the documentation for the target face."
604 (let ((alias (get face 'face-alias))
605 doc)
606 (if alias
607 (progn
608 (setq doc (get alias 'face-documentation))
609 (format "%s is an alias for the face `%s'.%s" face alias
610 (if doc (format "\n%s" doc)
611 "")))
612 (get face 'face-documentation))))
615 (defun set-face-documentation (face string)
616 "Set the documentation string for FACE to STRING."
617 ;; Perhaps the text should go in DOC.
618 (put face 'face-documentation (purecopy string)))
621 (defalias 'face-doc-string 'face-documentation)
622 (defalias 'set-face-doc-string 'set-face-documentation)
626 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
627 ;; Setting face attributes.
628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
631 (defvar inhibit-face-set-after-frame-default nil
632 "If non-nil, that tells `face-set-after-frame-default' to do nothing.")
634 (defun set-face-attribute (face frame &rest args)
635 "Set attributes of FACE on FRAME from ARGS.
637 FRAME nil means change attributes on all frames. FRAME t means change
638 the default for new frames (this is done automatically each time an
639 attribute is changed on all frames).
641 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
642 face attribute name. All attributes can be set to `unspecified';
643 this fact is not further mentioned below.
645 The following attributes are recognized:
647 `:family'
649 VALUE must be a string specifying the font family, e.g. ``courier'',
650 or a fontset alias name. If a font family is specified, wild-cards `*'
651 and `?' are allowed.
653 `:width'
655 VALUE specifies the relative proportionate width of the font to use.
656 It must be one of the symbols `ultra-condensed', `extra-condensed',
657 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
658 `extra-expanded', or `ultra-expanded'.
660 `:height'
662 VALUE must be either an integer specifying the height of the font to use
663 in 1/10 pt, a floating point number specifying the amount by which to
664 scale any underlying face, or a function, which is called with the old
665 height (from the underlying face), and should return the new height.
667 `:weight'
669 VALUE specifies the weight of the font to use. It must be one of the
670 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
671 `semi-light', `light', `extra-light', `ultra-light'.
673 `:slant'
675 VALUE specifies the slant of the font to use. It must be one of the
676 symbols `italic', `oblique', `normal', `reverse-italic', or
677 `reverse-oblique'.
679 `:foreground', `:background'
681 VALUE must be a color name, a string.
683 `:underline'
685 VALUE specifies whether characters in FACE should be underlined. If
686 VALUE is t, underline with foreground color of the face. If VALUE is
687 a string, underline with that color. If VALUE is nil, explicitly
688 don't underline.
690 `:overline'
692 VALUE specifies whether characters in FACE should be overlined. If
693 VALUE is t, overline with foreground color of the face. If VALUE is a
694 string, overline with that color. If VALUE is nil, explicitly don't
695 overline.
697 `:strike-through'
699 VALUE specifies whether characters in FACE should be drawn with a line
700 striking through them. If VALUE is t, use the foreground color of the
701 face. If VALUE is a string, strike-through with that color. If VALUE
702 is nil, explicitly don't strike through.
704 `:box'
706 VALUE specifies whether characters in FACE should have a box drawn
707 around them. If VALUE is nil, explicitly don't draw boxes. If
708 VALUE is t, draw a box with lines of width 1 in the foreground color
709 of the face. If VALUE is a string, the string must be a color name,
710 and the box is drawn in that color with a line width of 1. Otherwise,
711 VALUE must be a property list of the form `(:line-width WIDTH
712 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
713 the property list, a default value will be used for the value, as
714 specified below. WIDTH specifies the width of the lines to draw; it
715 defaults to 1. If WIDTH is negative, the absolute value is the width
716 of the lines, and draw top/bottom lines inside the characters area,
717 not around it. COLOR is the name of the color to draw in, default is
718 the foreground color of the face for simple boxes, and the background
719 color of the face for 3D boxes. STYLE specifies whether a 3D box
720 should be draw. If STYLE is `released-button', draw a box looking
721 like a released 3D button. If STYLE is `pressed-button' draw a box
722 that appears like a pressed button. If STYLE is nil, the default if
723 the property list doesn't contain a style specification, draw a 2D
724 box.
726 `:inverse-video'
728 VALUE specifies whether characters in FACE should be displayed in
729 inverse video. VALUE must be one of t or nil.
731 `:stipple'
733 If VALUE is a string, it must be the name of a file of pixmap data.
734 The directories listed in the `x-bitmap-file-path' variable are
735 searched. Alternatively, VALUE may be a list of the form (WIDTH
736 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
737 is a string containing the raw bits of the bitmap. VALUE nil means
738 explicitly don't use a stipple pattern.
740 For convenience, attributes `:family', `:width', `:height', `:weight',
741 and `:slant' may also be set in one step from an X font name:
743 `:font'
745 Set font-related face attributes from VALUE. VALUE must be a valid
746 XLFD font name. If it is a font name pattern, the first matching font
747 will be used.
749 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
750 be used to specify that a bold or italic font should be used. VALUE
751 must be t or nil in that case. A value of `unspecified' is not allowed.
753 `:inherit'
755 VALUE is the name of a face from which to inherit attributes, or a list
756 of face names. Attributes from inherited faces are merged into the face
757 like an underlying face would be, with higher priority than underlying faces."
758 (let ((where (if (null frame) 0 frame)))
759 (setq args (purecopy args))
760 ;; If we set the new-frame defaults, this face is modified outside Custom.
761 (if (memq where '(0 t))
762 (put (or (get face 'face-alias) face) 'face-modified t))
763 (while args
764 ;; Don't recursively set the attributes from the frame's font param
765 ;; when we update the frame's font param fro the attributes.
766 (let ((inhibit-face-set-after-frame-default t))
767 (internal-set-lisp-face-attribute face (car args)
768 (purecopy (cadr args))
769 where))
770 (setq args (cdr (cdr args))))))
773 (defun make-face-bold (face &optional frame noerror)
774 "Make the font of FACE be bold, if possible.
775 FRAME nil or not specified means change face on all frames.
776 Argument NOERROR is ignored and retained for compatibility.
777 Use `set-face-attribute' for finer control of the font weight."
778 (interactive (list (read-face-name "Make which face bold")))
779 (set-face-attribute face frame :weight 'bold))
782 (defun make-face-unbold (face &optional frame noerror)
783 "Make the font of FACE be non-bold, if possible.
784 FRAME nil or not specified means change face on all frames.
785 Argument NOERROR is ignored and retained for compatibility."
786 (interactive (list (read-face-name "Make which face non-bold")))
787 (set-face-attribute face frame :weight 'normal))
790 (defun make-face-italic (face &optional frame noerror)
791 "Make the font of FACE be italic, if possible.
792 FRAME nil or not specified means change face on all frames.
793 Argument NOERROR is ignored and retained for compatibility.
794 Use `set-face-attribute' for finer control of the font slant."
795 (interactive (list (read-face-name "Make which face italic")))
796 (set-face-attribute face frame :slant 'italic))
799 (defun make-face-unitalic (face &optional frame noerror)
800 "Make the font of FACE be non-italic, if possible.
801 FRAME nil or not specified means change face on all frames.
802 Argument NOERROR is ignored and retained for compatibility."
803 (interactive (list (read-face-name "Make which face non-italic")))
804 (set-face-attribute face frame :slant 'normal))
807 (defun make-face-bold-italic (face &optional frame noerror)
808 "Make the font of FACE be bold and italic, if possible.
809 FRAME nil or not specified means change face on all frames.
810 Argument NOERROR is ignored and retained for compatibility.
811 Use `set-face-attribute' for finer control of font weight and slant."
812 (interactive (list (read-face-name "Make which face bold-italic")))
813 (set-face-attribute face frame :weight 'bold :slant 'italic))
816 (defun set-face-font (face font &optional frame)
817 "Change font-related attributes of FACE to those of FONT (a string).
818 FRAME nil or not specified means change face on all frames.
819 This sets the attributes `:family', `:width', `:height', `:weight',
820 and `:slant'. When called interactively, prompt for the face and font."
821 (interactive (read-face-and-attribute :font))
822 (set-face-attribute face frame :font font))
825 ;; Implementation note: Emulating gray background colors with a
826 ;; stipple pattern is now part of the face realization process, and is
827 ;; done in C depending on the frame on which the face is realized.
829 (defun set-face-background (face color &optional frame)
830 "Change the background color of face FACE to COLOR (a string).
831 FRAME nil or not specified means change face on all frames.
832 COLOR can be a system-defined color name (see `list-colors-display')
833 or a hex spec of the form #RRGGBB.
834 When called interactively, prompts for the face and color."
835 (interactive (read-face-and-attribute :background))
836 (set-face-attribute face frame :background (or color 'unspecified)))
839 (defun set-face-foreground (face color &optional frame)
840 "Change the foreground 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 :foreground))
846 (set-face-attribute face frame :foreground (or color 'unspecified)))
849 (defun set-face-stipple (face stipple &optional frame)
850 "Change the stipple pixmap of face FACE to STIPPLE.
851 FRAME nil or not specified means change face on all frames.
852 STIPPLE should be a string, the name of a file of pixmap data.
853 The directories listed in the `x-bitmap-file-path' variable are searched.
855 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
856 where WIDTH and HEIGHT are the size in pixels,
857 and DATA is a string, containing the raw bits of the bitmap."
858 (interactive (read-face-and-attribute :stipple))
859 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
862 (defun set-face-underline-p (face underline &optional frame)
863 "Specify whether face FACE is underlined.
864 UNDERLINE nil means FACE explicitly doesn't underline.
865 UNDERLINE non-nil means FACE explicitly does underlining
866 with the same of the foreground color.
867 If UNDERLINE is a string, underline with the color named UNDERLINE.
868 FRAME nil or not specified means change face on all frames.
869 Use `set-face-attribute' to ``unspecify'' underlining."
870 (interactive
871 (let ((list (read-face-and-attribute :underline)))
872 (list (car list) (eq (car (cdr list)) t))))
873 (set-face-attribute face frame :underline underline))
875 (define-obsolete-function-alias 'set-face-underline
876 'set-face-underline-p "22.1")
879 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
880 "Specify whether face FACE is in inverse video.
881 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
882 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
883 FRAME nil or not specified means change face on all frames.
884 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
885 (interactive
886 (let ((list (read-face-and-attribute :inverse-video)))
887 (list (car list) (eq (car (cdr list)) t))))
888 (set-face-attribute face frame :inverse-video inverse-video-p))
891 (defun set-face-bold-p (face bold-p &optional frame)
892 "Specify whether face FACE is bold.
893 BOLD-P non-nil means FACE should explicitly display bold.
894 BOLD-P nil means FACE should explicitly display non-bold.
895 FRAME nil or not specified means change face on all frames.
896 Use `set-face-attribute' or `modify-face' for finer control."
897 (if (null bold-p)
898 (make-face-unbold face frame)
899 (make-face-bold face frame)))
902 (defun set-face-italic-p (face italic-p &optional frame)
903 "Specify whether face FACE is italic.
904 ITALIC-P non-nil means FACE should explicitly display italic.
905 ITALIC-P nil means FACE should explicitly display non-italic.
906 FRAME nil or not specified means change face on all frames.
907 Use `set-face-attribute' or `modify-face' for finer control."
908 (if (null italic-p)
909 (make-face-unitalic face frame)
910 (make-face-italic face frame)))
913 (defalias 'set-face-background-pixmap 'set-face-stipple)
916 (defun invert-face (face &optional frame)
917 "Swap the foreground and background colors of FACE.
918 If FRAME is omitted or nil, it means change face on all frames.
919 If FACE specifies neither foreground nor background color,
920 set its foreground and background to the background and foreground
921 of the default face. Value is FACE."
922 (interactive (list (read-face-name "Invert face")))
923 (let ((fg (face-attribute face :foreground frame))
924 (bg (face-attribute face :background frame)))
925 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
926 (set-face-attribute face frame :foreground bg :background fg)
927 (set-face-attribute face frame
928 :foreground
929 (face-attribute 'default :background frame)
930 :background
931 (face-attribute 'default :foreground frame))))
932 face)
935 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
936 ;;; Interactively modifying faces.
937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
939 (defun read-face-name (prompt &optional string-describing-default multiple)
940 "Read a face, defaulting to the face or faces on the char after point.
941 If it has the property `read-face-name', that overrides the `face' property.
942 PROMPT should be a string that describes what the caller will do with the face;
943 it should not end in a space.
944 STRING-DESCRIBING-DEFAULT should describe what default the caller will use if
945 the user just types RET; you can omit it.
946 If MULTIPLE is non-nil, return a list of faces (possibly only one).
947 Otherwise, return a single face."
948 (let ((faceprop (or (get-char-property (point) 'read-face-name)
949 (get-char-property (point) 'face)))
950 (aliasfaces nil)
951 (nonaliasfaces nil)
952 faces)
953 ;; Try to get a face name from the buffer.
954 (if (memq (intern-soft (thing-at-point 'symbol)) (face-list))
955 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
956 ;; Add the named faces that the `face' property uses.
957 (if (and (listp faceprop)
958 ;; Don't treat an attribute spec as a list of faces.
959 (not (keywordp (car faceprop)))
960 (not (memq (car faceprop) '(foreground-color background-color))))
961 (dolist (f faceprop)
962 (if (symbolp f)
963 (push f faces)))
964 (if (symbolp faceprop)
965 (push faceprop faces)))
966 (delete-dups faces)
968 ;; Build up the completion tables.
969 (mapatoms (lambda (s)
970 (if (custom-facep s)
971 (if (get s 'face-alias)
972 (push (symbol-name s) aliasfaces)
973 (push (symbol-name s) nonaliasfaces)))))
975 ;; If we only want one, and the default is more than one,
976 ;; discard the unwanted ones now.
977 (unless multiple
978 (if faces
979 (setq faces (list (car faces)))))
980 (require 'crm)
981 (let* ((input
982 ;; Read the input.
983 (completing-read-multiple
984 (if (or faces string-describing-default)
985 (format "%s (default %s): " prompt
986 (if faces (mapconcat 'symbol-name faces ",")
987 string-describing-default))
988 (format "%s: " prompt))
989 (complete-in-turn nonaliasfaces aliasfaces)
990 nil t nil nil
991 (if faces (mapconcat 'symbol-name faces ","))))
992 ;; Canonicalize the output.
993 (output
994 (cond ((or (equal input "") (equal input '("")))
995 faces)
996 ((stringp input)
997 (mapcar 'intern (split-string input ", *" t)))
998 ((listp input)
999 (mapcar 'intern input))
1000 (input))))
1001 ;; Return either a list of faces or just one face.
1002 (if multiple
1003 output
1004 (car output)))))
1007 (defun face-valid-attribute-values (attribute &optional frame)
1008 "Return valid values for face attribute ATTRIBUTE.
1009 The optional argument FRAME is used to determine available fonts
1010 and colors. If it is nil or not specified, the selected frame is
1011 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
1012 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1013 an integer value."
1014 (let ((valid
1015 (case attribute
1016 (:family
1017 (if (window-system frame)
1018 (mapcar #'(lambda (x) (cons (car x) (car x)))
1019 (x-font-family-list))
1020 ;; Only one font on TTYs.
1021 (list (cons "default" "default"))))
1022 ((:width :weight :slant :inverse-video)
1023 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1024 (internal-lisp-face-attribute-values attribute)))
1025 ((:underline :overline :strike-through :box)
1026 (if (window-system frame)
1027 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
1028 (internal-lisp-face-attribute-values attribute))
1029 (mapcar #'(lambda (c) (cons c c))
1030 (defined-colors frame)))
1031 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1032 (internal-lisp-face-attribute-values attribute))))
1033 ((:foreground :background)
1034 (mapcar #'(lambda (c) (cons c c))
1035 (defined-colors frame)))
1036 ((:height)
1037 'integerp)
1038 (:stipple
1039 (and (memq (window-system frame) '(x w32 mac))
1040 (mapcar #'list
1041 (apply #'nconc
1042 (mapcar (lambda (dir)
1043 (and (file-readable-p dir)
1044 (file-directory-p dir)
1045 (directory-files dir)))
1046 x-bitmap-file-path)))))
1047 (:inherit
1048 (cons '("none" . nil)
1049 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1050 (face-list))))
1052 (error "Internal error")))))
1053 (if (and (listp valid) (not (memq attribute '(:inherit))))
1054 (nconc (list (cons "unspecified" 'unspecified)) valid)
1055 valid)))
1058 (defvar face-attribute-name-alist
1059 '((:family . "font family")
1060 (:width . "character set width")
1061 (:height . "height in 1/10 pt")
1062 (:weight . "weight")
1063 (:slant . "slant")
1064 (:underline . "underline")
1065 (:overline . "overline")
1066 (:strike-through . "strike-through")
1067 (:box . "box")
1068 (:inverse-video . "inverse-video display")
1069 (:foreground . "foreground color")
1070 (:background . "background color")
1071 (:stipple . "background stipple")
1072 (:inherit . "inheritance"))
1073 "An alist of descriptive names for face attributes.
1074 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1075 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1076 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1079 (defun face-descriptive-attribute-name (attribute)
1080 "Return a descriptive name for ATTRIBUTE."
1081 (cdr (assq attribute face-attribute-name-alist)))
1084 (defun face-read-string (face default name &optional completion-alist)
1085 "Interactively read a face attribute string value.
1086 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1087 default string to return if no new value is entered. NAME is a
1088 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1089 alist of valid values, if non-nil.
1091 Entering nothing accepts the default string DEFAULT.
1092 Value is the new attribute value."
1093 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1094 ;; each word in a string separately).
1095 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1096 (let* ((completion-ignore-case t)
1097 (value (completing-read
1098 (if default
1099 (format "%s for face `%s' (default %s): "
1100 name face default)
1101 (format "%s for face `%s': " name face))
1102 completion-alist nil nil nil nil default)))
1103 (if (equal value "") default value)))
1106 (defun face-read-integer (face default name)
1107 "Interactively read an integer face attribute value.
1108 FACE is the face whose attribute is read. DEFAULT is the default
1109 value to return if no new value is entered. NAME is a descriptive
1110 name of the attribute for prompting. Value is the new attribute value."
1111 (let ((new-value
1112 (face-read-string face
1113 (format "%s" default)
1114 name
1115 (list (cons "unspecified" 'unspecified)))))
1116 (cond ((equal new-value "unspecified")
1117 'unspecified)
1118 ((member new-value '("unspecified-fg" "unspecified-bg"))
1119 new-value)
1121 (string-to-number new-value)))))
1124 (defun read-face-attribute (face attribute &optional frame)
1125 "Interactively read a new value for FACE's ATTRIBUTE.
1126 Optional argument FRAME nil or unspecified means read an attribute value
1127 of a global face. Value is the new attribute value."
1128 (let* ((old-value (face-attribute face attribute frame))
1129 (attribute-name (face-descriptive-attribute-name attribute))
1130 (valid (face-valid-attribute-values attribute frame))
1131 new-value)
1132 ;; Represent complex attribute values as strings by printing them
1133 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1134 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1135 ;; SHADOW)'.
1136 (when (and (or (eq attribute :stipple)
1137 (eq attribute :box))
1138 (or (consp old-value)
1139 (vectorp old-value)))
1140 (setq old-value (prin1-to-string old-value)))
1141 (cond ((listp valid)
1142 (let ((default
1143 (or (car (rassoc old-value valid))
1144 (format "%s" old-value))))
1145 (setq new-value
1146 (face-read-string face default attribute-name valid))
1147 (if (equal new-value default)
1148 ;; Nothing changed, so don't bother with all the stuff
1149 ;; below. In particular, this avoids a non-tty color
1150 ;; from being canonicalized for a tty when the user
1151 ;; just uses the default.
1152 (setq new-value old-value)
1153 ;; Terminal frames can support colors that don't appear
1154 ;; explicitly in VALID, using color approximation code
1155 ;; in tty-colors.el.
1156 (when (and (memq attribute '(:foreground :background))
1157 (not (memq (window-system frame) '(x w32 mac)))
1158 (not (member new-value
1159 '("unspecified"
1160 "unspecified-fg" "unspecified-bg"))))
1161 (setq new-value (car (tty-color-desc new-value frame))))
1162 (when (assoc new-value valid)
1163 (setq new-value (cdr (assoc new-value valid)))))))
1164 ((eq valid 'integerp)
1165 (setq new-value (face-read-integer face old-value attribute-name)))
1166 (t (error "Internal error")))
1167 ;; Convert stipple and box value text we read back to a list or
1168 ;; vector if it looks like one. This makes the assumption that a
1169 ;; pixmap file name won't start with an open-paren.
1170 (when (and (or (eq attribute :stipple)
1171 (eq attribute :box))
1172 (stringp new-value)
1173 (string-match "^[[(]" new-value))
1174 (setq new-value (read new-value)))
1175 new-value))
1178 (defun read-face-font (face &optional frame)
1179 "Read the name of a font for FACE on FRAME.
1180 If optional argument FRAME is nil or omitted, use the selected frame."
1181 (let ((completion-ignore-case t))
1182 (completing-read (format "Set font attributes of face `%s' from font: " face)
1183 (append (fontset-list) (x-list-fonts "*" nil frame)))))
1186 (defun read-all-face-attributes (face &optional frame)
1187 "Interactively read all attributes for FACE.
1188 If optional argument FRAME is nil or omitted, use the selected frame.
1189 Value is a property list of attribute names and new values."
1190 (let (result)
1191 (dolist (attribute face-attribute-name-alist result)
1192 (setq result (cons (car attribute)
1193 (cons (read-face-attribute face (car attribute) frame)
1194 result))))))
1196 (defun modify-face (&optional face foreground background stipple
1197 bold-p italic-p underline inverse-p frame)
1198 "Modify attributes of faces interactively.
1199 If optional argument FRAME is nil or omitted, modify the face used
1200 for newly created frame, i.e. the global face.
1201 For non-interactive use, `set-face-attribute' is preferred.
1202 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1203 and the face and its settings are obtained by querying the user."
1204 (interactive)
1205 (if face
1206 (set-face-attribute face frame
1207 :foreground (or foreground 'unspecified)
1208 :background (or background 'unspecified)
1209 :stipple stipple
1210 :bold bold-p
1211 :italic italic-p
1212 :underline underline
1213 :inverse-video inverse-p)
1214 (setq face (read-face-name "Modify face"))
1215 (apply #'set-face-attribute face frame
1216 (read-all-face-attributes face frame))))
1218 (defun read-face-and-attribute (attribute &optional frame)
1219 "Read face name and face attribute value.
1220 ATTRIBUTE is the attribute whose new value is read.
1221 FRAME nil or unspecified means read attribute value of global face.
1222 Value is a list (FACE NEW-VALUE) where FACE is the face read
1223 \(a symbol), and NEW-VALUE is value read."
1224 (cond ((eq attribute :font)
1225 (let* ((prompt "Set font-related attributes of face")
1226 (face (read-face-name prompt))
1227 (font (read-face-font face frame)))
1228 (list face font)))
1230 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1231 (prompt (format "Set %s of face" attribute-name))
1232 (face (read-face-name prompt))
1233 (new-value (read-face-attribute face attribute frame)))
1234 (list face new-value)))))
1238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1239 ;;; Listing faces.
1240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1242 (defvar list-faces-sample-text
1243 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1244 "*Text string to display as the sample text for `list-faces-display'.")
1247 ;; The name list-faces would be more consistent, but let's avoid a
1248 ;; conflict with Lucid, which uses that name differently.
1250 (defvar help-xref-stack)
1251 (defun list-faces-display (&optional regexp)
1252 "List all faces, using the same sample text in each.
1253 The sample text is a string that comes from the variable
1254 `list-faces-sample-text'.
1256 If REGEXP is non-nil, list only those faces with names matching
1257 this regular expression. When called interactively with a prefix
1258 arg, prompt for a regular expression."
1259 (interactive (list (and current-prefix-arg
1260 (read-string "List faces matching regexp: "))))
1261 (let ((all-faces (zerop (length regexp)))
1262 (frame (selected-frame))
1263 (max-length 0)
1264 faces line-format
1265 disp-frame window face-name)
1266 ;; We filter and take the max length in one pass
1267 (setq faces
1268 (delq nil
1269 (mapcar (lambda (f)
1270 (let ((s (symbol-name f)))
1271 (when (or all-faces (string-match regexp s))
1272 (setq max-length (max (length s) max-length))
1273 f)))
1274 (sort (face-list) #'string-lessp))))
1275 (unless faces
1276 (error "No faces matching \"%s\"" regexp))
1277 (setq max-length (1+ max-length)
1278 line-format (format "%%-%ds" max-length))
1279 (with-help-window "*Faces*"
1280 (save-excursion
1281 (set-buffer standard-output)
1282 (setq truncate-lines t)
1283 (insert
1284 (substitute-command-keys
1285 (concat
1286 "Use "
1287 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1288 "\\[help-follow] on a face name to customize it\n"
1289 "or on its sample text for a description of the face.\n\n")))
1290 (setq help-xref-stack nil)
1291 (dolist (face faces)
1292 (setq face-name (symbol-name face))
1293 (insert (format line-format face-name))
1294 ;; Hyperlink to a customization buffer for the face. Using
1295 ;; the help xref mechanism may not be the best way.
1296 (save-excursion
1297 (save-match-data
1298 (search-backward face-name)
1299 (setq help-xref-stack-item `(list-faces-display ,regexp))
1300 (help-xref-button 0 'help-customize-face face)))
1301 (let ((beg (point))
1302 (line-beg (line-beginning-position)))
1303 (insert list-faces-sample-text)
1304 ;; Hyperlink to a help buffer for the face.
1305 (save-excursion
1306 (save-match-data
1307 (search-backward list-faces-sample-text)
1308 (help-xref-button 0 'help-face face)))
1309 (insert "\n")
1310 (put-text-property beg (1- (point)) 'face face)
1311 ;; Make all face commands default to the proper face
1312 ;; anywhere in the line.
1313 (put-text-property line-beg (1- (point)) 'read-face-name face)
1314 ;; If the sample text has multiple lines, line up all of them.
1315 (goto-char beg)
1316 (forward-line 1)
1317 (while (not (eobp))
1318 (insert-char ?\s max-length)
1319 (forward-line 1))))
1320 (goto-char (point-min))))
1321 ;; If the *Faces* buffer appears in a different frame,
1322 ;; copy all the face definitions from FRAME,
1323 ;; so that the display will reflect the frame that was selected.
1324 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1325 (setq disp-frame (if window (window-frame window)
1326 (car (frame-list))))
1327 (or (eq frame disp-frame)
1328 (let ((faces (face-list)))
1329 (while faces
1330 (copy-face (car faces) (car faces) frame disp-frame)
1331 (setq faces (cdr faces)))))))
1334 (defun describe-face (face &optional frame)
1335 "Display the properties of face FACE on FRAME.
1336 Interactively, FACE defaults to the faces of the character after point
1337 and FRAME defaults to the selected frame.
1339 If the optional argument FRAME is given, report on face FACE in that frame.
1340 If FRAME is t, report on the defaults for face FACE (for new frames).
1341 If FRAME is omitted or nil, use the selected frame."
1342 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1343 (let* ((attrs '((:family . "Family")
1344 (:width . "Width")
1345 (:height . "Height")
1346 (:weight . "Weight")
1347 (:slant . "Slant")
1348 (:foreground . "Foreground")
1349 (:background . "Background")
1350 (:underline . "Underline")
1351 (:overline . "Overline")
1352 (:strike-through . "Strike-through")
1353 (:box . "Box")
1354 (:inverse-video . "Inverse")
1355 (:stipple . "Stipple")
1356 (:font . "Font")
1357 (:fontset . "Fontset")
1358 (:inherit . "Inherit")))
1359 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1360 attrs))))
1361 (help-setup-xref (list #'describe-face face) (interactive-p))
1362 (unless face
1363 (setq face 'default))
1364 (if (not (listp face))
1365 (setq face (list face)))
1366 (with-help-window (help-buffer)
1367 (save-excursion
1368 (set-buffer standard-output)
1369 (dolist (f face)
1370 (if (stringp f) (setq f (intern f)))
1371 (insert "Face: " (symbol-name f))
1372 (if (not (facep f))
1373 (insert " undefined face.\n")
1374 (let ((customize-label "customize this face")
1375 file-name)
1376 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1377 (princ (concat " (" customize-label ")\n"))
1378 (insert "Documentation: "
1379 (or (face-documentation f)
1380 "Not documented as a face.")
1381 "\n")
1382 (with-current-buffer standard-output
1383 (save-excursion
1384 (re-search-backward
1385 (concat "\\(" customize-label "\\)") nil t)
1386 (help-xref-button 1 'help-customize-face f)))
1387 ;; The next 4 sexps are copied from describe-function-1
1388 ;; and simplified.
1389 (setq file-name (symbol-file f 'defface))
1390 (setq file-name (describe-simplify-lib-file-name file-name))
1391 (when file-name
1392 (princ "Defined in `")
1393 (princ file-name)
1394 (princ "'")
1395 ;; Make a hyperlink to the library.
1396 (save-excursion
1397 (re-search-backward "`\\([^`']+\\)'" nil t)
1398 (help-xref-button 1 'help-face-def f file-name))
1399 (princ ".")
1400 (terpri)
1401 (terpri))
1402 (dolist (a attrs)
1403 (let ((attr (face-attribute f (car a) frame)))
1404 (insert (make-string (- max-width (length (cdr a))) ?\s)
1405 (cdr a) ": " (format "%s" attr))
1406 (if (and (eq (car a) :inherit)
1407 (not (eq attr 'unspecified)))
1408 ;; Make a hyperlink to the parent face.
1409 (save-excursion
1410 (re-search-backward ": \\([^:]+\\)" nil t)
1411 (help-xref-button 1 'help-face attr)))
1412 (insert "\n")))))
1413 (terpri))))))
1416 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1417 ;;; Face specifications (defface).
1418 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1420 ;; Parameter FRAME Is kept for call compatibility to with previous
1421 ;; face implementation.
1423 (defun face-attr-construct (face &optional frame)
1424 "Return a `defface'-style attribute list for FACE on FRAME.
1425 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1426 face attributes of FACE where ATTRIBUTE is the attribute name and
1427 VALUE is the specified value of that attribute."
1428 (let (result)
1429 (dolist (entry face-attribute-name-alist result)
1430 (let* ((attribute (car entry))
1431 (value (face-attribute face attribute)))
1432 (unless (eq value 'unspecified)
1433 (setq result (nconc (list attribute value) result)))))))
1436 (defun face-spec-set-match-display (display frame)
1437 "Non-nil if DISPLAY matches FRAME.
1438 DISPLAY is part of a spec such as can be used in `defface'.
1439 If FRAME is nil, the current FRAME is used."
1440 (let* ((conjuncts display)
1441 conjunct req options
1442 ;; t means we have succeeded against all the conjuncts in
1443 ;; DISPLAY that have been tested so far.
1444 (match t))
1445 (if (eq conjuncts t)
1446 (setq conjuncts nil))
1447 (while (and conjuncts match)
1448 (setq conjunct (car conjuncts)
1449 conjuncts (cdr conjuncts)
1450 req (car conjunct)
1451 options (cdr conjunct)
1452 match (cond ((eq req 'type)
1453 (or (memq (window-system frame) options)
1454 ;; FIXME: This should be revisited to use
1455 ;; display-graphic-p, provided that the
1456 ;; color selection depends on the number
1457 ;; of supported colors, and all defface's
1458 ;; are changed to look at number of colors
1459 ;; instead of (type graphic) etc.
1460 (and (null (window-system frame))
1461 (memq 'tty options))
1462 (and (memq 'motif options)
1463 (featurep 'motif))
1464 (and (memq 'gtk options)
1465 (featurep 'gtk))
1466 (and (memq 'lucid options)
1467 (featurep 'x-toolkit)
1468 (not (featurep 'motif))
1469 (not (featurep 'gtk)))
1470 (and (memq 'x-toolkit options)
1471 (featurep 'x-toolkit))))
1472 ((eq req 'min-colors)
1473 (>= (display-color-cells frame) (car options)))
1474 ((eq req 'class)
1475 (memq (frame-parameter frame 'display-type) options))
1476 ((eq req 'background)
1477 (memq (frame-parameter frame 'background-mode)
1478 options))
1479 ((eq req 'supports)
1480 (display-supports-face-attributes-p options frame))
1481 (t (error "Unknown req `%S' with options `%S'"
1482 req options)))))
1483 match))
1486 (defun face-spec-choose (spec &optional frame)
1487 "Choose the proper attributes for FRAME, out of SPEC.
1488 If SPEC is nil, return nil."
1489 (unless frame
1490 (setq frame (selected-frame)))
1491 (let ((tail spec)
1492 result defaults)
1493 (while tail
1494 (let* ((entry (pop tail))
1495 (display (car entry))
1496 (attrs (cdr entry))
1497 thisval)
1498 ;; Get the attributes as actually specified by this alternative.
1499 (setq thisval
1500 (if (null (cdr attrs)) ;; was (listp (car attrs))
1501 ;; Old-style entry, the attribute list is the
1502 ;; first element.
1503 (car attrs)
1504 attrs))
1506 ;; If the condition is `default', that sets the default
1507 ;; for following conditions.
1508 (if (eq display 'default)
1509 (setq defaults thisval)
1510 ;; Otherwise, if it matches, use it.
1511 (when (face-spec-set-match-display display frame)
1512 (setq result thisval)
1513 (setq tail nil)))))
1514 (if defaults (append result defaults) result)))
1517 (defun face-spec-reset-face (face &optional frame)
1518 "Reset all attributes of FACE on FRAME to unspecified."
1519 (let ((attrs face-attribute-name-alist))
1520 (while attrs
1521 (let ((attr-and-name (car attrs)))
1522 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1523 (setq attrs (cdr attrs)))))
1526 (defun face-spec-set (face spec &optional for-defface)
1527 "Set FACE's face spec, which controls its appearance, to SPEC.
1528 If FOR-DEFFACE is t, set the base spec, the one that `defface'
1529 and Custom set. (In that case, the caller must put it in the
1530 appropriate property, because that depends on the caller.)
1531 If FOR-DEFFACE is nil, set the overriding spec (and store it
1532 in the `face-override-spec' property of FACE).
1534 The appearance of FACE is controlled by the base spec,
1535 by any custom theme specs on top of that, and by the
1536 overriding spec on top of all the rest.
1538 FOR-DEFFACE can also be a frame, in which case we set the
1539 frame-specific attributes of FACE for that frame based on SPEC.
1540 That usage is deprecated.
1542 See `defface' for information about the format and meaning of SPEC."
1543 (if (framep for-defface)
1544 ;; Handle the deprecated case where third arg is a frame.
1545 (face-spec-set-2 face for-defface spec)
1546 (if for-defface
1547 ;; When we reset the face based on its custom spec, then it is
1548 ;; unmodified as far as Custom is concerned.
1549 (put (or (get face 'face-alias) face) 'face-modified nil)
1550 ;; When we change a face based on a spec from outside custom,
1551 ;; record it for future frames.
1552 (put (or (get face 'face-alias) face) 'face-override-spec spec))
1553 ;;; RMS 29 dec 2007: Perhaps this code should be reinstated.
1554 ;;; That depends on whether the overriding spec
1555 ;;; or the default face attributes
1556 ;;; should take priority.
1557 ;;; ;; Clear all the new-frame default attributes for this face.
1558 ;;; ;; face-spec-reset-face won't do it right.
1559 ;;; (let ((facevec (cdr (assq face face-new-frame-defaults))))
1560 ;;; (dotimes (i (length facevec))
1561 ;;; (unless (= i 0)
1562 ;;; (aset facevec i 'unspecified))))
1563 ;; Reset each frame according to the rules implied by all its specs.
1564 (dolist (frame (frame-list))
1565 (face-spec-recalc face frame))))
1567 (defun face-spec-recalc (face frame)
1568 "Reset the face attributes of FACE on FRAME according to its specs.
1569 This applies the defface/custom spec first, then the custom theme specs,
1570 then the override spec."
1571 (face-spec-reset-face face frame)
1572 (let ((face-sym (or (get face 'face-alias) face)))
1573 (face-spec-set-2 face frame
1574 (face-user-default-spec face))
1575 (let ((theme-faces (reverse (get face-sym 'theme-face))))
1576 (dolist (spec theme-faces)
1577 (face-spec-set-2 face frame (cadr spec))))
1578 (face-spec-set-2 face frame (get face-sym 'face-override-spec))))
1580 (defun face-spec-set-2 (face frame spec)
1581 "Set the face attributes of FACE on FRAME according to SPEC."
1582 (let* ((attrs (face-spec-choose spec frame)))
1583 (while attrs
1584 (let ((attribute (car attrs))
1585 (value (car (cdr attrs))))
1586 ;; Support some old-style attribute names and values.
1587 (case attribute
1588 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1589 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1590 ((:foreground :background)
1591 ;; Compatibility with 20.x. Some bogus face specs seem to
1592 ;; exist containing things like `:foreground nil'.
1593 (if (null value) (setq value 'unspecified)))
1594 (t (unless (assq attribute face-x-resources)
1595 (setq attribute nil))))
1596 (when attribute
1597 (set-face-attribute face frame attribute value)))
1598 (setq attrs (cdr (cdr attrs))))))
1600 (defun face-attr-match-p (face attrs &optional frame)
1601 "Return t if attributes of FACE match values in plist ATTRS.
1602 Optional parameter FRAME is the frame whose definition of FACE
1603 is used. If nil or omitted, use the selected frame."
1604 (unless frame
1605 (setq frame (selected-frame)))
1606 (let ((list face-attribute-name-alist)
1607 (match t))
1608 (while (and match (not (null list)))
1609 (let* ((attr (car (car list)))
1610 (specified-value
1611 (if (plist-member attrs attr)
1612 (plist-get attrs attr)
1613 'unspecified))
1614 (value-now (face-attribute face attr frame)))
1615 (setq match (equal specified-value value-now))
1616 (setq list (cdr list))))
1617 match))
1619 (defun face-spec-match-p (face spec &optional frame)
1620 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1621 (face-attr-match-p face (face-spec-choose spec frame) frame))
1623 (defsubst face-default-spec (face)
1624 "Return the default face-spec for FACE, ignoring any user customization.
1625 If there is no default for FACE, return nil."
1626 (get face 'face-defface-spec))
1628 (defsubst face-user-default-spec (face)
1629 "Return the user's customized face-spec for FACE, or the default if none.
1630 If there is neither a user setting nor a default for FACE, return nil."
1631 (or (get face 'customized-face)
1632 (get face 'saved-face)
1633 (face-default-spec face)))
1636 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1637 ;;; Frame-type independent color support.
1638 ;;; We keep the old x-* names as aliases for back-compatibility.
1639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1641 (defun defined-colors (&optional frame)
1642 "Return a list of colors supported for a particular frame.
1643 The argument FRAME specifies which frame to try.
1644 The value may be different for frames on different display types.
1645 If FRAME doesn't support colors, the value is nil.
1646 If FRAME is nil, that stands for the selected frame."
1647 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1648 (xw-defined-colors frame)
1649 (mapcar 'car (tty-color-alist frame))))
1650 (defalias 'x-defined-colors 'defined-colors)
1652 (defun color-defined-p (color &optional frame)
1653 "Return non-nil if color COLOR is supported on frame FRAME.
1654 If FRAME is omitted or nil, use the selected frame.
1655 If COLOR is the symbol `unspecified' or one of the strings
1656 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1657 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1659 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1660 (xw-color-defined-p color frame)
1661 (numberp (tty-color-translate color frame)))))
1662 (defalias 'x-color-defined-p 'color-defined-p)
1664 (defun color-values (color &optional frame)
1665 "Return a description of the color named COLOR on frame FRAME.
1666 The value is a list of integer RGB values--(RED GREEN BLUE).
1667 These values appear to range from 0 to 65280 or 65535, depending
1668 on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
1669 If FRAME is omitted or nil, use the selected frame.
1670 If FRAME cannot display COLOR, the value is nil.
1671 If COLOR is the symbol `unspecified' or one of the strings
1672 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1673 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1675 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1676 (xw-color-values color frame)
1677 (tty-color-values color frame))))
1678 (defalias 'x-color-values 'color-values)
1680 (defun display-color-p (&optional display)
1681 "Return t if DISPLAY supports color.
1682 The optional argument DISPLAY specifies which display to ask about.
1683 DISPLAY should be either a frame or a display name (a string).
1684 If omitted or nil, that stands for the selected frame's display."
1685 (if (memq (framep-on-display display) '(x w32 mac))
1686 (xw-display-color-p display)
1687 (tty-display-color-p display)))
1688 (defalias 'x-display-color-p 'display-color-p)
1690 (defun display-grayscale-p (&optional display)
1691 "Return non-nil if frames on DISPLAY can display shades of gray."
1692 (let ((frame-type (framep-on-display display)))
1693 (cond
1694 ((memq frame-type '(x w32 mac))
1695 (x-display-grayscale-p display))
1697 (> (tty-color-gray-shades display) 2)))))
1699 (defun read-color (&optional prompt convert-to-RGB-p allow-empty-name-p msg-p)
1700 "Read a color name or RGB hex value: #RRRRGGGGBBBB.
1701 Completion is available for color names, but not for RGB hex strings.
1702 If the user inputs an RGB hex string, it must have the form
1703 #XXXXXXXXXXXX or XXXXXXXXXXXX, where each X is a hex digit. The
1704 number of Xs must be a multiple of 3, with the same number of Xs for
1705 each of red, green, and blue. The order is red, green, blue.
1707 In addition to standard color names and RGB hex values, the following
1708 are available as color candidates. In each case, the corresponding
1709 color is used.
1711 * `foreground at point' - foreground under the cursor
1712 * `background at point' - background under the cursor
1714 Checks input to be sure it represents a valid color. If not, raises
1715 an error (but see exception for empty input with non-nil
1716 ALLOW-EMPTY-NAME-P).
1718 Optional arg PROMPT is the prompt; if nil, uses a default prompt.
1720 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, converts
1721 an input color name to an RGB hex string. Returns the RGB hex string.
1723 Optional arg ALLOW-EMPTY-NAME-P controls what happens if the user
1724 enters an empty color name (that is, just hits `RET'). If non-nil,
1725 then returns an empty color name, \"\". If nil, then raises an error.
1726 Programs must test for \"\" if ALLOW-EMPTY-NAME-P is non-nil. They
1727 can then perform an appropriate action in case of empty input.
1729 Interactively, or with optional arg MSG-P non-nil, echoes the color in
1730 a message."
1731 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1732 (let* ((completion-ignore-case t)
1733 (colors (append '("foreground at point" "background at point")
1734 (defined-colors)))
1735 (color (completing-read (or prompt "Color (name or #R+G+B+): ")
1736 colors))
1737 hex-string)
1738 (cond ((string= "foreground at point" color)
1739 (setq color (foreground-color-at-point)))
1740 ((string= "background at point" color)
1741 (setq color (background-color-at-point))))
1742 (unless color
1743 (setq color ""))
1744 (setq hex-string
1745 (string-match "^#?\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color))
1746 (if (and allow-empty-name-p (string= "" color))
1748 (when (and hex-string (not (eq (aref color 0) ?#)))
1749 (setq color (concat "#" color))) ; No #; add it.
1750 (unless hex-string
1751 (when (or (string= "" color) (not (test-completion color colors)))
1752 (error "No such color: %S" color))
1753 (when convert-to-RGB-p
1754 (let ((components (x-color-values color)))
1755 (unless components (error "No such color: %S" color))
1756 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1757 (setq color (format "#%04X%04X%04X"
1758 (logand 65535 (nth 0 components))
1759 (logand 65535 (nth 1 components))
1760 (logand 65535 (nth 2 components))))))))
1761 (when msg-p (message "Color: `%s'" color))
1762 color)))
1764 ;; Commented out because I decided it is better to include the
1765 ;; duplicates in read-color's completion list.
1767 ;; (defun defined-colors-without-duplicates ()
1768 ;; "Return the list of defined colors, without the no-space versions.
1769 ;; For each color name, we keep the variant that DOES have spaces."
1770 ;; (let ((result (copy-sequence (defined-colors)))
1771 ;; to-be-rejected)
1772 ;; (save-match-data
1773 ;; (dolist (this result)
1774 ;; (if (string-match " " this)
1775 ;; (push (replace-regexp-in-string " " ""
1776 ;; this)
1777 ;; to-be-rejected)))
1778 ;; (dolist (elt to-be-rejected)
1779 ;; (let ((as-found (car (member-ignore-case elt result))))
1780 ;; (setq result (delete as-found result)))))
1781 ;; result))
1783 (defun face-at-point ()
1784 "Return the face of the character after point.
1785 If it has more than one face, return the first one.
1786 Return nil if it has no specified face."
1787 (let* ((faceprop (or (get-char-property (point) 'read-face-name)
1788 (get-char-property (point) 'face)
1789 'default))
1790 (face (cond ((symbolp faceprop) faceprop)
1791 ;; List of faces (don't treat an attribute spec).
1792 ;; Just use the first face.
1793 ((and (consp faceprop) (not (keywordp (car faceprop)))
1794 (not (memq (car faceprop)
1795 '(foreground-color background-color))))
1796 (car faceprop))
1797 (t nil)))) ; Invalid face value.
1798 (if (facep face) face nil)))
1800 (defun foreground-color-at-point ()
1801 "Return the foreground color of the character after point."
1802 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1803 ;; Need also pick up any face properties that are not associated with named faces.
1804 (let ((face (or (face-at-point)
1805 (get-char-property (point) 'read-face-name)
1806 (get-char-property (point) 'face))))
1807 (cond ((and face (symbolp face))
1808 (let ((value (face-foreground face nil 'default)))
1809 (if (member value '("unspecified-fg" "unspecified-bg"))
1811 value)))
1812 ((consp face)
1813 (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face)))
1814 ((memq ':foreground face) (cadr (memq ':foreground face)))))
1815 (t nil)))) ; Invalid face value.
1817 (defun background-color-at-point ()
1818 "Return the background color of the character after point."
1819 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1820 ;; Need also pick up any face properties that are not associated with named faces.
1821 (let ((face (or (face-at-point)
1822 (get-char-property (point) 'read-face-name)
1823 (get-char-property (point) 'face))))
1824 (cond ((and face (symbolp face))
1825 (let ((value (face-background face nil 'default)))
1826 (if (member value '("unspecified-fg" "unspecified-bg"))
1828 value)))
1829 ((consp face)
1830 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1831 ((memq ':background face) (cadr (memq ':background face)))))
1832 (t nil)))) ; Invalid face value.
1834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1835 ;;; Background mode.
1836 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1838 (defcustom frame-background-mode nil
1839 "*The brightness of the background.
1840 Set this to the symbol `dark' if your background color is dark,
1841 `light' if your background is light, or nil (automatic by default)
1842 if you want Emacs to examine the brightness for you. Don't set this
1843 variable with `setq'; this won't have the expected effect."
1844 :group 'faces
1845 :set #'(lambda (var value)
1846 (set-default var value)
1847 (mapc 'frame-set-background-mode (frame-list)))
1848 :initialize 'custom-initialize-changed
1849 :type '(choice (const dark)
1850 (const light)
1851 (const :tag "automatic" nil)))
1854 (defun frame-set-background-mode (frame)
1855 "Set up display-dependent faces on FRAME.
1856 Display-dependent faces are those which have different definitions
1857 according to the `background-mode' and `display-type' frame parameters."
1858 (let* ((bg-resource
1859 (and (window-system frame)
1860 (x-get-resource "backgroundMode" "BackgroundMode")))
1861 (bg-color (frame-parameter frame 'background-color))
1862 (terminal-bg-mode (terminal-parameter frame 'background-mode))
1863 (tty-type (tty-type frame))
1864 (bg-mode
1865 (cond (frame-background-mode)
1866 (bg-resource
1867 (intern (downcase bg-resource)))
1868 (terminal-bg-mode)
1869 ((and (null (window-system frame))
1870 ;; Unspecified frame background color can only
1871 ;; happen on tty's.
1872 (member bg-color '(nil unspecified "unspecified-bg")))
1873 ;; There is no way to determine the background mode
1874 ;; automatically, so we make a guess based on the
1875 ;; terminal type.
1876 (if (and tty-type
1877 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1878 tty-type))
1879 'light
1880 'dark))
1881 ((equal bg-color "unspecified-fg") ; inverted colors
1882 (if (and tty-type
1883 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1884 tty-type))
1885 'dark
1886 'light))
1887 ((>= (apply '+ (color-values bg-color frame))
1888 ;; Just looking at the screen, colors whose
1889 ;; values add up to .6 of the white total
1890 ;; still look dark to me.
1891 (* (apply '+ (color-values "white" frame)) .6))
1892 'light)
1893 (t 'dark)))
1894 (display-type
1895 (cond ((null (window-system frame))
1896 (if (tty-display-color-p frame) 'color 'mono))
1897 ((display-color-p frame)
1898 'color)
1899 ((x-display-grayscale-p frame)
1900 'grayscale)
1901 (t 'mono)))
1902 (old-bg-mode
1903 (frame-parameter frame 'background-mode))
1904 (old-display-type
1905 (frame-parameter frame 'display-type)))
1907 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1908 (let ((locally-modified-faces nil))
1909 ;; Before modifying the frame parameters, we collect a list of
1910 ;; faces that don't match what their face-spec says they should
1911 ;; look like; we then avoid changing these faces below.
1912 ;; These are the faces whose attributes were modified on FRAME.
1913 ;; We use a negative list on the assumption that most faces will
1914 ;; be unmodified, so we can avoid consing in the common case.
1915 (dolist (face (face-list))
1916 (and (not (get face 'face-override-spec))
1917 (not (face-spec-match-p face
1918 (face-user-default-spec face)
1919 (selected-frame)))
1920 (push face locally-modified-faces)))
1921 ;; Now change to the new frame parameters
1922 (modify-frame-parameters frame
1923 (list (cons 'background-mode bg-mode)
1924 (cons 'display-type display-type)))
1925 ;; For all named faces, choose face specs matching the new frame
1926 ;; parameters, unless they have been locally modified.
1927 (dolist (face (face-list))
1928 (unless (memq face locally-modified-faces)
1929 (face-spec-recalc face frame)))))))
1932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1933 ;;; Frame creation.
1934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1936 (defun x-handle-named-frame-geometry (parameters)
1937 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1938 Value is the new parameter list."
1939 (let* ((name (or (cdr (assq 'name parameters))
1940 (cdr (assq 'name default-frame-alist))))
1941 (x-resource-name name)
1942 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1943 (when res-geometry
1944 (let ((parsed (x-parse-geometry res-geometry)))
1945 ;; If the resource specifies a position, call the position
1946 ;; and size "user-specified".
1947 (when (or (assq 'top parsed)
1948 (assq 'left parsed))
1949 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1950 ;; Put the geometry parameters at the end. Copy
1951 ;; default-frame-alist so that they go after it.
1952 (setq parameters (append parameters default-frame-alist parsed))))
1953 parameters))
1956 (defun x-handle-reverse-video (frame parameters)
1957 "Handle the reverse-video frame parameter and X resource.
1958 `x-create-frame' does not handle this one."
1959 (when (cdr (or (assq 'reverse parameters)
1960 (assq 'reverse default-frame-alist)
1961 (let ((resource (x-get-resource "reverseVideo"
1962 "ReverseVideo")))
1963 (if resource
1964 (cons nil (member (downcase resource)
1965 '("on" "true")))))))
1966 (let* ((params (frame-parameters frame))
1967 (bg (cdr (assq 'foreground-color params)))
1968 (fg (cdr (assq 'background-color params))))
1969 (modify-frame-parameters frame
1970 (list (cons 'foreground-color fg)
1971 (cons 'background-color bg)))
1972 (if (equal bg (cdr (assq 'border-color params)))
1973 (modify-frame-parameters frame
1974 (list (cons 'border-color fg))))
1975 (if (equal bg (cdr (assq 'mouse-color params)))
1976 (modify-frame-parameters frame
1977 (list (cons 'mouse-color fg))))
1978 (if (equal bg (cdr (assq 'cursor-color params)))
1979 (modify-frame-parameters frame
1980 (list (cons 'cursor-color fg)))))))
1983 (defun x-create-frame-with-faces (&optional parameters)
1984 "Create a frame from optional frame parameters PARAMETERS.
1985 Parameters not specified by PARAMETERS are taken from
1986 `default-frame-alist'. If PARAMETERS specify a frame name,
1987 handle X geometry resources for that name. If either PARAMETERS
1988 or `default-frame-alist' contains a `reverse' parameter, or
1989 the X resource ``reverseVideo'' is present, handle that.
1990 Value is the new frame created."
1991 (setq parameters (x-handle-named-frame-geometry parameters))
1992 (let ((visibility-spec (assq 'visibility parameters))
1993 (frame (x-create-frame `((visibility . nil) . ,parameters)))
1994 success)
1995 (unwind-protect
1996 (progn
1997 (x-setup-function-keys frame)
1998 (x-handle-reverse-video frame parameters)
1999 (frame-set-background-mode frame)
2000 (face-set-after-frame-default frame)
2001 ;; Make sure the tool-bar is ready to be enabled. The
2002 ;; `tool-bar-lines' frame parameter will not take effect
2003 ;; without this call.
2004 (tool-bar-setup frame)
2005 (if (null visibility-spec)
2006 (make-frame-visible frame)
2007 (modify-frame-parameters frame (list visibility-spec)))
2008 (setq success t))
2009 (unless success
2010 (delete-frame frame)))
2011 frame))
2013 (defun face-set-after-frame-default (frame)
2014 "Set frame-local faces of FRAME from face specs and resources.
2015 Initialize colors of certain faces from frame parameters."
2016 (unless inhibit-face-set-after-frame-default
2017 (if (face-attribute 'default :font t)
2018 (set-face-attribute 'default frame :font
2019 (face-attribute 'default :font t))
2020 (set-face-attribute 'default frame :family
2021 (face-attribute 'default :family t))
2022 (set-face-attribute 'default frame :height
2023 (face-attribute 'default :height t))
2024 (set-face-attribute 'default frame :slant
2025 (face-attribute 'default :slant t))
2026 (set-face-attribute 'default frame :weight
2027 (face-attribute 'default :weight t))
2028 (set-face-attribute 'default frame :width
2029 (face-attribute 'default :width t))))
2030 ;; Find attributes that should be initialized from frame parameters.
2031 (let ((face-params '((foreground-color default :foreground)
2032 (background-color default :background)
2033 (border-color border :background)
2034 (cursor-color cursor :background)
2035 (scroll-bar-foreground scroll-bar :foreground)
2036 (scroll-bar-background scroll-bar :background)
2037 (mouse-color mouse :background)))
2038 apply-params)
2039 (dolist (param face-params)
2040 (let* ((value (frame-parameter frame (nth 0 param)))
2041 (face (nth 1 param))
2042 (attr (nth 2 param))
2043 (default-value (face-attribute face attr t)))
2044 ;; Compile a list of face attributes to set, but don't set
2045 ;; them yet. The call to make-face-x-resource-internal,
2046 ;; below, can change frame parameters, and the final set of
2047 ;; frame parameters should be the ones acquired at this step.
2048 (if (eq default-value 'unspecified)
2049 ;; The face spec does not specify a new-frame value for
2050 ;; this attribute. Check if the existing frame parameter
2051 ;; specifies it.
2052 (if value
2053 (push (list face frame attr value) apply-params))
2054 ;; The face spec specifies a value for this attribute, to be
2055 ;; applied to the face on all new frames.
2056 (push (list face frame attr default-value) apply-params))))
2057 ;; Initialize faces from face specs and X resources. The
2058 ;; condition-case prevents invalid specs from causing frame
2059 ;; creation to fail.
2060 (dolist (face (delq 'default (face-list)))
2061 (condition-case ()
2062 (progn
2063 (face-spec-recalc face frame)
2064 (if (memq (window-system frame) '(x w32 mac))
2065 (make-face-x-resource-internal face frame))
2066 (internal-merge-in-global-face face frame))
2067 (error nil)))
2068 ;; Apply the attributes specified by frame parameters. This
2069 ;; rewrites parameters changed by make-face-x-resource-internal
2070 (dolist (param apply-params)
2071 (apply 'set-face-attribute param))))
2073 (defun tty-handle-reverse-video (frame parameters)
2074 "Handle the reverse-video frame parameter for terminal frames."
2075 (when (cdr (or (assq 'reverse parameters)
2076 (assq 'reverse default-frame-alist)))
2077 (let* ((params (frame-parameters frame))
2078 (bg (cdr (assq 'foreground-color params)))
2079 (fg (cdr (assq 'background-color params))))
2080 (modify-frame-parameters frame
2081 (list (cons 'foreground-color fg)
2082 (cons 'background-color bg)))
2083 (if (equal bg (cdr (assq 'mouse-color params)))
2084 (modify-frame-parameters frame
2085 (list (cons 'mouse-color fg))))
2086 (if (equal bg (cdr (assq 'cursor-color params)))
2087 (modify-frame-parameters frame
2088 (list (cons 'cursor-color fg)))))))
2091 (defun tty-create-frame-with-faces (&optional parameters)
2092 "Create a frame from optional frame parameters PARAMETERS.
2093 Parameters not specified by PARAMETERS are taken from
2094 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
2095 contains a `reverse' parameter, handle that. Value is the new frame
2096 created."
2097 (let ((frame (make-terminal-frame parameters))
2098 success)
2099 (unwind-protect
2100 (with-selected-frame frame
2101 (tty-handle-reverse-video frame (frame-parameters frame))
2103 (unless (terminal-parameter frame 'terminal-initted)
2104 (set-terminal-parameter frame 'terminal-initted t)
2105 (set-locale-environment nil frame)
2106 (tty-run-terminal-initialization frame))
2107 (frame-set-background-mode frame)
2108 (face-set-after-frame-default frame)
2109 (setq success t))
2110 (unless success
2111 (delete-frame frame)))
2112 frame))
2114 (defun tty-find-type (pred type)
2115 "Return the longest prefix of TYPE to which PRED returns non-nil.
2116 TYPE should be a tty type name such as \"xterm-16color\".
2118 The function tries only those prefixes that are followed by a
2119 dash or underscore in the original type name, like \"xterm\" in
2120 the above example."
2121 (let (hyphend)
2122 (while (and type
2123 (not (funcall pred type)))
2124 ;; Strip off last hyphen and what follows, then try again
2125 (setq type
2126 (if (setq hyphend (string-match "[-_][^-_]+$" type))
2127 (substring type 0 hyphend)
2128 nil))))
2129 type)
2131 (defun tty-run-terminal-initialization (frame &optional type)
2132 "Run the special initialization code for the terminal type of FRAME.
2133 The optional TYPE parameter may be used to override the autodetected
2134 terminal type to a different value."
2135 (setq type (or type (tty-type frame)))
2136 ;; Load library for our terminal type.
2137 ;; User init file can set term-file-prefix to nil to prevent this.
2138 (with-selected-frame frame
2139 (unless (null term-file-prefix)
2140 (let* (term-init-func)
2141 ;; First, load the terminal initialization file, if it is
2142 ;; available and it hasn't been loaded already.
2143 (tty-find-type #'(lambda (type)
2144 (let ((file (locate-library (concat term-file-prefix type))))
2145 (and file
2146 (or (assoc file load-history)
2147 (load file t t)))))
2148 type)
2149 ;; Next, try to find a matching initialization function, and call it.
2150 (tty-find-type #'(lambda (type)
2151 (fboundp (setq term-init-func
2152 (intern (concat "terminal-init-" type)))))
2153 type)
2154 (when (fboundp term-init-func)
2155 (funcall term-init-func))
2156 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
2158 ;; Called from C function init_display to initialize faces of the
2159 ;; dumped terminal frame on startup.
2161 (defun tty-set-up-initial-frame-faces ()
2162 (let ((frame (selected-frame)))
2163 (frame-set-background-mode frame)
2164 (face-set-after-frame-default frame)))
2169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2170 ;;; Compatiblity with 20.2
2171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2173 ;; Update a frame's faces when we change its default font.
2175 (defalias 'frame-update-faces 'ignore "")
2176 (make-obsolete 'frame-update-faces "no longer necessary." "21.1")
2178 ;; Update the colors of FACE, after FRAME's own colors have been
2179 ;; changed.
2181 (define-obsolete-function-alias 'frame-update-face-colors
2182 'frame-set-background-mode "21.1")
2185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2186 ;;; Standard faces.
2187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2189 (defgroup basic-faces nil
2190 "The standard faces of Emacs."
2191 :group 'faces)
2193 (defface default nil
2194 "Basic default face."
2195 :group 'basic-faces)
2197 (defface bold
2198 '((t :weight bold))
2199 "Basic bold face."
2200 :group 'basic-faces)
2202 (defface italic
2203 '((((supports :slant italic))
2204 :slant italic)
2205 (((supports :underline t))
2206 :underline t)
2208 ;; default to italic, even it doesn't appear to be supported,
2209 ;; because in some cases the display engine will do it's own
2210 ;; workaround (to `dim' on ttys)
2211 :slant italic))
2212 "Basic italic face."
2213 :group 'basic-faces)
2215 (defface bold-italic
2216 '((t :weight bold :slant italic))
2217 "Basic bold-italic face."
2218 :group 'basic-faces)
2220 (defface underline
2221 '((((supports :underline t))
2222 :underline t)
2223 (((supports :weight bold))
2224 :weight bold)
2225 (t :underline t))
2226 "Basic underlined face."
2227 :group 'basic-faces)
2229 (defface fixed-pitch
2230 '((t :family "courier"))
2231 "The basic fixed-pitch face."
2232 :group 'basic-faces)
2234 (defface variable-pitch
2235 '((t :family "helv"))
2236 "The basic variable-pitch face."
2237 :group 'basic-faces)
2239 (defface shadow
2240 '((((class color grayscale) (min-colors 88) (background light))
2241 :foreground "grey50")
2242 (((class color grayscale) (min-colors 88) (background dark))
2243 :foreground "grey70")
2244 (((class color) (min-colors 8) (background light))
2245 :foreground "green")
2246 (((class color) (min-colors 8) (background dark))
2247 :foreground "yellow"))
2248 "Basic face for shadowed text."
2249 :group 'basic-faces
2250 :version "22.1")
2252 (defface link
2253 '((((class color) (min-colors 88) (background light))
2254 :foreground "blue1" :underline t)
2255 (((class color) (background light))
2256 :foreground "blue" :underline t)
2257 (((class color) (min-colors 88) (background dark))
2258 :foreground "cyan1" :underline t)
2259 (((class color) (background dark))
2260 :foreground "cyan" :underline t)
2261 (t :inherit underline))
2262 "Basic face for unvisited links."
2263 :group 'basic-faces
2264 :version "22.1")
2266 (defface link-visited
2267 '((default :inherit link)
2268 (((class color) (background light)) :foreground "magenta4")
2269 (((class color) (background dark)) :foreground "violet"))
2270 "Basic face for visited links."
2271 :group 'basic-faces
2272 :version "22.1")
2274 (defface highlight
2275 '((((class color) (min-colors 88) (background light))
2276 :background "darkseagreen2")
2277 (((class color) (min-colors 88) (background dark))
2278 :background "darkolivegreen")
2279 (((class color) (min-colors 16) (background light))
2280 :background "darkseagreen2")
2281 (((class color) (min-colors 16) (background dark))
2282 :background "darkolivegreen")
2283 (((class color) (min-colors 8))
2284 :background "green" :foreground "black")
2285 (t :inverse-video t))
2286 "Basic face for highlighting."
2287 :group 'basic-faces)
2289 (defface region
2290 '((((class color) (min-colors 88) (background dark))
2291 :background "blue3")
2292 (((class color) (min-colors 88) (background light))
2293 :background "lightgoldenrod2")
2294 (((class color) (min-colors 16) (background dark))
2295 :background "blue3")
2296 (((class color) (min-colors 16) (background light))
2297 :background "lightgoldenrod2")
2298 (((class color) (min-colors 8))
2299 :background "blue" :foreground "white")
2300 (((type tty) (class mono))
2301 :inverse-video t)
2302 (t :background "gray"))
2303 "Basic face for highlighting the region."
2304 :version "21.1"
2305 :group 'basic-faces)
2307 (defface secondary-selection
2308 '((((class color) (min-colors 88) (background light))
2309 :background "yellow1")
2310 (((class color) (min-colors 88) (background dark))
2311 :background "SkyBlue4")
2312 (((class color) (min-colors 16) (background light))
2313 :background "yellow")
2314 (((class color) (min-colors 16) (background dark))
2315 :background "SkyBlue4")
2316 (((class color) (min-colors 8))
2317 :background "cyan" :foreground "black")
2318 (t :inverse-video t))
2319 "Basic face for displaying the secondary selection."
2320 :group 'basic-faces)
2322 (defface trailing-whitespace
2323 '((((class color) (background light))
2324 :background "red1")
2325 (((class color) (background dark))
2326 :background "red1")
2327 (t :inverse-video t))
2328 "Basic face for highlighting trailing whitespace."
2329 :version "21.1"
2330 :group 'whitespace-faces ; like `show-trailing-whitespace'
2331 :group 'basic-faces)
2333 (defface escape-glyph
2334 '((((background dark)) :foreground "cyan")
2335 ;; See the comment in minibuffer-prompt for
2336 ;; the reason not to use blue on MS-DOS.
2337 (((type pc)) :foreground "magenta")
2338 ;; red4 is too dark, but some say blue is too loud.
2339 ;; brown seems to work ok. -- rms.
2340 (t :foreground "brown"))
2341 "Face for characters displayed as sequences using `^' or `\\'."
2342 :group 'basic-faces
2343 :version "22.1")
2345 (defface nobreak-space
2346 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2347 (((class color) (min-colors 8)) :background "magenta")
2348 (t :inverse-video t))
2349 "Face for displaying nobreak space."
2350 :group 'basic-faces
2351 :version "22.1")
2353 (defgroup mode-line-faces nil
2354 "Faces used in the mode line."
2355 :group 'mode-line
2356 :group 'faces
2357 :version "22.1")
2359 (defface mode-line
2360 '((((class color) (min-colors 88))
2361 :box (:line-width -1 :style released-button)
2362 :background "grey75" :foreground "black")
2364 :inverse-video t))
2365 "Basic mode line face for selected window."
2366 :version "21.1"
2367 :group 'mode-line-faces
2368 :group 'basic-faces)
2370 (defface mode-line-inactive
2371 '((default
2372 :inherit mode-line)
2373 (((class color) (min-colors 88) (background light))
2374 :weight light
2375 :box (:line-width -1 :color "grey75" :style nil)
2376 :foreground "grey20" :background "grey90")
2377 (((class color) (min-colors 88) (background dark) )
2378 :weight light
2379 :box (:line-width -1 :color "grey40" :style nil)
2380 :foreground "grey80" :background "grey30"))
2381 "Basic mode line face for non-selected windows."
2382 :version "22.1"
2383 :group 'mode-line-faces
2384 :group 'basic-faces)
2386 (defface mode-line-highlight
2387 '((((class color) (min-colors 88))
2388 :box (:line-width 2 :color "grey40" :style released-button))
2390 :inherit highlight))
2391 "Basic mode line face for highlighting."
2392 :version "22.1"
2393 :group 'mode-line-faces
2394 :group 'basic-faces)
2396 (defface mode-line-emphasis
2397 '((t (:weight bold)))
2398 "Face used to emphasize certain mode line features.
2399 Use the face `mode-line-highlight' for features that can be selected."
2400 :version "23.1"
2401 :group 'mode-line-faces
2402 :group 'basic-faces)
2404 (defface mode-line-buffer-id
2405 '((t (:weight bold)))
2406 "Face used for buffer identification parts of the mode line."
2407 :version "22.1"
2408 :group 'mode-line-faces
2409 :group 'basic-faces)
2411 ;; Make `modeline' an alias for `mode-line', for compatibility.
2412 (put 'modeline 'face-alias 'mode-line)
2413 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
2414 (put 'modeline-highlight 'face-alias 'mode-line-highlight)
2415 (put 'modeline-buffer-id 'face-alias 'mode-line-buffer-id)
2417 (defface header-line
2418 '((default
2419 :inherit mode-line)
2420 (((type tty))
2421 ;; This used to be `:inverse-video t', but that doesn't look very
2422 ;; good when combined with inverse-video mode-lines and multiple
2423 ;; windows. Underlining looks better, and is more consistent with
2424 ;; the window-system face variants, which deemphasize the
2425 ;; header-line in relation to the mode-line face. If a terminal
2426 ;; can't underline, then the header-line will end up without any
2427 ;; highlighting; this may be too confusing in general, although it
2428 ;; happens to look good with the only current use of header-lines,
2429 ;; the info browser. XXX
2430 :inverse-video nil ;Override the value inherited from mode-line.
2431 :underline t)
2432 (((class color grayscale) (background light))
2433 :background "grey90" :foreground "grey20"
2434 :box nil)
2435 (((class color grayscale) (background dark))
2436 :background "grey20" :foreground "grey90"
2437 :box nil)
2438 (((class mono) (background light))
2439 :background "white" :foreground "black"
2440 :inverse-video nil
2441 :box nil
2442 :underline t)
2443 (((class mono) (background dark))
2444 :background "black" :foreground "white"
2445 :inverse-video nil
2446 :box nil
2447 :underline t))
2448 "Basic header-line face."
2449 :version "21.1"
2450 :group 'basic-faces)
2452 (defface vertical-border
2453 '((((type tty)) :inherit mode-line-inactive))
2454 "Face used for vertical window dividers on ttys."
2455 :version "22.1"
2456 :group 'basic-faces)
2458 (defface minibuffer-prompt
2459 '((((background dark)) :foreground "cyan")
2460 ;; Don't use blue because many users of the MS-DOS port customize
2461 ;; their foreground color to be blue.
2462 (((type pc)) :foreground "magenta")
2463 (t :foreground "medium blue"))
2464 "Face for minibuffer prompts.
2465 By default, Emacs automatically adds this face to the value of
2466 `minibuffer-prompt-properties', which is a list of text properties
2467 used to display the prompt text."
2468 :version "22.1"
2469 :group 'basic-faces)
2471 (setq minibuffer-prompt-properties
2472 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2474 (defface fringe
2475 '((((class color) (background light))
2476 :background "grey95")
2477 (((class color) (background dark))
2478 :background "grey10")
2480 :background "gray"))
2481 "Basic face for the fringes to the left and right of windows under X."
2482 :version "21.1"
2483 :group 'frames
2484 :group 'basic-faces)
2486 (defface scroll-bar '((t nil))
2487 "Basic face for the scroll bar colors under X."
2488 :version "21.1"
2489 :group 'frames
2490 :group 'basic-faces)
2492 (defface border '((t nil))
2493 "Basic face for the frame border under X."
2494 :version "21.1"
2495 :group 'frames
2496 :group 'basic-faces)
2498 (defface cursor '((t nil))
2499 "Basic face for the cursor color under X.
2500 Note: Other faces cannot inherit from the cursor face."
2501 :version "21.1"
2502 :group 'cursor
2503 :group 'basic-faces)
2505 (put 'cursor 'face-no-inherit t)
2507 (defface mouse '((t nil))
2508 "Basic face for the mouse color under X."
2509 :version "21.1"
2510 :group 'mouse
2511 :group 'basic-faces)
2513 (defface tool-bar
2514 '((default
2515 :box (:line-width 1 :style released-button)
2516 :foreground "black")
2517 (((type x w32 mac) (class color))
2518 :background "grey75")
2519 (((type x) (class mono))
2520 :background "grey"))
2521 "Basic tool-bar face."
2522 :version "21.1"
2523 :group 'basic-faces)
2525 (defface menu
2526 '((((type tty))
2527 :inverse-video t)
2528 (((type x-toolkit))
2531 :inverse-video t))
2532 "Basic face for the font and colors of the menu bar and popup menus."
2533 :version "21.1"
2534 :group 'menu
2535 :group 'basic-faces)
2538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2539 ;;; Manipulating font names.
2540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2542 ;; This is here for compatibilty with Emacs 20.2. For example,
2543 ;; international/fontset.el uses x-resolve-font-name. The following
2544 ;; functions are not used in the face implementation itself.
2546 (defvar x-font-regexp nil)
2547 (defvar x-font-regexp-head nil)
2548 (defvar x-font-regexp-weight nil)
2549 (defvar x-font-regexp-slant nil)
2551 (defconst x-font-regexp-weight-subnum 1)
2552 (defconst x-font-regexp-slant-subnum 2)
2553 (defconst x-font-regexp-swidth-subnum 3)
2554 (defconst x-font-regexp-adstyle-subnum 4)
2556 ;;; Regexps matching font names in "Host Portable Character Representation."
2558 (let ((- "[-?]")
2559 (foundry "[^-]+")
2560 (family "[^-]+")
2561 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2562 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2563 (weight\? "\\([^-]*\\)") ; 1
2564 (slant "\\([ior]\\)") ; 2
2565 ; (slant\? "\\([ior?*]?\\)") ; 2
2566 (slant\? "\\([^-]?\\)") ; 2
2567 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2568 (swidth "\\([^-]*\\)") ; 3
2569 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2570 (adstyle "\\([^-]*\\)") ; 4
2571 (pixelsize "[0-9]+")
2572 (pointsize "[0-9][0-9]+")
2573 (resx "[0-9][0-9]+")
2574 (resy "[0-9][0-9]+")
2575 (spacing "[cmp?*]")
2576 (avgwidth "[0-9]+")
2577 (registry "[^-]+")
2578 (encoding "[^-]+")
2580 (setq x-font-regexp
2581 (concat "\\`\\*?[-?*]"
2582 foundry - family - weight\? - slant\? - swidth - adstyle -
2583 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2584 registry - encoding "\\*?\\'"
2586 (setq x-font-regexp-head
2587 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2588 "\\([-*?]\\|\\'\\)"))
2589 (setq x-font-regexp-slant (concat - slant -))
2590 (setq x-font-regexp-weight (concat - weight -))
2591 nil)
2594 (defun x-resolve-font-name (pattern &optional face frame)
2595 "Return a font name matching PATTERN.
2596 All wildcards in PATTERN are instantiated.
2597 If PATTERN is nil, return the name of the frame's base font, which never
2598 contains wildcards.
2599 Given optional arguments FACE and FRAME, return a font which is
2600 also the same size as FACE on FRAME, or fail."
2601 (or (symbolp face)
2602 (setq face (face-name face)))
2603 (and (eq frame t)
2604 (setq frame nil))
2605 (if pattern
2606 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2607 (let ((fonts (x-list-fonts pattern face frame 1)))
2608 (or fonts
2609 (if face
2610 (if (string-match "\\*" pattern)
2611 (if (null (face-font face))
2612 (error "No matching fonts are the same height as the frame default font")
2613 (error "No matching fonts are the same height as face `%s'" face))
2614 (if (null (face-font face))
2615 (error "Height of font `%s' doesn't match the frame default font"
2616 pattern)
2617 (error "Height of font `%s' doesn't match face `%s'"
2618 pattern face)))
2619 (error "No fonts match `%s'" pattern)))
2620 (car fonts))
2621 (cdr (assq 'font (frame-parameters (selected-frame))))))
2624 (defun x-frob-font-weight (font which)
2625 (let ((case-fold-search t))
2626 (cond ((string-match x-font-regexp font)
2627 (concat (substring font 0
2628 (match-beginning x-font-regexp-weight-subnum))
2629 which
2630 (substring font (match-end x-font-regexp-weight-subnum)
2631 (match-beginning x-font-regexp-adstyle-subnum))
2632 ;; Replace the ADD_STYLE_NAME field with *
2633 ;; because the info in it may not be the same
2634 ;; for related fonts.
2636 (substring font (match-end x-font-regexp-adstyle-subnum))))
2637 ((string-match x-font-regexp-head font)
2638 (concat (substring font 0 (match-beginning 1)) which
2639 (substring font (match-end 1))))
2640 ((string-match x-font-regexp-weight font)
2641 (concat (substring font 0 (match-beginning 1)) which
2642 (substring font (match-end 1)))))))
2643 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
2645 (defun x-frob-font-slant (font which)
2646 (let ((case-fold-search t))
2647 (cond ((string-match x-font-regexp font)
2648 (concat (substring font 0
2649 (match-beginning x-font-regexp-slant-subnum))
2650 which
2651 (substring font (match-end x-font-regexp-slant-subnum)
2652 (match-beginning x-font-regexp-adstyle-subnum))
2653 ;; Replace the ADD_STYLE_NAME field with *
2654 ;; because the info in it may not be the same
2655 ;; for related fonts.
2657 (substring font (match-end x-font-regexp-adstyle-subnum))))
2658 ((string-match x-font-regexp-head font)
2659 (concat (substring font 0 (match-beginning 2)) which
2660 (substring font (match-end 2))))
2661 ((string-match x-font-regexp-slant font)
2662 (concat (substring font 0 (match-beginning 1)) which
2663 (substring font (match-end 1)))))))
2664 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
2666 ;; These aliases are here so that we don't get warnings about obsolete
2667 ;; functions from the byte compiler.
2668 (defalias 'internal-frob-font-weight 'x-frob-font-weight)
2669 (defalias 'internal-frob-font-slant 'x-frob-font-slant)
2671 (defun x-make-font-bold (font)
2672 "Given an X font specification, make a bold version of it.
2673 If that can't be done, return nil."
2674 (internal-frob-font-weight font "bold"))
2675 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
2677 (defun x-make-font-demibold (font)
2678 "Given an X font specification, make a demibold version of it.
2679 If that can't be done, return nil."
2680 (internal-frob-font-weight font "demibold"))
2681 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
2683 (defun x-make-font-unbold (font)
2684 "Given an X font specification, make a non-bold version of it.
2685 If that can't be done, return nil."
2686 (internal-frob-font-weight font "medium"))
2687 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
2689 (defun x-make-font-italic (font)
2690 "Given an X font specification, make an italic version of it.
2691 If that can't be done, return nil."
2692 (internal-frob-font-slant font "i"))
2693 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
2695 (defun x-make-font-oblique (font) ; you say tomayto...
2696 "Given an X font specification, make an oblique version of it.
2697 If that can't be done, return nil."
2698 (internal-frob-font-slant font "o"))
2699 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
2701 (defun x-make-font-unitalic (font)
2702 "Given an X font specification, make a non-italic version of it.
2703 If that can't be done, return nil."
2704 (internal-frob-font-slant font "r"))
2705 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
2707 (defun x-make-font-bold-italic (font)
2708 "Given an X font specification, make a bold and italic version of it.
2709 If that can't be done, return nil."
2710 (and (setq font (internal-frob-font-weight font "bold"))
2711 (internal-frob-font-slant font "i")))
2712 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2714 (provide 'faces)
2716 ;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
2717 ;;; faces.el ends here