*** empty log message ***
[emacs.git] / lisp / faces.el
blobe4002246148f2b3d9a3cc8c20628e0e5daef4459
1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;;; Code:
29 (eval-when-compile
30 (require 'cl)
31 ;; Warning suppression -- can't require x-win in batch:
32 (autoload 'xw-defined-colors "x-win"))
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 tries to find a best matching font for
50 those face attributes first that appear first 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")
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*")
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)))
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 ;;; Creation, copying.
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110 (defun face-list ()
111 "Return a list of all defined face names."
112 (mapcar #'car face-new-frame-defaults))
115 ;;; ### If not frame-local initialize by what X resources?
117 (defun make-face (face &optional no-init-from-resources)
118 "Define a new face with name FACE, a symbol.
119 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
120 variants of FACE from X resources. (X resources recognized are found
121 in the global variable `face-x-resources'.) If FACE is already known
122 as a face, leave it unmodified. Value is FACE."
123 (interactive "SMake face: ")
124 (unless (facep face)
125 ;; Make frame-local faces (this also makes the global one).
126 (dolist (frame (frame-list))
127 (internal-make-lisp-face face frame))
128 ;; Add the face to the face menu.
129 (when (fboundp 'facemenu-add-new-face)
130 (facemenu-add-new-face face))
131 ;; Define frame-local faces for all frames from X resources.
132 (unless no-init-from-resources
133 (make-face-x-resource-internal face)))
134 face)
137 (defun make-empty-face (face)
138 "Define a new, empty face with name FACE.
139 If the face already exists, it is left unmodified. Value is FACE."
140 (interactive "SMake empty face: ")
141 (make-face face 'no-init-from-resources))
144 (defun copy-face (old-face new-face &optional frame new-frame)
145 "Define a face just like OLD-FACE, with name NEW-FACE.
147 If NEW-FACE already exists as a face, it is modified to be like
148 OLD-FACE. If it doesn't already exist, it is created.
150 If the optional argument FRAME is given as a frame, NEW-FACE is
151 changed on FRAME only.
152 If FRAME is t, the frame-independent default specification for OLD-FACE
153 is copied to NEW-FACE.
154 If FRAME is nil, copying is done for the frame-independent defaults
155 and for each existing frame.
157 If the optional fourth argument NEW-FRAME is given,
158 copy the information from face OLD-FACE on frame FRAME
159 to NEW-FACE on frame NEW-FRAME."
160 (let ((inhibit-quit t))
161 (if (null frame)
162 (progn
163 (dolist (frame (frame-list))
164 (copy-face old-face new-face frame))
165 (copy-face old-face new-face t))
166 (internal-copy-lisp-face old-face new-face frame new-frame))
167 new-face))
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 ;;; Obsolete functions
173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175 ;; The functions in this section are defined because Lisp packages use
176 ;; them, despite the prefix `internal-' suggesting that they are
177 ;; private to the face implementation.
179 (defun internal-find-face (name &optional frame)
180 "Retrieve the face named NAME.
181 Return nil if there is no such face.
182 If the optional argument FRAME is given, this gets the face NAME for
183 that frame; otherwise, it uses the selected frame.
184 If FRAME is the symbol t, then the global, non-frame face is returned.
185 If NAME is already a face, it is simply returned.
187 This function is defined for compatibility with Emacs 20.2. It
188 should not be used anymore."
189 (facep name))
190 (make-obsolete 'internal-find-face 'facep "21.1")
193 (defun internal-get-face (name &optional frame)
194 "Retrieve the face named NAME; error if there is none.
195 If the optional argument FRAME is given, this gets the face NAME for
196 that frame; otherwise, it uses the selected frame.
197 If FRAME is the symbol t, then the global, non-frame face is returned.
198 If NAME is already a face, it is simply returned.
200 This function is defined for compatibility with Emacs 20.2. It
201 should not be used anymore."
202 (or (facep name)
203 (check-face name)))
204 (make-obsolete 'internal-get-face "See `facep' and `check-face'." "21.1")
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
208 ;;; Predicates, type checks.
209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
211 (defun facep (face)
212 "Return non-nil if FACE is a face name."
213 (internal-lisp-face-p face))
216 (defun check-face (face)
217 "Signal an error if FACE doesn't name a face.
218 Value is FACE."
219 (unless (facep face)
220 (error "Not a face: %s" face))
221 face)
224 ;; The ID returned is not to be confused with the internally used IDs
225 ;; of realized faces. The ID assigned to Lisp faces is used to
226 ;; support faces in display table entries.
228 (defun face-id (face &optional frame)
229 "Return the interNal ID of face with name FACE.
230 If optional argument FRAME is nil or omitted, use the selected frame."
231 (check-face face)
232 (get face 'face))
235 (defun face-equal (face1 face2 &optional frame)
236 "Non-nil if faces FACE1 and FACE2 are equal.
237 Faces are considered equal if all their attributes are equal.
238 If the optional argument FRAME is given, report on face FACE in that frame.
239 If FRAME is t, report on the defaults for face FACE (for new frames).
240 If FRAME is omitted or nil, use the selected frame."
241 (internal-lisp-face-equal-p face1 face2 frame))
244 (defun face-differs-from-default-p (face &optional frame)
245 "Non-nil if FACE displays differently from the default face.
246 If the optional argument FRAME is given, report on face FACE in that frame.
247 If FRAME is t, report on the defaults for face FACE (for new frames).
248 If FRAME is omitted or nil, use the selected frame.
249 A face is considered to be ``the same'' as the default face if it is
250 actually specified in the same way (equal attributes) or if it is
251 fully-unspecified, and thus inherits the attributes of any face it
252 is displayed on top of."
253 (cond ((eq frame t) (setq frame nil))
254 ((null frame) (setq frame (selected-frame))))
255 (let* ((v1 (internal-lisp-face-p face frame))
256 (n (if v1 (length v1) 0))
257 (v2 (internal-lisp-face-p 'default frame))
258 (i 1))
259 (unless v1
260 (error "Not a face: %S" face))
261 (while (and (< i n)
262 (or (eq 'unspecified (aref v1 i))
263 (equal (aref v1 i) (aref v2 i))))
264 (setq i (1+ i)))
265 (< i n)))
268 (defun face-nontrivial-p (face &optional frame)
269 "True if face FACE has some non-nil attribute.
270 If the optional argument FRAME is given, report on face FACE in that frame.
271 If FRAME is t, report on the defaults for face FACE (for new frames).
272 If FRAME is omitted or nil, use the selected frame."
273 (not (internal-lisp-face-empty-p face frame)))
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278 ;;; Setting face attributes from X resources.
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
281 (defcustom face-x-resources
282 '((:family (".attributeFamily" . "Face.AttributeFamily"))
283 (:width (".attributeWidth" . "Face.AttributeWidth"))
284 (:height (".attributeHeight" . "Face.AttributeHeight"))
285 (:weight (".attributeWeight" . "Face.AttributeWeight"))
286 (:slant (".attributeSlant" . "Face.AttributeSlant"))
287 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
288 (:background (".attributeBackground" . "Face.AttributeBackground"))
289 (:overline (".attributeOverline" . "Face.AttributeOverline"))
290 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
291 (:box (".attributeBox" . "Face.AttributeBox"))
292 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
293 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
294 (:stipple
295 (".attributeStipple" . "Face.AttributeStipple")
296 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
297 (:bold (".attributeBold" . "Face.AttributeBold"))
298 (:italic (".attributeItalic" . "Face.AttributeItalic"))
299 (:font (".attributeFont" . "Face.AttributeFont"))
300 (:inherit (".attributeInherit" . "Face.AttributeInherit")))
301 "*List of X resources and classes for face attributes.
302 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
303 the name of a face attribute, and each ENTRY is a cons of the form
304 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
305 X resource class for the attribute."
306 :type '(repeat (cons symbol (repeat (cons string string))))
307 :group 'faces)
310 (defun set-face-attribute-from-resource (face attribute resource class frame)
311 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
312 Value is the attribute value specified by the resource, or nil
313 if not present. This function displays a message if the resource
314 specifies an invalid attribute."
315 (let* ((face-name (face-name face))
316 (value (internal-face-x-get-resource (concat face-name resource)
317 class frame)))
318 (when value
319 (condition-case ()
320 (internal-set-lisp-face-attribute-from-resource
321 face attribute (downcase value) frame)
322 (error
323 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
324 face-name frame attribute value))))
325 value))
328 (defun set-face-attributes-from-resources (face frame)
329 "Set attributes of FACE from X resources for FRAME."
330 (when (memq (framep frame) '(x w32 mac))
331 (dolist (definition face-x-resources)
332 (let ((attribute (car definition)))
333 (dolist (entry (cdr definition))
334 (set-face-attribute-from-resource face attribute (car entry)
335 (cdr entry) frame))))))
338 (defun make-face-x-resource-internal (face &optional frame)
339 "Fill frame-local FACE on FRAME from X resources.
340 FRAME nil or not specified means do it for all frames."
341 (if (null frame)
342 (dolist (frame (frame-list))
343 (set-face-attributes-from-resources face frame))
344 (set-face-attributes-from-resources face frame)))
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
349 ;;; Retrieving face attributes.
350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
352 (defun face-name (face)
353 "Return the name of face FACE."
354 (symbol-name (check-face face)))
357 (defun face-attribute (face attribute &optional frame inherit)
358 "Return the value of FACE's ATTRIBUTE on FRAME.
359 If the optional argument FRAME is given, report on face FACE in that frame.
360 If FRAME is t, report on the defaults for face FACE (for new frames).
361 If FRAME is omitted or nil, use the selected frame.
363 If INHERIT is nil, only attributes directly defined by FACE are considered,
364 so the return value may be `unspecified', or a relative value.
365 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
366 faces specified by its `:inherit' attribute; however the return value
367 may still be `unspecified' or relative.
368 If INHERIT is a face or a list of faces, then the result is further merged
369 with that face (or faces), until it becomes specified and absolute.
371 To ensure that the return value is always specified and absolute, use a
372 value of `default' for INHERIT; this will resolve any unspecified or
373 relative values by merging with the `default' face (which is always
374 completely specified)."
375 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
376 (when (and inherit (face-attribute-relative-p attribute value))
377 ;; VALUE is relative, so merge with inherited faces
378 (let ((inh-from (face-attribute face :inherit frame)))
379 (unless (or (null inh-from) (eq inh-from 'unspecified))
380 (setq value
381 (face-attribute-merged-with attribute value inh-from frame)))))
382 (when (and inherit
383 (not (eq inherit t))
384 (face-attribute-relative-p attribute value))
385 ;; We should merge with INHERIT as well
386 (setq value (face-attribute-merged-with attribute value inherit frame)))
387 value))
389 (defun face-attribute-merged-with (attribute value faces &optional frame)
390 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
391 FACES may be either a single face or a list of faces.
392 \[This is an internal function]"
393 (cond ((not (face-attribute-relative-p attribute value))
394 value)
395 ((null faces)
396 value)
397 ((consp faces)
398 (face-attribute-merged-with
399 attribute
400 (face-attribute-merged-with attribute value (car faces) frame)
401 (cdr faces)
402 frame))
404 (merge-face-attribute attribute
405 value
406 (face-attribute faces attribute frame t)))))
409 (defmacro face-attribute-specified-or (value &rest body)
410 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
411 (let ((temp (make-symbol "value")))
412 `(let ((,temp ,value))
413 (if (not (eq ,temp 'unspecified))
414 ,temp
415 ,@body))))
417 (defun face-foreground (face &optional frame inherit)
418 "Return the foreground color name of FACE, or nil if unspecified.
419 If the optional argument FRAME is given, report on face FACE in that frame.
420 If FRAME is t, report on the defaults for face FACE (for new frames).
421 If FRAME is omitted or nil, use the selected frame.
423 If INHERIT is nil, only a foreground color directly defined by FACE is
424 considered, so the return value may be nil.
425 If INHERIT is t, and FACE doesn't define a foreground color, then any
426 foreground color that FACE inherits through its `:inherit' attribute
427 is considered as well; however the return value may still be nil.
428 If INHERIT is a face or a list of faces, then it is used to try to
429 resolve an unspecified foreground color.
431 To ensure that a valid color is always returned, use a value of
432 `default' for INHERIT; this will resolve any unspecified values by
433 merging with the `default' face (which is always completely specified)."
434 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
435 nil))
437 (defun face-background (face &optional frame inherit)
438 "Return the background color name of FACE, or nil if unspecified.
439 If the optional argument FRAME is given, report on face FACE in that frame.
440 If FRAME is t, report on the defaults for face FACE (for new frames).
441 If FRAME is omitted or nil, use the selected frame.
443 If INHERIT is nil, only a background color directly defined by FACE is
444 considered, so the return value may be nil.
445 If INHERIT is t, and FACE doesn't define a background color, then any
446 background color that FACE inherits through its `:inherit' attribute
447 is considered as well; however the return value may still be nil.
448 If INHERIT is a face or a list of faces, then it is used to try to
449 resolve an unspecified background color.
451 To ensure that a valid color is always returned, use a value of
452 `default' for INHERIT; this will resolve any unspecified values by
453 merging with the `default' face (which is always completely specified)."
454 (face-attribute-specified-or (face-attribute face :background frame inherit)
455 nil))
457 (defun face-stipple (face &optional frame inherit)
458 "Return the stipple pixmap name of FACE, or nil if unspecified.
459 If the optional argument FRAME is given, report on face FACE in that frame.
460 If FRAME is t, report on the defaults for face FACE (for new frames).
461 If FRAME is omitted or nil, use the selected frame.
463 If INHERIT is nil, only a stipple directly defined by FACE is
464 considered, so the return value may be nil.
465 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
466 that FACE inherits through its `:inherit' attribute is considered as
467 well; however the return value may still be nil.
468 If INHERIT is a face or a list of faces, then it is used to try to
469 resolve an unspecified stipple.
471 To ensure that a valid stipple or nil is always returned, use a value of
472 `default' for INHERIT; this will resolve any unspecified values by merging
473 with the `default' face (which is always completely specified)."
474 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
475 nil))
478 (defalias 'face-background-pixmap 'face-stipple)
481 (defun face-underline-p (face &optional frame)
482 "Return non-nil if FACE is underlined.
483 If the optional argument FRAME is given, report on face FACE in that frame.
484 If FRAME is t, report on the defaults for face FACE (for new frames).
485 If FRAME is omitted or nil, use the selected frame."
486 (eq (face-attribute face :underline frame) t))
489 (defun face-inverse-video-p (face &optional frame)
490 "Return non-nil if FACE is in inverse video on FRAME.
491 If the optional argument FRAME is given, report on face FACE in that frame.
492 If FRAME is t, report on the defaults for face FACE (for new frames).
493 If FRAME is omitted or nil, use the selected frame."
494 (eq (face-attribute face :inverse-video frame) t))
497 (defun face-bold-p (face &optional frame)
498 "Return non-nil if the font of FACE is bold on FRAME.
499 If the optional argument FRAME is given, report on face FACE in that frame.
500 If FRAME is t, report on the defaults for face FACE (for new frames).
501 If FRAME is omitted or nil, use the selected frame.
502 Use `face-attribute' for finer control."
503 (let ((bold (face-attribute face :weight frame)))
504 (memq bold '(semi-bold bold extra-bold ultra-bold))))
507 (defun face-italic-p (face &optional frame)
508 "Return non-nil if the font of FACE is italic on FRAME.
509 If the optional argument FRAME is given, report on face FACE in that frame.
510 If FRAME is t, report on the defaults for face FACE (for new frames).
511 If FRAME is omitted or nil, use the selected frame.
512 Use `face-attribute' for finer control."
513 (let ((italic (face-attribute face :slant frame)))
514 (memq italic '(italic oblique))))
518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
519 ;;; Face documentation.
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
522 (defun face-documentation (face)
523 "Get the documentation string for FACE."
524 (get face 'face-documentation))
527 (defun set-face-documentation (face string)
528 "Set the documentation string for FACE to STRING."
529 ;; Perhaps the text should go in DOC.
530 (put face 'face-documentation (purecopy string)))
533 (defalias 'face-doc-string 'face-documentation)
534 (defalias 'set-face-doc-string 'set-face-documentation)
538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
539 ;; Setting face attributes.
540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
543 (defun set-face-attribute (face frame &rest args)
544 "Set attributes of FACE on FRAME from ARGS.
546 FRAME nil means change attributes on all frames. FRAME t means change
547 the default for new frames (this is done automatically each time an
548 attribute is changed on all frames).
550 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
551 face attribute name. All attributes can be set to `unspecified';
552 this fact is not further mentioned below.
554 The following attributes are recognized:
556 `:family'
558 VALUE must be a string specifying the font family, e.g. ``courier'',
559 or a fontset alias name. If a font family is specified, wild-cards `*'
560 and `?' are allowed.
562 `:width'
564 VALUE specifies the relative proportionate width of the font to use.
565 It must be one of the symbols `ultra-condensed', `extra-condensed',
566 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
567 `extra-expanded', or `ultra-expanded'.
569 `:height'
571 VALUE must be either an integer specifying the height of the font to use
572 in 1/10 pt, a floating point number specifying the amount by which to
573 scale any underlying face, or a function, which is called with the old
574 height (from the underlying face), and should return the new height.
576 `:weight'
578 VALUE specifies the weight of the font to use. It must be one of the
579 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
580 `semi-light', `light', `extra-light', `ultra-light'.
582 `:slant'
584 VALUE specifies the slant of the font to use. It must be one of the
585 symbols `italic', `oblique', `normal', `reverse-italic', or
586 `reverse-oblique'.
588 `:foreground', `:background'
590 VALUE must be a color name, a string.
592 `:underline'
594 VALUE specifies whether characters in FACE should be underlined. If
595 VALUE is t, underline with foreground color of the face. If VALUE is
596 a string, underline with that color. If VALUE is nil, explicitly
597 don't underline.
599 `:overline'
601 VALUE specifies whether characters in FACE should be overlined. If
602 VALUE is t, overline with foreground color of the face. If VALUE is a
603 string, overline with that color. If VALUE is nil, explicitly don't
604 overline.
606 `:strike-through'
608 VALUE specifies whether characters in FACE should be drawn with a line
609 striking through them. If VALUE is t, use the foreground color of the
610 face. If VALUE is a string, strike-through with that color. If VALUE
611 is nil, explicitly don't strike through.
613 `:box'
615 VALUE specifies whether characters in FACE should have a box drawn
616 around them. If VALUE is nil, explicitly don't draw boxes. If
617 VALUE is t, draw a box with lines of width 1 in the foreground color
618 of the face. If VALUE is a string, the string must be a color name,
619 and the box is drawn in that color with a line width of 1. Otherwise,
620 VALUE must be a property list of the form `(:line-width WIDTH
621 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
622 the property list, a default value will be used for the value, as
623 specified below. WIDTH specifies the width of the lines to draw; it
624 defaults to 1. If WIDTH is negative, the absolute value is the width
625 of the lines, and draw top/bottom lines inside the characters area,
626 not around it. COLOR is the name of the color to draw in, default is
627 the foreground color of the face for simple boxes, and the background
628 color of the face for 3D boxes. STYLE specifies whether a 3D box
629 should be draw. If STYLE is `released-button', draw a box looking
630 like a released 3D button. If STYLE is `pressed-button' draw a box
631 that appears like a pressed button. If STYLE is nil, the default if
632 the property list doesn't contain a style specification, draw a 2D
633 box.
635 `:inverse-video'
637 VALUE specifies whether characters in FACE should be displayed in
638 inverse video. VALUE must be one of t or nil.
640 `:stipple'
642 If VALUE is a string, it must be the name of a file of pixmap data.
643 The directories listed in the `x-bitmap-file-path' variable are
644 searched. Alternatively, VALUE may be a list of the form (WIDTH
645 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
646 is a string containing the raw bits of the bitmap. VALUE nil means
647 explicitly don't use a stipple pattern.
649 For convenience, attributes `:family', `:width', `:height', `:weight',
650 and `:slant' may also be set in one step from an X font name:
652 `:font'
654 Set font-related face attributes from VALUE. VALUE must be a valid
655 XLFD font name. If it is a font name pattern, the first matching font
656 will be used.
658 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
659 be used to specify that a bold or italic font should be used. VALUE
660 must be t or nil in that case. A value of `unspecified' is not allowed.
662 `:inherit'
664 VALUE is the name of a face from which to inherit attributes, or a list
665 of face names. Attributes from inherited faces are merged into the face
666 like an underlying face would be, with higher priority than underlying faces."
667 (let ((where (if (null frame) 0 frame)))
668 (setq args (purecopy args))
669 (while args
670 (internal-set-lisp-face-attribute face (car args)
671 (purecopy (cadr args))
672 where)
673 (setq args (cdr (cdr args))))))
676 (defun make-face-bold (face &optional frame noerror)
677 "Make the font of FACE be bold, if possible.
678 FRAME nil or not specified means change face on all frames.
679 Argument NOERROR is ignored and retained for compatibility.
680 Use `set-face-attribute' for finer control of the font weight."
681 (interactive (list (read-face-name "Make which face bold")))
682 (set-face-attribute face frame :weight 'bold))
685 (defun make-face-unbold (face &optional frame noerror)
686 "Make the font of FACE be non-bold, if possible.
687 FRAME nil or not specified means change face on all frames.
688 Argument NOERROR is ignored and retained for compatibility."
689 (interactive (list (read-face-name "Make which face non-bold")))
690 (set-face-attribute face frame :weight 'normal))
693 (defun make-face-italic (face &optional frame noerror)
694 "Make the font of FACE be italic, if possible.
695 FRAME nil or not specified means change face on all frames.
696 Argument NOERROR is ignored and retained for compatibility.
697 Use `set-face-attribute' for finer control of the font slant."
698 (interactive (list (read-face-name "Make which face italic")))
699 (set-face-attribute face frame :slant 'italic))
702 (defun make-face-unitalic (face &optional frame noerror)
703 "Make the font of FACE be non-italic, if possible.
704 FRAME nil or not specified means change face on all frames.
705 Argument NOERROR is ignored and retained for compatibility."
706 (interactive (list (read-face-name "Make which face non-italic")))
707 (set-face-attribute face frame :slant 'normal))
710 (defun make-face-bold-italic (face &optional frame noerror)
711 "Make the font of FACE be bold and italic, if possible.
712 FRAME nil or not specified means change face on all frames.
713 Argument NOERROR is ignored and retained for compatibility.
714 Use `set-face-attribute' for finer control of font weight and slant."
715 (interactive (list (read-face-name "Make which face bold-italic")))
716 (set-face-attribute face frame :weight 'bold :slant 'italic))
719 (defun set-face-font (face font &optional frame)
720 "Change font-related attributes of FACE to those of FONT (a string).
721 FRAME nil or not specified means change face on all frames.
722 This sets the attributes `:family', `:width', `:height', `:weight',
723 and `:slant'. When called interactively, prompt for the face and font."
724 (interactive (read-face-and-attribute :font))
725 (set-face-attribute face frame :font font))
728 ;; Implementation note: Emulating gray background colors with a
729 ;; stipple pattern is now part of the face realization process, and is
730 ;; done in C depending on the frame on which the face is realized.
732 (defun set-face-background (face color &optional frame)
733 "Change the background color of face FACE to COLOR (a string).
734 FRAME nil or not specified means change face on all frames.
735 When called interactively, prompt for the face and color."
736 (interactive (read-face-and-attribute :background))
737 (set-face-attribute face frame :background (or color 'unspecified)))
740 (defun set-face-foreground (face color &optional frame)
741 "Change the foreground color of face FACE to COLOR (a string).
742 FRAME nil or not specified means change face on all frames.
743 When called interactively, prompt for the face and color."
744 (interactive (read-face-and-attribute :foreground))
745 (set-face-attribute face frame :foreground (or color 'unspecified)))
748 (defun set-face-stipple (face stipple &optional frame)
749 "Change the stipple pixmap of face FACE to STIPPLE.
750 FRAME nil or not specified means change face on all frames.
751 STIPPLE should be a string, the name of a file of pixmap data.
752 The directories listed in the `x-bitmap-file-path' variable are searched.
754 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
755 where WIDTH and HEIGHT are the size in pixels,
756 and DATA is a string, containing the raw bits of the bitmap."
757 (interactive (read-face-and-attribute :stipple))
758 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
761 (defun set-face-underline (face underline &optional frame)
762 "Specify whether face FACE is underlined.
763 UNDERLINE nil means FACE explicitly doesn't underline.
764 UNDERLINE non-nil means FACE explicitly does underlining
765 with the same of the foreground color.
766 If UNDERLINE is a string, underline with the color named UNDERLINE.
767 FRAME nil or not specified means change face on all frames.
768 Use `set-face-attribute' to ``unspecify'' underlining."
769 (interactive
770 (let ((list (read-face-and-attribute :underline)))
771 (list (car list) (eq (car (cdr list)) t))))
772 (set-face-attribute face frame :underline underline))
775 (defun set-face-underline-p (face underline-p &optional frame)
776 "Specify whether face FACE is underlined.
777 UNDERLINE-P nil means FACE explicitly doesn't underline.
778 UNDERLINE-P non-nil means FACE explicitly does underlining.
779 FRAME nil or not specified means change face on all frames.
780 Use `set-face-attribute' to ``unspecify'' underlining."
781 (interactive
782 (let ((list (read-face-and-attribute :underline)))
783 (list (car list) (eq (car (cdr list)) t))))
784 (set-face-attribute face frame :underline underline-p))
787 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
788 "Specify whether face FACE is in inverse video.
789 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
790 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
791 FRAME nil or not specified means change face on all frames.
792 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
793 (interactive
794 (let ((list (read-face-and-attribute :inverse-video)))
795 (list (car list) (eq (car (cdr list)) t))))
796 (set-face-attribute face frame :inverse-video inverse-video-p))
799 (defun set-face-bold-p (face bold-p &optional frame)
800 "Specify whether face FACE is bold.
801 BOLD-P non-nil means FACE should explicitly display bold.
802 BOLD-P nil means FACE should explicitly display non-bold.
803 FRAME nil or not specified means change face on all frames.
804 Use `set-face-attribute' or `modify-face' for finer control."
805 (if (null bold-p)
806 (make-face-unbold face frame)
807 (make-face-bold face frame)))
810 (defun set-face-italic-p (face italic-p &optional frame)
811 "Specify whether face FACE is italic.
812 ITALIC-P non-nil means FACE should explicitly display italic.
813 ITALIC-P nil means FACE should explicitly display non-italic.
814 FRAME nil or not specified means change face on all frames.
815 Use `set-face-attribute' or `modify-face' for finer control."
816 (if (null italic-p)
817 (make-face-unitalic face frame)
818 (make-face-italic face frame)))
821 (defalias 'set-face-background-pixmap 'set-face-stipple)
824 (defun invert-face (face &optional frame)
825 "Swap the foreground and background colors of FACE.
826 If FRAME is omitted or nil, it means change face on all frames.
827 If FACE specifies neither foreground nor background color,
828 set its foreground and background to the background and foreground
829 of the default face. Value is FACE."
830 (interactive (list (read-face-name "Invert face")))
831 (let ((fg (face-attribute face :foreground frame))
832 (bg (face-attribute face :background frame)))
833 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
834 (set-face-attribute face frame :foreground bg :background fg)
835 (set-face-attribute face frame
836 :foreground
837 (face-attribute 'default :background frame)
838 :background
839 (face-attribute 'default :foreground frame))))
840 face)
843 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
844 ;;; Interactively modifying faces.
845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
847 (defun read-face-name (prompt &optional string-describing-default multiple)
848 "Read a face, defaulting to the face or faces on the char after point.
849 If it has a `read-face-name' property, that overrides the `face' property.
850 PROMPT describes what you will do with the face (don't end in a space).
851 STRING-DESCRIBING-DEFAULT describes what default you will use
852 if this function returns nil.
853 If MULTIPLE is non-nil, return a list of faces (possibly only one).
854 Otherwise, return a single face."
855 (let ((faceprop (or (get-char-property (point) 'read-face-name)
856 (get-char-property (point) 'face)))
857 faces)
858 ;; Make a list of the named faces that the `face' property uses.
859 (if (listp faceprop)
860 (dolist (f faceprop)
861 (if (symbolp f)
862 (push f faces)))
863 (if (symbolp faceprop)
864 (setq faces (list faceprop))))
865 ;; If there are none, try to get a face name from the buffer.
866 (if (and (null faces)
867 (memq (intern-soft (thing-at-point 'symbol)) (face-list)))
868 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
870 ;; If we only want one, and the default is more than one,
871 ;; discard the unwanted ones now.
872 (unless multiple
873 (if faces
874 (setq faces (list (car faces)))))
875 (let* ((input
876 ;; Read the input.
877 (completing-read
878 (if (or faces string-describing-default)
879 (format "%s (default %s): " prompt
880 (if faces (mapconcat 'symbol-name faces ", ")
881 string-describing-default))
882 (format "%s: " prompt))
883 obarray 'custom-facep t))
884 ;; Canonicalize the output.
885 (output
886 (if (equal input "")
887 faces
888 (if (stringp input)
889 (list (intern input))
890 input))))
891 ;; Return either a list of faces or just one face.
892 (if multiple
893 output
894 (car output)))))
897 (defun face-valid-attribute-values (attribute &optional frame)
898 "Return valid values for face attribute ATTRIBUTE.
899 The optional argument FRAME is used to determine available fonts
900 and colors. If it is nil or not specified, the selected frame is
901 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
902 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
903 an integer value."
904 (let ((valid
905 (case attribute
906 (:family
907 (if window-system
908 (mapcar #'(lambda (x) (cons (car x) (car x)))
909 (x-font-family-list))
910 ;; Only one font on TTYs.
911 (list (cons "default" "default"))))
912 ((:width :weight :slant :inverse-video)
913 (mapcar #'(lambda (x) (cons (symbol-name x) x))
914 (internal-lisp-face-attribute-values attribute)))
915 ((:underline :overline :strike-through :box)
916 (if window-system
917 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
918 (internal-lisp-face-attribute-values attribute))
919 (mapcar #'(lambda (c) (cons c c))
920 (x-defined-colors frame)))
921 (mapcar #'(lambda (x) (cons (symbol-name x) x))
922 (internal-lisp-face-attribute-values attribute))))
923 ((:foreground :background)
924 (mapcar #'(lambda (c) (cons c c))
925 (defined-colors frame)))
926 ((:height)
927 'integerp)
928 (:stipple
929 (and (memq window-system '(x w32 mac))
930 (mapcar #'list
931 (apply #'nconc
932 (mapcar (lambda (dir)
933 (and (file-readable-p dir)
934 (file-directory-p dir)
935 (directory-files dir)))
936 x-bitmap-file-path)))))
937 (:inherit
938 (cons '("none" . nil)
939 (mapcar #'(lambda (c) (cons (symbol-name c) c))
940 (face-list))))
942 (error "Internal error")))))
943 (if (and (listp valid) (not (memq attribute '(:inherit))))
944 (nconc (list (cons "unspecified" 'unspecified)) valid)
945 valid)))
948 (defvar face-attribute-name-alist
949 '((:family . "font family")
950 (:width . "character set width")
951 (:height . "height in 1/10 pt")
952 (:weight . "weight")
953 (:slant . "slant")
954 (:underline . "underline")
955 (:overline . "overline")
956 (:strike-through . "strike-through")
957 (:box . "box")
958 (:inverse-video . "inverse-video display")
959 (:foreground . "foreground color")
960 (:background . "background color")
961 (:stipple . "background stipple")
962 (:inherit . "inheritance"))
963 "An alist of descriptive names for face attributes.
964 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
965 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
966 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
969 (defun face-descriptive-attribute-name (attribute)
970 "Return a descriptive name for ATTRIBUTE."
971 (cdr (assq attribute face-attribute-name-alist)))
974 (defun face-read-string (face default name &optional completion-alist)
975 "Interactively read a face attribute string value.
976 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
977 default string to return if no new value is entered. NAME is a
978 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
979 alist of valid values, if non-nil.
981 Entering nothing accepts the default string DEFAULT.
982 Value is the new attribute value."
983 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
984 ;; each word in a string separately).
985 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
986 (let* ((completion-ignore-case t)
987 (value (completing-read
988 (if default
989 (format "%s for face `%s' (default %s): "
990 name face default)
991 (format "%s for face `%s': " name face))
992 completion-alist)))
993 (if (equal value "") default value)))
996 (defun face-read-integer (face default name)
997 "Interactively read an integer face attribute value.
998 FACE is the face whose attribute is read. DEFAULT is the default
999 value to return if no new value is entered. NAME is a descriptive
1000 name of the attribute for prompting. Value is the new attribute value."
1001 (let ((new-value
1002 (face-read-string face
1003 (format "%s" default)
1004 name
1005 (list (cons "unspecified" 'unspecified)))))
1006 (cond ((equal new-value "unspecified")
1007 'unspecified)
1008 ((member new-value '("unspecified-fg" "unspecified-bg"))
1009 new-value)
1011 (string-to-int new-value)))))
1014 (defun read-face-attribute (face attribute &optional frame)
1015 "Interactively read a new value for FACE's ATTRIBUTE.
1016 Optional argument FRAME nil or unspecified means read an attribute value
1017 of a global face. Value is the new attribute value."
1018 (let* ((old-value (face-attribute face attribute frame))
1019 (attribute-name (face-descriptive-attribute-name attribute))
1020 (valid (face-valid-attribute-values attribute frame))
1021 new-value)
1022 ;; Represent complex attribute values as strings by printing them
1023 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1024 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1025 ;; SHADOW)'.
1026 (when (and (or (eq attribute :stipple)
1027 (eq attribute :box))
1028 (or (consp old-value)
1029 (vectorp old-value)))
1030 (setq old-value (prin1-to-string old-value)))
1031 (cond ((listp valid)
1032 (let ((default
1033 (or (car (rassoc old-value valid))
1034 (format "%s" old-value))))
1035 (setq new-value
1036 (face-read-string face default attribute-name valid))
1037 (if (equal new-value default)
1038 ;; Nothing changed, so don't bother with all the stuff
1039 ;; below. In particular, this avoids a non-tty color
1040 ;; from being canonicalized for a tty when the user
1041 ;; just uses the default.
1042 (setq new-value old-value)
1043 ;; Terminal frames can support colors that don't appear
1044 ;; explicitly in VALID, using color approximation code
1045 ;; in tty-colors.el.
1046 (when (and (memq attribute '(:foreground :background))
1047 (not (memq window-system '(x w32 mac)))
1048 (not (member new-value
1049 '("unspecified"
1050 "unspecified-fg" "unspecified-bg"))))
1051 (setq new-value (car (tty-color-desc new-value frame))))
1052 (when (assoc new-value valid)
1053 (setq new-value (cdr (assoc new-value valid)))))))
1054 ((eq valid 'integerp)
1055 (setq new-value (face-read-integer face old-value attribute-name)))
1056 (t (error "Internal error")))
1057 ;; Convert stipple and box value text we read back to a list or
1058 ;; vector if it looks like one. This makes the assumption that a
1059 ;; pixmap file name won't start with an open-paren.
1060 (when (and (or (eq attribute :stipple)
1061 (eq attribute :box))
1062 (stringp new-value)
1063 (string-match "^[[(]" new-value))
1064 (setq new-value (read new-value)))
1065 new-value))
1068 (defun read-face-font (face &optional frame)
1069 "Read the name of a font for FACE on FRAME.
1070 If optional argument FRAME Is nil or omitted, use the selected frame."
1071 (let ((completion-ignore-case t))
1072 (completing-read (format "Set font attributes of face `%s' from font: " face)
1073 (mapcar 'list (x-list-fonts "*" nil frame)))))
1076 (defun read-all-face-attributes (face &optional frame)
1077 "Interactively read all attributes for FACE.
1078 If optional argument FRAME Is nil or omitted, use the selected frame.
1079 Value is a property list of attribute names and new values."
1080 (let (result)
1081 (dolist (attribute face-attribute-name-alist result)
1082 (setq result (cons (car attribute)
1083 (cons (read-face-attribute face (car attribute) frame)
1084 result))))))
1086 (defun modify-face (&optional face foreground background stipple
1087 bold-p italic-p underline-p inverse-p frame)
1088 "Modify attributes of faces interactively.
1089 If optional argument FRAME is nil or omitted, modify the face used
1090 for newly created frame, i.e. the global face.
1091 For non-interactive use, `set-face-attribute' is preferred.
1092 When called from elisp, if FACE is nil, all arguments but FRAME are ignored
1093 and the face and its settings are obtained by querying the user."
1094 (interactive)
1095 (if face
1096 (set-face-attribute face frame
1097 :foreground (or foreground 'unspecified)
1098 :background (or background 'unspecified)
1099 :stipple stipple
1100 :bold bold-p
1101 :italic italic-p
1102 :underline underline-p
1103 :inverse-video inverse-p)
1104 (setq face (read-face-name "Modify face"))
1105 (apply #'set-face-attribute face frame
1106 (read-all-face-attributes face frame))))
1108 (defun read-face-and-attribute (attribute &optional frame)
1109 "Read face name and face attribute value.
1110 ATTRIBUTE is the attribute whose new value is read.
1111 FRAME nil or unspecified means read attribute value of global face.
1112 Value is a list (FACE NEW-VALUE) where FACE is the face read
1113 \(a symbol), and NEW-VALUE is value read."
1114 (cond ((eq attribute :font)
1115 (let* ((prompt "Set font-related attributes of face")
1116 (face (read-face-name prompt))
1117 (font (read-face-font face frame)))
1118 (list face font)))
1120 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1121 (prompt (format "Set %s of face" attribute-name))
1122 (face (read-face-name prompt))
1123 (new-value (read-face-attribute face attribute frame)))
1124 (list face new-value)))))
1128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1129 ;;; Listing faces.
1130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1132 (defvar list-faces-sample-text
1133 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1134 "*Text string to display as the sample text for `list-faces-display'.")
1137 ;; The name list-faces would be more consistent, but let's avoid a
1138 ;; conflict with Lucid, which uses that name differently.
1140 (defun list-faces-display ()
1141 "List all faces, using the same sample text in each.
1142 The sample text is a string that comes from the variable
1143 `list-faces-sample-text'."
1144 (interactive)
1145 (let ((faces (sort (face-list) #'string-lessp))
1146 (face nil)
1147 (frame (selected-frame))
1148 disp-frame window face-name)
1149 (with-output-to-temp-buffer "*Faces*"
1150 (save-excursion
1151 (set-buffer standard-output)
1152 (setq truncate-lines t)
1153 (insert
1154 (substitute-command-keys
1155 (concat
1156 "Use "
1157 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1158 "\\[help-follow] on a face name to customize it\n"
1159 "or on its sample text for a description of the face.\n\n")))
1160 (setq help-xref-stack nil)
1161 (while faces
1162 (setq face (car faces))
1163 (setq faces (cdr faces))
1164 (setq face-name (symbol-name face))
1165 (insert (format "%25s " face-name))
1166 ;; Hyperlink to a customization buffer for the face. Using
1167 ;; the help xref mechanism may not be the best way.
1168 (save-excursion
1169 (save-match-data
1170 (search-backward face-name)
1171 (help-xref-button 0 'help-customize-face face)))
1172 (let ((beg (point))
1173 (line-beg (line-beginning-position)))
1174 (insert list-faces-sample-text)
1175 ;; Hyperlink to a help buffer for the face.
1176 (save-excursion
1177 (save-match-data
1178 (search-backward list-faces-sample-text)
1179 (help-xref-button 0 'help-face face)))
1180 (insert "\n")
1181 (put-text-property beg (1- (point)) 'face face)
1182 ;; Make all face commands default to the proper face
1183 ;; anywhere in the line.
1184 (put-text-property line-beg (1- (point)) 'read-face-name face)
1185 ;; If the sample text has multiple lines, line up all of them.
1186 (goto-char beg)
1187 (forward-line 1)
1188 (while (not (eobp))
1189 (insert " ")
1190 (forward-line 1))))
1191 (goto-char (point-min)))
1192 (print-help-return-message))
1193 ;; If the *Faces* buffer appears in a different frame,
1194 ;; copy all the face definitions from FRAME,
1195 ;; so that the display will reflect the frame that was selected.
1196 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1197 (setq disp-frame (if window (window-frame window)
1198 (car (frame-list))))
1199 (or (eq frame disp-frame)
1200 (let ((faces (face-list)))
1201 (while faces
1202 (copy-face (car faces) (car faces) frame disp-frame)
1203 (setq faces (cdr faces)))))))
1205 (defun describe-face (face &optional frame)
1206 "Display the properties of face FACE on FRAME.
1207 Interactevely, FACE defaults to the faces of the character after point
1208 and FRAME defaults to the selected frame.
1210 If the optional argument FRAME is given, report on face FACE in that frame.
1211 If FRAME is t, report on the defaults for face FACE (for new frames).
1212 If FRAME is omitted or nil, use the selected frame."
1213 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1214 (let* ((attrs '((:family . "Family")
1215 (:width . "Width")
1216 (:height . "Height")
1217 (:weight . "Weight")
1218 (:slant . "Slant")
1219 (:foreground . "Foreground")
1220 (:background . "Background")
1221 (:underline . "Underline")
1222 (:overline . "Overline")
1223 (:strike-through . "Strike-through")
1224 (:box . "Box")
1225 (:inverse-video . "Inverse")
1226 (:stipple . "Stipple")
1227 (:font . "Font or fontset")
1228 (:inherit . "Inherit")))
1229 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1230 attrs))))
1231 (help-setup-xref (list #'describe-face face) (interactive-p))
1232 (unless face
1233 (setq face 'default))
1234 (if (not (listp face))
1235 (setq face (list face)))
1236 (with-output-to-temp-buffer (help-buffer)
1237 (save-excursion
1238 (set-buffer standard-output)
1239 (dolist (f face)
1240 (insert "Face: " (symbol-name f))
1241 (if (not (facep f))
1242 (insert " undefined face.\n")
1243 (let ((customize-label "customize this face"))
1244 (princ (concat " (" customize-label ")\n"))
1245 (insert "Documentation: "
1246 (or (face-documentation f)
1247 "not documented as a face.")
1248 "\n\n")
1249 (with-current-buffer standard-output
1250 (save-excursion
1251 (re-search-backward
1252 (concat "\\(" customize-label "\\)") nil t)
1253 (help-xref-button 1 'help-customize-face f)))
1254 (dolist (a attrs)
1255 (let ((attr (face-attribute f (car a) frame)))
1256 (insert (make-string (- max-width (length (cdr a))) ?\ )
1257 (cdr a) ": " (format "%s" attr) "\n")))))
1258 (terpri)))
1259 (print-help-return-message))))
1262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1263 ;;; Face specifications (defface).
1264 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1266 ;; Parameter FRAME Is kept for call compatibility to with previous
1267 ;; face implementation.
1269 (defun face-attr-construct (face &optional frame)
1270 "Return a defface-style attribute list for FACE on FRAME.
1271 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1272 face attributes of FACE where ATTRIBUTE is the attribute name and
1273 VALUE is the specified value of that attribute."
1274 (let (result)
1275 (dolist (entry face-attribute-name-alist result)
1276 (let* ((attribute (car entry))
1277 (value (face-attribute face attribute)))
1278 (unless (eq value 'unspecified)
1279 (setq result (nconc (list attribute value) result)))))))
1282 (defun face-spec-set-match-display (display frame)
1283 "Non-nil if DISPLAY matches FRAME.
1284 DISPLAY is part of a spec such as can be used in `defface'.
1285 If FRAME is nil, the current FRAME is used."
1286 (let* ((conjuncts display)
1287 conjunct req options
1288 ;; t means we have succeeded against all the conjuncts in
1289 ;; DISPLAY that have been tested so far.
1290 (match t))
1291 (if (eq conjuncts t)
1292 (setq conjuncts nil))
1293 (while (and conjuncts match)
1294 (setq conjunct (car conjuncts)
1295 conjuncts (cdr conjuncts)
1296 req (car conjunct)
1297 options (cdr conjunct)
1298 match (cond ((eq req 'type)
1299 (or (memq window-system options)
1300 ;; FIXME: This should be revisited to use
1301 ;; display-graphic-p, provided that the
1302 ;; color selection depends on the number
1303 ;; of supported colors, and all defface's
1304 ;; are changed to look at number of colors
1305 ;; instead of (type graphic) etc.
1306 (and (null window-system)
1307 (memq 'tty options))
1308 (and (memq 'motif options)
1309 (featurep 'motif))
1310 (and (memq 'lucid options)
1311 (featurep 'x-toolkit)
1312 (not (featurep 'motif)))
1313 (and (memq 'x-toolkit options)
1314 (featurep 'x-toolkit))))
1315 ((eq req 'class)
1316 (memq (frame-parameter frame 'display-type) options))
1317 ((eq req 'background)
1318 (memq (frame-parameter frame 'background-mode)
1319 options))
1320 (t (error "Unknown req `%S' with options `%S'"
1321 req options)))))
1322 match))
1325 (defun face-spec-choose (spec &optional frame)
1326 "Choose the proper attributes for FRAME, out of SPEC.
1327 If SPEC is nil, return nil."
1328 (unless frame
1329 (setq frame (selected-frame)))
1330 (let ((tail spec)
1331 result all)
1332 (while tail
1333 (let* ((entry (pop tail))
1334 (display (car entry))
1335 (attrs (cdr entry)))
1336 (when (face-spec-set-match-display display frame)
1337 (setq result (if (null (cdr attrs)) ;; was (listp (car attrs))
1338 ;; Old-style entry, the attribute list is the
1339 ;; first element.
1340 (car attrs)
1341 attrs))
1342 (if (eq display t)
1343 (setq all result result nil)
1344 (setq tail nil)))))
1345 (if all (append result all) result)))
1348 (defun face-spec-reset-face (face &optional frame)
1349 "Reset all attributes of FACE on FRAME to unspecified."
1350 (let ((attrs face-attribute-name-alist))
1351 (while attrs
1352 (let ((attr-and-name (car attrs)))
1353 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1354 (setq attrs (cdr attrs)))))
1357 (defun face-spec-set (face spec &optional frame)
1358 "Set FACE's attributes according to the first matching entry in SPEC.
1359 FRAME is the frame whose frame-local face is set. FRAME nil means
1360 do it on all frames. See `defface' for information about SPEC.
1361 If SPEC is nil, do nothing."
1362 (let ((attrs (face-spec-choose spec frame)))
1363 (when attrs
1364 (face-spec-reset-face face frame))
1365 (while attrs
1366 (let ((attribute (car attrs))
1367 (value (car (cdr attrs))))
1368 ;; Support some old-style attribute names and values.
1369 (case attribute
1370 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1371 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1372 ((:foreground :background)
1373 ;; Compatibility with 20.x. Some bogus face specs seem to
1374 ;; exist containing things like `:foreground nil'.
1375 (if (null value) (setq value 'unspecified)))
1376 (t (unless (assq attribute face-x-resources)
1377 (setq attribute nil))))
1378 (when attribute
1379 (set-face-attribute face frame attribute value)))
1380 (setq attrs (cdr (cdr attrs))))))
1383 (defun face-attr-match-p (face attrs &optional frame)
1384 "Return t if attributes of FACE match values in plist ATTRS.
1385 Optional parameter FRAME is the frame whose definition of FACE
1386 is used. If nil or omitted, use the selected frame."
1387 (unless frame
1388 (setq frame (selected-frame)))
1389 (let ((list face-attribute-name-alist)
1390 (match t))
1391 (while (and match (not (null list)))
1392 (let* ((attr (car (car list)))
1393 (specified-value
1394 (if (plist-member attrs attr)
1395 (plist-get attrs attr)
1396 'unspecified))
1397 (value-now (face-attribute face attr frame)))
1398 (setq match (equal specified-value value-now))
1399 (setq list (cdr list))))
1400 match))
1402 (defun face-spec-match-p (face spec &optional frame)
1403 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1404 (face-attr-match-p face (face-spec-choose spec frame) frame))
1406 (defsubst face-default-spec (face)
1407 "Return the default face-spec for FACE, ignoring any user customization.
1408 If there is no default for FACE, return nil."
1409 (get face 'face-defface-spec))
1411 (defsubst face-user-default-spec (face)
1412 "Return the user's customized face-spec for FACE, or the default if none.
1413 If there is neither a user setting nor a default for FACE, return nil."
1414 (or (get face 'saved-face)
1415 (face-default-spec face)))
1418 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1419 ;;; Frame-type independent color support.
1420 ;;; We keep the old x-* names as aliases for back-compatibility.
1421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1423 (defun defined-colors (&optional frame)
1424 "Return a list of colors supported for a particular frame.
1425 The argument FRAME specifies which frame to try.
1426 The value may be different for frames on different display types.
1427 If FRAME doesn't support colors, the value is nil."
1428 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1429 (xw-defined-colors frame)
1430 (mapcar 'car (tty-color-alist frame))))
1431 (defalias 'x-defined-colors 'defined-colors)
1433 (defun color-defined-p (color &optional frame)
1434 "Return non-nil if color COLOR is supported on frame FRAME.
1435 If FRAME is omitted or nil, use the selected frame.
1436 If COLOR is the symbol `unspecified' or one of the strings
1437 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1438 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1440 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1441 (xw-color-defined-p color frame)
1442 (numberp (tty-color-translate color frame)))))
1443 (defalias 'x-color-defined-p 'color-defined-p)
1445 (defun color-values (color &optional frame)
1446 "Return a description of the color named COLOR on frame FRAME.
1447 The value is a list of integer RGB values--\(RED GREEN BLUE\).
1448 These values appear to range from 0 65535; white is \(65535 65535 65535\).
1449 If FRAME is omitted or nil, use the selected frame.
1450 If FRAME cannot display COLOR, the value is nil.
1451 If COLOR is the symbol `unspecified' or one of the strings
1452 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1453 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1455 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1456 (xw-color-values color frame)
1457 (tty-color-values color frame))))
1458 (defalias 'x-color-values 'color-values)
1460 (defun display-color-p (&optional display)
1461 "Return t if DISPLAY supports color.
1462 The optional argument DISPLAY specifies which display to ask about.
1463 DISPLAY should be either a frame or a display name (a string).
1464 If omitted or nil, that stands for the selected frame's display."
1465 (if (memq (framep-on-display display) '(x w32 mac))
1466 (xw-display-color-p display)
1467 (tty-display-color-p display)))
1468 (defalias 'x-display-color-p 'display-color-p)
1470 (defun display-grayscale-p (&optional display)
1471 "Return non-nil if frames on DISPLAY can display shades of gray."
1472 (let ((frame-type (framep-on-display display)))
1473 (cond
1474 ((memq frame-type '(x w32 mac))
1475 (x-display-grayscale-p display))
1477 (> (tty-color-gray-shades display) 2)))))
1480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1481 ;;; Background mode.
1482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1484 (defcustom frame-background-mode nil
1485 "*The brightness of the background.
1486 Set this to the symbol `dark' if your background color is dark, `light' if
1487 your background is light, or nil (default) if you want Emacs to
1488 examine the brightness for you. Don't set this variable with `setq';
1489 this won't have the expected effect."
1490 :group 'faces
1491 :set #'(lambda (var value)
1492 (set-default var value)
1493 (mapc 'frame-set-background-mode (frame-list)))
1494 :initialize 'custom-initialize-changed
1495 :type '(choice (choice-item dark)
1496 (choice-item light)
1497 (choice-item :tag "default" nil)))
1500 (defun frame-set-background-mode (frame)
1501 "Set up display-dependent faces on FRAME.
1502 Display-dependent faces are those which have different definitions
1503 according to the `background-mode' and `display-type' frame parameters."
1504 (let* ((bg-resource
1505 (and window-system
1506 (x-get-resource ".backgroundMode" "BackgroundMode")))
1507 (bg-color (frame-parameter frame 'background-color))
1508 (bg-mode
1509 (cond (frame-background-mode)
1510 (bg-resource
1511 (intern (downcase bg-resource)))
1512 ((and (null window-system) (null bg-color))
1513 ;; No way to determine this automatically (?).
1514 'dark)
1515 ;; Unspecified frame background color can only happen
1516 ;; on tty's.
1517 ((member bg-color '(unspecified "unspecified-bg"))
1518 'dark)
1519 ((equal bg-color "unspecified-fg") ; inverted colors
1520 'light)
1521 ((>= (apply '+ (x-color-values bg-color frame))
1522 ;; Just looking at the screen, colors whose
1523 ;; values add up to .6 of the white total
1524 ;; still look dark to me.
1525 (* (apply '+ (x-color-values "white" frame)) .6))
1526 'light)
1527 (t 'dark)))
1528 (display-type
1529 (cond ((null window-system)
1530 (if (tty-display-color-p frame) 'color 'mono))
1531 ((x-display-color-p frame)
1532 'color)
1533 ((x-display-grayscale-p frame)
1534 'grayscale)
1535 (t 'mono)))
1536 (old-bg-mode
1537 (frame-parameter frame 'background-mode))
1538 (old-display-type
1539 (frame-parameter frame 'display-type)))
1541 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1542 (let ((locally-modified-faces nil))
1543 ;; Before modifying the frame parameters, we collect a list of
1544 ;; faces that don't match what their face-spec says they should
1545 ;; look like; we then avoid changing these faces below. A
1546 ;; negative list is used on the assumption that most faces will
1547 ;; be unmodified, so we can avoid consing in the common case.
1548 (dolist (face (face-list))
1549 (when (not (face-spec-match-p face
1550 (face-user-default-spec face)
1551 (selected-frame)))
1552 (push face locally-modified-faces)))
1553 ;; Now change to the new frame parameters
1554 (modify-frame-parameters frame
1555 (list (cons 'background-mode bg-mode)
1556 (cons 'display-type display-type)))
1557 ;; For all named faces, choose face specs matching the new frame
1558 ;; parameters, unless they have been locally modified.
1559 (dolist (face (face-list))
1560 (unless (memq face locally-modified-faces)
1561 (face-spec-set face (face-user-default-spec face) frame)))))))
1564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1565 ;;; Frame creation.
1566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1568 (defun x-handle-named-frame-geometry (parameters)
1569 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1570 Value is the new parameter list."
1571 (let* ((name (or (cdr (assq 'name parameters))
1572 (cdr (assq 'name default-frame-alist))))
1573 (x-resource-name name)
1574 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1575 (when res-geometry
1576 (let ((parsed (x-parse-geometry res-geometry)))
1577 ;; If the resource specifies a position, call the position
1578 ;; and size "user-specified".
1579 (when (or (assq 'top parsed)
1580 (assq 'left parsed))
1581 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1582 ;; Put the geometry parameters at the end. Copy
1583 ;; default-frame-alist so that they go after it.
1584 (setq parameters (append parameters default-frame-alist parsed))))
1585 parameters))
1588 (defun x-handle-reverse-video (frame parameters)
1589 "Handle the reverse-video frame parameter and X resource.
1590 `x-create-frame' does not handle this one."
1591 (when (cdr (or (assq 'reverse parameters)
1592 (assq 'reverse default-frame-alist)
1593 (let ((resource (x-get-resource "reverseVideo"
1594 "ReverseVideo")))
1595 (if resource
1596 (cons nil (member (downcase resource)
1597 '("on" "true")))))))
1598 (let* ((params (frame-parameters frame))
1599 (bg (cdr (assq 'foreground-color params)))
1600 (fg (cdr (assq 'background-color params))))
1601 (modify-frame-parameters frame
1602 (list (cons 'foreground-color fg)
1603 (cons 'background-color bg)))
1604 (if (equal bg (cdr (assq 'border-color params)))
1605 (modify-frame-parameters frame
1606 (list (cons 'border-color fg))))
1607 (if (equal bg (cdr (assq 'mouse-color params)))
1608 (modify-frame-parameters frame
1609 (list (cons 'mouse-color fg))))
1610 (if (equal bg (cdr (assq 'cursor-color params)))
1611 (modify-frame-parameters frame
1612 (list (cons 'cursor-color fg)))))))
1615 (defun x-create-frame-with-faces (&optional parameters)
1616 "Create a frame from optional frame parameters PARAMETERS.
1617 Parameters not specified by PARAMETERS are taken from
1618 `default-frame-alist'. If PARAMETERS specify a frame name,
1619 handle X geometry resources for that name. If either PARAMETERS
1620 or `default-frame-alist' contains a `reverse' parameter, or
1621 the X resource ``reverseVideo'' is present, handle that.
1622 Value is the new frame created."
1623 (setq parameters (x-handle-named-frame-geometry parameters))
1624 (let ((visibility-spec (assq 'visibility parameters))
1625 (frame-list (frame-list))
1626 (frame (x-create-frame (cons '(visibility . nil) parameters)))
1627 success)
1628 (unwind-protect
1629 (progn
1630 (x-handle-reverse-video frame parameters)
1631 (frame-set-background-mode frame)
1632 (face-set-after-frame-default frame)
1633 (if (or (null frame-list) (null visibility-spec))
1634 (make-frame-visible frame)
1635 (modify-frame-parameters frame (list visibility-spec)))
1636 (setq success t))
1637 (unless success
1638 (delete-frame frame)))
1639 frame))
1642 (defun face-set-after-frame-default (frame)
1643 "Set frame-local faces of FRAME from face specs and resources.
1644 Initialize colors of certain faces from frame parameters."
1645 (dolist (face (face-list))
1646 (when (not (equal face 'default))
1647 (face-spec-set face (face-user-default-spec face) frame)
1648 (internal-merge-in-global-face face frame)
1649 (when (and (memq window-system '(x w32 mac))
1650 (or (not (boundp 'inhibit-default-face-x-resources))
1651 (not (eq face 'default))))
1652 (make-face-x-resource-internal face frame))))
1654 ;; Initialize attributes from frame parameters.
1655 (let ((params '((foreground-color default :foreground)
1656 (background-color default :background)
1657 (border-color border :background)
1658 (cursor-color cursor :background)
1659 (scroll-bar-foreground scroll-bar :foreground)
1660 (scroll-bar-background scroll-bar :background)
1661 (mouse-color mouse :background))))
1662 (dolist (param params)
1663 (let ((frame-param (frame-parameter frame (nth 0 param)))
1664 (face (nth 1 param))
1665 (attr (nth 2 param)))
1666 (when (and frame-param
1667 ;; Don't override face attributes explicitly
1668 ;; specified for new frames.
1669 (eq (face-attribute face attr t) 'unspecified))
1670 (set-face-attribute face frame attr frame-param))))))
1673 (defun tty-handle-reverse-video (frame parameters)
1674 "Handle the reverse-video frame parameter for terminal frames."
1675 (when (cdr (or (assq 'reverse parameters)
1676 (assq 'reverse default-frame-alist)))
1677 (let* ((params (frame-parameters frame))
1678 (bg (cdr (assq 'foreground-color params)))
1679 (fg (cdr (assq 'background-color params))))
1680 (modify-frame-parameters frame
1681 (list (cons 'foreground-color fg)
1682 (cons 'background-color bg)))
1683 (if (equal bg (cdr (assq 'mouse-color params)))
1684 (modify-frame-parameters frame
1685 (list (cons 'mouse-color fg))))
1686 (if (equal bg (cdr (assq 'cursor-color params)))
1687 (modify-frame-parameters frame
1688 (list (cons 'cursor-color fg)))))))
1691 (defun tty-create-frame-with-faces (&optional parameters)
1692 "Create a frame from optional frame parameters PARAMETERS.
1693 Parameters not specified by PARAMETERS are taken from
1694 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
1695 contains a `reverse' parameter, handle that. Value is the new frame
1696 created."
1697 (let ((frame (make-terminal-frame parameters))
1698 success)
1699 (unwind-protect
1700 (progn
1701 (tty-handle-reverse-video frame (frame-parameters frame))
1702 (frame-set-background-mode frame)
1703 (face-set-after-frame-default frame)
1704 (setq success t))
1705 (unless success
1706 (delete-frame frame)))
1707 frame))
1710 ;; Called from C function init_display to initialize faces of the
1711 ;; dumped terminal frame on startup.
1713 (defun tty-set-up-initial-frame-faces ()
1714 (let ((frame (selected-frame)))
1715 (frame-set-background-mode frame)
1716 (face-set-after-frame-default frame)))
1721 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1722 ;;; Compatiblity with 20.2
1723 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1725 ;; Update a frame's faces when we change its default font.
1727 (defalias 'frame-update-faces 'ignore)
1728 (make-obsolete 'frame-update-faces "No longer necessary" "21.1")
1730 ;; Update the colors of FACE, after FRAME's own colors have been
1731 ;; changed.
1733 (defalias 'frame-update-face-colors 'frame-set-background-mode)
1734 (make-obsolete 'frame-update-face-colors 'frame-set-background-mode "21.1")
1737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1738 ;;; Standard faces.
1739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1741 (defgroup basic-faces nil
1742 "The standard faces of Emacs."
1743 :group 'faces)
1746 (defface default
1747 '((t nil))
1748 "Basic default face."
1749 :group 'basic-faces)
1752 (defface mode-line
1753 '((((type x w32 mac) (class color))
1754 :box (:line-width -1 :style released-button)
1755 :background "grey75" :foreground "black")
1757 :inverse-video t))
1758 "Basic mode line face for selected window."
1759 :version "21.1"
1760 :group 'modeline
1761 :group 'basic-faces)
1763 (defface mode-line-inactive
1764 '((t
1765 :inherit mode-line)
1766 (((type x w32 mac) (background light) (class color))
1767 :weight light
1768 :box (:line-width -1 :color "grey75" :style nil)
1769 :foreground "grey20" :background "grey90")
1770 (((type x w32 mac) (background dark) (class color))
1771 :weight light
1772 :box (:line-width -1 :color "grey40" :style nil)
1773 :foreground "grey80" :background "grey30"))
1774 "Basic mode line face for non-selected windows."
1775 :version "21.2"
1776 :group 'modeline
1777 :group 'basic-faces)
1779 ;; Make `modeline' an alias for `mode-line', for compatibility.
1780 (put 'modeline 'face-alias 'mode-line)
1781 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
1783 (defface header-line
1784 '((t
1785 :inherit mode-line)
1786 (((type tty))
1787 ;; This used to be `:inverse-video t', but that doesn't look very
1788 ;; good when combined with inverse-video mode-lines and multiple
1789 ;; windows. Underlining looks better, and is more consistent with
1790 ;; the window-system face variants, which deemphasize the
1791 ;; header-line in relation to the mode-line face. If a terminal
1792 ;; can't underline, then the header-line will end up without any
1793 ;; highlighting; this may be too confusing in general, although it
1794 ;; happens to look good with the only current use of header-lines,
1795 ;; the info browser. XXX
1796 :underline t)
1797 (((class color grayscale) (background light))
1798 :background "grey90" :foreground "grey20"
1799 :box nil)
1800 (((class color grayscale) (background dark))
1801 :background "grey20" :foreground "grey90"
1802 :box nil)
1803 (((class mono) (background light))
1804 :background "white" :foreground "black"
1805 :inverse-video nil
1806 :box nil
1807 :underline t)
1808 (((class mono) (background dark))
1809 :background "black" :foreground "white"
1810 :inverse-video nil
1811 :box nil
1812 :underline t))
1813 "Basic header-line face."
1814 :version "21.1"
1815 :group 'basic-faces)
1818 (defface tool-bar
1819 '((((type x w32 mac) (class color))
1820 :box (:line-width 1 :style released-button)
1821 :background "grey75" :foreground "black")
1822 (((type x) (class mono))
1823 :box (:line-width 1 :style released-button)
1824 :background "grey" :foreground "black")
1826 ()))
1827 "Basic tool-bar face."
1828 :version "21.1"
1829 :group 'basic-faces)
1832 (defface minibuffer-prompt '((((background dark)) :foreground "cyan")
1833 (((type pc)) :foreground "magenta")
1834 (t :foreground "dark blue"))
1835 "Face for minibuffer prompts."
1836 :version "21.3"
1837 :group 'basic-faces)
1839 (setq minibuffer-prompt-properties
1840 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
1842 (defface region
1843 '((((type tty) (class color))
1844 :background "blue" :foreground "white")
1845 (((type tty) (class mono))
1846 :inverse-video t)
1847 (((class color) (background dark))
1848 :background "blue3")
1849 (((class color) (background light))
1850 :background "lightgoldenrod2")
1851 (t :background "gray"))
1852 "Basic face for highlighting the region."
1853 :version "21.1"
1854 :group 'basic-faces)
1857 (defface fringe
1858 '((((class color) (background light))
1859 :background "grey95")
1860 (((class color) (background dark))
1861 :background "grey10")
1863 :background "gray"))
1864 "Basic face for the fringes to the left and right of windows under X."
1865 :version "21.1"
1866 :group 'frames
1867 :group 'basic-faces)
1870 (defface scroll-bar '()
1871 "Basic face for the scroll bar colors under X."
1872 :version "21.1"
1873 :group 'frames
1874 :group 'basic-faces)
1877 (defface menu
1878 '((((type tty))
1879 :inverse-video t)
1880 (((type x-toolkit))
1883 :inverse-video t))
1884 "Basic face for the font and colors of the menu bar and popup menus."
1885 :version "21.1"
1886 :group 'menu
1887 :group 'basic-faces)
1890 (defface border '()
1891 "Basic face for the frame border under X."
1892 :version "21.1"
1893 :group 'frames
1894 :group 'basic-faces)
1897 (defface cursor '()
1898 "Basic face for the cursor color under X."
1899 :version "21.1"
1900 :group 'cursor
1901 :group 'basic-faces)
1904 (defface mouse '()
1905 "Basic face for the mouse color under X."
1906 :version "21.1"
1907 :group 'mouse
1908 :group 'basic-faces)
1911 (defface bold '((t :weight bold))
1912 "Basic bold face."
1913 :group 'basic-faces)
1916 (defface italic '((t :slant italic))
1917 "Basic italic font."
1918 :group 'basic-faces)
1921 (defface bold-italic '((t :weight bold :slant italic))
1922 "Basic bold-italic face."
1923 :group 'basic-faces)
1926 (defface underline '((t :underline t))
1927 "Basic underlined face."
1928 :group 'basic-faces)
1931 (defface highlight
1932 '((((type tty) (class color))
1933 :background "green" :foreground "black")
1934 (((class color) (background light))
1935 :background "darkseagreen2")
1936 (((class color) (background dark))
1937 :background "darkolivegreen")
1938 (t :inverse-video t))
1939 "Basic face for highlighting."
1940 :group 'basic-faces)
1943 (defface secondary-selection
1944 '((((type tty) (class color))
1945 :background "cyan" :foreground "black")
1946 (((class color) (background light))
1947 :background "yellow")
1948 (((class color) (background dark))
1949 :background "SkyBlue4")
1950 (t :inverse-video t))
1951 "Basic face for displaying the secondary selection."
1952 :group 'basic-faces)
1955 (defface fixed-pitch '((t :family "courier"))
1956 "The basic fixed-pitch face."
1957 :group 'basic-faces)
1960 (defface variable-pitch '((t :family "helv"))
1961 "The basic variable-pitch face."
1962 :group 'basic-faces)
1965 (defface trailing-whitespace
1966 '((((class color) (background light))
1967 :background "red")
1968 (((class color) (background dark))
1969 :background "red")
1970 (t :inverse-video t))
1971 "Basic face for highlighting trailing whitespace."
1972 :version "21.1"
1973 :group 'font-lock ; like `show-trailing-whitespace'
1974 :group 'basic-faces)
1978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1979 ;;; Manipulating font names.
1980 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1982 ;; This is here for compatibilty with Emacs 20.2. For example,
1983 ;; international/fontset.el uses x-resolve-font-name. The following
1984 ;; functions are not used in the face implementation itself.
1986 (defvar x-font-regexp nil)
1987 (defvar x-font-regexp-head nil)
1988 (defvar x-font-regexp-weight nil)
1989 (defvar x-font-regexp-slant nil)
1991 (defconst x-font-regexp-weight-subnum 1)
1992 (defconst x-font-regexp-slant-subnum 2)
1993 (defconst x-font-regexp-swidth-subnum 3)
1994 (defconst x-font-regexp-adstyle-subnum 4)
1996 ;;; Regexps matching font names in "Host Portable Character Representation."
1998 (let ((- "[-?]")
1999 (foundry "[^-]+")
2000 (family "[^-]+")
2001 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2002 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2003 (weight\? "\\([^-]*\\)") ; 1
2004 (slant "\\([ior]\\)") ; 2
2005 ; (slant\? "\\([ior?*]?\\)") ; 2
2006 (slant\? "\\([^-]?\\)") ; 2
2007 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2008 (swidth "\\([^-]*\\)") ; 3
2009 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2010 (adstyle "\\([^-]*\\)") ; 4
2011 (pixelsize "[0-9]+")
2012 (pointsize "[0-9][0-9]+")
2013 (resx "[0-9][0-9]+")
2014 (resy "[0-9][0-9]+")
2015 (spacing "[cmp?*]")
2016 (avgwidth "[0-9]+")
2017 (registry "[^-]+")
2018 (encoding "[^-]+")
2020 (setq x-font-regexp
2021 (concat "\\`\\*?[-?*]"
2022 foundry - family - weight\? - slant\? - swidth - adstyle -
2023 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2024 registry - encoding "\\*?\\'"
2026 (setq x-font-regexp-head
2027 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2028 "\\([-*?]\\|\\'\\)"))
2029 (setq x-font-regexp-slant (concat - slant -))
2030 (setq x-font-regexp-weight (concat - weight -))
2031 nil)
2034 (defun x-resolve-font-name (pattern &optional face frame)
2035 "Return a font name matching PATTERN.
2036 All wildcards in PATTERN are instantiated.
2037 If PATTERN is nil, return the name of the frame's base font, which never
2038 contains wildcards.
2039 Given optional arguments FACE and FRAME, return a font which is
2040 also the same size as FACE on FRAME, or fail."
2041 (or (symbolp face)
2042 (setq face (face-name face)))
2043 (and (eq frame t)
2044 (setq frame nil))
2045 (if pattern
2046 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2047 (let ((fonts (x-list-fonts pattern face frame 1)))
2048 (or fonts
2049 (if face
2050 (if (string-match "\\*" pattern)
2051 (if (null (face-font face))
2052 (error "No matching fonts are the same height as the frame default font")
2053 (error "No matching fonts are the same height as face `%s'" face))
2054 (if (null (face-font face))
2055 (error "Height of font `%s' doesn't match the frame default font"
2056 pattern)
2057 (error "Height of font `%s' doesn't match face `%s'"
2058 pattern face)))
2059 (error "No fonts match `%s'" pattern)))
2060 (car fonts))
2061 (cdr (assq 'font (frame-parameters (selected-frame))))))
2064 (defun x-frob-font-weight (font which)
2065 (let ((case-fold-search t))
2066 (cond ((string-match x-font-regexp font)
2067 (concat (substring font 0
2068 (match-beginning x-font-regexp-weight-subnum))
2069 which
2070 (substring font (match-end x-font-regexp-weight-subnum)
2071 (match-beginning x-font-regexp-adstyle-subnum))
2072 ;; Replace the ADD_STYLE_NAME field with *
2073 ;; because the info in it may not be the same
2074 ;; for related fonts.
2076 (substring font (match-end x-font-regexp-adstyle-subnum))))
2077 ((string-match x-font-regexp-head font)
2078 (concat (substring font 0 (match-beginning 1)) which
2079 (substring font (match-end 1))))
2080 ((string-match x-font-regexp-weight font)
2081 (concat (substring font 0 (match-beginning 1)) which
2082 (substring font (match-end 1)))))))
2083 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
2085 (defun x-frob-font-slant (font which)
2086 (let ((case-fold-search t))
2087 (cond ((string-match x-font-regexp font)
2088 (concat (substring font 0
2089 (match-beginning x-font-regexp-slant-subnum))
2090 which
2091 (substring font (match-end x-font-regexp-slant-subnum)
2092 (match-beginning x-font-regexp-adstyle-subnum))
2093 ;; Replace the ADD_STYLE_NAME field with *
2094 ;; because the info in it may not be the same
2095 ;; for related fonts.
2097 (substring font (match-end x-font-regexp-adstyle-subnum))))
2098 ((string-match x-font-regexp-head font)
2099 (concat (substring font 0 (match-beginning 2)) which
2100 (substring font (match-end 2))))
2101 ((string-match x-font-regexp-slant font)
2102 (concat (substring font 0 (match-beginning 1)) which
2103 (substring font (match-end 1)))))))
2104 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
2106 ;; These aliases are here so that we don't get warnings about obsolete
2107 ;; functions from the byte compiler.
2108 (defalias 'internal-frob-font-weight 'x-frob-font-weight)
2109 (defalias 'internal-frob-font-slant 'x-frob-font-slant)
2111 (defun x-make-font-bold (font)
2112 "Given an X font specification, make a bold version of it.
2113 If that can't be done, return nil."
2114 (internal-frob-font-weight font "bold"))
2115 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
2117 (defun x-make-font-demibold (font)
2118 "Given an X font specification, make a demibold version of it.
2119 If that can't be done, return nil."
2120 (internal-frob-font-weight font "demibold"))
2121 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
2123 (defun x-make-font-unbold (font)
2124 "Given an X font specification, make a non-bold version of it.
2125 If that can't be done, return nil."
2126 (internal-frob-font-weight font "medium"))
2127 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
2129 (defun x-make-font-italic (font)
2130 "Given an X font specification, make an italic version of it.
2131 If that can't be done, return nil."
2132 (internal-frob-font-slant font "i"))
2133 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
2135 (defun x-make-font-oblique (font) ; you say tomayto...
2136 "Given an X font specification, make an oblique version of it.
2137 If that can't be done, return nil."
2138 (internal-frob-font-slant font "o"))
2139 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
2141 (defun x-make-font-unitalic (font)
2142 "Given an X font specification, make a non-italic version of it.
2143 If that can't be done, return nil."
2144 (internal-frob-font-slant font "r"))
2145 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
2147 (defun x-make-font-bold-italic (font)
2148 "Given an X font specification, make a bold and italic version of it.
2149 If that can't be done, return nil."
2150 (and (setq font (internal-frob-font-weight font "bold"))
2151 (internal-frob-font-slant font "i")))
2152 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2154 (provide 'faces)
2156 ;;; faces.el ends here