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