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