2004-06-03 Karl Fogel <kfogel@red-bean.com>
[emacs.git] / lisp / faces.el
blobcdc5607571187980e3bf13955e502ff273042919
1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992,1993,1994,1995,1996,1998,1999,2000,2001,2002,2004
4 ;; 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 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;;; Code:
30 (eval-when-compile
31 (require 'cl)
32 ;; Warning suppression -- can't require x-win in batch:
33 (autoload 'xw-defined-colors "x-win"))
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 ;;; Font selection.
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 (defgroup font-selection nil
41 "Influencing face font selection."
42 :group 'faces)
45 (defcustom face-font-selection-order
46 '(:width :height :weight :slant)
47 "*A list specifying how face font selection chooses fonts.
48 Each of the four symbols `:width', `:height', `:weight', and `:slant'
49 must appear once in the list, and the list must not contain any other
50 elements. Font selection tries to find a best matching font for
51 those face attributes first that appear first in the list. For
52 example, if `:slant' appears before `:height', font selection first
53 tries to find a font with a suitable slant, even if this results in
54 a font height that isn't optimal."
55 :tag "Font selection order"
56 :type '(list symbol symbol symbol symbol)
57 :group 'font-selection
58 :set #'(lambda (symbol value)
59 (set-default symbol value)
60 (internal-set-font-selection-order value)))
63 ;; This is defined originally in xfaces.c.
64 (defcustom face-font-family-alternatives
65 '(("courier" "fixed")
66 ("helv" "helvetica" "arial" "fixed"))
67 "*Alist of alternative font family names.
68 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
69 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
70 ALTERNATIVE2 etc."
71 :tag "Alternative font families to try"
72 :type '(repeat (repeat string))
73 :group 'font-selection
74 :set #'(lambda (symbol value)
75 (set-default symbol value)
76 (internal-set-alternative-font-family-alist value)))
79 ;; This is defined originally in xfaces.c.
80 (defcustom face-font-registry-alternatives
81 (if (eq system-type 'windows-nt)
82 '(("iso8859-1" "ms-oemlatin")
83 ("gb2312.1980" "gb2312")
84 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
85 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
86 ("muletibetan-2" "muletibetan-0"))
87 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk*")
88 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
89 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
90 ("muletibetan-2" "muletibetan-0")))
91 "*Alist of alternative font registry names.
92 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
93 If fonts of registry REGISTRY can be loaded, font selection
94 tries to find a best matching font among all fonts of registry
95 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
96 :tag "Alternative font registries to try"
97 :type '(repeat (repeat string))
98 :version "21.1"
99 :group 'font-selection
100 :set #'(lambda (symbol value)
101 (set-default symbol value)
102 (internal-set-alternative-font-registry-alist value)))
106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 ;;; Creation, copying.
108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111 (defun face-list ()
112 "Return a list of all defined face names."
113 (mapcar #'car face-new-frame-defaults))
116 ;;; ### If not frame-local initialize by what X resources?
118 (defun make-face (face &optional no-init-from-resources)
119 "Define a new face with name FACE, a symbol.
120 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
121 variants of FACE from X resources. (X resources recognized are found
122 in the global variable `face-x-resources'.) If FACE is already known
123 as a face, leave it unmodified. Value is FACE."
124 (interactive "SMake face: ")
125 (unless (facep face)
126 ;; Make frame-local faces (this also makes the global one).
127 (dolist (frame (frame-list))
128 (internal-make-lisp-face face frame))
129 ;; Add the face to the face menu.
130 (when (fboundp 'facemenu-add-new-face)
131 (facemenu-add-new-face face))
132 ;; Define frame-local faces for all frames from X resources.
133 (unless no-init-from-resources
134 (make-face-x-resource-internal face)))
135 face)
138 (defun make-empty-face (face)
139 "Define a new, empty face with name FACE.
140 If the face already exists, it is left unmodified. Value is FACE."
141 (interactive "SMake empty face: ")
142 (make-face face 'no-init-from-resources))
145 (defun copy-face (old-face new-face &optional frame new-frame)
146 "Define a face just like OLD-FACE, with name NEW-FACE.
148 If NEW-FACE already exists as a face, it is modified to be like
149 OLD-FACE. If it doesn't already exist, it is created.
151 If the optional argument FRAME is given as a frame, NEW-FACE is
152 changed on FRAME only.
153 If FRAME is t, the frame-independent default specification for OLD-FACE
154 is copied to NEW-FACE.
155 If FRAME is nil, copying is done for the frame-independent defaults
156 and for each existing frame.
158 If the optional fourth argument NEW-FRAME is given,
159 copy the information from face OLD-FACE on frame FRAME
160 to NEW-FACE on frame NEW-FRAME."
161 (let ((inhibit-quit t))
162 (if (null frame)
163 (progn
164 (dolist (frame (frame-list))
165 (copy-face old-face new-face frame))
166 (copy-face old-face new-face t))
167 (internal-copy-lisp-face old-face new-face frame new-frame))
168 new-face))
172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173 ;;; Obsolete functions
174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
176 ;; The functions in this section are defined because Lisp packages use
177 ;; them, despite the prefix `internal-' suggesting that they are
178 ;; private to the face implementation.
180 (defun internal-find-face (name &optional frame)
181 "Retrieve the face named NAME.
182 Return nil if there is no such face.
183 If the optional argument FRAME is given, this gets the face NAME for
184 that frame; otherwise, it uses the selected frame.
185 If FRAME is the symbol t, then the global, non-frame face is returned.
186 If NAME is already a face, it is simply returned.
188 This function is defined for compatibility with Emacs 20.2. It
189 should not be used anymore."
190 (facep name))
191 (make-obsolete 'internal-find-face 'facep "21.1")
194 (defun internal-get-face (name &optional frame)
195 "Retrieve the face named NAME; error if there is none.
196 If the optional argument FRAME is given, this gets the face NAME for
197 that frame; otherwise, it uses the selected frame.
198 If FRAME is the symbol t, then the global, non-frame face is returned.
199 If NAME is already a face, it is simply returned."
200 (or (facep name)
201 (check-face name)))
202 (make-obsolete 'internal-get-face "see `facep' and `check-face'." "21.1")
205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206 ;;; Predicates, type checks.
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
209 (defun facep (face)
210 "Return non-nil if FACE is a face name."
211 (internal-lisp-face-p face))
214 (defun check-face (face)
215 "Signal an error if FACE doesn't name a face.
216 Value is FACE."
217 (unless (facep face)
218 (error "Not a face: %s" face))
219 face)
222 ;; The ID returned is not to be confused with the internally used IDs
223 ;; of realized faces. The ID assigned to Lisp faces is used to
224 ;; support faces in display table entries.
226 (defun face-id (face &optional frame)
227 "Return the internal ID of face with name FACE.
228 If optional argument FRAME is nil or omitted, use the selected frame."
229 (check-face face)
230 (get face 'face))
233 (defun face-equal (face1 face2 &optional frame)
234 "Non-nil if faces FACE1 and FACE2 are equal.
235 Faces are considered equal if all their attributes are equal.
236 If the optional argument FRAME is given, report on face FACE in that frame.
237 If FRAME is t, report on the defaults for face FACE (for new frames).
238 If FRAME is omitted or nil, use the selected frame."
239 (internal-lisp-face-equal-p face1 face2 frame))
242 (defun face-differs-from-default-p (face &optional frame)
243 "Return non-nil if FACE displays differently from the default face.
244 If the optional argument FRAME is given, report on face FACE in that frame.
245 If FRAME is t, report on the defaults for face FACE (for new frames).
246 If FRAME is omitted or nil, use the selected frame."
247 (if (not (equal (face-font face frame) (face-font 'default frame)))
248 ;; The font is different from the default face's font, so clearly it
249 ;; differs. This only really works on window-systems; on ttys, the
250 ;; "font" is a constant, with attributes layered on top of it.
251 :font
252 ;; General face attribute check. On graphical displays
253 ;; `display-supports-face-attributes-p' just checks whether each
254 ;; attribute is different that the default face, so we just check to
255 ;; make sure each attribute of the merged face is not `unspecified';
256 ;; we already checked the font above, so font-related attributes are
257 ;; omitted for that reason. On a tty,
258 ;; display-supports-face-attributes-p actually does do further
259 ;; checks, and correctly deals with the display's capabilities, so
260 ;; we use it to check all attributes.
261 (let ((attrs
262 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
263 ;; Omit font-related attributes on a window-system
264 '(:foreground :foreground :background :underline :overline
265 :strike-through :box :inverse-video :stipple)
266 ;; On a tty, check all attributes
267 '(:family :width :height :weight :slant :foreground
268 :foreground :background :underline :overline
269 :strike-through :box :inverse-video :stipple)))
270 (differs nil))
271 (while (and attrs (not differs))
272 (let* ((attr (pop attrs))
273 (attr-val (face-attribute face attr frame t)))
274 (when (and
275 (not (eq attr-val 'unspecified))
276 (display-supports-face-attributes-p (list attr attr-val)
277 frame))
278 (setq differs attr))))
279 differs)))
282 (defun face-nontrivial-p (face &optional frame)
283 "True if face FACE has some non-nil attribute.
284 If the optional argument FRAME is given, report on face FACE in that frame.
285 If FRAME is t, report on the defaults for face FACE (for new frames).
286 If FRAME is omitted or nil, use the selected frame."
287 (not (internal-lisp-face-empty-p face frame)))
291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
292 ;;; Setting face attributes from X resources.
293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
295 (defcustom face-x-resources
296 '((:family (".attributeFamily" . "Face.AttributeFamily"))
297 (:width (".attributeWidth" . "Face.AttributeWidth"))
298 (:height (".attributeHeight" . "Face.AttributeHeight"))
299 (:weight (".attributeWeight" . "Face.AttributeWeight"))
300 (:slant (".attributeSlant" . "Face.AttributeSlant"))
301 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
302 (:background (".attributeBackground" . "Face.AttributeBackground"))
303 (:overline (".attributeOverline" . "Face.AttributeOverline"))
304 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
305 (:box (".attributeBox" . "Face.AttributeBox"))
306 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
307 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
308 (:stipple
309 (".attributeStipple" . "Face.AttributeStipple")
310 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
311 (:bold (".attributeBold" . "Face.AttributeBold"))
312 (:italic (".attributeItalic" . "Face.AttributeItalic"))
313 (:font (".attributeFont" . "Face.AttributeFont"))
314 (:inherit (".attributeInherit" . "Face.AttributeInherit")))
315 "*List of X resources and classes for face attributes.
316 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
317 the name of a face attribute, and each ENTRY is a cons of the form
318 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
319 X resource class for the attribute."
320 :type '(repeat (cons symbol (repeat (cons string string))))
321 :group 'faces)
324 (defun set-face-attribute-from-resource (face attribute resource class frame)
325 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
326 Value is the attribute value specified by the resource, or nil
327 if not present. This function displays a message if the resource
328 specifies an invalid attribute."
329 (let* ((face-name (face-name face))
330 (value (internal-face-x-get-resource (concat face-name resource)
331 class frame)))
332 (when value
333 (condition-case ()
334 (internal-set-lisp-face-attribute-from-resource
335 face attribute (downcase value) frame)
336 (error
337 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
338 face-name frame attribute value))))
339 value))
342 (defun set-face-attributes-from-resources (face frame)
343 "Set attributes of FACE from X resources for FRAME."
344 (when (memq (framep frame) '(x w32 mac))
345 (dolist (definition face-x-resources)
346 (let ((attribute (car definition)))
347 (dolist (entry (cdr definition))
348 (set-face-attribute-from-resource face attribute (car entry)
349 (cdr entry) frame))))))
352 (defun make-face-x-resource-internal (face &optional frame)
353 "Fill frame-local FACE on FRAME from X resources.
354 FRAME nil or not specified means do it for all frames."
355 (if (null frame)
356 (dolist (frame (frame-list))
357 (set-face-attributes-from-resources face frame))
358 (set-face-attributes-from-resources face frame)))
362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
363 ;;; Retrieving face attributes.
364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
366 (defun face-name (face)
367 "Return the name of face FACE."
368 (symbol-name (check-face face)))
371 (defun face-attribute (face attribute &optional frame inherit)
372 "Return the value of FACE's ATTRIBUTE on FRAME.
373 If the optional argument FRAME is given, report on face FACE in that frame.
374 If FRAME is t, report on the defaults for face FACE (for new frames).
375 If FRAME is omitted or nil, use the selected frame.
377 If INHERIT is nil, only attributes directly defined by FACE are considered,
378 so the return value may be `unspecified', or a relative value.
379 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
380 faces specified by its `:inherit' attribute; however the return value
381 may still be `unspecified' or relative.
382 If INHERIT is a face or a list of faces, then the result is further merged
383 with that face (or faces), until it becomes specified and absolute.
385 To ensure that the return value is always specified and absolute, use a
386 value of `default' for INHERIT; this will resolve any unspecified or
387 relative values by merging with the `default' face (which is always
388 completely specified)."
389 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
390 (when (and inherit (face-attribute-relative-p attribute value))
391 ;; VALUE is relative, so merge with inherited faces
392 (let ((inh-from (face-attribute face :inherit frame)))
393 (unless (or (null inh-from) (eq inh-from 'unspecified))
394 (setq value
395 (face-attribute-merged-with attribute value inh-from frame)))))
396 (when (and inherit
397 (not (eq inherit t))
398 (face-attribute-relative-p attribute value))
399 ;; We should merge with INHERIT as well
400 (setq value (face-attribute-merged-with attribute value inherit frame)))
401 value))
403 (defun face-attribute-merged-with (attribute value faces &optional frame)
404 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
405 FACES may be either a single face or a list of faces.
406 \[This is an internal function]"
407 (cond ((not (face-attribute-relative-p attribute value))
408 value)
409 ((null faces)
410 value)
411 ((consp faces)
412 (face-attribute-merged-with
413 attribute
414 (face-attribute-merged-with attribute value (car faces) frame)
415 (cdr faces)
416 frame))
418 (merge-face-attribute attribute
419 value
420 (face-attribute faces attribute frame t)))))
423 (defmacro face-attribute-specified-or (value &rest body)
424 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
425 (let ((temp (make-symbol "value")))
426 `(let ((,temp ,value))
427 (if (not (eq ,temp 'unspecified))
428 ,temp
429 ,@body))))
431 (defun face-foreground (face &optional frame inherit)
432 "Return the foreground color name of FACE, or nil if unspecified.
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 a foreground color directly defined by FACE is
438 considered, so the return value may be nil.
439 If INHERIT is t, and FACE doesn't define a foreground color, then any
440 foreground color that FACE inherits through its `:inherit' attribute
441 is considered as well; however the return value may still be nil.
442 If INHERIT is a face or a list of faces, then it is used to try to
443 resolve an unspecified foreground color.
445 To ensure that a valid color is always returned, use a value of
446 `default' for INHERIT; this will resolve any unspecified values by
447 merging with the `default' face (which is always completely specified)."
448 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
449 nil))
451 (defun face-background (face &optional frame inherit)
452 "Return the background color name of FACE, or nil if unspecified.
453 If the optional argument FRAME is given, report on face FACE in that frame.
454 If FRAME is t, report on the defaults for face FACE (for new frames).
455 If FRAME is omitted or nil, use the selected frame.
457 If INHERIT is nil, only a background color directly defined by FACE is
458 considered, so the return value may be nil.
459 If INHERIT is t, and FACE doesn't define a background color, then any
460 background color that FACE inherits through its `:inherit' attribute
461 is considered as well; however the return value may still be nil.
462 If INHERIT is a face or a list of faces, then it is used to try to
463 resolve an unspecified background color.
465 To ensure that a valid color is always returned, use a value of
466 `default' for INHERIT; this will resolve any unspecified values by
467 merging with the `default' face (which is always completely specified)."
468 (face-attribute-specified-or (face-attribute face :background frame inherit)
469 nil))
471 (defun face-stipple (face &optional frame inherit)
472 "Return the stipple pixmap name of FACE, or nil if unspecified.
473 If the optional argument FRAME is given, report on face FACE in that frame.
474 If FRAME is t, report on the defaults for face FACE (for new frames).
475 If FRAME is omitted or nil, use the selected frame.
477 If INHERIT is nil, only a stipple directly defined by FACE is
478 considered, so the return value may be nil.
479 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
480 that FACE inherits through its `:inherit' attribute is considered as
481 well; however the return value may still be nil.
482 If INHERIT is a face or a list of faces, then it is used to try to
483 resolve an unspecified stipple.
485 To ensure that a valid stipple or nil is always returned, use a value of
486 `default' for INHERIT; this will resolve any unspecified values by merging
487 with the `default' face (which is always completely specified)."
488 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
489 nil))
492 (defalias 'face-background-pixmap 'face-stipple)
495 (defun face-underline-p (face &optional frame)
496 "Return non-nil if FACE is underlined.
497 If the optional argument FRAME is given, report on face FACE in that frame.
498 If FRAME is t, report on the defaults for face FACE (for new frames).
499 If FRAME is omitted or nil, use the selected frame."
500 (eq (face-attribute face :underline frame) t))
503 (defun face-inverse-video-p (face &optional frame)
504 "Return non-nil if FACE is in inverse video on FRAME.
505 If the optional argument FRAME is given, report on face FACE in that frame.
506 If FRAME is t, report on the defaults for face FACE (for new frames).
507 If FRAME is omitted or nil, use the selected frame."
508 (eq (face-attribute face :inverse-video frame) t))
511 (defun face-bold-p (face &optional frame)
512 "Return non-nil if the font of FACE is bold on FRAME.
513 If the optional argument FRAME is given, report on face FACE in that frame.
514 If FRAME is t, report on the defaults for face FACE (for new frames).
515 If FRAME is omitted or nil, use the selected frame.
516 Use `face-attribute' for finer control."
517 (let ((bold (face-attribute face :weight frame)))
518 (memq bold '(semi-bold bold extra-bold ultra-bold))))
521 (defun face-italic-p (face &optional frame)
522 "Return non-nil if the font of FACE is italic on FRAME.
523 If the optional argument FRAME is given, report on face FACE in that frame.
524 If FRAME is t, report on the defaults for face FACE (for new frames).
525 If FRAME is omitted or nil, use the selected frame.
526 Use `face-attribute' for finer control."
527 (let ((italic (face-attribute face :slant frame)))
528 (memq italic '(italic oblique))))
532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
533 ;;; Face documentation.
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
536 (defun face-documentation (face)
537 "Get the documentation string for FACE."
538 (get face 'face-documentation))
541 (defun set-face-documentation (face string)
542 "Set the documentation string for FACE to STRING."
543 ;; Perhaps the text should go in DOC.
544 (put face 'face-documentation (purecopy string)))
547 (defalias 'face-doc-string 'face-documentation)
548 (defalias 'set-face-doc-string 'set-face-documentation)
552 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
553 ;; Setting face attributes.
554 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
557 (defun set-face-attribute (face frame &rest args)
558 "Set attributes of FACE on FRAME from ARGS.
560 FRAME nil means change attributes on all frames. FRAME t means change
561 the default for new frames (this is done automatically each time an
562 attribute is changed on all frames).
564 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
565 face attribute name. All attributes can be set to `unspecified';
566 this fact is not further mentioned below.
568 The following attributes are recognized:
570 `:family'
572 VALUE must be a string specifying the font family, e.g. ``courier'',
573 or a fontset alias name. If a font family is specified, wild-cards `*'
574 and `?' are allowed.
576 `:width'
578 VALUE specifies the relative proportionate width of the font to use.
579 It must be one of the symbols `ultra-condensed', `extra-condensed',
580 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
581 `extra-expanded', or `ultra-expanded'.
583 `:height'
585 VALUE must be either an integer specifying the height of the font to use
586 in 1/10 pt, a floating point number specifying the amount by which to
587 scale any underlying face, or a function, which is called with the old
588 height (from the underlying face), and should return the new height.
590 `:weight'
592 VALUE specifies the weight of the font to use. It must be one of the
593 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
594 `semi-light', `light', `extra-light', `ultra-light'.
596 `:slant'
598 VALUE specifies the slant of the font to use. It must be one of the
599 symbols `italic', `oblique', `normal', `reverse-italic', or
600 `reverse-oblique'.
602 `:foreground', `:background'
604 VALUE must be a color name, a string.
606 `:underline'
608 VALUE specifies whether characters in FACE should be underlined. If
609 VALUE is t, underline with foreground color of the face. If VALUE is
610 a string, underline with that color. If VALUE is nil, explicitly
611 don't underline.
613 `:overline'
615 VALUE specifies whether characters in FACE should be overlined. If
616 VALUE is t, overline with foreground color of the face. If VALUE is a
617 string, overline with that color. If VALUE is nil, explicitly don't
618 overline.
620 `:strike-through'
622 VALUE specifies whether characters in FACE should be drawn with a line
623 striking through them. If VALUE is t, use the foreground color of the
624 face. If VALUE is a string, strike-through with that color. If VALUE
625 is nil, explicitly don't strike through.
627 `:box'
629 VALUE specifies whether characters in FACE should have a box drawn
630 around them. If VALUE is nil, explicitly don't draw boxes. If
631 VALUE is t, draw a box with lines of width 1 in the foreground color
632 of the face. If VALUE is a string, the string must be a color name,
633 and the box is drawn in that color with a line width of 1. Otherwise,
634 VALUE must be a property list of the form `(:line-width WIDTH
635 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
636 the property list, a default value will be used for the value, as
637 specified below. WIDTH specifies the width of the lines to draw; it
638 defaults to 1. If WIDTH is negative, the absolute value is the width
639 of the lines, and draw top/bottom lines inside the characters area,
640 not around it. COLOR is the name of the color to draw in, default is
641 the foreground color of the face for simple boxes, and the background
642 color of the face for 3D boxes. STYLE specifies whether a 3D box
643 should be draw. If STYLE is `released-button', draw a box looking
644 like a released 3D button. If STYLE is `pressed-button' draw a box
645 that appears like a pressed button. If STYLE is nil, the default if
646 the property list doesn't contain a style specification, draw a 2D
647 box.
649 `:inverse-video'
651 VALUE specifies whether characters in FACE should be displayed in
652 inverse video. VALUE must be one of t or nil.
654 `:stipple'
656 If VALUE is a string, it must be the name of a file of pixmap data.
657 The directories listed in the `x-bitmap-file-path' variable are
658 searched. Alternatively, VALUE may be a list of the form (WIDTH
659 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
660 is a string containing the raw bits of the bitmap. VALUE nil means
661 explicitly don't use a stipple pattern.
663 For convenience, attributes `:family', `:width', `:height', `:weight',
664 and `:slant' may also be set in one step from an X font name:
666 `:font'
668 Set font-related face attributes from VALUE. VALUE must be a valid
669 XLFD font name. If it is a font name pattern, the first matching font
670 will be used.
672 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
673 be used to specify that a bold or italic font should be used. VALUE
674 must be t or nil in that case. A value of `unspecified' is not allowed.
676 `:inherit'
678 VALUE is the name of a face from which to inherit attributes, or a list
679 of face names. Attributes from inherited faces are merged into the face
680 like an underlying face would be, with higher priority than underlying faces."
681 (let ((where (if (null frame) 0 frame)))
682 (setq args (purecopy args))
683 ;; If we set the new-frame defaults, this face is modified outside Custom.
684 (if (memq where '(0 t))
685 (put face 'face-modified t))
686 (while args
687 (internal-set-lisp-face-attribute face (car args)
688 (purecopy (cadr args))
689 where)
690 (setq args (cdr (cdr args))))))
693 (defun make-face-bold (face &optional frame noerror)
694 "Make the font of FACE be bold, 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 weight."
698 (interactive (list (read-face-name "Make which face bold")))
699 (set-face-attribute face frame :weight 'bold))
702 (defun make-face-unbold (face &optional frame noerror)
703 "Make the font of FACE be non-bold, 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-bold")))
707 (set-face-attribute face frame :weight 'normal))
710 (defun make-face-italic (face &optional frame noerror)
711 "Make the font of FACE be 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 the font slant."
715 (interactive (list (read-face-name "Make which face italic")))
716 (set-face-attribute face frame :slant 'italic))
719 (defun make-face-unitalic (face &optional frame noerror)
720 "Make the font of FACE be non-italic, if possible.
721 FRAME nil or not specified means change face on all frames.
722 Argument NOERROR is ignored and retained for compatibility."
723 (interactive (list (read-face-name "Make which face non-italic")))
724 (set-face-attribute face frame :slant 'normal))
727 (defun make-face-bold-italic (face &optional frame noerror)
728 "Make the font of FACE be bold and italic, if possible.
729 FRAME nil or not specified means change face on all frames.
730 Argument NOERROR is ignored and retained for compatibility.
731 Use `set-face-attribute' for finer control of font weight and slant."
732 (interactive (list (read-face-name "Make which face bold-italic")))
733 (set-face-attribute face frame :weight 'bold :slant 'italic))
736 (defun set-face-font (face font &optional frame)
737 "Change font-related attributes of FACE to those of FONT (a string).
738 FRAME nil or not specified means change face on all frames.
739 This sets the attributes `:family', `:width', `:height', `:weight',
740 and `:slant'. When called interactively, prompt for the face and font."
741 (interactive (read-face-and-attribute :font))
742 (set-face-attribute face frame :font font))
745 ;; Implementation note: Emulating gray background colors with a
746 ;; stipple pattern is now part of the face realization process, and is
747 ;; done in C depending on the frame on which the face is realized.
749 (defun set-face-background (face color &optional frame)
750 "Change the background color of face FACE to COLOR (a string).
751 FRAME nil or not specified means change face on all frames.
752 When called interactively, prompt for the face and color."
753 (interactive (read-face-and-attribute :background))
754 (set-face-attribute face frame :background (or color 'unspecified)))
757 (defun set-face-foreground (face color &optional frame)
758 "Change the foreground color of face FACE to COLOR (a string).
759 FRAME nil or not specified means change face on all frames.
760 When called interactively, prompt for the face and color."
761 (interactive (read-face-and-attribute :foreground))
762 (set-face-attribute face frame :foreground (or color 'unspecified)))
765 (defun set-face-stipple (face stipple &optional frame)
766 "Change the stipple pixmap of face FACE to STIPPLE.
767 FRAME nil or not specified means change face on all frames.
768 STIPPLE should be a string, the name of a file of pixmap data.
769 The directories listed in the `x-bitmap-file-path' variable are searched.
771 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
772 where WIDTH and HEIGHT are the size in pixels,
773 and DATA is a string, containing the raw bits of the bitmap."
774 (interactive (read-face-and-attribute :stipple))
775 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
778 (defun set-face-underline (face underline &optional frame)
779 "Specify whether face FACE is underlined.
780 UNDERLINE nil means FACE explicitly doesn't underline.
781 UNDERLINE non-nil means FACE explicitly does underlining
782 with the same of the foreground color.
783 If UNDERLINE is a string, underline with the color named UNDERLINE.
784 FRAME nil or not specified means change face on all frames.
785 Use `set-face-attribute' to ``unspecify'' underlining."
786 (interactive
787 (let ((list (read-face-and-attribute :underline)))
788 (list (car list) (eq (car (cdr list)) t))))
789 (set-face-attribute face frame :underline underline))
792 (defun set-face-underline-p (face underline-p &optional frame)
793 "Specify whether face FACE is underlined.
794 UNDERLINE-P nil means FACE explicitly doesn't underline.
795 UNDERLINE-P non-nil means FACE explicitly does underlining.
796 FRAME nil or not specified means change face on all frames.
797 Use `set-face-attribute' to ``unspecify'' underlining."
798 (interactive
799 (let ((list (read-face-and-attribute :underline)))
800 (list (car list) (eq (car (cdr list)) t))))
801 (set-face-attribute face frame :underline underline-p))
804 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
805 "Specify whether face FACE is in inverse video.
806 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
807 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
808 FRAME nil or not specified means change face on all frames.
809 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
810 (interactive
811 (let ((list (read-face-and-attribute :inverse-video)))
812 (list (car list) (eq (car (cdr list)) t))))
813 (set-face-attribute face frame :inverse-video inverse-video-p))
816 (defun set-face-bold-p (face bold-p &optional frame)
817 "Specify whether face FACE is bold.
818 BOLD-P non-nil means FACE should explicitly display bold.
819 BOLD-P nil means FACE should explicitly display non-bold.
820 FRAME nil or not specified means change face on all frames.
821 Use `set-face-attribute' or `modify-face' for finer control."
822 (if (null bold-p)
823 (make-face-unbold face frame)
824 (make-face-bold face frame)))
827 (defun set-face-italic-p (face italic-p &optional frame)
828 "Specify whether face FACE is italic.
829 ITALIC-P non-nil means FACE should explicitly display italic.
830 ITALIC-P nil means FACE should explicitly display non-italic.
831 FRAME nil or not specified means change face on all frames.
832 Use `set-face-attribute' or `modify-face' for finer control."
833 (if (null italic-p)
834 (make-face-unitalic face frame)
835 (make-face-italic face frame)))
838 (defalias 'set-face-background-pixmap 'set-face-stipple)
841 (defun invert-face (face &optional frame)
842 "Swap the foreground and background colors of FACE.
843 If FRAME is omitted or nil, it means change face on all frames.
844 If FACE specifies neither foreground nor background color,
845 set its foreground and background to the background and foreground
846 of the default face. Value is FACE."
847 (interactive (list (read-face-name "Invert face")))
848 (let ((fg (face-attribute face :foreground frame))
849 (bg (face-attribute face :background frame)))
850 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
851 (set-face-attribute face frame :foreground bg :background fg)
852 (set-face-attribute face frame
853 :foreground
854 (face-attribute 'default :background frame)
855 :background
856 (face-attribute 'default :foreground frame))))
857 face)
860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
861 ;;; Interactively modifying faces.
862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
864 (defun read-face-name (prompt &optional string-describing-default multiple)
865 "Read a face, defaulting to the face or faces on the char after point.
866 If it has a `read-face-name' property, that overrides the `face' property.
867 PROMPT describes what you will do with the face (don't end in a space).
868 STRING-DESCRIBING-DEFAULT describes what default you will use
869 if this function returns nil.
870 If MULTIPLE is non-nil, return a list of faces (possibly only one).
871 Otherwise, return a single face."
872 (let ((faceprop (or (get-char-property (point) 'read-face-name)
873 (get-char-property (point) 'face)))
874 faces)
875 ;; Make a list of the named faces that the `face' property uses.
876 (if (listp faceprop)
877 (dolist (f faceprop)
878 (if (symbolp f)
879 (push f faces)))
880 (if (symbolp faceprop)
881 (setq faces (list faceprop))))
882 ;; If there are none, try to get a face name from the buffer.
883 (if (and (null faces)
884 (memq (intern-soft (thing-at-point 'symbol)) (face-list)))
885 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
887 ;; If we only want one, and the default is more than one,
888 ;; discard the unwanted ones now.
889 (unless multiple
890 (if faces
891 (setq faces (list (car faces)))))
892 (let* ((input
893 ;; Read the input.
894 (completing-read
895 (if (or faces string-describing-default)
896 (format "%s (default %s): " prompt
897 (if faces (mapconcat 'symbol-name faces ", ")
898 string-describing-default))
899 (format "%s: " prompt))
900 obarray 'custom-facep t))
901 ;; Canonicalize the output.
902 (output
903 (if (equal input "")
904 faces
905 (if (stringp input)
906 (list (intern input))
907 input))))
908 ;; Return either a list of faces or just one face.
909 (if multiple
910 output
911 (car output)))))
914 (defun face-valid-attribute-values (attribute &optional frame)
915 "Return valid values for face attribute ATTRIBUTE.
916 The optional argument FRAME is used to determine available fonts
917 and colors. If it is nil or not specified, the selected frame is
918 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
919 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
920 an integer value."
921 (let ((valid
922 (case attribute
923 (:family
924 (if window-system
925 (mapcar #'(lambda (x) (cons (car x) (car x)))
926 (x-font-family-list))
927 ;; Only one font on TTYs.
928 (list (cons "default" "default"))))
929 ((:width :weight :slant :inverse-video)
930 (mapcar #'(lambda (x) (cons (symbol-name x) x))
931 (internal-lisp-face-attribute-values attribute)))
932 ((:underline :overline :strike-through :box)
933 (if window-system
934 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
935 (internal-lisp-face-attribute-values attribute))
936 (mapcar #'(lambda (c) (cons c c))
937 (x-defined-colors frame)))
938 (mapcar #'(lambda (x) (cons (symbol-name x) x))
939 (internal-lisp-face-attribute-values attribute))))
940 ((:foreground :background)
941 (mapcar #'(lambda (c) (cons c c))
942 (defined-colors frame)))
943 ((:height)
944 'integerp)
945 (:stipple
946 (and (memq window-system '(x w32 mac))
947 (mapcar #'list
948 (apply #'nconc
949 (mapcar (lambda (dir)
950 (and (file-readable-p dir)
951 (file-directory-p dir)
952 (directory-files dir)))
953 x-bitmap-file-path)))))
954 (:inherit
955 (cons '("none" . nil)
956 (mapcar #'(lambda (c) (cons (symbol-name c) c))
957 (face-list))))
959 (error "Internal error")))))
960 (if (and (listp valid) (not (memq attribute '(:inherit))))
961 (nconc (list (cons "unspecified" 'unspecified)) valid)
962 valid)))
965 (defvar face-attribute-name-alist
966 '((:family . "font family")
967 (:width . "character set width")
968 (:height . "height in 1/10 pt")
969 (:weight . "weight")
970 (:slant . "slant")
971 (:underline . "underline")
972 (:overline . "overline")
973 (:strike-through . "strike-through")
974 (:box . "box")
975 (:inverse-video . "inverse-video display")
976 (:foreground . "foreground color")
977 (:background . "background color")
978 (:stipple . "background stipple")
979 (:inherit . "inheritance"))
980 "An alist of descriptive names for face attributes.
981 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
982 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
983 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
986 (defun face-descriptive-attribute-name (attribute)
987 "Return a descriptive name for ATTRIBUTE."
988 (cdr (assq attribute face-attribute-name-alist)))
991 (defun face-read-string (face default name &optional completion-alist)
992 "Interactively read a face attribute string value.
993 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
994 default string to return if no new value is entered. NAME is a
995 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
996 alist of valid values, if non-nil.
998 Entering nothing accepts the default string DEFAULT.
999 Value is the new attribute value."
1000 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1001 ;; each word in a string separately).
1002 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1003 (let* ((completion-ignore-case t)
1004 (value (completing-read
1005 (if default
1006 (format "%s for face `%s' (default %s): "
1007 name face default)
1008 (format "%s for face `%s': " name face))
1009 completion-alist)))
1010 (if (equal value "") default value)))
1013 (defun face-read-integer (face default name)
1014 "Interactively read an integer face attribute value.
1015 FACE is the face whose attribute is read. DEFAULT is the default
1016 value to return if no new value is entered. NAME is a descriptive
1017 name of the attribute for prompting. Value is the new attribute value."
1018 (let ((new-value
1019 (face-read-string face
1020 (format "%s" default)
1021 name
1022 (list (cons "unspecified" 'unspecified)))))
1023 (cond ((equal new-value "unspecified")
1024 'unspecified)
1025 ((member new-value '("unspecified-fg" "unspecified-bg"))
1026 new-value)
1028 (string-to-int new-value)))))
1031 (defun read-face-attribute (face attribute &optional frame)
1032 "Interactively read a new value for FACE's ATTRIBUTE.
1033 Optional argument FRAME nil or unspecified means read an attribute value
1034 of a global face. Value is the new attribute value."
1035 (let* ((old-value (face-attribute face attribute frame))
1036 (attribute-name (face-descriptive-attribute-name attribute))
1037 (valid (face-valid-attribute-values attribute frame))
1038 new-value)
1039 ;; Represent complex attribute values as strings by printing them
1040 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1041 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1042 ;; SHADOW)'.
1043 (when (and (or (eq attribute :stipple)
1044 (eq attribute :box))
1045 (or (consp old-value)
1046 (vectorp old-value)))
1047 (setq old-value (prin1-to-string old-value)))
1048 (cond ((listp valid)
1049 (let ((default
1050 (or (car (rassoc old-value valid))
1051 (format "%s" old-value))))
1052 (setq new-value
1053 (face-read-string face default attribute-name valid))
1054 (if (equal new-value default)
1055 ;; Nothing changed, so don't bother with all the stuff
1056 ;; below. In particular, this avoids a non-tty color
1057 ;; from being canonicalized for a tty when the user
1058 ;; just uses the default.
1059 (setq new-value old-value)
1060 ;; Terminal frames can support colors that don't appear
1061 ;; explicitly in VALID, using color approximation code
1062 ;; in tty-colors.el.
1063 (when (and (memq attribute '(:foreground :background))
1064 (not (memq window-system '(x w32 mac)))
1065 (not (member new-value
1066 '("unspecified"
1067 "unspecified-fg" "unspecified-bg"))))
1068 (setq new-value (car (tty-color-desc new-value frame))))
1069 (when (assoc new-value valid)
1070 (setq new-value (cdr (assoc new-value valid)))))))
1071 ((eq valid 'integerp)
1072 (setq new-value (face-read-integer face old-value attribute-name)))
1073 (t (error "Internal error")))
1074 ;; Convert stipple and box value text we read back to a list or
1075 ;; vector if it looks like one. This makes the assumption that a
1076 ;; pixmap file name won't start with an open-paren.
1077 (when (and (or (eq attribute :stipple)
1078 (eq attribute :box))
1079 (stringp new-value)
1080 (string-match "^[[(]" new-value))
1081 (setq new-value (read new-value)))
1082 new-value))
1085 (defun read-face-font (face &optional frame)
1086 "Read the name of a font for FACE on FRAME.
1087 If optional argument FRAME Is nil or omitted, use the selected frame."
1088 (let ((completion-ignore-case t))
1089 (completing-read (format "Set font attributes of face `%s' from font: " face)
1090 (x-list-fonts "*" nil frame))))
1093 (defun read-all-face-attributes (face &optional frame)
1094 "Interactively read all attributes for FACE.
1095 If optional argument FRAME Is nil or omitted, use the selected frame.
1096 Value is a property list of attribute names and new values."
1097 (let (result)
1098 (dolist (attribute face-attribute-name-alist result)
1099 (setq result (cons (car attribute)
1100 (cons (read-face-attribute face (car attribute) frame)
1101 result))))))
1103 (defun modify-face (&optional face foreground background stipple
1104 bold-p italic-p underline-p inverse-p frame)
1105 "Modify attributes of faces interactively.
1106 If optional argument FRAME is nil or omitted, modify the face used
1107 for newly created frame, i.e. the global face.
1108 For non-interactive use, `set-face-attribute' is preferred.
1109 When called from elisp, if FACE is nil, all arguments but FRAME are ignored
1110 and the face and its settings are obtained by querying the user."
1111 (interactive)
1112 (if face
1113 (set-face-attribute face frame
1114 :foreground (or foreground 'unspecified)
1115 :background (or background 'unspecified)
1116 :stipple stipple
1117 :bold bold-p
1118 :italic italic-p
1119 :underline underline-p
1120 :inverse-video inverse-p)
1121 (setq face (read-face-name "Modify face"))
1122 (apply #'set-face-attribute face frame
1123 (read-all-face-attributes face frame))))
1125 (defun read-face-and-attribute (attribute &optional frame)
1126 "Read face name and face attribute value.
1127 ATTRIBUTE is the attribute whose new value is read.
1128 FRAME nil or unspecified means read attribute value of global face.
1129 Value is a list (FACE NEW-VALUE) where FACE is the face read
1130 \(a symbol), and NEW-VALUE is value read."
1131 (cond ((eq attribute :font)
1132 (let* ((prompt "Set font-related attributes of face")
1133 (face (read-face-name prompt))
1134 (font (read-face-font face frame)))
1135 (list face font)))
1137 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1138 (prompt (format "Set %s of face" attribute-name))
1139 (face (read-face-name prompt))
1140 (new-value (read-face-attribute face attribute frame)))
1141 (list face new-value)))))
1145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1146 ;;; Listing faces.
1147 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1149 (defvar list-faces-sample-text
1150 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1151 "*Text string to display as the sample text for `list-faces-display'.")
1154 ;; The name list-faces would be more consistent, but let's avoid a
1155 ;; conflict with Lucid, which uses that name differently.
1157 (defvar help-xref-stack)
1158 (defun list-faces-display ()
1159 "List all faces, using the same sample text in each.
1160 The sample text is a string that comes from the variable
1161 `list-faces-sample-text'."
1162 (interactive)
1163 (let ((faces (sort (face-list) #'string-lessp))
1164 (face nil)
1165 (frame (selected-frame))
1166 disp-frame window face-name)
1167 (with-output-to-temp-buffer "*Faces*"
1168 (save-excursion
1169 (set-buffer standard-output)
1170 (setq truncate-lines t)
1171 (insert
1172 (substitute-command-keys
1173 (concat
1174 "Use "
1175 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1176 "\\[help-follow] on a face name to customize it\n"
1177 "or on its sample text for a description of the face.\n\n")))
1178 (setq help-xref-stack nil)
1179 (while faces
1180 (setq face (car faces))
1181 (setq faces (cdr faces))
1182 (setq face-name (symbol-name face))
1183 (insert (format "%25s " face-name))
1184 ;; Hyperlink to a customization buffer for the face. Using
1185 ;; the help xref mechanism may not be the best way.
1186 (save-excursion
1187 (save-match-data
1188 (search-backward face-name)
1189 (help-xref-button 0 'help-customize-face face)))
1190 (let ((beg (point))
1191 (line-beg (line-beginning-position)))
1192 (insert list-faces-sample-text)
1193 ;; Hyperlink to a help buffer for the face.
1194 (save-excursion
1195 (save-match-data
1196 (search-backward list-faces-sample-text)
1197 (help-xref-button 0 'help-face face)))
1198 (insert "\n")
1199 (put-text-property beg (1- (point)) 'face face)
1200 ;; Make all face commands default to the proper face
1201 ;; anywhere in the line.
1202 (put-text-property line-beg (1- (point)) 'read-face-name face)
1203 ;; If the sample text has multiple lines, line up all of them.
1204 (goto-char beg)
1205 (forward-line 1)
1206 (while (not (eobp))
1207 (insert " ")
1208 (forward-line 1))))
1209 (goto-char (point-min)))
1210 (print-help-return-message))
1211 ;; If the *Faces* buffer appears in a different frame,
1212 ;; copy all the face definitions from FRAME,
1213 ;; so that the display will reflect the frame that was selected.
1214 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1215 (setq disp-frame (if window (window-frame window)
1216 (car (frame-list))))
1217 (or (eq frame disp-frame)
1218 (let ((faces (face-list)))
1219 (while faces
1220 (copy-face (car faces) (car faces) frame disp-frame)
1221 (setq faces (cdr faces)))))))
1223 (defun describe-face (face &optional frame)
1224 "Display the properties of face FACE on FRAME.
1225 Interactively, FACE defaults to the faces of the character after point
1226 and FRAME defaults to the selected frame.
1228 If the optional argument FRAME is given, report on face FACE in that frame.
1229 If FRAME is t, report on the defaults for face FACE (for new frames).
1230 If FRAME is omitted or nil, use the selected frame."
1231 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1232 (let* ((attrs '((:family . "Family")
1233 (:width . "Width")
1234 (:height . "Height")
1235 (:weight . "Weight")
1236 (:slant . "Slant")
1237 (:foreground . "Foreground")
1238 (:background . "Background")
1239 (:underline . "Underline")
1240 (:overline . "Overline")
1241 (:strike-through . "Strike-through")
1242 (:box . "Box")
1243 (:inverse-video . "Inverse")
1244 (:stipple . "Stipple")
1245 (:font . "Font or fontset")
1246 (:inherit . "Inherit")))
1247 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1248 attrs))))
1249 (help-setup-xref (list #'describe-face face) (interactive-p))
1250 (unless face
1251 (setq face 'default))
1252 (if (not (listp face))
1253 (setq face (list face)))
1254 (with-output-to-temp-buffer (help-buffer)
1255 (save-excursion
1256 (set-buffer standard-output)
1257 (dolist (f face)
1258 (insert "Face: " (symbol-name f))
1259 (if (not (facep f))
1260 (insert " undefined face.\n")
1261 (let ((customize-label "customize this face"))
1262 (princ (concat " (" customize-label ")\n"))
1263 (insert "Documentation: "
1264 (or (face-documentation f)
1265 "Not documented as a face.")
1266 "\n\n")
1267 (with-current-buffer standard-output
1268 (save-excursion
1269 (re-search-backward
1270 (concat "\\(" customize-label "\\)") nil t)
1271 (help-xref-button 1 'help-customize-face f)))
1272 (dolist (a attrs)
1273 (let ((attr (face-attribute f (car a) frame)))
1274 (insert (make-string (- max-width (length (cdr a))) ?\ )
1275 (cdr a) ": " (format "%s" attr) "\n")))))
1276 (terpri)))
1277 (print-help-return-message))))
1280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1281 ;;; Face specifications (defface).
1282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1284 ;; Parameter FRAME Is kept for call compatibility to with previous
1285 ;; face implementation.
1287 (defun face-attr-construct (face &optional frame)
1288 "Return a defface-style attribute list for FACE on FRAME.
1289 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1290 face attributes of FACE where ATTRIBUTE is the attribute name and
1291 VALUE is the specified value of that attribute."
1292 (let (result)
1293 (dolist (entry face-attribute-name-alist result)
1294 (let* ((attribute (car entry))
1295 (value (face-attribute face attribute)))
1296 (unless (eq value 'unspecified)
1297 (setq result (nconc (list attribute value) result)))))))
1300 (defun face-spec-set-match-display (display frame)
1301 "Non-nil if DISPLAY matches FRAME.
1302 DISPLAY is part of a spec such as can be used in `defface'.
1303 If FRAME is nil, the current FRAME is used."
1304 (let* ((conjuncts display)
1305 conjunct req options
1306 ;; t means we have succeeded against all the conjuncts in
1307 ;; DISPLAY that have been tested so far.
1308 (match t))
1309 (if (eq conjuncts t)
1310 (setq conjuncts nil))
1311 (while (and conjuncts match)
1312 (setq conjunct (car conjuncts)
1313 conjuncts (cdr conjuncts)
1314 req (car conjunct)
1315 options (cdr conjunct)
1316 match (cond ((eq req 'type)
1317 (or (memq window-system options)
1318 ;; FIXME: This should be revisited to use
1319 ;; display-graphic-p, provided that the
1320 ;; color selection depends on the number
1321 ;; of supported colors, and all defface's
1322 ;; are changed to look at number of colors
1323 ;; instead of (type graphic) etc.
1324 (and (null window-system)
1325 (memq 'tty options))
1326 (and (memq 'motif options)
1327 (featurep 'motif))
1328 (and (memq 'gtk options)
1329 (featurep 'gtk))
1330 (and (memq 'lucid options)
1331 (featurep 'x-toolkit)
1332 (not (featurep 'motif))
1333 (not (featurep 'gtk)))
1334 (and (memq 'x-toolkit options)
1335 (featurep 'x-toolkit))))
1336 ((eq req 'min-colors)
1337 (>= (display-color-cells frame) (car options)))
1338 ((eq req 'class)
1339 (memq (frame-parameter frame 'display-type) options))
1340 ((eq req 'background)
1341 (memq (frame-parameter frame 'background-mode)
1342 options))
1343 ((eq req 'supports)
1344 (display-supports-face-attributes-p options frame))
1345 (t (error "Unknown req `%S' with options `%S'"
1346 req options)))))
1347 match))
1350 (defun face-spec-choose (spec &optional frame)
1351 "Choose the proper attributes for FRAME, out of SPEC.
1352 If SPEC is nil, return nil."
1353 (unless frame
1354 (setq frame (selected-frame)))
1355 (let ((tail spec)
1356 result all)
1357 (while tail
1358 (let* ((entry (pop tail))
1359 (display (car entry))
1360 (attrs (cdr entry)))
1361 (when (face-spec-set-match-display display frame)
1362 (setq result (if (null (cdr attrs)) ;; was (listp (car attrs))
1363 ;; Old-style entry, the attribute list is the
1364 ;; first element.
1365 (car attrs)
1366 attrs))
1367 (if (eq display t)
1368 (setq all result result nil)
1369 (setq tail nil)))))
1370 (if all (append result all) result)))
1373 (defun face-spec-reset-face (face &optional frame)
1374 "Reset all attributes of FACE on FRAME to unspecified."
1375 (let ((attrs face-attribute-name-alist))
1376 (while attrs
1377 (let ((attr-and-name (car attrs)))
1378 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1379 (setq attrs (cdr attrs)))))
1382 (defun face-spec-set (face spec &optional frame)
1383 "Set FACE's attributes according to the first matching entry in SPEC.
1384 FRAME is the frame whose frame-local face is set. FRAME nil means
1385 do it on all frames. See `defface' for information about SPEC.
1386 If SPEC is nil, do nothing."
1387 (let ((attrs (face-spec-choose spec frame)))
1388 (when attrs
1389 (face-spec-reset-face face frame))
1390 (while attrs
1391 (let ((attribute (car attrs))
1392 (value (car (cdr attrs))))
1393 ;; Support some old-style attribute names and values.
1394 (case attribute
1395 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1396 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1397 ((:foreground :background)
1398 ;; Compatibility with 20.x. Some bogus face specs seem to
1399 ;; exist containing things like `:foreground nil'.
1400 (if (null value) (setq value 'unspecified)))
1401 (t (unless (assq attribute face-x-resources)
1402 (setq attribute nil))))
1403 (when attribute
1404 (set-face-attribute face frame attribute value)))
1405 (setq attrs (cdr (cdr attrs)))))
1406 ;; When we reset the face based on its spec, then it is unmodified
1407 ;; as far as Custom is concerned.
1408 (if (null frame)
1409 (put face 'face-modified nil)))
1412 (defun face-attr-match-p (face attrs &optional frame)
1413 "Return t if attributes of FACE match values in plist ATTRS.
1414 Optional parameter FRAME is the frame whose definition of FACE
1415 is used. If nil or omitted, use the selected frame."
1416 (unless frame
1417 (setq frame (selected-frame)))
1418 (let ((list face-attribute-name-alist)
1419 (match t))
1420 (while (and match (not (null list)))
1421 (let* ((attr (car (car list)))
1422 (specified-value
1423 (if (plist-member attrs attr)
1424 (plist-get attrs attr)
1425 'unspecified))
1426 (value-now (face-attribute face attr frame)))
1427 (setq match (equal specified-value value-now))
1428 (setq list (cdr list))))
1429 match))
1431 (defun face-spec-match-p (face spec &optional frame)
1432 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1433 (face-attr-match-p face (face-spec-choose spec frame) frame))
1435 (defsubst face-default-spec (face)
1436 "Return the default face-spec for FACE, ignoring any user customization.
1437 If there is no default for FACE, return nil."
1438 (get face 'face-defface-spec))
1440 (defsubst face-user-default-spec (face)
1441 "Return the user's customized face-spec for FACE, or the default if none.
1442 If there is neither a user setting nor a default for FACE, return nil."
1443 (or (get face 'saved-face)
1444 (face-default-spec face)))
1447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1448 ;;; Frame-type independent color support.
1449 ;;; We keep the old x-* names as aliases for back-compatibility.
1450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1452 (defun defined-colors (&optional frame)
1453 "Return a list of colors supported for a particular frame.
1454 The argument FRAME specifies which frame to try.
1455 The value may be different for frames on different display types.
1456 If FRAME doesn't support colors, the value is nil."
1457 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1458 (xw-defined-colors frame)
1459 (mapcar 'car (tty-color-alist frame))))
1460 (defalias 'x-defined-colors 'defined-colors)
1462 (defun color-defined-p (color &optional frame)
1463 "Return non-nil if color COLOR is supported on frame FRAME.
1464 If FRAME is omitted or nil, use the selected frame.
1465 If COLOR is the symbol `unspecified' or one of the strings
1466 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1467 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1469 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1470 (xw-color-defined-p color frame)
1471 (numberp (tty-color-translate color frame)))))
1472 (defalias 'x-color-defined-p 'color-defined-p)
1474 (defun color-values (color &optional frame)
1475 "Return a description of the color named COLOR on frame FRAME.
1476 The value is a list of integer RGB values--\(RED GREEN BLUE\).
1477 These values appear to range from 0 65535; white is \(65535 65535 65535\).
1478 If FRAME is omitted or nil, use the selected frame.
1479 If FRAME cannot display COLOR, the value is nil.
1480 If COLOR is the symbol `unspecified' or one of the strings
1481 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1482 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1484 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1485 (xw-color-values color frame)
1486 (tty-color-values color frame))))
1487 (defalias 'x-color-values 'color-values)
1489 (defun display-color-p (&optional display)
1490 "Return t if DISPLAY supports color.
1491 The optional argument DISPLAY specifies which display to ask about.
1492 DISPLAY should be either a frame or a display name (a string).
1493 If omitted or nil, that stands for the selected frame's display."
1494 (if (memq (framep-on-display display) '(x w32 mac))
1495 (xw-display-color-p display)
1496 (tty-display-color-p display)))
1497 (defalias 'x-display-color-p 'display-color-p)
1499 (defun display-grayscale-p (&optional display)
1500 "Return non-nil if frames on DISPLAY can display shades of gray."
1501 (let ((frame-type (framep-on-display display)))
1502 (cond
1503 ((memq frame-type '(x w32 mac))
1504 (x-display-grayscale-p display))
1506 (> (tty-color-gray-shades display) 2)))))
1508 (defun display-supports-face-attributes-p (attributes &optional display)
1509 "Return non-nil if all the face attributes in ATTRIBUTES are supported.
1510 The optional argument DISPLAY can be a display name, a frame, or
1511 nil (meaning the selected frame's display)
1513 The definition of `supported' is somewhat heuristic, but basically means
1514 that a face containing all the attributes in ATTRIBUTES, when merged
1515 with the default face for display, can be represented in a way that's
1517 (1) different in appearance than the default face, and
1518 (2) `close in spirit' to what the attributes specify, if not exact.
1520 Point (2) implies that a `:weight black' attribute will be satisfied by
1521 any display that can display bold, and a `:foreground \"yellow\"' as long
1522 as it can display a yellowish color, but `:slant italic' will _not_ be
1523 satisfied by the tty display code's automatic substitution of a `dim'
1524 face for italic."
1525 (let ((frame
1526 (if (framep display)
1527 display
1528 (car (frames-on-display-list display)))))
1529 (if (not (memq (framep frame) '(x w32 mac)))
1530 ;; On ttys, `tty-supports-face-attributes-p' does all the work we need.
1531 (tty-supports-face-attributes-p attributes frame)
1532 ;; For now, we assume that non-tty displays can support everything,
1533 ;; and so we just check to see if any of the specified attributes is
1534 ;; different from the default -- though this probably isn't always
1535 ;; accurate for font-related attributes. Later, we should add the
1536 ;; ability to query about specific fonts, colors, etc.
1537 (while (and attributes
1538 (let* ((attr (car attributes))
1539 (val (cadr attributes))
1540 (default-val (face-attribute 'default attr frame)))
1541 (if (and (stringp val) (stringp default-val))
1542 ;; compare string attributes case-insensitively
1543 (eq (compare-strings val nil nil default-val nil nil t)
1545 (equal val default-val))))
1546 (setq attributes (cddr attributes)))
1547 (not (null attributes)))))
1550 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1551 ;;; Background mode.
1552 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1554 (defcustom frame-background-mode nil
1555 "*The brightness of the background.
1556 Set this to the symbol `dark' if your background color is dark, `light' if
1557 your background is light, or nil (default) if you want Emacs to
1558 examine the brightness for you. Don't set this variable with `setq';
1559 this won't have the expected effect."
1560 :group 'faces
1561 :set #'(lambda (var value)
1562 (set-default var value)
1563 (mapc 'frame-set-background-mode (frame-list)))
1564 :initialize 'custom-initialize-changed
1565 :type '(choice (choice-item dark)
1566 (choice-item light)
1567 (choice-item :tag "default" nil)))
1570 (defun frame-set-background-mode (frame)
1571 "Set up display-dependent faces on FRAME.
1572 Display-dependent faces are those which have different definitions
1573 according to the `background-mode' and `display-type' frame parameters."
1574 (let* ((bg-resource
1575 (and window-system
1576 (x-get-resource "backgroundMode" "BackgroundMode")))
1577 (bg-color (frame-parameter frame 'background-color))
1578 (bg-mode
1579 (cond (frame-background-mode)
1580 (bg-resource
1581 (intern (downcase bg-resource)))
1582 ((and (null window-system) (null bg-color))
1583 ;; No way to determine this automatically (?).
1584 'dark)
1585 ;; Unspecified frame background color can only happen
1586 ;; on tty's.
1587 ((member bg-color '(unspecified "unspecified-bg"))
1588 'dark)
1589 ((equal bg-color "unspecified-fg") ; inverted colors
1590 'light)
1591 ((>= (apply '+ (x-color-values bg-color frame))
1592 ;; Just looking at the screen, colors whose
1593 ;; values add up to .6 of the white total
1594 ;; still look dark to me.
1595 (* (apply '+ (x-color-values "white" frame)) .6))
1596 'light)
1597 (t 'dark)))
1598 (display-type
1599 (cond ((null window-system)
1600 (if (tty-display-color-p frame) 'color 'mono))
1601 ((x-display-color-p frame)
1602 'color)
1603 ((x-display-grayscale-p frame)
1604 'grayscale)
1605 (t 'mono)))
1606 (old-bg-mode
1607 (frame-parameter frame 'background-mode))
1608 (old-display-type
1609 (frame-parameter frame 'display-type)))
1611 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1612 (let ((locally-modified-faces nil))
1613 ;; Before modifying the frame parameters, we collect a list of
1614 ;; faces that don't match what their face-spec says they should
1615 ;; look like; we then avoid changing these faces below. A
1616 ;; negative list is used on the assumption that most faces will
1617 ;; be unmodified, so we can avoid consing in the common case.
1618 (dolist (face (face-list))
1619 (when (not (face-spec-match-p face
1620 (face-user-default-spec face)
1621 (selected-frame)))
1622 (push face locally-modified-faces)))
1623 ;; Now change to the new frame parameters
1624 (modify-frame-parameters frame
1625 (list (cons 'background-mode bg-mode)
1626 (cons 'display-type display-type)))
1627 ;; For all named faces, choose face specs matching the new frame
1628 ;; parameters, unless they have been locally modified.
1629 (dolist (face (face-list))
1630 (unless (memq face locally-modified-faces)
1631 (face-spec-set face (face-user-default-spec face) frame)))))))
1634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1635 ;;; Frame creation.
1636 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1638 (defun x-handle-named-frame-geometry (parameters)
1639 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1640 Value is the new parameter list."
1641 (let* ((name (or (cdr (assq 'name parameters))
1642 (cdr (assq 'name default-frame-alist))))
1643 (x-resource-name name)
1644 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1645 (when res-geometry
1646 (let ((parsed (x-parse-geometry res-geometry)))
1647 ;; If the resource specifies a position, call the position
1648 ;; and size "user-specified".
1649 (when (or (assq 'top parsed)
1650 (assq 'left parsed))
1651 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1652 ;; Put the geometry parameters at the end. Copy
1653 ;; default-frame-alist so that they go after it.
1654 (setq parameters (append parameters default-frame-alist parsed))))
1655 parameters))
1658 (defun x-handle-reverse-video (frame parameters)
1659 "Handle the reverse-video frame parameter and X resource.
1660 `x-create-frame' does not handle this one."
1661 (when (cdr (or (assq 'reverse parameters)
1662 (assq 'reverse default-frame-alist)
1663 (let ((resource (x-get-resource "reverseVideo"
1664 "ReverseVideo")))
1665 (if resource
1666 (cons nil (member (downcase resource)
1667 '("on" "true")))))))
1668 (let* ((params (frame-parameters frame))
1669 (bg (cdr (assq 'foreground-color params)))
1670 (fg (cdr (assq 'background-color params))))
1671 (modify-frame-parameters frame
1672 (list (cons 'foreground-color fg)
1673 (cons 'background-color bg)))
1674 (if (equal bg (cdr (assq 'border-color params)))
1675 (modify-frame-parameters frame
1676 (list (cons 'border-color fg))))
1677 (if (equal bg (cdr (assq 'mouse-color params)))
1678 (modify-frame-parameters frame
1679 (list (cons 'mouse-color fg))))
1680 (if (equal bg (cdr (assq 'cursor-color params)))
1681 (modify-frame-parameters frame
1682 (list (cons 'cursor-color fg)))))))
1685 (defun x-create-frame-with-faces (&optional parameters)
1686 "Create a frame from optional frame parameters PARAMETERS.
1687 Parameters not specified by PARAMETERS are taken from
1688 `default-frame-alist'. If PARAMETERS specify a frame name,
1689 handle X geometry resources for that name. If either PARAMETERS
1690 or `default-frame-alist' contains a `reverse' parameter, or
1691 the X resource ``reverseVideo'' is present, handle that.
1692 Value is the new frame created."
1693 (setq parameters (x-handle-named-frame-geometry parameters))
1694 (let ((visibility-spec (assq 'visibility parameters))
1695 (frame-list (frame-list))
1696 (frame (x-create-frame (cons '(visibility . nil) parameters)))
1697 success)
1698 (unwind-protect
1699 (progn
1700 (x-handle-reverse-video frame parameters)
1701 (frame-set-background-mode frame)
1702 (face-set-after-frame-default frame)
1703 (if (or (null frame-list) (null visibility-spec))
1704 (make-frame-visible frame)
1705 (modify-frame-parameters frame (list visibility-spec)))
1706 (setq success t))
1707 (unless success
1708 (delete-frame frame)))
1709 frame))
1712 (defun face-set-after-frame-default (frame)
1713 "Set frame-local faces of FRAME from face specs and resources.
1714 Initialize colors of certain faces from frame parameters."
1715 (if (face-attribute 'default :font t)
1716 (set-face-attribute 'default frame :font
1717 (face-attribute 'default :font t))
1718 (set-face-attribute 'default frame :family
1719 (face-attribute 'default :family t))
1720 (set-face-attribute 'default frame :height
1721 (face-attribute 'default :height t))
1722 (set-face-attribute 'default frame :slant
1723 (face-attribute 'default :slant t))
1724 (set-face-attribute 'default frame :weight
1725 (face-attribute 'default :weight t))
1726 (set-face-attribute 'default frame :width
1727 (face-attribute 'default :width t)))
1728 (dolist (face (face-list))
1729 ;; Don't let frame creation fail because of an invalid face spec.
1730 (condition-case ()
1731 (when (not (equal face 'default))
1732 (face-spec-set face (face-user-default-spec face) frame)
1733 (internal-merge-in-global-face face frame)
1734 (when (and (memq window-system '(x w32 mac))
1735 (or (not (boundp 'inhibit-default-face-x-resources))
1736 (not (eq face 'default))))
1737 (make-face-x-resource-internal face frame)))
1738 (error nil)))
1739 ;; Initialize attributes from frame parameters.
1740 (let ((params '((foreground-color default :foreground)
1741 (background-color default :background)
1742 (border-color border :background)
1743 (cursor-color cursor :background)
1744 (scroll-bar-foreground scroll-bar :foreground)
1745 (scroll-bar-background scroll-bar :background)
1746 (mouse-color mouse :background))))
1747 (dolist (param params)
1748 (let ((frame-param (frame-parameter frame (nth 0 param)))
1749 (face (nth 1 param))
1750 (attr (nth 2 param)))
1751 (when (and frame-param
1752 ;; Don't override face attributes explicitly
1753 ;; specified for new frames.
1754 (eq (face-attribute face attr t) 'unspecified))
1755 (set-face-attribute face frame attr frame-param))))))
1758 (defun tty-handle-reverse-video (frame parameters)
1759 "Handle the reverse-video frame parameter for terminal frames."
1760 (when (cdr (or (assq 'reverse parameters)
1761 (assq 'reverse default-frame-alist)))
1762 (let* ((params (frame-parameters frame))
1763 (bg (cdr (assq 'foreground-color params)))
1764 (fg (cdr (assq 'background-color params))))
1765 (modify-frame-parameters frame
1766 (list (cons 'foreground-color fg)
1767 (cons 'background-color bg)))
1768 (if (equal bg (cdr (assq 'mouse-color params)))
1769 (modify-frame-parameters frame
1770 (list (cons 'mouse-color fg))))
1771 (if (equal bg (cdr (assq 'cursor-color params)))
1772 (modify-frame-parameters frame
1773 (list (cons 'cursor-color fg)))))))
1776 (defun tty-create-frame-with-faces (&optional parameters)
1777 "Create a frame from optional frame parameters PARAMETERS.
1778 Parameters not specified by PARAMETERS are taken from
1779 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
1780 contains a `reverse' parameter, handle that. Value is the new frame
1781 created."
1782 (let ((frame (make-terminal-frame parameters))
1783 success)
1784 (unwind-protect
1785 (progn
1786 (tty-handle-reverse-video frame (frame-parameters frame))
1787 (frame-set-background-mode frame)
1788 (face-set-after-frame-default frame)
1789 (setq success t))
1790 (unless success
1791 (delete-frame frame)))
1792 frame))
1795 ;; Called from C function init_display to initialize faces of the
1796 ;; dumped terminal frame on startup.
1798 (defun tty-set-up-initial-frame-faces ()
1799 (let ((frame (selected-frame)))
1800 (frame-set-background-mode frame)
1801 (face-set-after-frame-default frame)))
1806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1807 ;;; Compatiblity with 20.2
1808 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1810 ;; Update a frame's faces when we change its default font.
1812 (defalias 'frame-update-faces 'ignore "")
1813 (make-obsolete 'frame-update-faces "no longer necessary." "21.1")
1815 ;; Update the colors of FACE, after FRAME's own colors have been
1816 ;; changed.
1818 (defalias 'frame-update-face-colors 'frame-set-background-mode)
1819 (make-obsolete 'frame-update-face-colors 'frame-set-background-mode "21.1")
1822 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1823 ;;; Standard faces.
1824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1826 (defgroup basic-faces nil
1827 "The standard faces of Emacs."
1828 :group 'faces)
1831 (defface default
1832 '((t nil))
1833 "Basic default face."
1834 :group 'basic-faces)
1837 (defface mode-line
1838 '((((type x w32 mac) (class color))
1839 :box (:line-width -1 :style released-button)
1840 :background "grey75" :foreground "black")
1842 :inverse-video t))
1843 "Basic mode line face for selected window."
1844 :version "21.1"
1845 :group 'modeline
1846 :group 'basic-faces)
1848 (defface mode-line-inactive
1849 '((t
1850 :inherit mode-line)
1851 (((type x w32 mac) (background light) (class color))
1852 :weight light
1853 :box (:line-width -1 :color "grey75" :style nil)
1854 :foreground "grey20" :background "grey90")
1855 (((type x w32 mac) (background dark) (class color))
1856 :weight light
1857 :box (:line-width -1 :color "grey40" :style nil)
1858 :foreground "grey80" :background "grey30"))
1859 "Basic mode line face for non-selected windows."
1860 :version "21.4"
1861 :group 'modeline
1862 :group 'basic-faces)
1864 ;; Make `modeline' an alias for `mode-line', for compatibility.
1865 (put 'modeline 'face-alias 'mode-line)
1866 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
1868 (defface header-line
1869 '((t
1870 :inherit mode-line)
1871 (((type tty))
1872 ;; This used to be `:inverse-video t', but that doesn't look very
1873 ;; good when combined with inverse-video mode-lines and multiple
1874 ;; windows. Underlining looks better, and is more consistent with
1875 ;; the window-system face variants, which deemphasize the
1876 ;; header-line in relation to the mode-line face. If a terminal
1877 ;; can't underline, then the header-line will end up without any
1878 ;; highlighting; this may be too confusing in general, although it
1879 ;; happens to look good with the only current use of header-lines,
1880 ;; the info browser. XXX
1881 :inverse-video nil ;Override the value inherited from mode-line.
1882 :underline t)
1883 (((class color grayscale) (background light))
1884 :background "grey90" :foreground "grey20"
1885 :box nil)
1886 (((class color grayscale) (background dark))
1887 :background "grey20" :foreground "grey90"
1888 :box nil)
1889 (((class mono) (background light))
1890 :background "white" :foreground "black"
1891 :inverse-video nil
1892 :box nil
1893 :underline t)
1894 (((class mono) (background dark))
1895 :background "black" :foreground "white"
1896 :inverse-video nil
1897 :box nil
1898 :underline t))
1899 "Basic header-line face."
1900 :version "21.1"
1901 :group 'basic-faces)
1904 (defface tool-bar
1905 '((t
1906 :box (:line-width 1 :style released-button)
1907 :foreground "black")
1908 (((type x w32 mac) (class color))
1909 :background "grey75")
1910 (((type x) (class mono))
1911 :background "grey"))
1912 "Basic tool-bar face."
1913 :version "21.1"
1914 :group 'basic-faces)
1917 (defface minibuffer-prompt '((((background dark)) :foreground "cyan")
1918 (((type pc)) :foreground "magenta")
1919 (t :foreground "dark blue"))
1920 "Face for minibuffer prompts."
1921 :version "21.4"
1922 :group 'basic-faces)
1924 (setq minibuffer-prompt-properties
1925 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
1927 (defface region
1928 '((((class color) (min-colors 88) (background dark))
1929 :background "blue3")
1930 (((class color) (min-colors 88) (background light))
1931 :background "lightgoldenrod2")
1932 (((class color) (min-colors 16) (background dark))
1933 :background "blue3")
1934 (((class color) (min-colors 16) (background light))
1935 :background "lightgoldenrod2")
1936 (((class color) (min-colors 8))
1937 :background "blue" :foreground "white")
1938 (((type tty) (class mono))
1939 :inverse-video t)
1940 (t :background "gray"))
1941 "Basic face for highlighting the region."
1942 :version "21.1"
1943 :group 'basic-faces)
1946 (defface fringe
1947 '((((class color) (background light))
1948 :background "grey95")
1949 (((class color) (background dark))
1950 :background "grey10")
1952 :background "gray"))
1953 "Basic face for the fringes to the left and right of windows under X."
1954 :version "21.1"
1955 :group 'frames
1956 :group 'basic-faces)
1959 (defface scroll-bar '()
1960 "Basic face for the scroll bar colors under X."
1961 :version "21.1"
1962 :group 'frames
1963 :group 'basic-faces)
1966 (defface menu
1967 '((((type tty))
1968 :inverse-video t)
1969 (((type x-toolkit))
1972 :inverse-video t))
1973 "Basic face for the font and colors of the menu bar and popup menus."
1974 :version "21.1"
1975 :group 'menu
1976 :group 'basic-faces)
1979 (defface border '()
1980 "Basic face for the frame border under X."
1981 :version "21.1"
1982 :group 'frames
1983 :group 'basic-faces)
1986 (defface cursor '()
1987 "Basic face for the cursor color under X."
1988 :version "21.1"
1989 :group 'cursor
1990 :group 'basic-faces)
1993 (defface mouse '()
1994 "Basic face for the mouse color under X."
1995 :version "21.1"
1996 :group 'mouse
1997 :group 'basic-faces)
2000 (defface bold '((t :weight bold))
2001 "Basic bold face."
2002 :group 'basic-faces)
2005 (defface italic
2006 '((((supports :slant italic))
2007 :slant italic)
2008 (((supports :underline t))
2009 :underline t)
2011 ;; default to italic, even it doesn't appear to be supported,
2012 ;; because in some cases the display engine will do it's own
2013 ;; workaround (to `dim' on ttys)
2014 :slant italic))
2015 "Basic italic font."
2016 :group 'basic-faces)
2019 (defface bold-italic '((t :weight bold :slant italic))
2020 "Basic bold-italic face."
2021 :group 'basic-faces)
2024 (defface underline '((t :underline t))
2025 "Basic underlined face."
2026 :group 'basic-faces)
2029 (defface highlight
2030 '((((class color) (min-colors 88) (background light))
2031 :background "darkseagreen2")
2032 (((class color) (min-colors 88) (background dark))
2033 :background "darkolivegreen")
2034 (((class color) (min-colors 16) (background light))
2035 :background "darkseagreen2")
2036 (((class color) (min-colors 16) (background dark))
2037 :background "darkolivegreen")
2038 (((class color) (min-colors 8))
2039 :background "green" :foreground "black")
2040 (t :inverse-video t))
2041 "Basic face for highlighting."
2042 :group 'basic-faces)
2045 (defface secondary-selection
2046 '((((class color) (min-colors 88) (background light))
2047 :background "yellow")
2048 (((class color) (min-colors 88) (background dark))
2049 :background "SkyBlue4")
2050 (((class color) (min-colors 16) (background light))
2051 :background "yellow")
2052 (((class color) (min-colors 16) (background dark))
2053 :background "SkyBlue4")
2054 (((class color) (min-colors 8))
2055 :background "cyan" :foreground "black")
2056 (t :inverse-video t))
2057 "Basic face for displaying the secondary selection."
2058 :group 'basic-faces)
2061 (defface fixed-pitch '((t :family "courier"))
2062 "The basic fixed-pitch face."
2063 :group 'basic-faces)
2066 (defface variable-pitch '((t :family "helv"))
2067 "The basic variable-pitch face."
2068 :group 'basic-faces)
2071 (defface trailing-whitespace
2072 '((((class color) (background light))
2073 :background "red")
2074 (((class color) (background dark))
2075 :background "red")
2076 (t :inverse-video t))
2077 "Basic face for highlighting trailing whitespace."
2078 :version "21.1"
2079 :group 'font-lock ; like `show-trailing-whitespace'
2080 :group 'basic-faces)
2084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2085 ;;; Manipulating font names.
2086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2088 ;; This is here for compatibilty with Emacs 20.2. For example,
2089 ;; international/fontset.el uses x-resolve-font-name. The following
2090 ;; functions are not used in the face implementation itself.
2092 (defvar x-font-regexp nil)
2093 (defvar x-font-regexp-head nil)
2094 (defvar x-font-regexp-weight nil)
2095 (defvar x-font-regexp-slant nil)
2097 (defconst x-font-regexp-weight-subnum 1)
2098 (defconst x-font-regexp-slant-subnum 2)
2099 (defconst x-font-regexp-swidth-subnum 3)
2100 (defconst x-font-regexp-adstyle-subnum 4)
2102 ;;; Regexps matching font names in "Host Portable Character Representation."
2104 (let ((- "[-?]")
2105 (foundry "[^-]+")
2106 (family "[^-]+")
2107 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2108 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2109 (weight\? "\\([^-]*\\)") ; 1
2110 (slant "\\([ior]\\)") ; 2
2111 ; (slant\? "\\([ior?*]?\\)") ; 2
2112 (slant\? "\\([^-]?\\)") ; 2
2113 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2114 (swidth "\\([^-]*\\)") ; 3
2115 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2116 (adstyle "\\([^-]*\\)") ; 4
2117 (pixelsize "[0-9]+")
2118 (pointsize "[0-9][0-9]+")
2119 (resx "[0-9][0-9]+")
2120 (resy "[0-9][0-9]+")
2121 (spacing "[cmp?*]")
2122 (avgwidth "[0-9]+")
2123 (registry "[^-]+")
2124 (encoding "[^-]+")
2126 (setq x-font-regexp
2127 (concat "\\`\\*?[-?*]"
2128 foundry - family - weight\? - slant\? - swidth - adstyle -
2129 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2130 registry - encoding "\\*?\\'"
2132 (setq x-font-regexp-head
2133 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2134 "\\([-*?]\\|\\'\\)"))
2135 (setq x-font-regexp-slant (concat - slant -))
2136 (setq x-font-regexp-weight (concat - weight -))
2137 nil)
2140 (defun x-resolve-font-name (pattern &optional face frame)
2141 "Return a font name matching PATTERN.
2142 All wildcards in PATTERN are instantiated.
2143 If PATTERN is nil, return the name of the frame's base font, which never
2144 contains wildcards.
2145 Given optional arguments FACE and FRAME, return a font which is
2146 also the same size as FACE on FRAME, or fail."
2147 (or (symbolp face)
2148 (setq face (face-name face)))
2149 (and (eq frame t)
2150 (setq frame nil))
2151 (if pattern
2152 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2153 (let ((fonts (x-list-fonts pattern face frame 1)))
2154 (or fonts
2155 (if face
2156 (if (string-match "\\*" pattern)
2157 (if (null (face-font face))
2158 (error "No matching fonts are the same height as the frame default font")
2159 (error "No matching fonts are the same height as face `%s'" face))
2160 (if (null (face-font face))
2161 (error "Height of font `%s' doesn't match the frame default font"
2162 pattern)
2163 (error "Height of font `%s' doesn't match face `%s'"
2164 pattern face)))
2165 (error "No fonts match `%s'" pattern)))
2166 (car fonts))
2167 (cdr (assq 'font (frame-parameters (selected-frame))))))
2170 (defun x-frob-font-weight (font which)
2171 (let ((case-fold-search t))
2172 (cond ((string-match x-font-regexp font)
2173 (concat (substring font 0
2174 (match-beginning x-font-regexp-weight-subnum))
2175 which
2176 (substring font (match-end x-font-regexp-weight-subnum)
2177 (match-beginning x-font-regexp-adstyle-subnum))
2178 ;; Replace the ADD_STYLE_NAME field with *
2179 ;; because the info in it may not be the same
2180 ;; for related fonts.
2182 (substring font (match-end x-font-regexp-adstyle-subnum))))
2183 ((string-match x-font-regexp-head font)
2184 (concat (substring font 0 (match-beginning 1)) which
2185 (substring font (match-end 1))))
2186 ((string-match x-font-regexp-weight font)
2187 (concat (substring font 0 (match-beginning 1)) which
2188 (substring font (match-end 1)))))))
2189 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
2191 (defun x-frob-font-slant (font which)
2192 (let ((case-fold-search t))
2193 (cond ((string-match x-font-regexp font)
2194 (concat (substring font 0
2195 (match-beginning x-font-regexp-slant-subnum))
2196 which
2197 (substring font (match-end x-font-regexp-slant-subnum)
2198 (match-beginning x-font-regexp-adstyle-subnum))
2199 ;; Replace the ADD_STYLE_NAME field with *
2200 ;; because the info in it may not be the same
2201 ;; for related fonts.
2203 (substring font (match-end x-font-regexp-adstyle-subnum))))
2204 ((string-match x-font-regexp-head font)
2205 (concat (substring font 0 (match-beginning 2)) which
2206 (substring font (match-end 2))))
2207 ((string-match x-font-regexp-slant font)
2208 (concat (substring font 0 (match-beginning 1)) which
2209 (substring font (match-end 1)))))))
2210 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
2212 ;; These aliases are here so that we don't get warnings about obsolete
2213 ;; functions from the byte compiler.
2214 (defalias 'internal-frob-font-weight 'x-frob-font-weight)
2215 (defalias 'internal-frob-font-slant 'x-frob-font-slant)
2217 (defun x-make-font-bold (font)
2218 "Given an X font specification, make a bold version of it.
2219 If that can't be done, return nil."
2220 (internal-frob-font-weight font "bold"))
2221 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
2223 (defun x-make-font-demibold (font)
2224 "Given an X font specification, make a demibold version of it.
2225 If that can't be done, return nil."
2226 (internal-frob-font-weight font "demibold"))
2227 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
2229 (defun x-make-font-unbold (font)
2230 "Given an X font specification, make a non-bold version of it.
2231 If that can't be done, return nil."
2232 (internal-frob-font-weight font "medium"))
2233 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
2235 (defun x-make-font-italic (font)
2236 "Given an X font specification, make an italic version of it.
2237 If that can't be done, return nil."
2238 (internal-frob-font-slant font "i"))
2239 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
2241 (defun x-make-font-oblique (font) ; you say tomayto...
2242 "Given an X font specification, make an oblique version of it.
2243 If that can't be done, return nil."
2244 (internal-frob-font-slant font "o"))
2245 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
2247 (defun x-make-font-unitalic (font)
2248 "Given an X font specification, make a non-italic version of it.
2249 If that can't be done, return nil."
2250 (internal-frob-font-slant font "r"))
2251 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
2253 (defun x-make-font-bold-italic (font)
2254 "Given an X font specification, make a bold and italic version of it.
2255 If that can't be done, return nil."
2256 (and (setq font (internal-frob-font-weight font "bold"))
2257 (internal-frob-font-slant font "i")))
2258 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2260 (provide 'faces)
2262 ;;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
2263 ;;; faces.el ends here