~alpha, not ~ftp !
[emacs.git] / lisp / faces.el
blobb161eb75f2ac5021415ffcf1cbe6dac62e74750d
1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
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"))
34 (require 'cus-face)
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;; Font selection.
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 (defgroup font-selection nil
42 "Influencing face font selection."
43 :group 'faces)
46 (defcustom face-font-selection-order
47 '(:width :height :weight :slant)
48 "*A list specifying how face font selection chooses fonts.
49 Each of the four symbols `:width', `:height', `:weight', and `:slant'
50 must appear once in the list, and the list must not contain any other
51 elements. Font selection tries to find a best matching font for
52 those face attributes first that appear first in the list. For
53 example, if `:slant' appears before `:height', font selection first
54 tries to find a font with a suitable slant, even if this results in
55 a font height that isn't optimal."
56 :tag "Font selection order."
57 :type '(list symbol symbol symbol symbol)
58 :group 'font-selection
59 :set #'(lambda (symbol value)
60 (set-default symbol value)
61 (internal-set-font-selection-order value)))
64 ;; This is defined originally in xfaces.c.
65 (defcustom face-font-family-alternatives
66 '(("courier" "fixed")
67 ("helv" "helvetica" "arial" "fixed"))
68 "*Alist of alternative font family names.
69 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
70 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
71 ALTERNATIVE2 etc."
72 :tag "Alternative font families to try."
73 :type '(repeat (repeat string))
74 :group 'font-selection
75 :set #'(lambda (symbol value)
76 (set-default symbol value)
77 (internal-set-alternative-font-family-alist value)))
80 ;; This is defined originally in xfaces.c.
81 (defcustom face-font-registry-alternatives
82 (if (eq system-type 'windows-nt)
83 '(("iso8859-1" "ms-oemlatin")
84 ("gb2312.1980" "gb2312")
85 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
86 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
87 ("muletibetan-2" "muletibetan-0"))
88 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk*")
89 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
90 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
91 ("muletibetan-2" "muletibetan-0")))
92 "*Alist of alternative font registry names.
93 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
94 If fonts of registry REGISTRY can be loaded, font selection
95 tries to find a best matching font among all fonts of registry
96 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
97 :tag "Alternative font registries to try."
98 :type '(repeat (repeat string))
99 :version "21.1"
100 :group 'font-selection
101 :set #'(lambda (symbol value)
102 (set-default symbol value)
103 (internal-set-alternative-font-registry-alist value)))
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
108 ;;; Creation, copying.
109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 (defun face-list ()
113 "Return a list of all defined face names."
114 (mapcar #'car face-new-frame-defaults))
117 ;;; ### If not frame-local initialize by what X resources?
119 (defun make-face (face &optional no-init-from-resources)
120 "Define a new face with name FACE, a symbol.
121 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
122 variants of FACE from X resources. (X resources recognized are found
123 in the global variable `face-x-resources'.) If FACE is already known
124 as a face, leave it unmodified. Value is FACE."
125 (interactive "SMake face: ")
126 (unless (facep face)
127 ;; Make frame-local faces (this also makes the global one).
128 (dolist (frame (frame-list))
129 (internal-make-lisp-face face frame))
130 ;; Add the face to the face menu.
131 (when (fboundp 'facemenu-add-new-face)
132 (facemenu-add-new-face face))
133 ;; Define frame-local faces for all frames from X resources.
134 (unless no-init-from-resources
135 (make-face-x-resource-internal face)))
136 face)
139 (defun make-empty-face (face)
140 "Define a new, empty face with name FACE.
141 If the face already exists, it is left unmodified. Value is FACE."
142 (interactive "SMake empty face: ")
143 (make-face face 'no-init-from-resources))
146 (defun copy-face (old-face new-face &optional frame new-frame)
147 "Define a face just like OLD-FACE, with name NEW-FACE.
149 If NEW-FACE already exists as a face, it is modified to be like
150 OLD-FACE. If it doesn't already exist, it is created.
152 If the optional argument FRAME is given as a frame, NEW-FACE is
153 changed on FRAME only.
154 If FRAME is t, the frame-independent default specification for OLD-FACE
155 is copied to NEW-FACE.
156 If FRAME is nil, copying is done for the frame-independent defaults
157 and for each existing frame.
159 If the optional fourth argument NEW-FRAME is given,
160 copy the information from face OLD-FACE on frame FRAME
161 to NEW-FACE on frame NEW-FRAME."
162 (let ((inhibit-quit t))
163 (if (null frame)
164 (progn
165 (dolist (frame (frame-list))
166 (copy-face old-face new-face frame))
167 (copy-face old-face new-face t))
168 (internal-copy-lisp-face old-face new-face frame new-frame))
169 new-face))
173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 ;;; Obsolete functions
175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177 ;; The functions in this section are defined because Lisp packages use
178 ;; them, despite the prefix `internal-' suggesting that they are
179 ;; private to the face implementation.
181 (defun internal-find-face (name &optional frame)
182 "Retrieve the face named NAME.
183 Return nil if there is no such face.
184 If the optional argument FRAME is given, this gets the face NAME for
185 that frame; otherwise, it uses the selected frame.
186 If FRAME is the symbol t, then the global, non-frame face is returned.
187 If NAME is already a face, it is simply returned.
189 This function is defined for compatibility with Emacs 20.2. It
190 should not be used anymore."
191 (facep name))
192 (make-obsolete 'internal-find-face 'facep "21.1")
195 (defun internal-get-face (name &optional frame)
196 "Retrieve the face named NAME; error if there is none.
197 If the optional argument FRAME is given, this gets the face NAME for
198 that frame; otherwise, it uses the selected frame.
199 If FRAME is the symbol t, then the global, non-frame face is returned.
200 If NAME is already a face, it is simply returned.
202 This function is defined for compatibility with Emacs 20.2. It
203 should not be used anymore."
204 (or (internal-find-face name frame)
205 (check-face name)))
206 (make-obsolete 'internal-get-face "See `facep' and `check-face'." "21.1")
209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
210 ;;; Predicates, type checks.
211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
213 (defun facep (face)
214 "Return non-nil if FACE is a face name."
215 (internal-lisp-face-p face))
218 (defun check-face (face)
219 "Signal an error if FACE doesn't name a face.
220 Value is FACE."
221 (unless (facep face)
222 (error "Not a face: %s" face))
223 face)
226 ;; The ID returned is not to be confused with the internally used IDs
227 ;; of realized faces. The ID assigned to Lisp faces is used to
228 ;; support faces in display table entries.
230 (defun face-id (face &optional frame)
231 "Return the internal ID of face with name FACE.
232 If optional argument FRAME is nil or omitted, use the selected frame."
233 (check-face face)
234 (get face 'face))
237 (defun face-equal (face1 face2 &optional frame)
238 "Non-nil if faces FACE1 and FACE2 are equal.
239 Faces are considered equal if all their attributes are equal.
240 If the optional argument FRAME is given, report on face FACE in that frame.
241 If FRAME is t, report on the defaults for face FACE (for new frames).
242 If FRAME is omitted or nil, use the selected frame."
243 (internal-lisp-face-equal-p face1 face2 frame))
246 (defun face-differs-from-default-p (face &optional frame)
247 "Non-nil if FACE displays differently from the default face.
248 If the optional argument FRAME is given, report on face FACE in that frame.
249 If FRAME is t, report on the defaults for face FACE (for new frames).
250 If FRAME is omitted or nil, use the selected frame.
251 A face is considered to be ``the same'' as the default face if it is
252 actually specified in the same way (equal attributes) or if it is
253 fully-unspecified, and thus inherits the attributes of any face it
254 is displayed on top of."
255 (cond ((eq frame t) (setq frame nil))
256 ((null frame) (setq frame (selected-frame))))
257 (let* ((v1 (internal-lisp-face-p face frame))
258 (n (if v1 (length v1) 0))
259 (v2 (internal-lisp-face-p 'default frame))
260 (i 1))
261 (unless v1
262 (error "Not a face: %S" face))
263 (while (and (< i n)
264 (or (eq 'unspecified (aref v1 i))
265 (equal (aref v1 i) (aref v2 i))))
266 (setq i (1+ i)))
267 (< i n)))
270 (defun face-nontrivial-p (face &optional frame)
271 "True if face FACE has some non-nil attribute.
272 If the optional argument FRAME is given, report on face FACE in that frame.
273 If FRAME is t, report on the defaults for face FACE (for new frames).
274 If FRAME is omitted or nil, use the selected frame."
275 (not (internal-lisp-face-empty-p face frame)))
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
280 ;;; Setting face attributes from X resources.
281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
283 (defcustom face-x-resources
284 '((:family (".attributeFamily" . "Face.AttributeFamily"))
285 (:width (".attributeWidth" . "Face.AttributeWidth"))
286 (:height (".attributeHeight" . "Face.AttributeHeight"))
287 (:weight (".attributeWeight" . "Face.AttributeWeight"))
288 (:slant (".attributeSlant" . "Face.AttributeSlant"))
289 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
290 (:background (".attributeBackground" . "Face.AttributeBackground"))
291 (:overline (".attributeOverline" . "Face.AttributeOverline"))
292 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
293 (:box (".attributeBox" . "Face.AttributeBox"))
294 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
295 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
296 (:stipple
297 (".attributeStipple" . "Face.AttributeStipple")
298 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
299 (:bold (".attributeBold" . "Face.AttributeBold"))
300 (:italic (".attributeItalic" . "Face.AttributeItalic"))
301 (:font (".attributeFont" . "Face.AttributeFont"))
302 (:inherit (".attributeInherit" . "Face.AttributeInherit")))
303 "*List of X resources and classes for face attributes.
304 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
305 the name of a face attribute, and each ENTRY is a cons of the form
306 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
307 X resource class for the attribute."
308 :type '(repeat (cons symbol (repeat (cons string string))))
309 :group 'faces)
312 (defun set-face-attribute-from-resource (face attribute resource class frame)
313 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
314 Value is the attribute value specified by the resource, or nil
315 if not present. This function displays a message if the resource
316 specifies an invalid attribute."
317 (let* ((face-name (face-name face))
318 (value (internal-face-x-get-resource (concat face-name resource)
319 class frame)))
320 (when value
321 (condition-case ()
322 (internal-set-lisp-face-attribute-from-resource
323 face attribute (downcase value) frame)
324 (error
325 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
326 face-name frame attribute value))))
327 value))
330 (defun set-face-attributes-from-resources (face frame)
331 "Set attributes of FACE from X resources for FRAME."
332 (when (memq (framep frame) '(x w32 mac))
333 (dolist (definition face-x-resources)
334 (let ((attribute (car definition)))
335 (dolist (entry (cdr definition))
336 (set-face-attribute-from-resource face attribute (car entry)
337 (cdr entry) frame))))))
340 (defun make-face-x-resource-internal (face &optional frame)
341 "Fill frame-local FACE on FRAME from X resources.
342 FRAME nil or not specified means do it for all frames."
343 (if (null frame)
344 (dolist (frame (frame-list))
345 (set-face-attributes-from-resources face frame))
346 (set-face-attributes-from-resources face frame)))
350 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
351 ;;; Retrieving face attributes.
352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
354 (defun face-name (face)
355 "Return the name of face FACE."
356 (symbol-name (check-face face)))
359 (defun face-attribute (face attribute &optional frame)
360 "Return the value of FACE's ATTRIBUTE on FRAME.
361 If the optional argument FRAME is given, report on face FACE in that frame.
362 If FRAME is t, report on the defaults for face FACE (for new frames).
363 If FRAME is omitted or nil, use the selected frame."
364 (internal-get-lisp-face-attribute face attribute frame))
367 (defun face-foreground (face &optional frame)
368 "Return the foreground color name of FACE, or nil if unspecified.
369 If the optional argument FRAME is given, report on face FACE in that frame.
370 If FRAME is t, report on the defaults for face FACE (for new frames).
371 If FRAME is omitted or nil, use the selected frame."
372 (let ((value (internal-get-lisp-face-attribute face :foreground frame)))
373 (if (eq value 'unspecified)
375 value)))
378 (defun face-background (face &optional frame)
379 "Return the background color name of FACE, or nil if unspecified.
380 If the optional argument FRAME is given, report on face FACE in that frame.
381 If FRAME is t, report on the defaults for face FACE (for new frames).
382 If FRAME is omitted or nil, use the selected frame."
383 (let ((value (internal-get-lisp-face-attribute face :background frame)))
384 (if (eq value 'unspecified)
386 value)))
389 (defun face-stipple (face &optional frame)
390 "Return the stipple pixmap name of FACE, or nil if unspecified.
391 If the optional argument FRAME is given, report on face FACE in that frame.
392 If FRAME is t, report on the defaults for face FACE (for new frames).
393 If FRAME is omitted or nil, use the selected frame."
394 (let ((value (internal-get-lisp-face-attribute face :stipple frame)))
395 (if (eq value 'unspecified)
397 value)))
400 (defalias 'face-background-pixmap 'face-stipple)
403 (defun face-underline-p (face &optional frame)
404 "Return non-nil if FACE is underlined.
405 If the optional argument FRAME is given, report on face FACE in that frame.
406 If FRAME is t, report on the defaults for face FACE (for new frames).
407 If FRAME is omitted or nil, use the selected frame."
408 (eq (face-attribute face :underline frame) t))
411 (defun face-inverse-video-p (face &optional frame)
412 "Return non-nil if FACE is in inverse video on FRAME.
413 If the optional argument FRAME is given, report on face FACE in that frame.
414 If FRAME is t, report on the defaults for face FACE (for new frames).
415 If FRAME is omitted or nil, use the selected frame."
416 (eq (face-attribute face :inverse-video frame) t))
419 (defun face-bold-p (face &optional frame)
420 "Return non-nil if the font of FACE is bold on FRAME.
421 If the optional argument FRAME is given, report on face FACE in that frame.
422 If FRAME is t, report on the defaults for face FACE (for new frames).
423 If FRAME is omitted or nil, use the selected frame.
424 Use `face-attribute' for finer control."
425 (let ((bold (face-attribute face :weight frame)))
426 (memq bold '(semi-bold bold extra-bold ultra-bold))))
429 (defun face-italic-p (face &optional frame)
430 "Return non-nil if the font of FACE is italic on FRAME.
431 If the optional argument FRAME is given, report on face FACE in that frame.
432 If FRAME is t, report on the defaults for face FACE (for new frames).
433 If FRAME is omitted or nil, use the selected frame.
434 Use `face-attribute' for finer control."
435 (let ((italic (face-attribute face :slant frame)))
436 (memq italic '(italic oblique))))
440 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
441 ;;; Face documentation.
442 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
444 (defun face-documentation (face)
445 "Get the documentation string for FACE."
446 (get face 'face-documentation))
449 (defun set-face-documentation (face string)
450 "Set the documentation string for FACE to STRING."
451 ;; Perhaps the text should go in DOC.
452 (put face 'face-documentation (purecopy string)))
455 (defalias 'face-doc-string 'face-documentation)
456 (defalias 'set-face-doc-string 'set-face-documentation)
460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
461 ;; Setting face attributes.
462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
465 (defun set-face-attribute (face frame &rest args)
466 "Set attributes of FACE on FRAME from ARGS.
468 FRAME nil means change attributes on all frames. FRAME t means change
469 the default for new frames (this is done automatically each time an
470 attribute is changed on all frames).
472 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
473 face attribute name. All attributes can be set to `unspecified';
474 this fact is not further mentioned below.
476 The following attributes are recognized:
478 `:family'
480 VALUE must be a string specifying the font family, e.g. ``courier'',
481 or a fontset alias name. If a font family is specified, wild-cards `*'
482 and `?' are allowed.
484 `:width'
486 VALUE specifies the relative proportionate width of the font to use.
487 It must be one of the symbols `ultra-condensed', `extra-condensed',
488 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
489 `extra-expanded', or `ultra-expanded'.
491 `:height'
493 VALUE must be either an integer specifying the height of the font to use
494 in 1/10 pt, a floating point number specifying the amount by which to
495 scale any underlying face, or a function, which is called with the old
496 height (from the underlying face), and should return the new height.
498 `:weight'
500 VALUE specifies the weight of the font to use. It must be one of the
501 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
502 `semi-light', `light', `extra-light', `ultra-light'.
504 `:slant'
506 VALUE specifies the slant of the font to use. It must be one of the
507 symbols `italic', `oblique', `normal', `reverse-italic', or
508 `reverse-oblique'.
510 `:foreground', `:background'
512 VALUE must be a color name, a string.
514 `:underline'
516 VALUE specifies whether characters in FACE should be underlined. If
517 VALUE is t, underline with foreground color of the face. If VALUE is
518 a string, underline with that color. If VALUE is nil, explicitly
519 don't underline.
521 `:overline'
523 VALUE specifies whether characters in FACE should be overlined. If
524 VALUE is t, overline with foreground color of the face. If VALUE is a
525 string, overline with that color. If VALUE is nil, explicitly don't
526 overline.
528 `:strike-through'
530 VALUE specifies whether characters in FACE should be drawn with a line
531 striking through them. If VALUE is t, use the foreground color of the
532 face. If VALUE is a string, strike-through with that color. If VALUE
533 is nil, explicitly don't strike through.
535 `:box'
537 VALUE specifies whether characters in FACE should have a box drawn
538 around them. If VALUE is nil, explicitly don't draw boxes. If
539 VALUE is t, draw a box with lines of width 1 in the foreground color
540 of the face. If VALUE is a string, the string must be a color name,
541 and the box is drawn in that color with a line width of 1. Otherwise,
542 VALUE must be a property list of the form `(:line-width WIDTH
543 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
544 the property list, a default value will be used for the value, as
545 specified below. WIDTH specifies the width of the lines to draw; it
546 defaults to 1. If WIDTH is negative, the absolute value is the width
547 of the lines, and draw top/bottom lines inside the characters area,
548 not around it. COLOR is the name of the color to draw in, default is
549 the foreground color of the face for simple boxes, and the background
550 color of the face for 3D boxes. STYLE specifies whether a 3D box
551 should be draw. If STYLE is `released-button', draw a box looking
552 like a released 3D button. If STYLE is `pressed-button' draw a box
553 that appears like a pressed button. If STYLE is nil, the default if
554 the property list doesn't contain a style specification, draw a 2D
555 box.
557 `:inverse-video'
559 VALUE specifies whether characters in FACE should be displayed in
560 inverse video. VALUE must be one of t or nil.
562 `:stipple'
564 If VALUE is a string, it must be the name of a file of pixmap data.
565 The directories listed in the `x-bitmap-file-path' variable are
566 searched. Alternatively, VALUE may be a list of the form (WIDTH
567 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
568 is a string containing the raw bits of the bitmap. VALUE nil means
569 explicitly don't use a stipple pattern.
571 For convenience, attributes `:family', `:width', `:height', `:weight',
572 and `:slant' may also be set in one step from an X font name:
574 `:font'
576 Set font-related face attributes from VALUE. VALUE must be a valid
577 XLFD font name. If it is a font name pattern, the first matching font
578 will be used.
580 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
581 be used to specify that a bold or italic font should be used. VALUE
582 must be t or nil in that case. A value of `unspecified' is not allowed.
584 `:inherit'
586 VALUE is the name of a face from which to inherit attributes, or a list
587 of face names. Attributes from inherited faces are merged into the face
588 like an underlying face would be, with higher priority than underlying faces."
589 (let ((where (if (null frame) 0 frame)))
590 (setq args (purecopy args))
591 (while args
592 (internal-set-lisp-face-attribute face (car args)
593 (purecopy (cadr args))
594 where)
595 (setq args (cdr (cdr args))))))
598 (defun make-face-bold (face &optional frame noerror)
599 "Make the font of FACE be bold, if possible.
600 FRAME nil or not specified means change face on all frames.
601 Argument NOERROR is ignored and retained for compatibility.
602 Use `set-face-attribute' for finer control of the font weight."
603 (interactive (list (read-face-name "Make which face bold ")))
604 (set-face-attribute face frame :weight 'bold))
607 (defun make-face-unbold (face &optional frame noerror)
608 "Make the font of FACE be non-bold, if possible.
609 FRAME nil or not specified means change face on all frames.
610 Argument NOERROR is ignored and retained for compatibility."
611 (interactive (list (read-face-name "Make which face non-bold ")))
612 (set-face-attribute face frame :weight 'normal))
615 (defun make-face-italic (face &optional frame noerror)
616 "Make the font of FACE be italic, if possible.
617 FRAME nil or not specified means change face on all frames.
618 Argument NOERROR is ignored and retained for compatibility.
619 Use `set-face-attribute' for finer control of the font slant."
620 (interactive (list (read-face-name "Make which face italic ")))
621 (set-face-attribute face frame :slant 'italic))
624 (defun make-face-unitalic (face &optional frame noerror)
625 "Make the font of FACE be non-italic, if possible.
626 FRAME nil or not specified means change face on all frames.
627 Argument NOERROR is ignored and retained for compatibility."
628 (interactive (list (read-face-name "Make which face non-italic ")))
629 (set-face-attribute face frame :slant 'normal))
632 (defun make-face-bold-italic (face &optional frame noerror)
633 "Make the font of FACE be bold and italic, if possible.
634 FRAME nil or not specified means change face on all frames.
635 Argument NOERROR is ignored and retained for compatibility.
636 Use `set-face-attribute' for finer control of font weight and slant."
637 (interactive (list (read-face-name "Make which face bold-italic ")))
638 (set-face-attribute face frame :weight 'bold :slant 'italic))
641 (defun set-face-font (face font &optional frame)
642 "Change font-related attributes of FACE to those of FONT (a string).
643 FRAME nil or not specified means change face on all frames.
644 This sets the attributes `:family', `:width', `:height', `:weight',
645 and `:slant'. When called interactively, prompt for the face and font."
646 (interactive (read-face-and-attribute :font))
647 (set-face-attribute face frame :font font))
650 ;; Implementation note: Emulating gray background colors with a
651 ;; stipple pattern is now part of the face realization process, and is
652 ;; done in C depending on the frame on which the face is realized.
654 (defun set-face-background (face color &optional frame)
655 "Change the background color of face FACE to COLOR (a string).
656 FRAME nil or not specified means change face on all frames.
657 When called interactively, prompt for the face and color."
658 (interactive (read-face-and-attribute :background))
659 (set-face-attribute face frame :background (or color 'unspecified)))
662 (defun set-face-foreground (face color &optional frame)
663 "Change the foreground color of face FACE to COLOR (a string).
664 FRAME nil or not specified means change face on all frames.
665 When called interactively, prompt for the face and color."
666 (interactive (read-face-and-attribute :foreground))
667 (set-face-attribute face frame :foreground (or color 'unspecified)))
670 (defun set-face-stipple (face stipple &optional frame)
671 "Change the stipple pixmap of face FACE to STIPPLE.
672 FRAME nil or not specified means change face on all frames.
673 STIPPLE should be a string, the name of a file of pixmap data.
674 The directories listed in the `x-bitmap-file-path' variable are searched.
676 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
677 where WIDTH and HEIGHT are the size in pixels,
678 and DATA is a string, containing the raw bits of the bitmap."
679 (interactive (read-face-and-attribute :stipple))
680 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
683 (defun set-face-underline (face underline &optional frame)
684 "Specify whether face FACE is underlined.
685 UNDERLINE nil means FACE explicitly doesn't underline.
686 UNDERLINE non-nil means FACE explicitly does underlining
687 with the same of the foreground color.
688 If UNDERLINE is a string, underline with the color named UNDERLINE.
689 FRAME nil or not specified means change face on all frames.
690 Use `set-face-attribute' to ``unspecify'' underlining."
691 (interactive
692 (let ((list (read-face-and-attribute :underline)))
693 (list (car list) (eq (car (cdr list)) t))))
694 (set-face-attribute face frame :underline underline))
697 (defun set-face-underline-p (face underline-p &optional frame)
698 "Specify whether face FACE is underlined.
699 UNDERLINE-P nil means FACE explicitly doesn't underline.
700 UNDERLINE-P non-nil means FACE explicitly does underlining.
701 FRAME nil or not specified means change face on all frames.
702 Use `set-face-attribute' to ``unspecify'' underlining."
703 (interactive
704 (let ((list (read-face-and-attribute :underline)))
705 (list (car list) (eq (car (cdr list)) t))))
706 (set-face-attribute face frame :underline underline-p))
709 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
710 "Specify whether face FACE is in inverse video.
711 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
712 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
713 FRAME nil or not specified means change face on all frames.
714 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
715 (interactive
716 (let ((list (read-face-and-attribute :inverse-video)))
717 (list (car list) (eq (car (cdr list)) t))))
718 (set-face-attribute face frame :inverse-video inverse-video-p))
721 (defun set-face-bold-p (face bold-p &optional frame)
722 "Specify whether face FACE is bold.
723 BOLD-P non-nil means FACE should explicitly display bold.
724 BOLD-P nil means FACE should explicitly display non-bold.
725 FRAME nil or not specified means change face on all frames.
726 Use `set-face-attribute' or `modify-face' for finer control."
727 (if (null bold-p)
728 (make-face-unbold face frame)
729 (make-face-bold face frame)))
732 (defun set-face-italic-p (face italic-p &optional frame)
733 "Specify whether face FACE is italic.
734 ITALIC-P non-nil means FACE should explicitly display italic.
735 ITALIC-P nil means FACE should explicitly display non-italic.
736 FRAME nil or not specified means change face on all frames.
737 Use `set-face-attribute' or `modify-face' for finer control."
738 (if (null italic-p)
739 (make-face-unitalic face frame)
740 (make-face-italic face frame)))
743 (defalias 'set-face-background-pixmap 'set-face-stipple)
746 (defun invert-face (face &optional frame)
747 "Swap the foreground and background colors of FACE.
748 If FRAME is omitted or nil, it means change face on all frames.
749 If FACE specifies neither foreground nor background color,
750 set its foreground and background to the background and foreground
751 of the default face. Value is FACE."
752 (interactive (list (read-face-name "Invert face ")))
753 (let ((fg (face-attribute face :foreground frame))
754 (bg (face-attribute face :background frame)))
755 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
756 (set-face-attribute face frame :foreground bg :background fg)
757 (set-face-attribute face frame
758 :foreground
759 (face-attribute 'default :background frame)
760 :background
761 (face-attribute 'default :foreground frame))))
762 face)
765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
766 ;;; Interactively modifying faces.
767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
769 (defun read-face-name (prompt)
770 "Read and return a face symbol, prompting with PROMPT.
771 Value is a symbol naming a known face."
772 (let ((face-list (mapcar #'(lambda (x) (cons (symbol-name x) x))
773 (face-list)))
774 (def (thing-at-point 'symbol))
775 face)
776 (cond ((assoc def face-list)
777 (setq prompt (concat prompt " (default " def "): ")))
778 (t (setq def nil)
779 (setq prompt (concat prompt ": "))))
780 (while (equal "" (setq face (completing-read
781 prompt face-list nil t nil nil def))))
782 (intern face)))
785 (defun face-valid-attribute-values (attribute &optional frame)
786 "Return valid values for face attribute ATTRIBUTE.
787 The optional argument FRAME is used to determine available fonts
788 and colors. If it is nil or not specified, the selected frame is
789 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
790 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
791 an integer value."
792 (let ((valid
793 (case attribute
794 (:family
795 (if window-system
796 (mapcar #'(lambda (x) (cons (car x) (car x)))
797 (x-font-family-list))
798 ;; Only one font on TTYs.
799 (list (cons "default" "default"))))
800 ((:width :weight :slant :inverse-video)
801 (mapcar #'(lambda (x) (cons (symbol-name x) x))
802 (internal-lisp-face-attribute-values attribute)))
803 ((:underline :overline :strike-through :box)
804 (if window-system
805 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
806 (internal-lisp-face-attribute-values attribute))
807 (mapcar #'(lambda (c) (cons c c))
808 (x-defined-colors frame)))
809 (mapcar #'(lambda (x) (cons (symbol-name x) x))
810 (internal-lisp-face-attribute-values attribute))))
811 ((:foreground :background)
812 (mapcar #'(lambda (c) (cons c c))
813 (defined-colors frame)))
814 ((:height)
815 'integerp)
816 (:stipple
817 (and (memq window-system '(x w32 mac))
818 (mapcar #'list
819 (apply #'nconc
820 (mapcar (lambda (dir)
821 (and (file-readable-p dir)
822 (file-directory-p dir)
823 (directory-files dir)))
824 x-bitmap-file-path)))))
825 (:inherit
826 (cons '("none" . nil)
827 (mapcar #'(lambda (c) (cons (symbol-name c) c))
828 (face-list))))
830 (error "Internal error")))))
831 (if (and (listp valid) (not (memq attribute '(:inherit))))
832 (nconc (list (cons "unspecified" 'unspecified)) valid)
833 valid)))
836 (defvar face-attribute-name-alist
837 '((:family . "font family")
838 (:width . "character set width")
839 (:height . "height in 1/10 pt")
840 (:weight . "weight")
841 (:slant . "slant")
842 (:underline . "underline")
843 (:overline . "overline")
844 (:strike-through . "strike-through")
845 (:box . "box")
846 (:inverse-video . "inverse-video display")
847 (:foreground . "foreground color")
848 (:background . "background color")
849 (:stipple . "background stipple")
850 (:inherit . "inheritance"))
851 "An alist of descriptive names for face attributes.
852 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
853 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
854 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
857 (defun face-descriptive-attribute-name (attribute)
858 "Return a descriptive name for ATTRIBUTE."
859 (cdr (assq attribute face-attribute-name-alist)))
862 (defun face-read-string (face default name &optional completion-alist)
863 "Interactively read a face attribute string value.
864 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
865 default string to return if no new value is entered. NAME is a
866 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
867 alist of valid values, if non-nil.
869 Entering nothing accepts the default string DEFAULT.
870 Value is the new attribute value."
871 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
872 ;; each word in a string separately).
873 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
874 (let* ((completion-ignore-case t)
875 (value (completing-read
876 (if default
877 (format "%s for face `%s' (default %s): "
878 name face default)
879 (format "%s for face `%s': " name face))
880 completion-alist)))
881 (if (equal value "") default value)))
884 (defun face-read-integer (face default name)
885 "Interactively read an integer face attribute value.
886 FACE is the face whose attribute is read. DEFAULT is the default
887 value to return if no new value is entered. NAME is a descriptive
888 name of the attribute for prompting. Value is the new attribute value."
889 (let ((new-value
890 (face-read-string face
891 (format "%s" default)
892 name
893 (list (cons "unspecified" 'unspecified)))))
894 (cond ((equal new-value "unspecified")
895 'unspecified)
896 ((member new-value '("unspecified-fg" "unspecified-bg"))
897 new-value)
899 (string-to-int new-value)))))
902 (defun read-face-attribute (face attribute &optional frame)
903 "Interactively read a new value for FACE's ATTRIBUTE.
904 Optional argument FRAME nil or unspecified means read an attribute value
905 of a global face. Value is the new attribute value."
906 (let* ((old-value (face-attribute face attribute frame))
907 (attribute-name (face-descriptive-attribute-name attribute))
908 (valid (face-valid-attribute-values attribute frame))
909 new-value)
910 ;; Represent complex attribute values as strings by printing them
911 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
912 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
913 ;; SHADOW)'.
914 (when (and (or (eq attribute :stipple)
915 (eq attribute :box))
916 (or (consp old-value)
917 (vectorp old-value)))
918 (setq old-value (prin1-to-string old-value)))
919 (cond ((listp valid)
920 (let ((default
921 (or (car (rassoc old-value valid))
922 (format "%s" old-value))))
923 (setq new-value
924 (face-read-string face default attribute-name valid))
925 (if (equal new-value default)
926 ;; Nothing changed, so don't bother with all the stuff
927 ;; below. In particular, this avoids a non-tty color
928 ;; from being canonicalized for a tty when the user
929 ;; just uses the default.
930 (setq new-value old-value)
931 ;; Terminal frames can support colors that don't appear
932 ;; explicitly in VALID, using color approximation code
933 ;; in tty-colors.el.
934 (when (and (memq attribute '(:foreground :background))
935 (not (memq window-system '(x w32 mac)))
936 (not (member new-value
937 '("unspecified"
938 "unspecified-fg" "unspecified-bg"))))
939 (setq new-value (car (tty-color-desc new-value frame))))
940 (when (assoc new-value valid)
941 (setq new-value (cdr (assoc new-value valid)))))))
942 ((eq valid 'integerp)
943 (setq new-value (face-read-integer face old-value attribute-name)))
944 (t (error "Internal error")))
945 ;; Convert stipple and box value text we read back to a list or
946 ;; vector if it looks like one. This makes the assumption that a
947 ;; pixmap file name won't start with an open-paren.
948 (when (and (or (eq attribute :stipple)
949 (eq attribute :box))
950 (stringp new-value)
951 (string-match "^[[(]" new-value))
952 (setq new-value (read new-value)))
953 new-value))
956 (defun read-face-font (face &optional frame)
957 "Read the name of a font for FACE on FRAME.
958 If optional argument FRAME Is nil or omitted, use the selected frame."
959 (let ((completion-ignore-case t))
960 (completing-read (format "Set font attributes of face `%s' from font: " face)
961 (mapcar 'list (x-list-fonts "*" nil frame)))))
964 (defun read-all-face-attributes (face &optional frame)
965 "Interactively read all attributes for FACE.
966 If optional argument FRAME Is nil or omitted, use the selected frame.
967 Value is a property list of attribute names and new values."
968 (let (result)
969 (dolist (attribute face-attribute-name-alist result)
970 (setq result (cons (car attribute)
971 (cons (read-face-attribute face (car attribute) frame)
972 result))))))
974 (defun modify-face (&optional face foreground background stipple
975 bold-p italic-p underline-p inverse-p frame)
976 "Modify attributes of faces interactively.
977 If optional argument FRAME is nil or omitted, modify the face used
978 for newly created frame, i.e. the global face.
979 For non-interactive use, `set-face-attribute' is preferred.
980 When called from elisp, if FACE is nil, all arguments but FRAME are ignored
981 and the face and its settings are obtained by querying the user."
982 (interactive)
983 (if face
984 (set-face-attribute face frame
985 :foreground (or foreground 'unspecified)
986 :background (or background 'unspecified)
987 :stipple stipple
988 :bold bold-p
989 :italic italic-p
990 :underline underline-p
991 :inverse-video inverse-p)
992 (setq face (read-face-name "Modify face"))
993 (apply #'set-face-attribute face frame
994 (read-all-face-attributes face frame))))
996 (defun read-face-and-attribute (attribute &optional frame)
997 "Read face name and face attribute value.
998 ATTRIBUTE is the attribute whose new value is read.
999 FRAME nil or unspecified means read attribute value of global face.
1000 Value is a list (FACE NEW-VALUE) where FACE is the face read
1001 \(a symbol), and NEW-VALUE is value read."
1002 (cond ((eq attribute :font)
1003 (let* ((prompt "Set font-related attributes of face")
1004 (face (read-face-name prompt))
1005 (font (read-face-font face frame)))
1006 (list face font)))
1008 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1009 (prompt (format "Set %s of face" attribute-name))
1010 (face (read-face-name prompt))
1011 (new-value (read-face-attribute face attribute frame)))
1012 (list face new-value)))))
1016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1017 ;;; Listing faces.
1018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1020 (defvar list-faces-sample-text
1021 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1022 "*Text string to display as the sample text for `list-faces-display'.")
1025 ;; The name list-faces would be more consistent, but let's avoid a
1026 ;; conflict with Lucid, which uses that name differently.
1028 (defun list-faces-display ()
1029 "List all faces, using the same sample text in each.
1030 The sample text is a string that comes from the variable
1031 `list-faces-sample-text'."
1032 (interactive)
1033 (let ((faces (sort (face-list) #'string-lessp))
1034 (face nil)
1035 (frame (selected-frame))
1036 disp-frame window face-name)
1037 (with-output-to-temp-buffer "*Faces*"
1038 (save-excursion
1039 (set-buffer standard-output)
1040 (setq truncate-lines t)
1041 (insert
1042 (substitute-command-keys
1043 (concat
1044 "Use "
1045 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1046 "\\[help-follow] on a face name to customize it\n"
1047 "or on its sample text for a description of the face.\n\n")))
1048 (setq help-xref-stack nil)
1049 (while faces
1050 (setq face (car faces))
1051 (setq faces (cdr faces))
1052 (setq face-name (symbol-name face))
1053 (insert (format "%25s " face-name))
1054 ;; Hyperlink to a customization buffer for the face. Using
1055 ;; the help xref mechanism may not be the best way.
1056 (save-excursion
1057 (save-match-data
1058 (search-backward face-name)
1059 (help-xref-button 0 (lambda (f)
1060 (if help-xref-stack
1061 (pop help-xref-stack))
1062 (customize-face f))
1063 face-name
1064 "mouse-2: customize this face")))
1065 (let ((beg (point)))
1066 (insert list-faces-sample-text)
1067 ;; Hyperlink to a help buffer for the face.
1068 (save-excursion
1069 (save-match-data
1070 (search-backward list-faces-sample-text)
1071 (help-xref-button 0 #'describe-face face
1072 "mouse-2: describe this face")))
1073 (insert "\n")
1074 (put-text-property beg (1- (point)) 'face face)
1075 ;; If the sample text has multiple lines, line up all of them.
1076 (goto-char beg)
1077 (forward-line 1)
1078 (while (not (eobp))
1079 (insert " ")
1080 (forward-line 1))))
1081 (goto-char (point-min)))
1082 (print-help-return-message))
1083 ;; If the *Faces* buffer appears in a different frame,
1084 ;; copy all the face definitions from FRAME,
1085 ;; so that the display will reflect the frame that was selected.
1086 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1087 (setq disp-frame (if window (window-frame window)
1088 (car (frame-list))))
1089 (or (eq frame disp-frame)
1090 (let ((faces (face-list)))
1091 (while faces
1092 (copy-face (car faces) (car faces) frame disp-frame)
1093 (setq faces (cdr faces)))))))
1096 (defun describe-face (face &optional frame)
1097 "Display the properties of face FACE on FRAME.
1098 If the optional argument FRAME is given, report on face FACE in that frame.
1099 If FRAME is t, report on the defaults for face FACE (for new frames).
1100 If FRAME is omitted or nil, use the selected frame."
1101 (interactive (list (read-face-name "Describe face")))
1102 (let* ((attrs '((:family . "Family")
1103 (:width . "Width")
1104 (:height . "Height")
1105 (:weight . "Weight")
1106 (:slant . "Slant")
1107 (:foreground . "Foreground")
1108 (:background . "Background")
1109 (:underline . "Underline")
1110 (:overline . "Overline")
1111 (:strike-through . "Strike-through")
1112 (:box . "Box")
1113 (:inverse-video . "Inverse")
1114 (:stipple . "Stipple")
1115 (:font . "Font or fontset")
1116 (:inherit . "Inherit")))
1117 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1118 attrs))))
1119 (with-output-to-temp-buffer "*Help*"
1120 (save-excursion
1121 (set-buffer standard-output)
1122 (dolist (a attrs)
1123 (let ((attr (face-attribute face (car a) frame)))
1124 (insert (make-string (- max-width (length (cdr a))) ?\ )
1125 (cdr a) ": " (format "%s" attr) "\n")))
1126 (insert "\nDocumentation:\n\n"
1127 (or (face-documentation face)
1128 "not documented as a face."))
1129 (let ((customize-label "customize"))
1130 (terpri)
1131 (terpri)
1132 (princ (concat "You can " customize-label " this face."))
1133 (with-current-buffer "*Help*"
1134 (save-excursion
1135 (re-search-backward
1136 (concat "\\(" customize-label "\\)") nil t)
1137 (help-xref-button 1 #'customize-face face
1138 "mouse-2, RET: customize face")))))
1139 (print-help-return-message)
1140 (with-current-buffer "*Help*"
1141 (help-setup-xref (list #'describe-face face) (interactive-p))
1142 (buffer-string)))))
1144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1145 ;;; Face specifications (defface).
1146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1148 ;; Parameter FRAME Is kept for call compatibility to with previous
1149 ;; face implementation.
1151 (defun face-attr-construct (face &optional frame)
1152 "Return a defface-style attribute list for FACE on FRAME.
1153 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1154 face attributes of FACE where ATTRIBUTE is the attribute name and
1155 VALUE is the specified value of that attribute."
1156 (let (result)
1157 (dolist (entry face-attribute-name-alist result)
1158 (let* ((attribute (car entry))
1159 (value (face-attribute face attribute)))
1160 (unless (eq value 'unspecified)
1161 (setq result (nconc (list attribute value) result)))))))
1164 (defun face-spec-set-match-display (display frame)
1165 "Non-nil if DISPLAY matches FRAME.
1166 DISPLAY is part of a spec such as can be used in `defface'.
1167 If FRAME is nil, the current FRAME is used."
1168 (let* ((conjuncts display)
1169 conjunct req options
1170 ;; t means we have succeeded against all the conjuncts in
1171 ;; DISPLAY that have been tested so far.
1172 (match t))
1173 (if (eq conjuncts t)
1174 (setq conjuncts nil))
1175 (while (and conjuncts match)
1176 (setq conjunct (car conjuncts)
1177 conjuncts (cdr conjuncts)
1178 req (car conjunct)
1179 options (cdr conjunct)
1180 match (cond ((eq req 'type)
1181 (or (memq window-system options)
1182 ;; FIXME: This should be revisited to use
1183 ;; display-graphic-p, provided that the
1184 ;; color selection depends on the number
1185 ;; of supported colors, and all defface's
1186 ;; are changed to look at number of colors
1187 ;; instead of (type graphic) etc.
1188 (and (null window-system)
1189 (memq 'tty options))
1190 (and (memq 'motif options)
1191 (featurep 'motif))
1192 (and (memq 'lucid options)
1193 (featurep 'x-toolkit)
1194 (not (featurep 'motif)))
1195 (and (memq 'x-toolkit options)
1196 (featurep 'x-toolkit))))
1197 ((eq req 'class)
1198 (memq (frame-parameter frame 'display-type) options))
1199 ((eq req 'background)
1200 (memq (frame-parameter frame 'background-mode)
1201 options))
1202 (t (error "Unknown req `%S' with options `%S'"
1203 req options)))))
1204 match))
1207 (defun face-spec-choose (spec &optional frame)
1208 "Choose the proper attributes for FRAME, out of SPEC.
1209 If SPEC is nil, return nil."
1210 (unless frame
1211 (setq frame (selected-frame)))
1212 (let ((tail spec)
1213 result)
1214 (while tail
1215 (let* ((entry (pop tail))
1216 (display (car entry))
1217 (attrs (cdr entry)))
1218 (when (face-spec-set-match-display display frame)
1219 (setq result (if (listp (car attrs))
1220 ;; Old-style entry, the attribute list is the
1221 ;; first element.
1222 (car attrs)
1223 attrs)
1224 tail nil))))
1225 result))
1228 (defun face-spec-reset-face (face &optional frame)
1229 "Reset all attributes of FACE on FRAME to unspecified."
1230 (let ((attrs face-attribute-name-alist))
1231 (while attrs
1232 (let ((attr-and-name (car attrs)))
1233 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1234 (setq attrs (cdr attrs)))))
1237 (defun face-spec-set (face spec &optional frame)
1238 "Set FACE's attributes according to the first matching entry in SPEC.
1239 FRAME is the frame whose frame-local face is set. FRAME nil means
1240 do it on all frames. See `defface' for information about SPEC.
1241 If SPEC is nil, do nothing."
1242 (let ((attrs (face-spec-choose spec frame)))
1243 (when attrs
1244 (face-spec-reset-face face frame))
1245 (while attrs
1246 (let ((attribute (car attrs))
1247 (value (car (cdr attrs))))
1248 ;; Support some old-style attribute names and values.
1249 (case attribute
1250 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1251 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1252 ((:foreground :background)
1253 ;; Compatibility with 20.x. Some bogus face specs seem to
1254 ;; exist containing things like `:foreground nil'.
1255 (if (null value) (setq value 'unspecified)))
1256 (t (unless (assq attribute face-x-resources)
1257 (setq attribute nil))))
1258 (when attribute
1259 (set-face-attribute face frame attribute value)))
1260 (setq attrs (cdr (cdr attrs))))))
1263 (defun face-attr-match-p (face attrs &optional frame)
1264 "Return t if attributes of FACE match values in plist ATTRS.
1265 Optional parameter FRAME is the frame whose definition of FACE
1266 is used. If nil or omitted, use the selected frame."
1267 (unless frame
1268 (setq frame (selected-frame)))
1269 (let ((list face-attribute-name-alist)
1270 (match t))
1271 (while (and match (not (null list)))
1272 (let* ((attr (car (car list)))
1273 (specified-value
1274 (if (plist-member attrs attr)
1275 (plist-get attrs attr)
1276 'unspecified))
1277 (value-now (face-attribute face attr frame)))
1278 (setq match (equal specified-value value-now))
1279 (setq list (cdr list))))
1280 match))
1282 (defun face-spec-match-p (face spec &optional frame)
1283 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1284 (face-attr-match-p face (face-spec-choose spec frame) frame))
1286 (defsubst face-default-spec (face)
1287 "Return the default face-spec for FACE, ignoring any user customization.
1288 If there is no default for FACE, return nil."
1289 (get face 'face-defface-spec))
1291 (defsubst face-user-default-spec (face)
1292 "Return the user's customized face-spec for FACE, or the default if none.
1293 If there is neither a user setting nor a default for FACE, return nil."
1294 (or (get face 'saved-face)
1295 (face-default-spec face)))
1298 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1299 ;;; Frame-type independent color support.
1300 ;;; We keep the old x-* names as aliases for back-compatibility.
1301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1303 (defun defined-colors (&optional frame)
1304 "Return a list of colors supported for a particular frame.
1305 The argument FRAME specifies which frame to try.
1306 The value may be different for frames on different display types.
1307 If FRAME doesn't support colors, the value is nil."
1308 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1309 (xw-defined-colors frame)
1310 (mapcar 'car (tty-color-alist frame))))
1311 (defalias 'x-defined-colors 'defined-colors)
1313 (defun color-defined-p (color &optional frame)
1314 "Return non-nil if color COLOR is supported on frame FRAME.
1315 If FRAME is omitted or nil, use the selected frame.
1316 If COLOR is the symbol `unspecified' or one of the strings
1317 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1318 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1320 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1321 (xw-color-defined-p color frame)
1322 (numberp (tty-color-translate color frame)))))
1323 (defalias 'x-color-defined-p 'color-defined-p)
1325 (defun color-values (color &optional frame)
1326 "Return a description of the color named COLOR on frame FRAME.
1327 The value is a list of integer RGB values--\(RED GREEN BLUE\).
1328 These values appear to range from 0 65535; white is \(65535 65535 65535\).
1329 If FRAME is omitted or nil, use the selected frame.
1330 If FRAME cannot display COLOR, the value is nil.
1331 If COLOR is the symbol `unspecified' or one of the strings
1332 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1333 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1335 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1336 (xw-color-values color frame)
1337 (tty-color-values color frame))))
1338 (defalias 'x-color-values 'color-values)
1340 (defun display-color-p (&optional display)
1341 "Return t if DISPLAY supports color.
1342 The optional argument DISPLAY specifies which display to ask about.
1343 DISPLAY should be either a frame or a display name (a string).
1344 If omitted or nil, that stands for the selected frame's display."
1345 (if (memq (framep-on-display display) '(x w32 mac))
1346 (xw-display-color-p display)
1347 (tty-display-color-p display)))
1348 (defalias 'x-display-color-p 'display-color-p)
1350 (defun display-grayscale-p (&optional display)
1351 "Return non-nil if frames on DISPLAY can display shades of gray."
1352 (let ((frame-type (framep-on-display display)))
1353 (cond
1354 ((memq frame-type '(x w32 mac))
1355 (x-display-grayscale-p display))
1357 (> (tty-color-gray-shades display) 2)))))
1360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1361 ;;; Background mode.
1362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1364 (defcustom frame-background-mode nil
1365 "*The brightness of the background.
1366 Set this to the symbol `dark' if your background color is dark, `light' if
1367 your background is light, or nil (default) if you want Emacs to
1368 examine the brightness for you. Don't set this variable with `setq';
1369 this won't have the expected effect."
1370 :group 'faces
1371 :set #'(lambda (var value)
1372 (set-default var value)
1373 (mapc 'frame-set-background-mode (frame-list)))
1374 :initialize 'custom-initialize-changed
1375 :type '(choice (choice-item dark)
1376 (choice-item light)
1377 (choice-item :tag "default" nil)))
1380 (defun frame-set-background-mode (frame)
1381 "Set up display-dependent faces on FRAME.
1382 Display-dependent faces are those which have different definitions
1383 according to the `background-mode' and `display-type' frame parameters."
1384 (let* ((bg-resource
1385 (and window-system
1386 (x-get-resource ".backgroundMode" "BackgroundMode")))
1387 (bg-color (frame-parameter frame 'background-color))
1388 (bg-mode
1389 (cond (frame-background-mode)
1390 (bg-resource
1391 (intern (downcase bg-resource)))
1392 ((and (null window-system) (null bg-color))
1393 ;; No way to determine this automatically (?).
1394 'dark)
1395 ;; Unspecified frame background color can only happen
1396 ;; on tty's.
1397 ((member bg-color '(unspecified "unspecified-bg"))
1398 'dark)
1399 ((equal bg-color "unspecified-fg") ; inverted colors
1400 'light)
1401 ((>= (apply '+ (x-color-values bg-color frame))
1402 ;; Just looking at the screen, colors whose
1403 ;; values add up to .6 of the white total
1404 ;; still look dark to me.
1405 (* (apply '+ (x-color-values "white" frame)) .6))
1406 'light)
1407 (t 'dark)))
1408 (display-type
1409 (cond ((null window-system)
1410 (if (tty-display-color-p frame) 'color 'mono))
1411 ((x-display-color-p frame)
1412 'color)
1413 ((x-display-grayscale-p frame)
1414 'grayscale)
1415 (t 'mono)))
1416 (old-bg-mode
1417 (frame-parameter frame 'background-mode))
1418 (old-display-type
1419 (frame-parameter frame 'display-type)))
1421 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1422 (let ((locally-modified-faces nil))
1423 ;; Before modifying the frame parameters, we collect a list of
1424 ;; faces that don't match what their face-spec says they should
1425 ;; look like; we then avoid changing these faces below. A
1426 ;; negative list is used on the assumption that most faces will
1427 ;; be unmodified, so we can avoid consing in the common case.
1428 (dolist (face (face-list))
1429 (when (not (face-spec-match-p face
1430 (face-user-default-spec face)
1431 (selected-frame)))
1432 (push face locally-modified-faces)))
1433 ;; Now change to the new frame parameters
1434 (modify-frame-parameters frame
1435 (list (cons 'background-mode bg-mode)
1436 (cons 'display-type display-type)))
1437 ;; For all named faces, choose face specs matching the new frame
1438 ;; parameters, unless they have been locally modified.
1439 (dolist (face (face-list))
1440 (unless (memq face locally-modified-faces)
1441 (face-spec-set face (face-user-default-spec face) frame)))))))
1444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1445 ;;; Frame creation.
1446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1448 (defun x-handle-named-frame-geometry (parameters)
1449 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1450 Value is the new parameter list."
1451 (let* ((name (or (cdr (assq 'name parameters))
1452 (cdr (assq 'name default-frame-alist))))
1453 (x-resource-name name)
1454 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1455 (when res-geometry
1456 (let ((parsed (x-parse-geometry res-geometry)))
1457 ;; If the resource specifies a position, call the position
1458 ;; and size "user-specified".
1459 (when (or (assq 'top parsed)
1460 (assq 'left parsed))
1461 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1462 ;; Put the geometry parameters at the end. Copy
1463 ;; default-frame-alist so that they go after it.
1464 (setq parameters (append parameters default-frame-alist parsed))))
1465 parameters))
1468 (defun x-handle-reverse-video (frame parameters)
1469 "Handle the reverse-video frame parameter and X resource.
1470 `x-create-frame' does not handle this one."
1471 (when (cdr (or (assq 'reverse parameters)
1472 (assq 'reverse default-frame-alist)
1473 (let ((resource (x-get-resource "reverseVideo"
1474 "ReverseVideo")))
1475 (if resource
1476 (cons nil (member (downcase resource)
1477 '("on" "true")))))))
1478 (let* ((params (frame-parameters frame))
1479 (bg (cdr (assq 'foreground-color params)))
1480 (fg (cdr (assq 'background-color params))))
1481 (modify-frame-parameters frame
1482 (list (cons 'foreground-color fg)
1483 (cons 'background-color bg)))
1484 (if (equal bg (cdr (assq 'border-color params)))
1485 (modify-frame-parameters frame
1486 (list (cons 'border-color fg))))
1487 (if (equal bg (cdr (assq 'mouse-color params)))
1488 (modify-frame-parameters frame
1489 (list (cons 'mouse-color fg))))
1490 (if (equal bg (cdr (assq 'cursor-color params)))
1491 (modify-frame-parameters frame
1492 (list (cons 'cursor-color fg)))))))
1495 (defun x-create-frame-with-faces (&optional parameters)
1496 "Create a frame from optional frame parameters PARAMETERS.
1497 Parameters not specified by PARAMETERS are taken from
1498 `default-frame-alist'. If PARAMETERS specify a frame name,
1499 handle X geometry resources for that name. If either PARAMETERS
1500 or `default-frame-alist' contains a `reverse' parameter, or
1501 the X resource ``reverseVideo'' is present, handle that.
1502 Value is the new frame created."
1503 (setq parameters (x-handle-named-frame-geometry parameters))
1504 (let ((visibility-spec (assq 'visibility parameters))
1505 (frame-list (frame-list))
1506 (frame (x-create-frame (cons '(visibility . nil) parameters)))
1507 success)
1508 (unwind-protect
1509 (progn
1510 (x-handle-reverse-video frame parameters)
1511 (frame-set-background-mode frame)
1512 (face-set-after-frame-default frame)
1513 (if (or (null frame-list) (null visibility-spec))
1514 (make-frame-visible frame)
1515 (modify-frame-parameters frame (list visibility-spec)))
1516 (setq success t))
1517 (unless success
1518 (delete-frame frame)))
1519 frame))
1521 (defun face-set-after-frame-default (frame)
1522 "Set frame-local faces of FRAME from face specs and resources.
1523 Initialize colors of certain faces from frame parameters."
1524 (dolist (face (face-list))
1525 (when (not (equal face 'default))
1526 (face-spec-set face (face-user-default-spec face) frame)
1527 (internal-merge-in-global-face face frame)
1528 (when (and (memq window-system '(x w32 mac))
1529 (or (not (boundp 'inhibit-default-face-x-resources))
1530 (not (eq face 'default))))
1531 (make-face-x-resource-internal face frame))))
1533 ;; Initialize attributes from frame parameters.
1534 (let ((params '((foreground-color default :foreground)
1535 (background-color default :background)
1536 (border-color border :background)
1537 (cursor-color cursor :background)
1538 (scroll-bar-foreground scroll-bar :foreground)
1539 (scroll-bar-background scroll-bar :background)
1540 (mouse-color mouse :background))))
1541 (dolist (param params)
1542 (let ((frame-param (frame-parameter frame (nth 0 param)))
1543 (face (nth 1 param))
1544 (attr (nth 2 param)))
1545 (when (and frame-param
1546 ;; Don't override face attributes explicitly
1547 ;; specified for new frames.
1548 (eq (face-attribute face attr t) 'unspecified))
1549 (set-face-attribute face frame attr frame-param))))))
1551 (defun tty-handle-reverse-video (frame parameters)
1552 "Handle the reverse-video frame parameter for terminal frames."
1553 (when (cdr (or (assq 'reverse parameters)
1554 (assq 'reverse default-frame-alist)))
1555 (let* ((params (frame-parameters frame))
1556 (bg (cdr (assq 'foreground-color params)))
1557 (fg (cdr (assq 'background-color params))))
1558 (modify-frame-parameters frame
1559 (list (cons 'foreground-color fg)
1560 (cons 'background-color bg)))
1561 (if (equal bg (cdr (assq 'mouse-color params)))
1562 (modify-frame-parameters frame
1563 (list (cons 'mouse-color fg))))
1564 (if (equal bg (cdr (assq 'cursor-color params)))
1565 (modify-frame-parameters frame
1566 (list (cons 'cursor-color fg)))))))
1569 (defun tty-create-frame-with-faces (&optional parameters)
1570 "Create a frame from optional frame parameters PARAMETERS.
1571 Parameters not specified by PARAMETERS are taken from
1572 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
1573 contains a `reverse' parameter, handle that. Value is the new frame
1574 created."
1575 (let ((frame (make-terminal-frame parameters))
1576 success)
1577 (unwind-protect
1578 (progn
1579 (tty-handle-reverse-video frame (frame-parameters frame))
1580 (frame-set-background-mode frame)
1581 (face-set-after-frame-default frame)
1582 (setq success t))
1583 (unless success
1584 (delete-frame frame)))
1585 frame))
1588 ;; Called from C function init_display to initialize faces of the
1589 ;; dumped terminal frame on startup.
1591 (defun tty-set-up-initial-frame-faces ()
1592 (let ((frame (selected-frame)))
1593 (frame-set-background-mode frame)
1594 (face-set-after-frame-default frame)))
1599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1600 ;;; Compatiblity with 20.2
1601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1603 ;; Update a frame's faces when we change its default font.
1605 (defalias 'frame-update-faces 'ignore)
1606 (make-obsolete 'frame-update-faces "No longer necessary" "21.1")
1608 ;; Update the colors of FACE, after FRAME's own colors have been
1609 ;; changed.
1611 (defalias 'frame-update-face-colors 'frame-set-background-mode)
1612 (make-obsolete 'frame-update-face-colors 'frame-set-background-mode "21.1")
1615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1616 ;;; Standard faces.
1617 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1619 (defgroup basic-faces nil
1620 "The standard faces of Emacs."
1621 :group 'faces)
1624 (defface default
1625 '((t nil))
1626 "Basic default face."
1627 :group 'basic-faces)
1630 (defface mode-line
1631 '((((type x w32 mac) (class color))
1632 (:box (:line-width -1 :style released-button)
1633 :background "grey75" :foreground "black"))
1635 (:inverse-video t)))
1636 "Basic mode line face."
1637 :version "21.1"
1638 :group 'modeline
1639 :group 'basic-faces)
1641 ;; Make `modeline' an alias for `mode-line', for compatibility.
1642 (put 'modeline 'face-alias 'mode-line)
1644 (defface header-line
1645 '((((type tty))
1646 ;; This used to be `:inverse-video t', but that doesn't look very
1647 ;; good when combined with inverse-video mode-lines and multiple
1648 ;; windows. Underlining looks better, and is more consistent with
1649 ;; the window-system face variants, which deemphasize the
1650 ;; header-line in relation to the mode-line face. If a terminal
1651 ;; can't underline, then the header-line will end up without any
1652 ;; highlighting; this may be too confusing in general, although it
1653 ;; happens to look good with the only current use of header-lines,
1654 ;; the info browser. XXX
1655 :underline t)
1656 (((class color grayscale) (background light))
1657 :inherit mode-line
1658 :background "grey90" :foreground "grey20"
1659 :box nil)
1660 (((class color grayscale) (background dark))
1661 :inherit mode-line
1662 :background "grey20" :foreground "grey90"
1663 :box nil)
1664 (((class mono) (background light))
1665 :inherit mode-line
1666 :background "white" :foreground "black"
1667 :inverse-video nil
1668 :box nil
1669 :underline t)
1670 (((class mono) (background dark))
1671 :inherit mode-line
1672 :background "black" :foreground "white"
1673 :inverse-video nil
1674 :box nil
1675 :underline t)
1677 :inverse-video t))
1678 "Basic header-line face."
1679 :version "21.1"
1680 :group 'basic-faces)
1683 (defface tool-bar
1684 '((((type x w32 mac) (class color))
1685 (:box (:line-width 1 :style released-button)
1686 :background "grey75" :foreground "black"))
1687 (((type x) (class mono))
1688 (:box (:line-width 1 :style released-button)
1689 :background "grey" :foreground "black"))
1691 ()))
1692 "Basic tool-bar face."
1693 :version "21.1"
1694 :group 'basic-faces)
1697 (defface region
1698 '((((type tty) (class color))
1699 (:background "blue" :foreground "white"))
1700 (((type tty) (class mono))
1701 (:inverse-video t))
1702 (((class color) (background dark))
1703 (:background "blue3"))
1704 (((class color) (background light))
1705 (:background "lightgoldenrod2"))
1706 (t (:background "gray")))
1707 "Basic face for highlighting the region."
1708 :version "21.1"
1709 :group 'basic-faces)
1712 (defface fringe
1713 '((((class color) (background light))
1714 (:background "grey95"))
1715 (((class color) (background dark))
1716 (:background "grey10"))
1718 (:background "gray")))
1719 "Basic face for the fringes to the left and right of windows under X."
1720 :version "21.1"
1721 :group 'frames
1722 :group 'basic-faces)
1725 (defface scroll-bar '()
1726 "Basic face for the scroll bar colors under X."
1727 :version "21.1"
1728 :group 'frames
1729 :group 'basic-faces)
1732 (defface menu
1733 '((((type tty))
1734 :inverse-video t)
1735 (((type x-toolkit))
1738 :inverse-video t))
1739 "Basic face for the font and colors of the menu bar and popup menus."
1740 :version "21.1"
1741 :group 'menu
1742 :group 'basic-faces)
1745 (defface border '()
1746 "Basic face for the frame border under X."
1747 :version "21.1"
1748 :group 'frames
1749 :group 'basic-faces)
1752 (defface cursor '()
1753 "Basic face for the cursor color under X."
1754 :version "21.1"
1755 :group 'cursor
1756 :group 'basic-faces)
1759 (defface mouse '()
1760 "Basic face for the mouse color under X."
1761 :version "21.1"
1762 :group 'mouse
1763 :group 'basic-faces)
1766 (defface bold '((t (:weight bold)))
1767 "Basic bold face."
1768 :group 'basic-faces)
1771 (defface italic '((t (:slant italic)))
1772 "Basic italic font."
1773 :group 'basic-faces)
1776 (defface bold-italic '((t (:weight bold :slant italic)))
1777 "Basic bold-italic face."
1778 :group 'basic-faces)
1781 (defface underline '((t (:underline t)))
1782 "Basic underlined face."
1783 :group 'basic-faces)
1786 (defface highlight
1787 '((((type tty) (class color))
1788 (:background "green"))
1789 (((class color) (background light))
1790 (:background "darkseagreen2"))
1791 (((class color) (background dark))
1792 (:background "darkolivegreen"))
1793 (t (:inverse-video t)))
1794 "Basic face for highlighting."
1795 :group 'basic-faces)
1798 (defface secondary-selection
1799 '((((type tty) (class color))
1800 (:background "cyan" :foreground "black"))
1801 (((class color) (background light))
1802 (:background "yellow"))
1803 (((class color) (background dark))
1804 (:background "SkyBlue4"))
1805 (t (:inverse-video t)))
1806 "Basic face for displaying the secondary selection."
1807 :group 'basic-faces)
1810 (defface fixed-pitch '((t (:family "courier")))
1811 "The basic fixed-pitch face."
1812 :group 'basic-faces)
1815 (defface variable-pitch '((t (:family "helv")))
1816 "The basic variable-pitch face."
1817 :group 'basic-faces)
1820 (defface trailing-whitespace
1821 '((((class color) (background light))
1822 (:background "red"))
1823 (((class color) (background dark))
1824 (:background "red"))
1825 (t (:inverse-video t)))
1826 "Basic face for highlighting trailing whitespace."
1827 :version "21.1"
1828 :group 'font-lock ; like `show-trailing-whitespace'
1829 :group 'basic-faces)
1833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1834 ;;; Manipulating font names.
1835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1837 ;; This is here for compatibilty with Emacs 20.2. For example,
1838 ;; international/fontset.el uses x-resolve-font-name. The following
1839 ;; functions are not used in the face implementation itself.
1841 (defvar x-font-regexp nil)
1842 (defvar x-font-regexp-head nil)
1843 (defvar x-font-regexp-weight nil)
1844 (defvar x-font-regexp-slant nil)
1846 (defconst x-font-regexp-weight-subnum 1)
1847 (defconst x-font-regexp-slant-subnum 2)
1848 (defconst x-font-regexp-swidth-subnum 3)
1849 (defconst x-font-regexp-adstyle-subnum 4)
1851 ;;; Regexps matching font names in "Host Portable Character Representation."
1853 (let ((- "[-?]")
1854 (foundry "[^-]+")
1855 (family "[^-]+")
1856 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
1857 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
1858 (weight\? "\\([^-]*\\)") ; 1
1859 (slant "\\([ior]\\)") ; 2
1860 ; (slant\? "\\([ior?*]?\\)") ; 2
1861 (slant\? "\\([^-]?\\)") ; 2
1862 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
1863 (swidth "\\([^-]*\\)") ; 3
1864 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
1865 (adstyle "\\([^-]*\\)") ; 4
1866 (pixelsize "[0-9]+")
1867 (pointsize "[0-9][0-9]+")
1868 (resx "[0-9][0-9]+")
1869 (resy "[0-9][0-9]+")
1870 (spacing "[cmp?*]")
1871 (avgwidth "[0-9]+")
1872 (registry "[^-]+")
1873 (encoding "[^-]+")
1875 (setq x-font-regexp
1876 (concat "\\`\\*?[-?*]"
1877 foundry - family - weight\? - slant\? - swidth - adstyle -
1878 pixelsize - pointsize - resx - resy - spacing - avgwidth -
1879 registry - encoding "\\*?\\'"
1881 (setq x-font-regexp-head
1882 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
1883 "\\([-*?]\\|\\'\\)"))
1884 (setq x-font-regexp-slant (concat - slant -))
1885 (setq x-font-regexp-weight (concat - weight -))
1886 nil)
1889 (defun x-resolve-font-name (pattern &optional face frame)
1890 "Return a font name matching PATTERN.
1891 All wildcards in PATTERN are instantiated.
1892 If PATTERN is nil, return the name of the frame's base font, which never
1893 contains wildcards.
1894 Given optional arguments FACE and FRAME, return a font which is
1895 also the same size as FACE on FRAME, or fail."
1896 (or (symbolp face)
1897 (setq face (face-name face)))
1898 (and (eq frame t)
1899 (setq frame nil))
1900 (if pattern
1901 ;; Note that x-list-fonts has code to handle a face with nil as its font.
1902 (let ((fonts (x-list-fonts pattern face frame 1)))
1903 (or fonts
1904 (if face
1905 (if (string-match "\\*" pattern)
1906 (if (null (face-font face))
1907 (error "No matching fonts are the same height as the frame default font")
1908 (error "No matching fonts are the same height as face `%s'" face))
1909 (if (null (face-font face))
1910 (error "Height of font `%s' doesn't match the frame default font"
1911 pattern)
1912 (error "Height of font `%s' doesn't match face `%s'"
1913 pattern face)))
1914 (error "No fonts match `%s'" pattern)))
1915 (car fonts))
1916 (cdr (assq 'font (frame-parameters (selected-frame))))))
1919 (defun x-frob-font-weight (font which)
1920 (let ((case-fold-search t))
1921 (cond ((string-match x-font-regexp font)
1922 (concat (substring font 0
1923 (match-beginning x-font-regexp-weight-subnum))
1924 which
1925 (substring font (match-end x-font-regexp-weight-subnum)
1926 (match-beginning x-font-regexp-adstyle-subnum))
1927 ;; Replace the ADD_STYLE_NAME field with *
1928 ;; because the info in it may not be the same
1929 ;; for related fonts.
1931 (substring font (match-end x-font-regexp-adstyle-subnum))))
1932 ((string-match x-font-regexp-head font)
1933 (concat (substring font 0 (match-beginning 1)) which
1934 (substring font (match-end 1))))
1935 ((string-match x-font-regexp-weight font)
1936 (concat (substring font 0 (match-beginning 1)) which
1937 (substring font (match-end 1)))))))
1938 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
1940 (defun x-frob-font-slant (font which)
1941 (let ((case-fold-search t))
1942 (cond ((string-match x-font-regexp font)
1943 (concat (substring font 0
1944 (match-beginning x-font-regexp-slant-subnum))
1945 which
1946 (substring font (match-end x-font-regexp-slant-subnum)
1947 (match-beginning x-font-regexp-adstyle-subnum))
1948 ;; Replace the ADD_STYLE_NAME field with *
1949 ;; because the info in it may not be the same
1950 ;; for related fonts.
1952 (substring font (match-end x-font-regexp-adstyle-subnum))))
1953 ((string-match x-font-regexp-head font)
1954 (concat (substring font 0 (match-beginning 2)) which
1955 (substring font (match-end 2))))
1956 ((string-match x-font-regexp-slant font)
1957 (concat (substring font 0 (match-beginning 1)) which
1958 (substring font (match-end 1)))))))
1959 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
1961 (defun x-make-font-bold (font)
1962 "Given an X font specification, make a bold version of it.
1963 If that can't be done, return nil."
1964 (x-frob-font-weight font "bold"))
1965 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
1967 (defun x-make-font-demibold (font)
1968 "Given an X font specification, make a demibold version of it.
1969 If that can't be done, return nil."
1970 (x-frob-font-weight font "demibold"))
1971 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
1973 (defun x-make-font-unbold (font)
1974 "Given an X font specification, make a non-bold version of it.
1975 If that can't be done, return nil."
1976 (x-frob-font-weight font "medium"))
1977 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
1979 (defun x-make-font-italic (font)
1980 "Given an X font specification, make an italic version of it.
1981 If that can't be done, return nil."
1982 (x-frob-font-slant font "i"))
1983 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
1985 (defun x-make-font-oblique (font) ; you say tomayto...
1986 "Given an X font specification, make an oblique version of it.
1987 If that can't be done, return nil."
1988 (x-frob-font-slant font "o"))
1989 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
1991 (defun x-make-font-unitalic (font)
1992 "Given an X font specification, make a non-italic version of it.
1993 If that can't be done, return nil."
1994 (x-frob-font-slant font "r"))
1995 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
1997 (defun x-make-font-bold-italic (font)
1998 "Given an X font specification, make a bold and italic version of it.
1999 If that can't be done, return nil."
2000 (and (setq font (x-make-font-bold font))
2001 (x-make-font-italic font)))
2002 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2004 (provide 'faces)
2006 ;;; faces.el ends here