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