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.
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)
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.
32 ;; Warning suppression -- can't require x-win in batch:
33 (autoload 'xw-defined-colors "x-win"))
35 (defvar help-xref-stack-item)
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41 (defgroup font-selection nil
42 "Influencing face font selection."
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
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
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" "gbk" "gb18030")
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" "gb18030")
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))
100 :group 'font-selection
101 :set #'(lambda (symbol value)
102 (set-default symbol value)
103 (internal-set-alternative-font-registry-alist value)))
106 (defcustom font-weight-table
107 (if (eq system-type 'windows-nt)
109 (ultralight . 200) (ultra-light . 200) (extra-light . 200)
111 (semilight . 330) (semi-light . 330)
113 (normal . 400) (regular . 400)
115 (semibold . 600) (semi-bold . 600) (demibold . 600) (demi . 600)
117 (extrabold . 800) (extra-bold . 800)
118 (ultrabold . 800) (ultra-bold . 800)
119 (black . 900) (heavy . 900))
121 (ultralight . 40) (ultra-light . 40) (extra-light . 40)
123 (semilight . 65) (semi-light . 65)
125 (medium . 100) (regular . 100) (normal . 100)
126 (semibold . 180) (semi-bold . 180) (demibold . 180) (demi . 180)
128 (extrabold . 205) (extra-bold . 205)
129 (ultrabold . 205) (ultra-bold . 205)
130 (black . 210) (heavy . 210)))
131 "*Alist of font weight symbols vs the corresponding numeric values."
132 :tag "Font weight table"
134 :group 'font-selection
135 :type '(repeat (cons symbol integer))
136 :set #'(lambda (symbol value)
137 (set-default symbol value)
138 (if (fboundp 'internal-set-font-style-table)
139 (internal-set-font-style-table :weight value))))
141 (defcustom font-slant-table
144 (r . 100) (roman . 100) (normal . 100)
145 (i . 200) (italic . 200) (ot . 200)
146 (o . 210) (oblique . 210))
147 "*Alist of font slant symbols vs the corresponding numeric values."
148 :tag "Font slant table"
150 :group 'font-selection
151 :type '(repeat (cons symbol integer))
152 :set #'(lambda (symbol value)
153 (set-default symbol value)
154 (if (fboundp 'internal-set-font-style-table)
155 (internal-set-font-style-table :slant value))))
157 (defcustom font-swidth-table
158 '((ultracondensed . 50) (ultra-condensed . 50)
159 (extracondensed . 63) (extra-condensed . 63)
160 (condensed . 75) (compressed . 75) (narrow . 75)
161 (semicondensed . 87) (semi-condensed . 87)
162 (normal . 100) (medium . 100) (regular . 100)
163 (semiexpanded . 113) (semi-expanded . 113) (demiexpanded . 113)
165 (extraexpanded . 150) (extra-expanded . 150)
166 (ultraexpanded . 200) (ultra-expanded . 200) (wide . 200))
167 "*Alist of font swidth symbols vs the corresponding numeric values."
168 :tag "Font swidth table"
170 :group 'font-selection
171 :type '(repeat (cons symbol integer))
172 :set #'(lambda (symbol value)
173 (set-default symbol value)
174 (if (fboundp 'internal-set-font-style-table)
175 (internal-set-font-style-table :width value))))
177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 ;;; Creation, copying.
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
183 "Return a list of all defined face names."
184 (mapcar #'car face-new-frame-defaults))
187 ;;; ### If not frame-local initialize by what X resources?
189 (defun make-face (face &optional no-init-from-resources)
190 "Define a new face with name FACE, a symbol.
191 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
192 variants of FACE from X resources. (X resources recognized are found
193 in the global variable `face-x-resources'.) If FACE is already known
194 as a face, leave it unmodified. Value is FACE."
195 (interactive "SMake face: ")
197 ;; Make frame-local faces (this also makes the global one).
198 (dolist (frame (frame-list))
199 (internal-make-lisp-face face frame))
200 ;; Add the face to the face menu.
201 (when (fboundp 'facemenu-add-new-face)
202 (facemenu-add-new-face face))
203 ;; Define frame-local faces for all frames from X resources.
204 (unless no-init-from-resources
205 (make-face-x-resource-internal face)))
209 (defun make-empty-face (face)
210 "Define a new, empty face with name FACE.
211 If the face already exists, it is left unmodified. Value is FACE."
212 (interactive "SMake empty face: ")
213 (make-face face 'no-init-from-resources))
216 (defun copy-face (old-face new-face &optional frame new-frame)
217 "Define a face just like OLD-FACE, with name NEW-FACE.
219 If NEW-FACE already exists as a face, it is modified to be like
220 OLD-FACE. If it doesn't already exist, it is created.
222 If the optional argument FRAME is given as a frame, NEW-FACE is
223 changed on FRAME only.
224 If FRAME is t, the frame-independent default specification for OLD-FACE
225 is copied to NEW-FACE.
226 If FRAME is nil, copying is done for the frame-independent defaults
227 and for each existing frame.
229 If the optional fourth argument NEW-FRAME is given,
230 copy the information from face OLD-FACE on frame FRAME
231 to NEW-FACE on frame NEW-FRAME. In this case, FRAME may not be nil."
232 (let ((inhibit-quit t))
236 (error "Copying face %s from all frames to one frame"
238 (make-empty-face new-face)
239 (dolist (frame (frame-list))
240 (copy-face old-face new-face frame))
241 (copy-face old-face new-face t))
242 (make-empty-face new-face)
243 (internal-copy-lisp-face old-face new-face frame new-frame))
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249 ;;; Obsolete functions
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 ;; The functions in this section are defined because Lisp packages use
253 ;; them, despite the prefix `internal-' suggesting that they are
254 ;; private to the face implementation.
256 (defun internal-find-face (name &optional frame)
257 "Retrieve the face named NAME.
258 Return nil if there is no such face.
259 If NAME is already a face, it is simply returned.
260 The optional argument FRAME is ignored."
262 (make-obsolete 'internal-find-face 'facep "21.1")
265 (defun internal-get-face (name &optional frame)
266 "Retrieve the face named NAME; error if there is none.
267 If NAME is already a face, it is simply returned.
268 The optional argument FRAME is ignored."
271 (make-obsolete 'internal-get-face "see `facep' and `check-face'." "21.1")
274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
275 ;;; Predicates, type checks.
276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
279 "Return non-nil if FACE is a face name or internal face object.
280 Return nil otherwise. A face name can be a string or a symbol.
281 An internal face object is a vector of the kind used internally
282 to record face data."
283 (internal-lisp-face-p face))
286 (defun check-face (face)
287 "Signal an error if FACE doesn't name a face.
290 (error "Not a face: %s" face))
294 ;; The ID returned is not to be confused with the internally used IDs
295 ;; of realized faces. The ID assigned to Lisp faces is used to
296 ;; support faces in display table entries.
298 (defun face-id (face &optional frame)
299 "Return the internal ID of face with name FACE.
300 If FACE is a face-alias, return the ID of the target face.
301 The optional argument FRAME is ignored, since the internal face ID
302 of a face name is the same for all frames."
305 (face-id (get face 'face-alias))))
307 (defun face-equal (face1 face2 &optional frame)
308 "Non-nil if faces FACE1 and FACE2 are equal.
309 Faces are considered equal if all their attributes are equal.
310 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
311 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
312 If FRAME is omitted or nil, use the selected frame."
313 (internal-lisp-face-equal-p face1 face2 frame))
316 (defun face-differs-from-default-p (face &optional frame)
317 "Return non-nil if FACE displays differently from the default face.
318 If the optional argument FRAME is given, report on face FACE in that frame.
319 If FRAME is t, report on the defaults for face FACE (for new frames).
320 If FRAME is omitted or nil, use the selected frame."
322 '(:family :width :height :weight :slant :foreground
323 :background :underline :overline :strike-through
324 :box :inverse-video))
326 (while (and attrs (not differs))
327 (let* ((attr (pop attrs))
328 (attr-val (face-attribute face attr frame t)))
330 (not (eq attr-val 'unspecified))
331 (display-supports-face-attributes-p (list attr attr-val)
333 (setq differs attr))))
337 (defun face-nontrivial-p (face &optional frame)
338 "True if face FACE has some non-nil attribute.
339 If the optional argument FRAME is given, report on face FACE in that frame.
340 If FRAME is t, report on the defaults for face FACE (for new frames).
341 If FRAME is omitted or nil, use the selected frame."
342 (not (internal-lisp-face-empty-p face frame)))
346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
347 ;;; Setting face attributes from X resources.
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
350 (defcustom face-x-resources
351 '((:family (".attributeFamily" . "Face.AttributeFamily"))
352 (:width (".attributeWidth" . "Face.AttributeWidth"))
353 (:height (".attributeHeight" . "Face.AttributeHeight"))
354 (:weight (".attributeWeight" . "Face.AttributeWeight"))
355 (:slant (".attributeSlant" . "Face.AttributeSlant"))
356 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
357 (:background (".attributeBackground" . "Face.AttributeBackground"))
358 (:overline (".attributeOverline" . "Face.AttributeOverline"))
359 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
360 (:box (".attributeBox" . "Face.AttributeBox"))
361 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
362 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
364 (".attributeStipple" . "Face.AttributeStipple")
365 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
366 (:bold (".attributeBold" . "Face.AttributeBold"))
367 (:italic (".attributeItalic" . "Face.AttributeItalic"))
368 (:font (".attributeFont" . "Face.AttributeFont"))
369 (:inherit (".attributeInherit" . "Face.AttributeInherit")))
370 "*List of X resources and classes for face attributes.
371 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
372 the name of a face attribute, and each ENTRY is a cons of the form
373 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
374 X resource class for the attribute."
375 :type '(repeat (cons symbol (repeat (cons string string))))
379 (defun set-face-attribute-from-resource (face attribute resource class frame)
380 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
381 Value is the attribute value specified by the resource, or nil
382 if not present. This function displays a message if the resource
383 specifies an invalid attribute."
384 (let* ((face-name (face-name face))
385 (value (internal-face-x-get-resource (concat face-name resource)
389 (internal-set-lisp-face-attribute-from-resource
390 face attribute (downcase value) frame)
392 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
393 face-name frame attribute value))))
397 (defun set-face-attributes-from-resources (face frame)
398 "Set attributes of FACE from X resources for FRAME."
399 (when (memq (framep frame) '(x w32 mac))
400 (dolist (definition face-x-resources)
401 (let ((attribute (car definition)))
402 (dolist (entry (cdr definition))
403 (set-face-attribute-from-resource face attribute (car entry)
404 (cdr entry) frame))))))
407 (defun make-face-x-resource-internal (face &optional frame)
408 "Fill frame-local FACE on FRAME from X resources.
409 FRAME nil or not specified means do it for all frames."
411 (dolist (frame (frame-list))
412 (set-face-attributes-from-resources face frame))
413 (set-face-attributes-from-resources face frame)))
417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
418 ;;; Retrieving face attributes.
419 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
421 (defun face-name (face)
422 "Return the name of face FACE."
423 (symbol-name (check-face face)))
426 (defun face-attribute (face attribute &optional frame inherit)
427 "Return the value of FACE's ATTRIBUTE on FRAME.
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 attributes directly defined by FACE are considered,
433 so the return value may be `unspecified', or a relative value.
434 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
435 faces specified by its `:inherit' attribute; however the return value
436 may still be `unspecified' or relative.
437 If INHERIT is a face or a list of faces, then the result is further merged
438 with that face (or faces), until it becomes specified and absolute.
440 To ensure that the return value is always specified and absolute, use a
441 value of `default' for INHERIT; this will resolve any unspecified or
442 relative values by merging with the `default' face (which is always
443 completely specified)."
444 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
445 (when (and inherit (face-attribute-relative-p attribute value))
446 ;; VALUE is relative, so merge with inherited faces
447 (let ((inh-from (face-attribute face :inherit frame)))
448 (unless (or (null inh-from) (eq inh-from 'unspecified))
451 (face-attribute-merged-with attribute value inh-from frame))
452 ;; The `inherit' attribute may point to non existent faces.
456 (face-attribute-relative-p attribute value))
457 ;; We should merge with INHERIT as well
458 (setq value (face-attribute-merged-with attribute value inherit frame)))
461 (defun face-attribute-merged-with (attribute value faces &optional frame)
462 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
463 FACES may be either a single face or a list of faces.
464 \[This is an internal function.]"
465 (cond ((not (face-attribute-relative-p attribute value))
470 (face-attribute-merged-with
472 (face-attribute-merged-with attribute value (car faces) frame)
476 (merge-face-attribute attribute
478 (face-attribute faces attribute frame t)))))
481 (defmacro face-attribute-specified-or (value &rest body)
482 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
483 (let ((temp (make-symbol "value")))
484 `(let ((,temp ,value))
485 (if (not (eq ,temp 'unspecified))
489 (defun face-foreground (face &optional frame inherit)
490 "Return the foreground color name of FACE, or nil if unspecified.
491 If the optional argument FRAME is given, report on face FACE in that frame.
492 If FRAME is t, report on the defaults for face FACE (for new frames).
493 If FRAME is omitted or nil, use the selected frame.
495 If INHERIT is nil, only a foreground color directly defined by FACE is
496 considered, so the return value may be nil.
497 If INHERIT is t, and FACE doesn't define a foreground color, then any
498 foreground color that FACE inherits through its `:inherit' attribute
499 is considered as well; however the return value may still be nil.
500 If INHERIT is a face or a list of faces, then it is used to try to
501 resolve an unspecified foreground color.
503 To ensure that a valid color is always returned, use a value of
504 `default' for INHERIT; this will resolve any unspecified values by
505 merging with the `default' face (which is always completely specified)."
506 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
509 (defun face-background (face &optional frame inherit)
510 "Return the background color name of FACE, or nil if unspecified.
511 If the optional argument FRAME is given, report on face FACE in that frame.
512 If FRAME is t, report on the defaults for face FACE (for new frames).
513 If FRAME is omitted or nil, use the selected frame.
515 If INHERIT is nil, only a background color directly defined by FACE is
516 considered, so the return value may be nil.
517 If INHERIT is t, and FACE doesn't define a background color, then any
518 background color that FACE inherits through its `:inherit' attribute
519 is considered as well; however the return value may still be nil.
520 If INHERIT is a face or a list of faces, then it is used to try to
521 resolve an unspecified background color.
523 To ensure that a valid color is always returned, use a value of
524 `default' for INHERIT; this will resolve any unspecified values by
525 merging with the `default' face (which is always completely specified)."
526 (face-attribute-specified-or (face-attribute face :background frame inherit)
529 (defun face-stipple (face &optional frame inherit)
530 "Return the stipple pixmap name of FACE, or nil if unspecified.
531 If the optional argument FRAME is given, report on face FACE in that frame.
532 If FRAME is t, report on the defaults for face FACE (for new frames).
533 If FRAME is omitted or nil, use the selected frame.
535 If INHERIT is nil, only a stipple directly defined by FACE is
536 considered, so the return value may be nil.
537 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
538 that FACE inherits through its `:inherit' attribute is considered as
539 well; however the return value may still be nil.
540 If INHERIT is a face or a list of faces, then it is used to try to
541 resolve an unspecified stipple.
543 To ensure that a valid stipple or nil is always returned, use a value of
544 `default' for INHERIT; this will resolve any unspecified values by merging
545 with the `default' face (which is always completely specified)."
546 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
550 (defalias 'face-background-pixmap 'face-stipple)
553 (defun face-underline-p (face &optional frame)
554 "Return non-nil if FACE is underlined.
555 If the optional argument FRAME is given, report on face FACE in that frame.
556 If FRAME is t, report on the defaults for face FACE (for new frames).
557 If FRAME is omitted or nil, use the selected frame."
558 (eq (face-attribute face :underline frame) t))
561 (defun face-inverse-video-p (face &optional frame)
562 "Return non-nil if FACE is in inverse video on FRAME.
563 If the optional argument FRAME is given, report on face FACE in that frame.
564 If FRAME is t, report on the defaults for face FACE (for new frames).
565 If FRAME is omitted or nil, use the selected frame."
566 (eq (face-attribute face :inverse-video frame) t))
569 (defun face-bold-p (face &optional frame)
570 "Return non-nil if the font of FACE is bold on FRAME.
571 If the optional argument FRAME is given, report on face FACE in that frame.
572 If FRAME is t, report on the defaults for face FACE (for new frames).
573 If FRAME is omitted or nil, use the selected frame.
574 Use `face-attribute' for finer control."
575 (let ((bold (face-attribute face :weight frame)))
576 (memq bold '(semi-bold bold extra-bold ultra-bold))))
579 (defun face-italic-p (face &optional frame)
580 "Return non-nil if the font of FACE is italic on FRAME.
581 If the optional argument FRAME is given, report on face FACE in that frame.
582 If FRAME is t, report on the defaults for face FACE (for new frames).
583 If FRAME is omitted or nil, use the selected frame.
584 Use `face-attribute' for finer control."
585 (let ((italic (face-attribute face :slant frame)))
586 (memq italic '(italic oblique))))
590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
591 ;;; Face documentation.
592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
594 (defun face-documentation (face)
595 "Get the documentation string for FACE.
596 If FACE is a face-alias, get the documentation for the target face."
597 (let ((alias (get face 'face-alias))
601 (setq doc (get alias 'face-documentation))
602 (format "%s is an alias for the face `%s'.%s" face alias
603 (if doc (format "\n%s" doc)
605 (get face 'face-documentation))))
608 (defun set-face-documentation (face string)
609 "Set the documentation string for FACE to STRING."
610 ;; Perhaps the text should go in DOC.
611 (put face 'face-documentation (purecopy string)))
614 (defalias 'face-doc-string 'face-documentation)
615 (defalias 'set-face-doc-string 'set-face-documentation)
619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
620 ;; Setting face attributes.
621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
624 (defvar inhibit-face-set-after-frame-default nil
625 "If non-nil, that tells `face-set-after-frame-default' to do nothing.")
627 (defun set-face-attribute (face frame &rest args)
628 "Set attributes of FACE on FRAME from ARGS.
630 FRAME nil means change attributes on all frames. FRAME t means change
631 the default for new frames (this is done automatically each time an
632 attribute is changed on all frames).
634 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
635 face attribute name. All attributes can be set to `unspecified';
636 this fact is not further mentioned below.
638 The following attributes are recognized:
642 VALUE must be a string specifying the font family, e.g. ``courier'',
643 or a fontset alias name. If a font family is specified, wild-cards `*'
648 VALUE specifies the relative proportionate width of the font to use.
649 It must be one of the symbols `ultra-condensed', `extra-condensed',
650 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
651 `extra-expanded', or `ultra-expanded'.
655 VALUE must be either an integer specifying the height of the font to use
656 in 1/10 pt, a floating point number specifying the amount by which to
657 scale any underlying face, or a function, which is called with the old
658 height (from the underlying face), and should return the new height.
662 VALUE specifies the weight of the font to use. It must be one of the
663 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
664 `semi-light', `light', `extra-light', `ultra-light'.
668 VALUE specifies the slant of the font to use. It must be one of the
669 symbols `italic', `oblique', `normal', `reverse-italic', or
672 `:foreground', `:background'
674 VALUE must be a color name, a string.
678 VALUE specifies whether characters in FACE should be underlined. If
679 VALUE is t, underline with foreground color of the face. If VALUE is
680 a string, underline with that color. If VALUE is nil, explicitly
685 VALUE specifies whether characters in FACE should be overlined. If
686 VALUE is t, overline with foreground color of the face. If VALUE is a
687 string, overline with that color. If VALUE is nil, explicitly don't
692 VALUE specifies whether characters in FACE should be drawn with a line
693 striking through them. If VALUE is t, use the foreground color of the
694 face. If VALUE is a string, strike-through with that color. If VALUE
695 is nil, explicitly don't strike through.
699 VALUE specifies whether characters in FACE should have a box drawn
700 around them. If VALUE is nil, explicitly don't draw boxes. If
701 VALUE is t, draw a box with lines of width 1 in the foreground color
702 of the face. If VALUE is a string, the string must be a color name,
703 and the box is drawn in that color with a line width of 1. Otherwise,
704 VALUE must be a property list of the form `(:line-width WIDTH
705 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
706 the property list, a default value will be used for the value, as
707 specified below. WIDTH specifies the width of the lines to draw; it
708 defaults to 1. If WIDTH is negative, the absolute value is the width
709 of the lines, and draw top/bottom lines inside the characters area,
710 not around it. COLOR is the name of the color to draw in, default is
711 the foreground color of the face for simple boxes, and the background
712 color of the face for 3D boxes. STYLE specifies whether a 3D box
713 should be draw. If STYLE is `released-button', draw a box looking
714 like a released 3D button. If STYLE is `pressed-button' draw a box
715 that appears like a pressed button. If STYLE is nil, the default if
716 the property list doesn't contain a style specification, draw a 2D
721 VALUE specifies whether characters in FACE should be displayed in
722 inverse video. VALUE must be one of t or nil.
726 If VALUE is a string, it must be the name of a file of pixmap data.
727 The directories listed in the `x-bitmap-file-path' variable are
728 searched. Alternatively, VALUE may be a list of the form (WIDTH
729 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
730 is a string containing the raw bits of the bitmap. VALUE nil means
731 explicitly don't use a stipple pattern.
733 For convenience, attributes `:family', `:width', `:height', `:weight',
734 and `:slant' may also be set in one step from an X font name:
738 Set font-related face attributes from VALUE. VALUE must be a valid
739 XLFD font name. If it is a font name pattern, the first matching font
742 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
743 be used to specify that a bold or italic font should be used. VALUE
744 must be t or nil in that case. A value of `unspecified' is not allowed.
748 VALUE is the name of a face from which to inherit attributes, or a list
749 of face names. Attributes from inherited faces are merged into the face
750 like an underlying face would be, with higher priority than underlying faces."
751 (let ((where (if (null frame) 0 frame)))
752 (setq args (purecopy args))
753 ;; If we set the new-frame defaults, this face is modified outside Custom.
754 (if (memq where '(0 t))
755 (put (or (get face 'face-alias) face) 'face-modified t))
757 ;; Don't recursively set the attributes from the frame's font param
758 ;; when we update the frame's font param fro the attributes.
759 (let ((inhibit-face-set-after-frame-default t))
760 (internal-set-lisp-face-attribute face (car args)
761 (purecopy (cadr args))
763 (setq args (cdr (cdr args))))))
766 (defun make-face-bold (face &optional frame noerror)
767 "Make the font of FACE be bold, if possible.
768 FRAME nil or not specified means change face on all frames.
769 Argument NOERROR is ignored and retained for compatibility.
770 Use `set-face-attribute' for finer control of the font weight."
771 (interactive (list (read-face-name "Make which face bold")))
772 (set-face-attribute face frame :weight 'bold))
775 (defun make-face-unbold (face &optional frame noerror)
776 "Make the font of FACE be non-bold, if possible.
777 FRAME nil or not specified means change face on all frames.
778 Argument NOERROR is ignored and retained for compatibility."
779 (interactive (list (read-face-name "Make which face non-bold")))
780 (set-face-attribute face frame :weight 'normal))
783 (defun make-face-italic (face &optional frame noerror)
784 "Make the font of FACE be italic, if possible.
785 FRAME nil or not specified means change face on all frames.
786 Argument NOERROR is ignored and retained for compatibility.
787 Use `set-face-attribute' for finer control of the font slant."
788 (interactive (list (read-face-name "Make which face italic")))
789 (set-face-attribute face frame :slant 'italic))
792 (defun make-face-unitalic (face &optional frame noerror)
793 "Make the font of FACE be non-italic, if possible.
794 FRAME nil or not specified means change face on all frames.
795 Argument NOERROR is ignored and retained for compatibility."
796 (interactive (list (read-face-name "Make which face non-italic")))
797 (set-face-attribute face frame :slant 'normal))
800 (defun make-face-bold-italic (face &optional frame noerror)
801 "Make the font of FACE be bold and italic, if possible.
802 FRAME nil or not specified means change face on all frames.
803 Argument NOERROR is ignored and retained for compatibility.
804 Use `set-face-attribute' for finer control of font weight and slant."
805 (interactive (list (read-face-name "Make which face bold-italic")))
806 (set-face-attribute face frame :weight 'bold :slant 'italic))
809 (defun set-face-font (face font &optional frame)
810 "Change font-related attributes of FACE to those of FONT (a string).
811 FRAME nil or not specified means change face on all frames.
812 This sets the attributes `:family', `:width', `:height', `:weight',
813 and `:slant'. When called interactively, prompt for the face and font."
814 (interactive (read-face-and-attribute :font))
815 (set-face-attribute face frame :font font))
818 ;; Implementation note: Emulating gray background colors with a
819 ;; stipple pattern is now part of the face realization process, and is
820 ;; done in C depending on the frame on which the face is realized.
822 (defun set-face-background (face color &optional frame)
823 "Change the background color of face FACE to COLOR (a string).
824 FRAME nil or not specified means change face on all frames.
825 COLOR can be a system-defined color name (see `list-colors-display')
826 or a hex spec of the form #RRGGBB.
827 When called interactively, prompts for the face and color."
828 (interactive (read-face-and-attribute :background))
829 (set-face-attribute face frame :background (or color 'unspecified)))
832 (defun set-face-foreground (face color &optional frame)
833 "Change the foreground color of face FACE to COLOR (a string).
834 FRAME nil or not specified means change face on all frames.
835 COLOR can be a system-defined color name (see `list-colors-display')
836 or a hex spec of the form #RRGGBB.
837 When called interactively, prompts for the face and color."
838 (interactive (read-face-and-attribute :foreground))
839 (set-face-attribute face frame :foreground (or color 'unspecified)))
842 (defun set-face-stipple (face stipple &optional frame)
843 "Change the stipple pixmap of face FACE to STIPPLE.
844 FRAME nil or not specified means change face on all frames.
845 STIPPLE should be a string, the name of a file of pixmap data.
846 The directories listed in the `x-bitmap-file-path' variable are searched.
848 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
849 where WIDTH and HEIGHT are the size in pixels,
850 and DATA is a string, containing the raw bits of the bitmap."
851 (interactive (read-face-and-attribute :stipple))
852 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
855 (defun set-face-underline-p (face underline &optional frame)
856 "Specify whether face FACE is underlined.
857 UNDERLINE nil means FACE explicitly doesn't underline.
858 UNDERLINE non-nil means FACE explicitly does underlining
859 with the same of the foreground color.
860 If UNDERLINE is a string, underline with the color named UNDERLINE.
861 FRAME nil or not specified means change face on all frames.
862 Use `set-face-attribute' to ``unspecify'' underlining."
864 (let ((list (read-face-and-attribute :underline)))
865 (list (car list) (eq (car (cdr list)) t))))
866 (set-face-attribute face frame :underline underline))
868 (define-obsolete-function-alias 'set-face-underline
869 'set-face-underline-p "22.1")
872 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
873 "Specify whether face FACE is in inverse video.
874 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
875 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
876 FRAME nil or not specified means change face on all frames.
877 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
879 (let ((list (read-face-and-attribute :inverse-video)))
880 (list (car list) (eq (car (cdr list)) t))))
881 (set-face-attribute face frame :inverse-video inverse-video-p))
884 (defun set-face-bold-p (face bold-p &optional frame)
885 "Specify whether face FACE is bold.
886 BOLD-P non-nil means FACE should explicitly display bold.
887 BOLD-P nil means FACE should explicitly display non-bold.
888 FRAME nil or not specified means change face on all frames.
889 Use `set-face-attribute' or `modify-face' for finer control."
891 (make-face-unbold face frame)
892 (make-face-bold face frame)))
895 (defun set-face-italic-p (face italic-p &optional frame)
896 "Specify whether face FACE is italic.
897 ITALIC-P non-nil means FACE should explicitly display italic.
898 ITALIC-P nil means FACE should explicitly display non-italic.
899 FRAME nil or not specified means change face on all frames.
900 Use `set-face-attribute' or `modify-face' for finer control."
902 (make-face-unitalic face frame)
903 (make-face-italic face frame)))
906 (defalias 'set-face-background-pixmap 'set-face-stipple)
909 (defun invert-face (face &optional frame)
910 "Swap the foreground and background colors of FACE.
911 If FRAME is omitted or nil, it means change face on all frames.
912 If FACE specifies neither foreground nor background color,
913 set its foreground and background to the background and foreground
914 of the default face. Value is FACE."
915 (interactive (list (read-face-name "Invert face")))
916 (let ((fg (face-attribute face :foreground frame))
917 (bg (face-attribute face :background frame)))
918 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
919 (set-face-attribute face frame :foreground bg :background fg)
920 (set-face-attribute face frame
922 (face-attribute 'default :background frame)
924 (face-attribute 'default :foreground frame))))
928 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
929 ;;; Interactively modifying faces.
930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
932 (defun read-face-name (prompt &optional string-describing-default multiple)
933 "Read a face, defaulting to the face or faces on the char after point.
934 If it has the property `read-face-name', that overrides the `face' property.
935 PROMPT should be a string that describes what the caller will do with the face;
936 it should not end in a space.
937 STRING-DESCRIBING-DEFAULT should describe what default the caller will use if
938 the user just types RET; you can omit it.
939 If MULTIPLE is non-nil, return a list of faces (possibly only one).
940 Otherwise, return a single face."
941 (let ((faceprop (or (get-char-property (point) 'read-face-name)
942 (get-char-property (point) 'face)))
946 ;; Try to get a face name from the buffer.
947 (if (memq (intern-soft (thing-at-point 'symbol)) (face-list))
948 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
949 ;; Add the named faces that the `face' property uses.
950 (if (and (listp faceprop)
951 ;; Don't treat an attribute spec as a list of faces.
952 (not (keywordp (car faceprop)))
953 (not (memq (car faceprop) '(foreground-color background-color))))
957 (if (symbolp faceprop)
958 (push faceprop faces)))
961 ;; Build up the completion tables.
962 (mapatoms (lambda (s)
964 (if (get s 'face-alias)
965 (push (symbol-name s) aliasfaces)
966 (push (symbol-name s) nonaliasfaces)))))
968 ;; If we only want one, and the default is more than one,
969 ;; discard the unwanted ones now.
972 (setq faces (list (car faces)))))
976 (completing-read-multiple
977 (if (or faces string-describing-default)
978 (format "%s (default %s): " prompt
979 (if faces (mapconcat 'symbol-name faces ",")
980 string-describing-default))
981 (format "%s: " prompt))
982 (complete-in-turn nonaliasfaces aliasfaces)
984 (if faces (mapconcat 'symbol-name faces ","))))
985 ;; Canonicalize the output.
987 (cond ((or (equal input "") (equal input '("")))
990 (mapcar 'intern (split-string input ", *" t)))
992 (mapcar 'intern input))
994 ;; Return either a list of faces or just one face.
1000 (defun face-valid-attribute-values (attribute &optional frame)
1001 "Return valid values for face attribute ATTRIBUTE.
1002 The optional argument FRAME is used to determine available fonts
1003 and colors. If it is nil or not specified, the selected frame is
1004 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
1005 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
1010 (if (window-system frame)
1011 (mapcar #'(lambda (x) (cons (car x) (car x)))
1012 (x-font-family-list))
1013 ;; Only one font on TTYs.
1014 (list (cons "default" "default"))))
1015 ((:width :weight :slant :inverse-video)
1016 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1017 (internal-lisp-face-attribute-values attribute)))
1018 ((:underline :overline :strike-through :box)
1019 (if (window-system frame)
1020 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
1021 (internal-lisp-face-attribute-values attribute))
1022 (mapcar #'(lambda (c) (cons c c))
1023 (defined-colors frame)))
1024 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1025 (internal-lisp-face-attribute-values attribute))))
1026 ((:foreground :background)
1027 (mapcar #'(lambda (c) (cons c c))
1028 (defined-colors frame)))
1032 (and (memq (window-system frame) '(x w32 mac))
1035 (mapcar (lambda (dir)
1036 (and (file-readable-p dir)
1037 (file-directory-p dir)
1038 (directory-files dir)))
1039 x-bitmap-file-path)))))
1041 (cons '("none" . nil)
1042 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1045 (error "Internal error")))))
1046 (if (and (listp valid) (not (memq attribute '(:inherit))))
1047 (nconc (list (cons "unspecified" 'unspecified)) valid)
1051 (defvar face-attribute-name-alist
1052 '((:family . "font family")
1053 (:width . "character set width")
1054 (:height . "height in 1/10 pt")
1055 (:weight . "weight")
1057 (:underline . "underline")
1058 (:overline . "overline")
1059 (:strike-through . "strike-through")
1061 (:inverse-video . "inverse-video display")
1062 (:foreground . "foreground color")
1063 (:background . "background color")
1064 (:stipple . "background stipple")
1065 (:inherit . "inheritance"))
1066 "An alist of descriptive names for face attributes.
1067 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1068 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1069 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1072 (defun face-descriptive-attribute-name (attribute)
1073 "Return a descriptive name for ATTRIBUTE."
1074 (cdr (assq attribute face-attribute-name-alist)))
1077 (defun face-read-string (face default name &optional completion-alist)
1078 "Interactively read a face attribute string value.
1079 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1080 default string to return if no new value is entered. NAME is a
1081 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1082 alist of valid values, if non-nil.
1084 Entering nothing accepts the default string DEFAULT.
1085 Value is the new attribute value."
1086 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1087 ;; each word in a string separately).
1088 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1089 (let* ((completion-ignore-case t)
1090 (value (completing-read
1092 (format "%s for face `%s' (default %s): "
1094 (format "%s for face `%s': " name face))
1095 completion-alist nil nil nil nil default)))
1096 (if (equal value "") default value)))
1099 (defun face-read-integer (face default name)
1100 "Interactively read an integer face attribute value.
1101 FACE is the face whose attribute is read. DEFAULT is the default
1102 value to return if no new value is entered. NAME is a descriptive
1103 name of the attribute for prompting. Value is the new attribute value."
1105 (face-read-string face
1106 (format "%s" default)
1108 (list (cons "unspecified" 'unspecified)))))
1109 (cond ((equal new-value "unspecified")
1111 ((member new-value '("unspecified-fg" "unspecified-bg"))
1114 (string-to-number new-value)))))
1117 (defun read-face-attribute (face attribute &optional frame)
1118 "Interactively read a new value for FACE's ATTRIBUTE.
1119 Optional argument FRAME nil or unspecified means read an attribute value
1120 of a global face. Value is the new attribute value."
1121 (let* ((old-value (face-attribute face attribute frame))
1122 (attribute-name (face-descriptive-attribute-name attribute))
1123 (valid (face-valid-attribute-values attribute frame))
1125 ;; Represent complex attribute values as strings by printing them
1126 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1127 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1129 (when (and (or (eq attribute :stipple)
1130 (eq attribute :box))
1131 (or (consp old-value)
1132 (vectorp old-value)))
1133 (setq old-value (prin1-to-string old-value)))
1134 (cond ((listp valid)
1136 (or (car (rassoc old-value valid))
1137 (format "%s" old-value))))
1139 (face-read-string face default attribute-name valid))
1140 (if (equal new-value default)
1141 ;; Nothing changed, so don't bother with all the stuff
1142 ;; below. In particular, this avoids a non-tty color
1143 ;; from being canonicalized for a tty when the user
1144 ;; just uses the default.
1145 (setq new-value old-value)
1146 ;; Terminal frames can support colors that don't appear
1147 ;; explicitly in VALID, using color approximation code
1148 ;; in tty-colors.el.
1149 (when (and (memq attribute '(:foreground :background))
1150 (not (memq (window-system frame) '(x w32 mac)))
1151 (not (member new-value
1153 "unspecified-fg" "unspecified-bg"))))
1154 (setq new-value (car (tty-color-desc new-value frame))))
1155 (when (assoc new-value valid)
1156 (setq new-value (cdr (assoc new-value valid)))))))
1157 ((eq valid 'integerp)
1158 (setq new-value (face-read-integer face old-value attribute-name)))
1159 (t (error "Internal error")))
1160 ;; Convert stipple and box value text we read back to a list or
1161 ;; vector if it looks like one. This makes the assumption that a
1162 ;; pixmap file name won't start with an open-paren.
1163 (when (and (or (eq attribute :stipple)
1164 (eq attribute :box))
1166 (string-match "^[[(]" new-value))
1167 (setq new-value (read new-value)))
1171 (defun read-face-font (face &optional frame)
1172 "Read the name of a font for FACE on FRAME.
1173 If optional argument FRAME is nil or omitted, use the selected frame."
1174 (let ((completion-ignore-case t))
1175 (completing-read (format "Set font attributes of face `%s' from font: " face)
1176 (append (fontset-list) (x-list-fonts "*" nil frame)))))
1179 (defun read-all-face-attributes (face &optional frame)
1180 "Interactively read all attributes for FACE.
1181 If optional argument FRAME is nil or omitted, use the selected frame.
1182 Value is a property list of attribute names and new values."
1184 (dolist (attribute face-attribute-name-alist result)
1185 (setq result (cons (car attribute)
1186 (cons (read-face-attribute face (car attribute) frame)
1189 (defun modify-face (&optional face foreground background stipple
1190 bold-p italic-p underline inverse-p frame)
1191 "Modify attributes of faces interactively.
1192 If optional argument FRAME is nil or omitted, modify the face used
1193 for newly created frame, i.e. the global face.
1194 For non-interactive use, `set-face-attribute' is preferred.
1195 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1196 and the face and its settings are obtained by querying the user."
1199 (set-face-attribute face frame
1200 :foreground (or foreground 'unspecified)
1201 :background (or background 'unspecified)
1205 :underline underline
1206 :inverse-video inverse-p)
1207 (setq face (read-face-name "Modify face"))
1208 (apply #'set-face-attribute face frame
1209 (read-all-face-attributes face frame))))
1211 (defun read-face-and-attribute (attribute &optional frame)
1212 "Read face name and face attribute value.
1213 ATTRIBUTE is the attribute whose new value is read.
1214 FRAME nil or unspecified means read attribute value of global face.
1215 Value is a list (FACE NEW-VALUE) where FACE is the face read
1216 \(a symbol), and NEW-VALUE is value read."
1217 (cond ((eq attribute :font)
1218 (let* ((prompt "Set font-related attributes of face")
1219 (face (read-face-name prompt))
1220 (font (read-face-font face frame)))
1223 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1224 (prompt (format "Set %s of face" attribute-name))
1225 (face (read-face-name prompt))
1226 (new-value (read-face-attribute face attribute frame)))
1227 (list face new-value)))))
1231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1235 (defvar list-faces-sample-text
1236 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1237 "*Text string to display as the sample text for `list-faces-display'.")
1240 ;; The name list-faces would be more consistent, but let's avoid a
1241 ;; conflict with Lucid, which uses that name differently.
1243 (defvar help-xref-stack)
1244 (defun list-faces-display (&optional regexp)
1245 "List all faces, using the same sample text in each.
1246 The sample text is a string that comes from the variable
1247 `list-faces-sample-text'.
1249 If REGEXP is non-nil, list only those faces with names matching
1250 this regular expression. When called interactively with a prefix
1251 arg, prompt for a regular expression."
1252 (interactive (list (and current-prefix-arg
1253 (read-string "List faces matching regexp: "))))
1254 (let ((all-faces (zerop (length regexp)))
1255 (frame (selected-frame))
1258 disp-frame window face-name)
1259 ;; We filter and take the max length in one pass
1263 (let ((s (symbol-name f)))
1264 (when (or all-faces (string-match regexp s))
1265 (setq max-length (max (length s) max-length))
1267 (sort (face-list) #'string-lessp))))
1269 (error "No faces matching \"%s\"" regexp))
1270 (setq max-length (1+ max-length)
1271 line-format (format "%%-%ds" max-length))
1272 (with-help-window "*Faces*"
1274 (set-buffer standard-output)
1275 (setq truncate-lines t)
1277 (substitute-command-keys
1280 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1281 "\\[help-follow] on a face name to customize it\n"
1282 "or on its sample text for a description of the face.\n\n")))
1283 (setq help-xref-stack nil)
1284 (dolist (face faces)
1285 (setq face-name (symbol-name face))
1286 (insert (format line-format face-name))
1287 ;; Hyperlink to a customization buffer for the face. Using
1288 ;; the help xref mechanism may not be the best way.
1291 (search-backward face-name)
1292 (setq help-xref-stack-item `(list-faces-display ,regexp))
1293 (help-xref-button 0 'help-customize-face face)))
1295 (line-beg (line-beginning-position)))
1296 (insert list-faces-sample-text)
1297 ;; Hyperlink to a help buffer for the face.
1300 (search-backward list-faces-sample-text)
1301 (help-xref-button 0 'help-face face)))
1303 (put-text-property beg (1- (point)) 'face face)
1304 ;; Make all face commands default to the proper face
1305 ;; anywhere in the line.
1306 (put-text-property line-beg (1- (point)) 'read-face-name face)
1307 ;; If the sample text has multiple lines, line up all of them.
1311 (insert-char ?\s max-length)
1313 (goto-char (point-min))))
1314 ;; If the *Faces* buffer appears in a different frame,
1315 ;; copy all the face definitions from FRAME,
1316 ;; so that the display will reflect the frame that was selected.
1317 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1318 (setq disp-frame (if window (window-frame window)
1319 (car (frame-list))))
1320 (or (eq frame disp-frame)
1321 (let ((faces (face-list)))
1323 (copy-face (car faces) (car faces) frame disp-frame)
1324 (setq faces (cdr faces)))))))
1327 (defun describe-face (face &optional frame)
1328 "Display the properties of face FACE on FRAME.
1329 Interactively, FACE defaults to the faces of the character after point
1330 and FRAME defaults to the selected frame.
1332 If the optional argument FRAME is given, report on face FACE in that frame.
1333 If FRAME is t, report on the defaults for face FACE (for new frames).
1334 If FRAME is omitted or nil, use the selected frame."
1335 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1336 (let* ((attrs '((:family . "Family")
1338 (:height . "Height")
1339 (:weight . "Weight")
1341 (:foreground . "Foreground")
1342 (:background . "Background")
1343 (:underline . "Underline")
1344 (:overline . "Overline")
1345 (:strike-through . "Strike-through")
1347 (:inverse-video . "Inverse")
1348 (:stipple . "Stipple")
1350 (:fontset . "Fontset")
1351 (:inherit . "Inherit")))
1352 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1354 (help-setup-xref (list #'describe-face face) (interactive-p))
1356 (setq face 'default))
1357 (if (not (listp face))
1358 (setq face (list face)))
1359 (with-help-window (help-buffer)
1361 (set-buffer standard-output)
1363 (if (stringp f) (setq f (intern f)))
1364 (insert "Face: " (symbol-name f))
1366 (insert " undefined face.\n")
1367 (let ((customize-label "customize this face")
1369 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1370 (princ (concat " (" customize-label ")\n"))
1371 (insert "Documentation: "
1372 (or (face-documentation f)
1373 "Not documented as a face.")
1375 (with-current-buffer standard-output
1378 (concat "\\(" customize-label "\\)") nil t)
1379 (help-xref-button 1 'help-customize-face f)))
1380 ;; The next 4 sexps are copied from describe-function-1
1382 (setq file-name (symbol-file f 'defface))
1383 (setq file-name (describe-simplify-lib-file-name file-name))
1385 (princ "Defined in `")
1388 ;; Make a hyperlink to the library.
1390 (re-search-backward "`\\([^`']+\\)'" nil t)
1391 (help-xref-button 1 'help-face-def f file-name))
1396 (let ((attr (face-attribute f (car a) frame)))
1397 (insert (make-string (- max-width (length (cdr a))) ?\s)
1398 (cdr a) ": " (format "%s" attr))
1399 (if (and (eq (car a) :inherit)
1400 (not (eq attr 'unspecified)))
1401 ;; Make a hyperlink to the parent face.
1403 (re-search-backward ": \\([^:]+\\)" nil t)
1404 (help-xref-button 1 'help-face attr)))
1409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1410 ;;; Face specifications (defface).
1411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1413 ;; Parameter FRAME Is kept for call compatibility to with previous
1414 ;; face implementation.
1416 (defun face-attr-construct (face &optional frame)
1417 "Return a `defface'-style attribute list for FACE on FRAME.
1418 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1419 face attributes of FACE where ATTRIBUTE is the attribute name and
1420 VALUE is the specified value of that attribute."
1422 (dolist (entry face-attribute-name-alist result)
1423 (let* ((attribute (car entry))
1424 (value (face-attribute face attribute)))
1425 (unless (eq value 'unspecified)
1426 (setq result (nconc (list attribute value) result)))))))
1429 (defun face-spec-set-match-display (display frame)
1430 "Non-nil if DISPLAY matches FRAME.
1431 DISPLAY is part of a spec such as can be used in `defface'.
1432 If FRAME is nil, the current FRAME is used."
1433 (let* ((conjuncts display)
1434 conjunct req options
1435 ;; t means we have succeeded against all the conjuncts in
1436 ;; DISPLAY that have been tested so far.
1438 (if (eq conjuncts t)
1439 (setq conjuncts nil))
1440 (while (and conjuncts match)
1441 (setq conjunct (car conjuncts)
1442 conjuncts (cdr conjuncts)
1444 options (cdr conjunct)
1445 match (cond ((eq req 'type)
1446 (or (memq (window-system frame) options)
1447 ;; FIXME: This should be revisited to use
1448 ;; display-graphic-p, provided that the
1449 ;; color selection depends on the number
1450 ;; of supported colors, and all defface's
1451 ;; are changed to look at number of colors
1452 ;; instead of (type graphic) etc.
1453 (and (null (window-system frame))
1454 (memq 'tty options))
1455 (and (memq 'motif options)
1457 (and (memq 'gtk options)
1459 (and (memq 'lucid options)
1460 (featurep 'x-toolkit)
1461 (not (featurep 'motif))
1462 (not (featurep 'gtk)))
1463 (and (memq 'x-toolkit options)
1464 (featurep 'x-toolkit))))
1465 ((eq req 'min-colors)
1466 (>= (display-color-cells frame) (car options)))
1468 (memq (frame-parameter frame 'display-type) options))
1469 ((eq req 'background)
1470 (memq (frame-parameter frame 'background-mode)
1473 (display-supports-face-attributes-p options frame))
1474 (t (error "Unknown req `%S' with options `%S'"
1479 (defun face-spec-choose (spec &optional frame)
1480 "Choose the proper attributes for FRAME, out of SPEC.
1481 If SPEC is nil, return nil."
1483 (setq frame (selected-frame)))
1487 (let* ((entry (pop tail))
1488 (display (car entry))
1491 ;; Get the attributes as actually specified by this alternative.
1493 (if (null (cdr attrs)) ;; was (listp (car attrs))
1494 ;; Old-style entry, the attribute list is the
1499 ;; If the condition is `default', that sets the default
1500 ;; for following conditions.
1501 (if (eq display 'default)
1502 (setq defaults thisval)
1503 ;; Otherwise, if it matches, use it.
1504 (when (face-spec-set-match-display display frame)
1505 (setq result thisval)
1507 (if defaults (append result defaults) result)))
1510 (defun face-spec-reset-face (face &optional frame)
1511 "Reset all attributes of FACE on FRAME to unspecified."
1512 (let ((attrs face-attribute-name-alist))
1514 (let ((attr-and-name (car attrs)))
1515 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1516 (setq attrs (cdr attrs)))))
1519 (defun face-spec-set (face spec &optional frame)
1520 "Set FACE's attributes according to the first matching entry in SPEC.
1521 FRAME is the frame whose frame-local face is set. FRAME nil means
1522 do it on all frames (and change the default for new frames).
1523 See `defface' for information about SPEC. If SPEC is nil, do nothing."
1524 (let ((attrs (face-spec-choose spec frame)))
1526 (face-spec-reset-face face (or frame t)))
1528 (let ((attribute (car attrs))
1529 (value (car (cdr attrs))))
1530 ;; Support some old-style attribute names and values.
1532 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1533 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1534 ((:foreground :background)
1535 ;; Compatibility with 20.x. Some bogus face specs seem to
1536 ;; exist containing things like `:foreground nil'.
1537 (if (null value) (setq value 'unspecified)))
1538 (t (unless (assq attribute face-x-resources)
1539 (setq attribute nil))))
1541 ;; If frame is nil, set the default for new frames.
1542 ;; Existing frames are handled below.
1543 (set-face-attribute face (or frame t) attribute value)))
1544 (setq attrs (cdr (cdr attrs)))))
1546 ;; When we reset the face based on its spec, then it is unmodified
1547 ;; as far as Custom is concerned.
1548 (put (or (get face 'face-alias) face) 'face-modified nil)
1549 ;;; ;; Clear all the new-frame defaults for this face.
1550 ;;; ;; face-spec-reset-face won't do it right.
1551 ;;; (let ((facevec (cdr (assq face face-new-frame-defaults))))
1552 ;;; (dotimes (i (length facevec))
1554 ;;; (aset facevec i 'unspecified))))
1555 ;; Set each frame according to the rules implied by SPEC.
1556 (dolist (frame (frame-list))
1557 (face-spec-set face spec frame))))
1560 (defun face-attr-match-p (face attrs &optional frame)
1561 "Return t if attributes of FACE match values in plist ATTRS.
1562 Optional parameter FRAME is the frame whose definition of FACE
1563 is used. If nil or omitted, use the selected frame."
1565 (setq frame (selected-frame)))
1566 (let ((list face-attribute-name-alist)
1568 (while (and match (not (null list)))
1569 (let* ((attr (car (car list)))
1571 (if (plist-member attrs attr)
1572 (plist-get attrs attr)
1574 (value-now (face-attribute face attr frame)))
1575 (setq match (equal specified-value value-now))
1576 (setq list (cdr list))))
1579 (defun face-spec-match-p (face spec &optional frame)
1580 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1581 (face-attr-match-p face (face-spec-choose spec frame) frame))
1583 (defsubst face-default-spec (face)
1584 "Return the default face-spec for FACE, ignoring any user customization.
1585 If there is no default for FACE, return nil."
1586 (get face 'face-defface-spec))
1588 (defsubst face-user-default-spec (face)
1589 "Return the user's customized face-spec for FACE, or the default if none.
1590 If there is neither a user setting nor a default for FACE, return nil."
1591 (or (get face 'customized-face)
1592 (get face 'saved-face)
1593 (face-default-spec face)))
1596 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1597 ;;; Frame-type independent color support.
1598 ;;; We keep the old x-* names as aliases for back-compatibility.
1599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1601 (defun defined-colors (&optional frame)
1602 "Return a list of colors supported for a particular frame.
1603 The argument FRAME specifies which frame to try.
1604 The value may be different for frames on different display types.
1605 If FRAME doesn't support colors, the value is nil.
1606 If FRAME is nil, that stands for the selected frame."
1607 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1608 (xw-defined-colors frame)
1609 (mapcar 'car (tty-color-alist frame))))
1610 (defalias 'x-defined-colors 'defined-colors)
1612 (defun color-defined-p (color &optional frame)
1613 "Return non-nil if color COLOR is supported on frame FRAME.
1614 If FRAME is omitted or nil, use the selected frame.
1615 If COLOR is the symbol `unspecified' or one of the strings
1616 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1617 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1619 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1620 (xw-color-defined-p color frame)
1621 (numberp (tty-color-translate color frame)))))
1622 (defalias 'x-color-defined-p 'color-defined-p)
1624 (defun color-values (color &optional frame)
1625 "Return a description of the color named COLOR on frame FRAME.
1626 The value is a list of integer RGB values--(RED GREEN BLUE).
1627 These values appear to range from 0 to 65280 or 65535, depending
1628 on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
1629 If FRAME is omitted or nil, use the selected frame.
1630 If FRAME cannot display COLOR, the value is nil.
1631 If COLOR is the symbol `unspecified' or one of the strings
1632 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1633 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1635 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1636 (xw-color-values color frame)
1637 (tty-color-values color frame))))
1638 (defalias 'x-color-values 'color-values)
1640 (defun display-color-p (&optional display)
1641 "Return t if DISPLAY supports color.
1642 The optional argument DISPLAY specifies which display to ask about.
1643 DISPLAY should be either a frame or a display name (a string).
1644 If omitted or nil, that stands for the selected frame's display."
1645 (if (memq (framep-on-display display) '(x w32 mac))
1646 (xw-display-color-p display)
1647 (tty-display-color-p display)))
1648 (defalias 'x-display-color-p 'display-color-p)
1650 (defun display-grayscale-p (&optional display)
1651 "Return non-nil if frames on DISPLAY can display shades of gray."
1652 (let ((frame-type (framep-on-display display)))
1654 ((memq frame-type '(x w32 mac))
1655 (x-display-grayscale-p display))
1657 (> (tty-color-gray-shades display) 2)))))
1659 (defun read-color (&optional prompt convert-to-RGB-p allow-empty-name-p msg-p)
1660 "Read a color name or RGB hex value: #RRRRGGGGBBBB.
1661 Completion is available for color names, but not for RGB hex strings.
1662 If the user inputs an RGB hex string, it must have the form
1663 #XXXXXXXXXXXX or XXXXXXXXXXXX, where each X is a hex digit. The
1664 number of Xs must be a multiple of 3, with the same number of Xs for
1665 each of red, green, and blue. The order is red, green, blue.
1667 In addition to standard color names and RGB hex values, the following
1668 are available as color candidates. In each case, the corresponding
1671 * `foreground at point' - foreground under the cursor
1672 * `background at point' - background under the cursor
1674 Checks input to be sure it represents a valid color. If not, raises
1675 an error (but see exception for empty input with non-nil
1676 ALLOW-EMPTY-NAME-P).
1678 Optional arg PROMPT is the prompt; if nil, uses a default prompt.
1680 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, converts
1681 an input color name to an RGB hex string. Returns the RGB hex string.
1683 Optional arg ALLOW-EMPTY-NAME-P controls what happens if the user
1684 enters an empty color name (that is, just hits `RET'). If non-nil,
1685 then returns an empty color name, \"\". If nil, then raises an error.
1686 Programs must test for \"\" if ALLOW-EMPTY-NAME-P is non-nil. They
1687 can then perform an appropriate action in case of empty input.
1689 Interactively, or with optional arg MSG-P non-nil, echoes the color in
1691 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1692 (let* ((completion-ignore-case t)
1693 (colors (append '("foreground at point" "background at point")
1695 (color (completing-read (or prompt "Color (name or #R+G+B+): ")
1698 (cond ((string= "foreground at point" color)
1699 (setq color (foreground-color-at-point)))
1700 ((string= "background at point" color)
1701 (setq color (background-color-at-point))))
1705 (string-match "^#?\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color))
1706 (if (and allow-empty-name-p (string= "" color))
1708 (when (and hex-string (not (eq (aref color 0) ?#)))
1709 (setq color (concat "#" color))) ; No #; add it.
1711 (when (or (string= "" color) (not (test-completion color colors)))
1712 (error "No such color: %S" color))
1713 (when convert-to-RGB-p
1714 (let ((components (x-color-values color)))
1715 (unless components (error "No such color: %S" color))
1716 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1717 (setq color (format "#%04X%04X%04X"
1718 (logand 65535 (nth 0 components))
1719 (logand 65535 (nth 1 components))
1720 (logand 65535 (nth 2 components))))))))
1721 (when msg-p (message "Color: `%s'" color))
1724 ;; Commented out because I decided it is better to include the
1725 ;; duplicates in read-color's completion list.
1727 ;; (defun defined-colors-without-duplicates ()
1728 ;; "Return the list of defined colors, without the no-space versions.
1729 ;; For each color name, we keep the variant that DOES have spaces."
1730 ;; (let ((result (copy-sequence (defined-colors)))
1733 ;; (dolist (this result)
1734 ;; (if (string-match " " this)
1735 ;; (push (replace-regexp-in-string " " ""
1737 ;; to-be-rejected)))
1738 ;; (dolist (elt to-be-rejected)
1739 ;; (let ((as-found (car (member-ignore-case elt result))))
1740 ;; (setq result (delete as-found result)))))
1743 (defun face-at-point ()
1744 "Return the face of the character after point.
1745 If it has more than one face, return the first one.
1746 Return nil if it has no specified face."
1747 (let* ((faceprop (or (get-char-property (point) 'read-face-name)
1748 (get-char-property (point) 'face)
1750 (face (cond ((symbolp faceprop) faceprop)
1751 ;; List of faces (don't treat an attribute spec).
1752 ;; Just use the first face.
1753 ((and (consp faceprop) (not (keywordp (car faceprop)))
1754 (not (memq (car faceprop)
1755 '(foreground-color background-color))))
1757 (t nil)))) ; Invalid face value.
1758 (if (facep face) face nil)))
1760 (defun foreground-color-at-point ()
1761 "Return the foreground color of the character after point."
1762 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1763 ;; Need also pick up any face properties that are not associated with named faces.
1764 (let ((face (or (face-at-point)
1765 (get-char-property (point) 'read-face-name)
1766 (get-char-property (point) 'face))))
1767 (cond ((and face (symbolp face))
1768 (let ((value (face-foreground face nil 'default)))
1769 (if (member value '("unspecified-fg" "unspecified-bg"))
1773 (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face)))
1774 ((memq ':foreground face) (cadr (memq ':foreground face)))))
1775 (t nil)))) ; Invalid face value.
1777 (defun background-color-at-point ()
1778 "Return the background color of the character after point."
1779 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1780 ;; Need also pick up any face properties that are not associated with named faces.
1781 (let ((face (or (face-at-point)
1782 (get-char-property (point) 'read-face-name)
1783 (get-char-property (point) 'face))))
1784 (cond ((and face (symbolp face))
1785 (let ((value (face-background face nil 'default)))
1786 (if (member value '("unspecified-fg" "unspecified-bg"))
1790 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1791 ((memq ':background face) (cadr (memq ':background face)))))
1792 (t nil)))) ; Invalid face value.
1794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1795 ;;; Background mode.
1796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1798 (defcustom frame-background-mode nil
1799 "*The brightness of the background.
1800 Set this to the symbol `dark' if your background color is dark,
1801 `light' if your background is light, or nil (automatic by default)
1802 if you want Emacs to examine the brightness for you. Don't set this
1803 variable with `setq'; this won't have the expected effect."
1805 :set #'(lambda (var value)
1806 (set-default var value)
1807 (mapc 'frame-set-background-mode (frame-list)))
1808 :initialize 'custom-initialize-changed
1809 :type '(choice (const dark)
1811 (const :tag "automatic" nil)))
1814 (defun frame-set-background-mode (frame)
1815 "Set up display-dependent faces on FRAME.
1816 Display-dependent faces are those which have different definitions
1817 according to the `background-mode' and `display-type' frame parameters."
1819 (and (window-system frame)
1820 (x-get-resource "backgroundMode" "BackgroundMode")))
1821 (bg-color (frame-parameter frame 'background-color))
1822 (terminal-bg-mode (terminal-parameter frame 'background-mode))
1823 (tty-type (tty-type frame))
1825 (cond (frame-background-mode)
1827 (intern (downcase bg-resource)))
1829 ((and (null (window-system frame))
1830 ;; Unspecified frame background color can only
1832 (member bg-color '(nil unspecified "unspecified-bg")))
1833 ;; There is no way to determine the background mode
1834 ;; automatically, so we make a guess based on the
1837 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1841 ((equal bg-color "unspecified-fg") ; inverted colors
1843 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1847 ((>= (apply '+ (color-values bg-color frame))
1848 ;; Just looking at the screen, colors whose
1849 ;; values add up to .6 of the white total
1850 ;; still look dark to me.
1851 (* (apply '+ (color-values "white" frame)) .6))
1855 (cond ((null (window-system frame))
1856 (if (tty-display-color-p frame) 'color 'mono))
1857 ((display-color-p frame)
1859 ((x-display-grayscale-p frame)
1863 (frame-parameter frame 'background-mode))
1865 (frame-parameter frame 'display-type)))
1867 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1868 (let ((locally-modified-faces nil))
1869 ;; Before modifying the frame parameters, we collect a list of
1870 ;; faces that don't match what their face-spec says they should
1871 ;; look like; we then avoid changing these faces below. A
1872 ;; negative list is used on the assumption that most faces will
1873 ;; be unmodified, so we can avoid consing in the common case.
1874 (dolist (face (face-list))
1875 (when (not (face-spec-match-p face
1876 (face-user-default-spec face)
1878 (push face locally-modified-faces)))
1879 ;; Now change to the new frame parameters
1880 (modify-frame-parameters frame
1881 (list (cons 'background-mode bg-mode)
1882 (cons 'display-type display-type)))
1883 ;; For all named faces, choose face specs matching the new frame
1884 ;; parameters, unless they have been locally modified.
1885 (dolist (face (face-list))
1886 (unless (memq face locally-modified-faces)
1887 (face-spec-set face (face-user-default-spec face) frame)))))))
1890 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1894 (defun x-handle-named-frame-geometry (parameters)
1895 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1896 Value is the new parameter list."
1897 (let* ((name (or (cdr (assq 'name parameters))
1898 (cdr (assq 'name default-frame-alist))))
1899 (x-resource-name name)
1900 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1902 (let ((parsed (x-parse-geometry res-geometry)))
1903 ;; If the resource specifies a position, call the position
1904 ;; and size "user-specified".
1905 (when (or (assq 'top parsed)
1906 (assq 'left parsed))
1907 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1908 ;; Put the geometry parameters at the end. Copy
1909 ;; default-frame-alist so that they go after it.
1910 (setq parameters (append parameters default-frame-alist parsed))))
1914 (defun x-handle-reverse-video (frame parameters)
1915 "Handle the reverse-video frame parameter and X resource.
1916 `x-create-frame' does not handle this one."
1917 (when (cdr (or (assq 'reverse parameters)
1918 (assq 'reverse default-frame-alist)
1919 (let ((resource (x-get-resource "reverseVideo"
1922 (cons nil (member (downcase resource)
1923 '("on" "true")))))))
1924 (let* ((params (frame-parameters frame))
1925 (bg (cdr (assq 'foreground-color params)))
1926 (fg (cdr (assq 'background-color params))))
1927 (modify-frame-parameters frame
1928 (list (cons 'foreground-color fg)
1929 (cons 'background-color bg)))
1930 (if (equal bg (cdr (assq 'border-color params)))
1931 (modify-frame-parameters frame
1932 (list (cons 'border-color fg))))
1933 (if (equal bg (cdr (assq 'mouse-color params)))
1934 (modify-frame-parameters frame
1935 (list (cons 'mouse-color fg))))
1936 (if (equal bg (cdr (assq 'cursor-color params)))
1937 (modify-frame-parameters frame
1938 (list (cons 'cursor-color fg)))))))
1941 (defun x-create-frame-with-faces (&optional parameters)
1942 "Create a frame from optional frame parameters PARAMETERS.
1943 Parameters not specified by PARAMETERS are taken from
1944 `default-frame-alist'. If PARAMETERS specify a frame name,
1945 handle X geometry resources for that name. If either PARAMETERS
1946 or `default-frame-alist' contains a `reverse' parameter, or
1947 the X resource ``reverseVideo'' is present, handle that.
1948 Value is the new frame created."
1949 (setq parameters (x-handle-named-frame-geometry parameters))
1950 (let ((visibility-spec (assq 'visibility parameters))
1951 (frame (x-create-frame `((visibility . nil) . ,parameters)))
1955 (x-setup-function-keys frame)
1956 (x-handle-reverse-video frame parameters)
1957 (frame-set-background-mode frame)
1958 (face-set-after-frame-default frame)
1959 ;; Make sure the tool-bar is ready to be enabled. The
1960 ;; `tool-bar-lines' frame parameter will not take effect
1961 ;; without this call.
1962 (tool-bar-setup frame)
1963 (if (null visibility-spec)
1964 (make-frame-visible frame)
1965 (modify-frame-parameters frame (list visibility-spec)))
1968 (delete-frame frame)))
1971 (defun face-set-after-frame-default (frame)
1972 "Set frame-local faces of FRAME from face specs and resources.
1973 Initialize colors of certain faces from frame parameters."
1974 (unless inhibit-face-set-after-frame-default
1975 (if (face-attribute 'default :font t)
1976 (set-face-attribute 'default frame :font
1977 (face-attribute 'default :font t))
1978 (set-face-attribute 'default frame :family
1979 (face-attribute 'default :family t))
1980 (set-face-attribute 'default frame :height
1981 (face-attribute 'default :height t))
1982 (set-face-attribute 'default frame :slant
1983 (face-attribute 'default :slant t))
1984 (set-face-attribute 'default frame :weight
1985 (face-attribute 'default :weight t))
1986 (set-face-attribute 'default frame :width
1987 (face-attribute 'default :width t))))
1988 ;; Find attributes that should be initialized from frame parameters.
1989 (let ((face-params '((foreground-color default :foreground)
1990 (background-color default :background)
1991 (border-color border :background)
1992 (cursor-color cursor :background)
1993 (scroll-bar-foreground scroll-bar :foreground)
1994 (scroll-bar-background scroll-bar :background)
1995 (mouse-color mouse :background)))
1997 (dolist (param face-params)
1998 (let* ((value (frame-parameter frame (nth 0 param)))
1999 (face (nth 1 param))
2000 (attr (nth 2 param))
2001 (default-value (face-attribute face attr t)))
2002 ;; Compile a list of face attributes to set, but don't set
2003 ;; them yet. The call to make-face-x-resource-internal,
2004 ;; below, can change frame parameters, and the final set of
2005 ;; frame parameters should be the ones acquired at this step.
2006 (if (eq default-value 'unspecified)
2007 ;; The face spec does not specify a new-frame value for
2008 ;; this attribute. Check if the existing frame parameter
2011 (push (list face frame attr value) apply-params))
2012 ;; The face spec specifies a value for this attribute, to be
2013 ;; applied to the face on all new frames.
2014 (push (list face frame attr default-value) apply-params))))
2015 ;; Initialize faces from face specs and X resources. The
2016 ;; condition-case prevents invalid specs from causing frame
2017 ;; creation to fail.
2018 (dolist (face (delq 'default (face-list)))
2021 (face-spec-set face (face-user-default-spec face) frame)
2022 (if (memq (window-system frame) '(x w32 mac))
2023 (make-face-x-resource-internal face frame))
2024 (internal-merge-in-global-face face frame))
2026 ;; Apply the attributes specified by frame parameters. This
2027 ;; rewrites parameters changed by make-face-x-resource-internal
2028 (dolist (param apply-params)
2029 (apply 'set-face-attribute param))))
2031 (defun tty-handle-reverse-video (frame parameters)
2032 "Handle the reverse-video frame parameter for terminal frames."
2033 (when (cdr (or (assq 'reverse parameters)
2034 (assq 'reverse default-frame-alist)))
2035 (let* ((params (frame-parameters frame))
2036 (bg (cdr (assq 'foreground-color params)))
2037 (fg (cdr (assq 'background-color params))))
2038 (modify-frame-parameters frame
2039 (list (cons 'foreground-color fg)
2040 (cons 'background-color bg)))
2041 (if (equal bg (cdr (assq 'mouse-color params)))
2042 (modify-frame-parameters frame
2043 (list (cons 'mouse-color fg))))
2044 (if (equal bg (cdr (assq 'cursor-color params)))
2045 (modify-frame-parameters frame
2046 (list (cons 'cursor-color fg)))))))
2049 (defun tty-create-frame-with-faces (&optional parameters)
2050 "Create a frame from optional frame parameters PARAMETERS.
2051 Parameters not specified by PARAMETERS are taken from
2052 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
2053 contains a `reverse' parameter, handle that. Value is the new frame
2055 (let ((frame (make-terminal-frame parameters))
2058 (with-selected-frame frame
2059 (tty-handle-reverse-video frame (frame-parameters frame))
2061 (unless (terminal-parameter frame 'terminal-initted)
2062 (set-terminal-parameter frame 'terminal-initted t)
2063 (set-locale-environment nil frame)
2064 (tty-run-terminal-initialization frame))
2065 (frame-set-background-mode frame)
2066 (face-set-after-frame-default frame)
2069 (delete-frame frame)))
2072 (defun tty-find-type (pred type)
2073 "Return the longest prefix of TYPE to which PRED returns non-nil.
2074 TYPE should be a tty type name such as \"xterm-16color\".
2076 The function tries only those prefixes that are followed by a
2077 dash or underscore in the original type name, like \"xterm\" in
2081 (not (funcall pred type)))
2082 ;; Strip off last hyphen and what follows, then try again
2084 (if (setq hyphend (string-match "[-_][^-_]+$" type))
2085 (substring type 0 hyphend)
2089 (defun tty-run-terminal-initialization (frame &optional type)
2090 "Run the special initialization code for the terminal type of FRAME.
2091 The optional TYPE parameter may be used to override the autodetected
2092 terminal type to a different value."
2093 (setq type (or type (tty-type frame)))
2094 ;; Load library for our terminal type.
2095 ;; User init file can set term-file-prefix to nil to prevent this.
2096 (with-selected-frame frame
2097 (unless (null term-file-prefix)
2098 (let* (term-init-func)
2099 ;; First, load the terminal initialization file, if it is
2100 ;; available and it hasn't been loaded already.
2101 (tty-find-type #'(lambda (type)
2102 (let ((file (locate-library (concat term-file-prefix type))))
2104 (or (assoc file load-history)
2107 ;; Next, try to find a matching initialization function, and call it.
2108 (tty-find-type #'(lambda (type)
2109 (fboundp (setq term-init-func
2110 (intern (concat "terminal-init-" type)))))
2112 (when (fboundp term-init-func)
2113 (funcall term-init-func))
2114 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
2116 ;; Called from C function init_display to initialize faces of the
2117 ;; dumped terminal frame on startup.
2119 (defun tty-set-up-initial-frame-faces ()
2120 (let ((frame (selected-frame)))
2121 (frame-set-background-mode frame)
2122 (face-set-after-frame-default frame)))
2127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2128 ;;; Compatiblity with 20.2
2129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2131 ;; Update a frame's faces when we change its default font.
2133 (defalias 'frame-update-faces 'ignore "")
2134 (make-obsolete 'frame-update-faces "no longer necessary." "21.1")
2136 ;; Update the colors of FACE, after FRAME's own colors have been
2139 (define-obsolete-function-alias 'frame-update-face-colors
2140 'frame-set-background-mode "21.1")
2143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2147 (defgroup basic-faces nil
2148 "The standard faces of Emacs."
2153 "Basic default face."
2154 :group 'basic-faces)
2159 :group 'basic-faces)
2162 '((((supports :slant italic))
2164 (((supports :underline t))
2167 ;; default to italic, even it doesn't appear to be supported,
2168 ;; because in some cases the display engine will do it's own
2169 ;; workaround (to `dim' on ttys)
2171 "Basic italic face."
2172 :group 'basic-faces)
2174 (defface bold-italic
2175 '((t :weight bold :slant italic))
2176 "Basic bold-italic face."
2177 :group 'basic-faces)
2180 '((((supports :underline t))
2182 (((supports :weight bold))
2185 "Basic underlined face."
2186 :group 'basic-faces)
2188 (defface fixed-pitch
2189 '((t :family "courier"))
2190 "The basic fixed-pitch face."
2191 :group 'basic-faces)
2193 (defface variable-pitch
2194 '((t :family "helv"))
2195 "The basic variable-pitch face."
2196 :group 'basic-faces)
2199 '((((class color grayscale) (min-colors 88) (background light))
2200 :foreground "grey50")
2201 (((class color grayscale) (min-colors 88) (background dark))
2202 :foreground "grey70")
2203 (((class color) (min-colors 8) (background light))
2204 :foreground "green")
2205 (((class color) (min-colors 8) (background dark))
2206 :foreground "yellow"))
2207 "Basic face for shadowed text."
2212 '((((class color) (min-colors 88) (background light))
2213 :foreground "blue1" :underline t)
2214 (((class color) (background light))
2215 :foreground "blue" :underline t)
2216 (((class color) (min-colors 88) (background dark))
2217 :foreground "cyan1" :underline t)
2218 (((class color) (background dark))
2219 :foreground "cyan" :underline t)
2220 (t :inherit underline))
2221 "Basic face for unvisited links."
2225 (defface link-visited
2226 '((default :inherit link)
2227 (((class color) (background light)) :foreground "magenta4")
2228 (((class color) (background dark)) :foreground "violet"))
2229 "Basic face for visited links."
2234 '((((class color) (min-colors 88) (background light))
2235 :background "darkseagreen2")
2236 (((class color) (min-colors 88) (background dark))
2237 :background "darkolivegreen")
2238 (((class color) (min-colors 16) (background light))
2239 :background "darkseagreen2")
2240 (((class color) (min-colors 16) (background dark))
2241 :background "darkolivegreen")
2242 (((class color) (min-colors 8))
2243 :background "green" :foreground "black")
2244 (t :inverse-video t))
2245 "Basic face for highlighting."
2246 :group 'basic-faces)
2249 '((((class color) (min-colors 88) (background dark))
2250 :background "blue3")
2251 (((class color) (min-colors 88) (background light))
2252 :background "lightgoldenrod2")
2253 (((class color) (min-colors 16) (background dark))
2254 :background "blue3")
2255 (((class color) (min-colors 16) (background light))
2256 :background "lightgoldenrod2")
2257 (((class color) (min-colors 8))
2258 :background "blue" :foreground "white")
2259 (((type tty) (class mono))
2261 (t :background "gray"))
2262 "Basic face for highlighting the region."
2264 :group 'basic-faces)
2266 (defface secondary-selection
2267 '((((class color) (min-colors 88) (background light))
2268 :background "yellow1")
2269 (((class color) (min-colors 88) (background dark))
2270 :background "SkyBlue4")
2271 (((class color) (min-colors 16) (background light))
2272 :background "yellow")
2273 (((class color) (min-colors 16) (background dark))
2274 :background "SkyBlue4")
2275 (((class color) (min-colors 8))
2276 :background "cyan" :foreground "black")
2277 (t :inverse-video t))
2278 "Basic face for displaying the secondary selection."
2279 :group 'basic-faces)
2281 (defface trailing-whitespace
2282 '((((class color) (background light))
2284 (((class color) (background dark))
2286 (t :inverse-video t))
2287 "Basic face for highlighting trailing whitespace."
2289 :group 'whitespace-faces ; like `show-trailing-whitespace'
2290 :group 'basic-faces)
2292 (defface escape-glyph
2293 '((((background dark)) :foreground "cyan")
2294 ;; See the comment in minibuffer-prompt for
2295 ;; the reason not to use blue on MS-DOS.
2296 (((type pc)) :foreground "magenta")
2297 ;; red4 is too dark, but some say blue is too loud.
2298 ;; brown seems to work ok. -- rms.
2299 (t :foreground "brown"))
2300 "Face for characters displayed as sequences using `^' or `\\'."
2304 (defface nobreak-space
2305 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2306 (((class color) (min-colors 8)) :background "magenta")
2307 (t :inverse-video t))
2308 "Face for displaying nobreak space."
2312 (defgroup mode-line-faces nil
2313 "Faces used in the mode line."
2319 '((((class color) (min-colors 88))
2320 :box (:line-width -1 :style released-button)
2321 :background "grey75" :foreground "black")
2324 "Basic mode line face for selected window."
2326 :group 'mode-line-faces
2327 :group 'basic-faces)
2329 (defface mode-line-inactive
2332 (((class color) (min-colors 88) (background light))
2334 :box (:line-width -1 :color "grey75" :style nil)
2335 :foreground "grey20" :background "grey90")
2336 (((class color) (min-colors 88) (background dark) )
2338 :box (:line-width -1 :color "grey40" :style nil)
2339 :foreground "grey80" :background "grey30"))
2340 "Basic mode line face for non-selected windows."
2342 :group 'mode-line-faces
2343 :group 'basic-faces)
2345 (defface mode-line-highlight
2346 '((((class color) (min-colors 88))
2347 :box (:line-width 2 :color "grey40" :style released-button))
2349 :inherit highlight))
2350 "Basic mode line face for highlighting."
2352 :group 'mode-line-faces
2353 :group 'basic-faces)
2355 (defface mode-line-buffer-id
2356 '((t (:weight bold)))
2357 "Face used for buffer identification parts of the mode line."
2359 :group 'mode-line-faces
2360 :group 'basic-faces)
2362 ;; Make `modeline' an alias for `mode-line', for compatibility.
2363 (put 'modeline 'face-alias 'mode-line)
2364 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
2365 (put 'modeline-highlight 'face-alias 'mode-line-highlight)
2366 (put 'modeline-buffer-id 'face-alias 'mode-line-buffer-id)
2368 (defface header-line
2372 ;; This used to be `:inverse-video t', but that doesn't look very
2373 ;; good when combined with inverse-video mode-lines and multiple
2374 ;; windows. Underlining looks better, and is more consistent with
2375 ;; the window-system face variants, which deemphasize the
2376 ;; header-line in relation to the mode-line face. If a terminal
2377 ;; can't underline, then the header-line will end up without any
2378 ;; highlighting; this may be too confusing in general, although it
2379 ;; happens to look good with the only current use of header-lines,
2380 ;; the info browser. XXX
2381 :inverse-video nil ;Override the value inherited from mode-line.
2383 (((class color grayscale) (background light))
2384 :background "grey90" :foreground "grey20"
2386 (((class color grayscale) (background dark))
2387 :background "grey20" :foreground "grey90"
2389 (((class mono) (background light))
2390 :background "white" :foreground "black"
2394 (((class mono) (background dark))
2395 :background "black" :foreground "white"
2399 "Basic header-line face."
2401 :group 'basic-faces)
2403 (defface vertical-border
2404 '((((type tty)) :inherit mode-line-inactive))
2405 "Face used for vertical window dividers on ttys."
2407 :group 'basic-faces)
2409 (defface minibuffer-prompt
2410 '((((background dark)) :foreground "cyan")
2411 ;; Don't use blue because many users of the MS-DOS port customize
2412 ;; their foreground color to be blue.
2413 (((type pc)) :foreground "magenta")
2414 (t :foreground "medium blue"))
2415 "Face for minibuffer prompts.
2416 By default, Emacs automatically adds this face to the value of
2417 `minibuffer-prompt-properties', which is a list of text properties
2418 used to display the prompt text."
2420 :group 'basic-faces)
2422 (setq minibuffer-prompt-properties
2423 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2426 '((((class color) (background light))
2427 :background "grey95")
2428 (((class color) (background dark))
2429 :background "grey10")
2431 :background "gray"))
2432 "Basic face for the fringes to the left and right of windows under X."
2435 :group 'basic-faces)
2437 (defface scroll-bar '((t nil))
2438 "Basic face for the scroll bar colors under X."
2441 :group 'basic-faces)
2443 (defface border '((t nil))
2444 "Basic face for the frame border under X."
2447 :group 'basic-faces)
2449 (defface cursor '((t nil))
2450 "Basic face for the cursor color under X.
2451 Note: Other faces cannot inherit from the cursor face."
2454 :group 'basic-faces)
2456 (put 'cursor 'face-no-inherit t)
2458 (defface mouse '((t nil))
2459 "Basic face for the mouse color under X."
2462 :group 'basic-faces)
2466 :box (:line-width 1 :style released-button)
2467 :foreground "black")
2468 (((type x w32 mac) (class color))
2469 :background "grey75")
2470 (((type x) (class mono))
2471 :background "grey"))
2472 "Basic tool-bar face."
2474 :group 'basic-faces)
2483 "Basic face for the font and colors of the menu bar and popup menus."
2486 :group 'basic-faces)
2489 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2490 ;;; Manipulating font names.
2491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2493 ;; This is here for compatibilty with Emacs 20.2. For example,
2494 ;; international/fontset.el uses x-resolve-font-name. The following
2495 ;; functions are not used in the face implementation itself.
2497 (defvar x-font-regexp nil)
2498 (defvar x-font-regexp-head nil)
2499 (defvar x-font-regexp-weight nil)
2500 (defvar x-font-regexp-slant nil)
2502 (defconst x-font-regexp-weight-subnum 1)
2503 (defconst x-font-regexp-slant-subnum 2)
2504 (defconst x-font-regexp-swidth-subnum 3)
2505 (defconst x-font-regexp-adstyle-subnum 4)
2507 ;;; Regexps matching font names in "Host Portable Character Representation."
2512 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2513 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2514 (weight\? "\\([^-]*\\)") ; 1
2515 (slant "\\([ior]\\)") ; 2
2516 ; (slant\? "\\([ior?*]?\\)") ; 2
2517 (slant\? "\\([^-]?\\)") ; 2
2518 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2519 (swidth "\\([^-]*\\)") ; 3
2520 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2521 (adstyle "\\([^-]*\\)") ; 4
2522 (pixelsize "[0-9]+")
2523 (pointsize "[0-9][0-9]+")
2524 (resx "[0-9][0-9]+")
2525 (resy "[0-9][0-9]+")
2532 (concat "\\`\\*?[-?*]"
2533 foundry - family - weight\? - slant\? - swidth - adstyle -
2534 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2535 registry - encoding "\\*?\\'"
2537 (setq x-font-regexp-head
2538 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2539 "\\([-*?]\\|\\'\\)"))
2540 (setq x-font-regexp-slant (concat - slant -))
2541 (setq x-font-regexp-weight (concat - weight -))
2545 (defun x-resolve-font-name (pattern &optional face frame)
2546 "Return a font name matching PATTERN.
2547 All wildcards in PATTERN are instantiated.
2548 If PATTERN is nil, return the name of the frame's base font, which never
2550 Given optional arguments FACE and FRAME, return a font which is
2551 also the same size as FACE on FRAME, or fail."
2553 (setq face (face-name face)))
2557 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2558 (let ((fonts (x-list-fonts pattern face frame 1)))
2561 (if (string-match "\\*" pattern)
2562 (if (null (face-font face))
2563 (error "No matching fonts are the same height as the frame default font")
2564 (error "No matching fonts are the same height as face `%s'" face))
2565 (if (null (face-font face))
2566 (error "Height of font `%s' doesn't match the frame default font"
2568 (error "Height of font `%s' doesn't match face `%s'"
2570 (error "No fonts match `%s'" pattern)))
2572 (cdr (assq 'font (frame-parameters (selected-frame))))))
2575 (defun x-frob-font-weight (font which)
2576 (let ((case-fold-search t))
2577 (cond ((string-match x-font-regexp font)
2578 (concat (substring font 0
2579 (match-beginning x-font-regexp-weight-subnum))
2581 (substring font (match-end x-font-regexp-weight-subnum)
2582 (match-beginning x-font-regexp-adstyle-subnum))
2583 ;; Replace the ADD_STYLE_NAME field with *
2584 ;; because the info in it may not be the same
2585 ;; for related fonts.
2587 (substring font (match-end x-font-regexp-adstyle-subnum))))
2588 ((string-match x-font-regexp-head font)
2589 (concat (substring font 0 (match-beginning 1)) which
2590 (substring font (match-end 1))))
2591 ((string-match x-font-regexp-weight font)
2592 (concat (substring font 0 (match-beginning 1)) which
2593 (substring font (match-end 1)))))))
2594 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
2596 (defun x-frob-font-slant (font which)
2597 (let ((case-fold-search t))
2598 (cond ((string-match x-font-regexp font)
2599 (concat (substring font 0
2600 (match-beginning x-font-regexp-slant-subnum))
2602 (substring font (match-end x-font-regexp-slant-subnum)
2603 (match-beginning x-font-regexp-adstyle-subnum))
2604 ;; Replace the ADD_STYLE_NAME field with *
2605 ;; because the info in it may not be the same
2606 ;; for related fonts.
2608 (substring font (match-end x-font-regexp-adstyle-subnum))))
2609 ((string-match x-font-regexp-head font)
2610 (concat (substring font 0 (match-beginning 2)) which
2611 (substring font (match-end 2))))
2612 ((string-match x-font-regexp-slant font)
2613 (concat (substring font 0 (match-beginning 1)) which
2614 (substring font (match-end 1)))))))
2615 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
2617 ;; These aliases are here so that we don't get warnings about obsolete
2618 ;; functions from the byte compiler.
2619 (defalias 'internal-frob-font-weight 'x-frob-font-weight)
2620 (defalias 'internal-frob-font-slant 'x-frob-font-slant)
2622 (defun x-make-font-bold (font)
2623 "Given an X font specification, make a bold version of it.
2624 If that can't be done, return nil."
2625 (internal-frob-font-weight font "bold"))
2626 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
2628 (defun x-make-font-demibold (font)
2629 "Given an X font specification, make a demibold version of it.
2630 If that can't be done, return nil."
2631 (internal-frob-font-weight font "demibold"))
2632 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
2634 (defun x-make-font-unbold (font)
2635 "Given an X font specification, make a non-bold version of it.
2636 If that can't be done, return nil."
2637 (internal-frob-font-weight font "medium"))
2638 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
2640 (defun x-make-font-italic (font)
2641 "Given an X font specification, make an italic version of it.
2642 If that can't be done, return nil."
2643 (internal-frob-font-slant font "i"))
2644 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
2646 (defun x-make-font-oblique (font) ; you say tomayto...
2647 "Given an X font specification, make an oblique version of it.
2648 If that can't be done, return nil."
2649 (internal-frob-font-slant font "o"))
2650 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
2652 (defun x-make-font-unitalic (font)
2653 "Given an X font specification, make a non-italic version of it.
2654 If that can't be done, return nil."
2655 (internal-frob-font-slant font "r"))
2656 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
2658 (defun x-make-font-bold-italic (font)
2659 "Given an X font specification, make a bold and italic version of it.
2660 If that can't be done, return nil."
2661 (and (setq font (internal-frob-font-weight font "bold"))
2662 (internal-frob-font-slant font "i")))
2663 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2667 ;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
2668 ;;; faces.el ends here