lisp/progmodes/python.el: Updated Copyright years.
[emacs.git] / lisp / faces.el
blob0c1eab474c3b8adb5c5cc09eb913de3efc8986bf
1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: internal
7 ;; Package: emacs
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 (defcustom term-file-prefix (purecopy "term/")
32 "If non-nil, Emacs startup performs terminal-specific initialization.
33 It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
35 You may set this variable to nil in your init file if you do not wish
36 the terminal-initialization file to be loaded."
37 :type '(choice (const :tag "No terminal-specific initialization" nil)
38 (string :tag "Name of directory with term files"))
39 :group 'terminals)
41 (declare-function xw-defined-colors "term/common-win" (&optional frame))
43 (defvar help-xref-stack-item)
45 (defvar face-name-history nil
46 "History list for some commands that read face names.
47 Maximum length of the history list is determined by the value
48 of `history-length', which see.")
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ;;; Font selection.
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 (defgroup font-selection nil
56 "Influencing face font selection."
57 :group 'faces)
60 (defcustom face-font-selection-order
61 '(:width :height :weight :slant)
62 "A list specifying how face font selection chooses fonts.
63 Each of the four symbols `:width', `:height', `:weight', and `:slant'
64 must appear once in the list, and the list must not contain any other
65 elements. Font selection first tries to find a best matching font
66 for those face attributes that appear before in the list. For
67 example, if `:slant' appears before `:height', font selection first
68 tries to find a font with a suitable slant, even if this results in
69 a font height that isn't optimal."
70 :tag "Font selection order"
71 :type '(list symbol symbol symbol symbol)
72 :group 'font-selection
73 :set #'(lambda (symbol value)
74 (set-default symbol value)
75 (internal-set-font-selection-order value)))
78 ;; In the absence of Fontconfig support, Monospace and Sans Serif are
79 ;; unavailable, and we fall back on the courier and helv families,
80 ;; which are generally available.
81 (defcustom face-font-family-alternatives
82 (mapcar (lambda (arg) (mapcar 'purecopy arg))
83 '(("Monospace" "courier" "fixed")
84 ("courier" "CMU Typewriter Text" "fixed")
85 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
86 ("helv" "helvetica" "arial" "fixed")))
87 "Alist of alternative font family names.
88 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
89 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
90 ALTERNATIVE2 etc."
91 :tag "Alternative font families to try"
92 :type '(repeat (repeat string))
93 :group 'font-selection
94 :set #'(lambda (symbol value)
95 (set-default symbol value)
96 (internal-set-alternative-font-family-alist value)))
99 ;; This is defined originally in xfaces.c.
100 (defcustom face-font-registry-alternatives
101 (mapcar (lambda (arg) (mapcar 'purecopy arg))
102 (if (eq system-type 'windows-nt)
103 '(("iso8859-1" "ms-oemlatin")
104 ("gb2312.1980" "gb2312" "gbk" "gb18030")
105 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
106 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
107 ("muletibetan-2" "muletibetan-0"))
108 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
109 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
110 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
111 ("muletibetan-2" "muletibetan-0"))))
112 "Alist of alternative font registry names.
113 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
114 If fonts of registry REGISTRY can be loaded, font selection
115 tries to find a best matching font among all fonts of registry
116 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
117 :tag "Alternative font registries to try"
118 :type '(repeat (repeat string))
119 :version "21.1"
120 :group 'font-selection
121 :set #'(lambda (symbol value)
122 (set-default symbol value)
123 (internal-set-alternative-font-registry-alist value)))
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;;; Creation, copying.
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131 (defun face-list ()
132 "Return a list of all defined faces."
133 (mapcar #'car face-new-frame-defaults))
135 (defun make-face (face &optional no-init-from-resources)
136 "Define a new face with name FACE, a symbol.
137 Do not call this directly from Lisp code; use `defface' instead.
139 If NO-INIT-FROM-RESOURCES is non-nil, don't initialize face
140 attributes from X resources. If FACE is already known as a face,
141 leave it unmodified. Return FACE."
142 (interactive (list (read-from-minibuffer
143 "Make face: " nil nil t 'face-name-history)))
144 (unless (facep face)
145 ;; Make frame-local faces (this also makes the global one).
146 (dolist (frame (frame-list))
147 (internal-make-lisp-face face frame))
148 ;; Add the face to the face menu.
149 (when (fboundp 'facemenu-add-new-face)
150 (facemenu-add-new-face face))
151 ;; Define frame-local faces for all frames from X resources.
152 (unless no-init-from-resources
153 (make-face-x-resource-internal face)))
154 face)
156 (defun make-empty-face (face)
157 "Define a new, empty face with name FACE.
158 Do not call this directly from Lisp code; use `defface' instead."
159 (interactive (list (read-from-minibuffer
160 "Make empty face: " nil nil t 'face-name-history)))
161 (make-face face 'no-init-from-resources))
163 (defun copy-face (old-face new-face &optional frame new-frame)
164 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
165 This function does not copy face customization data, so NEW-FACE
166 will not be made customizable. Most Lisp code should not call
167 this function; use `defface' with :inherit instead.
169 If NEW-FACE already exists as a face, modify it to be like
170 OLD-FACE. If NEW-FACE doesn't already exist, create it.
172 If the optional argument FRAME is a frame, change NEW-FACE on
173 FRAME only. If FRAME is t, copy the frame-independent default
174 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
175 the defaults as well as the faces on each existing frame.
177 If the optional fourth argument NEW-FRAME is given, copy the
178 information from face OLD-FACE on frame FRAME to NEW-FACE on
179 frame NEW-FRAME. In this case, FRAME must not be nil."
180 (let ((inhibit-quit t))
181 (if (null frame)
182 (progn
183 (when new-frame
184 (error "Copying face %s from all frames to one frame"
185 old-face))
186 (make-empty-face new-face)
187 (dolist (frame (frame-list))
188 (copy-face old-face new-face frame))
189 (copy-face old-face new-face t))
190 (make-empty-face new-face)
191 (internal-copy-lisp-face old-face new-face frame new-frame))
192 new-face))
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 ;;; Predicates, type checks.
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
199 (defun facep (face)
200 "Return non-nil if FACE is a face name; nil otherwise.
201 A face name can be a string or a symbol."
202 (internal-lisp-face-p face))
205 (defun check-face (face)
206 "Signal an error if FACE doesn't name a face.
207 Value is FACE."
208 (unless (facep face)
209 (error "Not a face: %s" face))
210 face)
213 ;; The ID returned is not to be confused with the internally used IDs
214 ;; of realized faces. The ID assigned to Lisp faces is used to
215 ;; support faces in display table entries.
217 (defun face-id (face &optional _frame)
218 "Return the internal ID of face with name FACE.
219 If FACE is a face-alias, return the ID of the target face.
220 The optional argument FRAME is ignored, since the internal face ID
221 of a face name is the same for all frames."
222 (check-face face)
223 (or (get face 'face)
224 (face-id (get face 'face-alias))))
226 (defun face-equal (face1 face2 &optional frame)
227 "Non-nil if faces FACE1 and FACE2 are equal.
228 Faces are considered equal if all their attributes are equal.
229 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
230 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
231 If FRAME is omitted or nil, use the selected frame."
232 (internal-lisp-face-equal-p face1 face2 frame))
235 (defun face-differs-from-default-p (face &optional frame)
236 "Return non-nil if FACE displays differently from the default face.
237 If the optional argument FRAME is given, report on face FACE in that frame.
238 If FRAME is t, report on the defaults for face FACE (for new frames).
239 If FRAME is omitted or nil, use the selected frame."
240 (let ((attrs
241 (delq :inherit (mapcar 'car face-attribute-name-alist)))
242 (differs nil))
243 (while (and attrs (not differs))
244 (let* ((attr (pop attrs))
245 (attr-val (face-attribute face attr frame t)))
246 (when (and
247 (not (eq attr-val 'unspecified))
248 (display-supports-face-attributes-p (list attr attr-val)
249 frame))
250 (setq differs attr))))
251 differs))
254 (defun face-nontrivial-p (face &optional frame)
255 "True if face FACE has some non-nil attribute.
256 If the optional argument FRAME is given, report on face FACE in that frame.
257 If FRAME is t, report on the defaults for face FACE (for new frames).
258 If FRAME is omitted or nil, use the selected frame."
259 (not (internal-lisp-face-empty-p face frame)))
263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 ;;; Setting face attributes from X resources.
265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
267 (defcustom face-x-resources
268 (mapcar
269 (lambda (arg)
270 ;; FIXME; can we purecopy some of the conses too?
271 (cons (car arg)
272 (cons (purecopy (car (cdr arg))) (purecopy (cdr (cdr arg))))))
273 '((:family (".attributeFamily" . "Face.AttributeFamily"))
274 (:foundry (".attributeFoundry" . "Face.AttributeFoundry"))
275 (:width (".attributeWidth" . "Face.AttributeWidth"))
276 (:height (".attributeHeight" . "Face.AttributeHeight"))
277 (:weight (".attributeWeight" . "Face.AttributeWeight"))
278 (:slant (".attributeSlant" . "Face.AttributeSlant"))
279 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
280 (:background (".attributeBackground" . "Face.AttributeBackground"))
281 (:overline (".attributeOverline" . "Face.AttributeOverline"))
282 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
283 (:box (".attributeBox" . "Face.AttributeBox"))
284 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
285 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
286 (:stipple
287 (".attributeStipple" . "Face.AttributeStipple")
288 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
289 (:bold (".attributeBold" . "Face.AttributeBold"))
290 (:italic (".attributeItalic" . "Face.AttributeItalic"))
291 (:font (".attributeFont" . "Face.AttributeFont"))
292 (:inherit (".attributeInherit" . "Face.AttributeInherit"))))
293 "List of X resources and classes for face attributes.
294 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
295 the name of a face attribute, and each ENTRY is a cons of the form
296 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
297 X resource class for the attribute."
298 :type '(repeat (cons symbol (repeat (cons string string))))
299 :group 'faces)
302 (declare-function internal-face-x-get-resource "xfaces.c"
303 (resource class frame))
305 (declare-function internal-set-lisp-face-attribute-from-resource "xfaces.c"
306 (face attr value &optional frame))
308 (defun set-face-attribute-from-resource (face attribute resource class frame)
309 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
310 Value is the attribute value specified by the resource, or nil
311 if not present. This function displays a message if the resource
312 specifies an invalid attribute."
313 (let* ((face-name (face-name face))
314 (value (internal-face-x-get-resource (concat face-name resource)
315 class frame)))
316 (when value
317 (condition-case ()
318 (internal-set-lisp-face-attribute-from-resource
319 face attribute (downcase value) frame)
320 (error
321 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
322 face-name frame attribute value))))
323 value))
326 (defun set-face-attributes-from-resources (face frame)
327 "Set attributes of FACE from X resources for FRAME."
328 (when (memq (framep frame) '(x w32))
329 (dolist (definition face-x-resources)
330 (let ((attribute (car definition)))
331 (dolist (entry (cdr definition))
332 (set-face-attribute-from-resource face attribute (car entry)
333 (cdr entry) frame))))))
336 (defun make-face-x-resource-internal (face &optional frame)
337 "Fill frame-local FACE on FRAME from X resources.
338 FRAME nil or not specified means do it for all frames."
339 (if (null frame)
340 (dolist (frame (frame-list))
341 (set-face-attributes-from-resources face frame))
342 (set-face-attributes-from-resources face frame)))
346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
347 ;;; Retrieving face attributes.
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
350 (defun face-name (face)
351 "Return the name of face FACE."
352 (symbol-name (check-face face)))
355 (defun face-all-attributes (face &optional frame)
356 "Return an alist stating the attributes of FACE.
357 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
358 If FRAME is omitted or nil the value describes the default attributes,
359 but if you specify FRAME, the value describes the attributes
360 of FACE on FRAME."
361 (mapcar (lambda (pair)
362 (let ((attr (car pair)))
363 (cons attr (face-attribute face attr (or frame t)))))
364 face-attribute-name-alist))
366 (defun face-attribute (face attribute &optional frame inherit)
367 "Return the value of FACE's ATTRIBUTE on FRAME.
368 If the optional argument FRAME is given, report on face FACE in that frame.
369 If FRAME is t, report on the defaults for face FACE (for new frames).
370 If FRAME is omitted or nil, use the selected frame.
372 If INHERIT is nil, only attributes directly defined by FACE are considered,
373 so the return value may be `unspecified', or a relative value.
374 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
375 faces specified by its `:inherit' attribute; however the return value
376 may still be `unspecified' or relative.
377 If INHERIT is a face or a list of faces, then the result is further merged
378 with that face (or faces), until it becomes specified and absolute.
380 To ensure that the return value is always specified and absolute, use a
381 value of `default' for INHERIT; this will resolve any unspecified or
382 relative values by merging with the `default' face (which is always
383 completely specified)."
384 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
385 (when (and inherit (face-attribute-relative-p attribute value))
386 ;; VALUE is relative, so merge with inherited faces
387 (let ((inh-from (face-attribute face :inherit frame)))
388 (unless (or (null inh-from) (eq inh-from 'unspecified))
389 (condition-case nil
390 (setq value
391 (face-attribute-merged-with attribute value inh-from frame))
392 ;; The `inherit' attribute may point to non existent faces.
393 (error nil)))))
394 (when (and inherit
395 (not (eq inherit t))
396 (face-attribute-relative-p attribute value))
397 ;; We should merge with INHERIT as well
398 (setq value (face-attribute-merged-with attribute value inherit frame)))
399 value))
401 (defun face-attribute-merged-with (attribute value faces &optional frame)
402 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
403 FACES may be either a single face or a list of faces.
404 \[This is an internal function.]"
405 (cond ((not (face-attribute-relative-p attribute value))
406 value)
407 ((null faces)
408 value)
409 ((consp faces)
410 (face-attribute-merged-with
411 attribute
412 (face-attribute-merged-with attribute value (car faces) frame)
413 (cdr faces)
414 frame))
416 (merge-face-attribute attribute
417 value
418 (face-attribute faces attribute frame t)))))
421 (defmacro face-attribute-specified-or (value &rest body)
422 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
423 (let ((temp (make-symbol "value")))
424 `(let ((,temp ,value))
425 (if (not (eq ,temp 'unspecified))
426 ,temp
427 ,@body))))
429 (defun face-foreground (face &optional frame inherit)
430 "Return the foreground color name of FACE, or nil if unspecified.
431 If the optional argument FRAME is given, report on face FACE in that frame.
432 If FRAME is t, report on the defaults for face FACE (for new frames).
433 If FRAME is omitted or nil, use the selected frame.
435 If INHERIT is nil, only a foreground color directly defined by FACE is
436 considered, so the return value may be nil.
437 If INHERIT is t, and FACE doesn't define a foreground color, then any
438 foreground color that FACE inherits through its `:inherit' attribute
439 is considered as well; however the return value may still be nil.
440 If INHERIT is a face or a list of faces, then it is used to try to
441 resolve an unspecified foreground color.
443 To ensure that a valid color is always returned, use a value of
444 `default' for INHERIT; this will resolve any unspecified values by
445 merging with the `default' face (which is always completely specified)."
446 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
447 nil))
449 (defun face-background (face &optional frame inherit)
450 "Return the background color name of FACE, or nil if unspecified.
451 If the optional argument FRAME is given, report on face FACE in that frame.
452 If FRAME is t, report on the defaults for face FACE (for new frames).
453 If FRAME is omitted or nil, use the selected frame.
455 If INHERIT is nil, only a background color directly defined by FACE is
456 considered, so the return value may be nil.
457 If INHERIT is t, and FACE doesn't define a background color, then any
458 background color that FACE inherits through its `:inherit' attribute
459 is considered as well; however the return value may still be nil.
460 If INHERIT is a face or a list of faces, then it is used to try to
461 resolve an unspecified background color.
463 To ensure that a valid color is always returned, use a value of
464 `default' for INHERIT; this will resolve any unspecified values by
465 merging with the `default' face (which is always completely specified)."
466 (face-attribute-specified-or (face-attribute face :background frame inherit)
467 nil))
469 (defun face-stipple (face &optional frame inherit)
470 "Return the stipple pixmap name of FACE, or nil if unspecified.
471 If the optional argument FRAME is given, report on face FACE in that frame.
472 If FRAME is t, report on the defaults for face FACE (for new frames).
473 If FRAME is omitted or nil, use the selected frame.
475 If INHERIT is nil, only a stipple directly defined by FACE is
476 considered, so the return value may be nil.
477 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
478 that FACE inherits through its `:inherit' attribute is considered as
479 well; however the return value may still be nil.
480 If INHERIT is a face or a list of faces, then it is used to try to
481 resolve an unspecified stipple.
483 To ensure that a valid stipple or nil is always returned, use a value of
484 `default' for INHERIT; this will resolve any unspecified values by merging
485 with the `default' face (which is always completely specified)."
486 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
487 nil))
490 (defalias 'face-background-pixmap 'face-stipple)
493 (defun face-underline-p (face &optional frame)
494 "Return non-nil if FACE is underlined.
495 If the optional argument FRAME is given, report on face FACE in that frame.
496 If FRAME is t, report on the defaults for face FACE (for new frames).
497 If FRAME is omitted or nil, use the selected frame."
498 (eq (face-attribute face :underline frame) t))
501 (defun face-inverse-video-p (face &optional frame)
502 "Return non-nil if FACE is in inverse video on FRAME.
503 If the optional argument FRAME is given, report on face FACE in that frame.
504 If FRAME is t, report on the defaults for face FACE (for new frames).
505 If FRAME is omitted or nil, use the selected frame."
506 (eq (face-attribute face :inverse-video frame) t))
509 (defun face-bold-p (face &optional frame)
510 "Return non-nil if the font of FACE is bold on FRAME.
511 If the optional argument FRAME is given, report on face FACE in that frame.
512 If FRAME is t, report on the defaults for face FACE (for new frames).
513 If FRAME is omitted or nil, use the selected frame.
514 Use `face-attribute' for finer control."
515 (let ((bold (face-attribute face :weight frame)))
516 (memq bold '(semi-bold bold extra-bold ultra-bold))))
519 (defun face-italic-p (face &optional frame)
520 "Return non-nil if the font of FACE is italic on FRAME.
521 If the optional argument FRAME is given, report on face FACE in that frame.
522 If FRAME is t, report on the defaults for face FACE (for new frames).
523 If FRAME is omitted or nil, use the selected frame.
524 Use `face-attribute' for finer control."
525 (let ((italic (face-attribute face :slant frame)))
526 (memq italic '(italic oblique))))
530 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
531 ;;; Face documentation.
532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
534 (defun face-documentation (face)
535 "Get the documentation string for FACE.
536 If FACE is a face-alias, get the documentation for the target face."
537 (let ((alias (get face 'face-alias))
538 doc)
539 (if alias
540 (progn
541 (setq doc (get alias 'face-documentation))
542 (format "%s is an alias for the face `%s'.%s" face alias
543 (if doc (format "\n%s" doc)
544 "")))
545 (get face 'face-documentation))))
548 (defun set-face-documentation (face string)
549 "Set the documentation string for FACE to STRING."
550 ;; Perhaps the text should go in DOC.
551 (put face 'face-documentation (purecopy string)))
554 (defalias 'face-doc-string 'face-documentation)
555 (defalias 'set-face-doc-string 'set-face-documentation)
559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
560 ;; Setting face attributes.
561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
564 (defun set-face-attribute (face frame &rest args)
565 "Set attributes of FACE on FRAME from ARGS.
566 This function overrides the face attributes specified by FACE's
567 face spec. It is mostly intended for internal use only.
569 If FRAME is nil, set the attributes for all existing frames, as
570 well as the default for new frames. If FRAME is t, change the
571 default for new frames only.
573 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a
574 valid face attribute name. All attributes can be set to
575 `unspecified'; this fact is not further mentioned below.
577 The following attributes are recognized:
579 `:family'
581 VALUE must be a string specifying the font family
582 \(e.g. \"Monospace\") or a fontset.
584 `:foundry'
586 VALUE must be a string specifying the font foundry,
587 e.g. ``adobe''. If a font foundry is specified, wild-cards `*'
588 and `?' are allowed.
590 `:width'
592 VALUE specifies the relative proportionate width of the font to use.
593 It must be one of the symbols `ultra-condensed', `extra-condensed',
594 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
595 `extra-expanded', or `ultra-expanded'.
597 `:height'
599 VALUE specifies the relative or absolute height of the font. An
600 absolute height is an integer, and specifies font height in units
601 of 1/10 pt. A relative height is either a floating point number,
602 which specifies a scaling factor for the underlying face height;
603 or a function that takes a single argument (the underlying face
604 height) and returns the new height. Note that for the `default'
605 face, you must specify an absolute height (since there is nothing
606 for it to be relative to).
608 `:weight'
610 VALUE specifies the weight of the font to use. It must be one of the
611 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
612 `semi-light', `light', `extra-light', `ultra-light'.
614 `:slant'
616 VALUE specifies the slant of the font to use. It must be one of the
617 symbols `italic', `oblique', `normal', `reverse-italic', or
618 `reverse-oblique'.
620 `:foreground', `:background'
622 VALUE must be a color name, a string.
624 `:underline'
626 VALUE specifies whether characters in FACE should be underlined. If
627 VALUE is t, underline with foreground color of the face. If VALUE is
628 a string, underline with that color. If VALUE is nil, explicitly
629 don't underline.
631 `:overline'
633 VALUE specifies whether characters in FACE should be overlined. If
634 VALUE is t, overline with foreground color of the face. If VALUE is a
635 string, overline with that color. If VALUE is nil, explicitly don't
636 overline.
638 `:strike-through'
640 VALUE specifies whether characters in FACE should be drawn with a line
641 striking through them. If VALUE is t, use the foreground color of the
642 face. If VALUE is a string, strike-through with that color. If VALUE
643 is nil, explicitly don't strike through.
645 `:box'
647 VALUE specifies whether characters in FACE should have a box drawn
648 around them. If VALUE is nil, explicitly don't draw boxes. If
649 VALUE is t, draw a box with lines of width 1 in the foreground color
650 of the face. If VALUE is a string, the string must be a color name,
651 and the box is drawn in that color with a line width of 1. Otherwise,
652 VALUE must be a property list of the form `(:line-width WIDTH
653 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
654 the property list, a default value will be used for the value, as
655 specified below. WIDTH specifies the width of the lines to draw; it
656 defaults to 1. If WIDTH is negative, the absolute value is the width
657 of the lines, and draw top/bottom lines inside the characters area,
658 not around it. COLOR is the name of the color to draw in, default is
659 the foreground color of the face for simple boxes, and the background
660 color of the face for 3D boxes. STYLE specifies whether a 3D box
661 should be draw. If STYLE is `released-button', draw a box looking
662 like a released 3D button. If STYLE is `pressed-button' draw a box
663 that appears like a pressed button. If STYLE is nil, the default if
664 the property list doesn't contain a style specification, draw a 2D
665 box.
667 `:inverse-video'
669 VALUE specifies whether characters in FACE should be displayed in
670 inverse video. VALUE must be one of t or nil.
672 `:stipple'
674 If VALUE is a string, it must be the name of a file of pixmap data.
675 The directories listed in the `x-bitmap-file-path' variable are
676 searched. Alternatively, VALUE may be a list of the form (WIDTH
677 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
678 is a string containing the raw bits of the bitmap. VALUE nil means
679 explicitly don't use a stipple pattern.
681 For convenience, attributes `:family', `:foundry', `:width',
682 `:height', `:weight', and `:slant' may also be set in one step
683 from an X font name:
685 `:font'
687 Set font-related face attributes from VALUE. VALUE must be a
688 valid font name or font object. Setting this attribute will also
689 set the `:family', `:foundry', `:width', `:height', `:weight',
690 and `:slant' attributes.
692 `:inherit'
694 VALUE is the name of a face from which to inherit attributes, or
695 a list of face names. Attributes from inherited faces are merged
696 into the face like an underlying face would be, with higher
697 priority than underlying faces.
699 For backward compatibility, the keywords `:bold' and `:italic'
700 can be used to specify weight and slant respectively. This usage
701 is considered obsolete. For these two keywords, the VALUE must
702 be either t or nil. A value of t for `:bold' is equivalent to
703 setting `:weight' to `bold', and a value of t for `:italic' is
704 equivalent to setting `:slant' to `italic'. But if `:weight' is
705 specified in the face spec, `:bold' is ignored, and if `:slant'
706 is specified, `:italic' is ignored."
707 (setq args (purecopy args))
708 (let ((where (if (null frame) 0 frame))
709 (spec args)
710 family foundry)
711 ;; If we set the new-frame defaults, this face is modified outside Custom.
712 (if (memq where '(0 t))
713 (put (or (get face 'face-alias) face) 'face-modified t))
714 ;; If family and/or foundry are specified, set it first. Certain
715 ;; face attributes, e.g. :weight semi-condensed, are not supported
716 ;; in every font. See bug#1127.
717 (while spec
718 (cond ((eq (car spec) :family)
719 (setq family (cadr spec)))
720 ((eq (car spec) :foundry)
721 (setq foundry (cadr spec))))
722 (setq spec (cddr spec)))
723 (when (or family foundry)
724 (when (and (stringp family)
725 (string-match "\\([^-]*\\)-\\([^-]*\\)" family))
726 (unless foundry
727 (setq foundry (match-string 1 family)))
728 (setq family (match-string 2 family)))
729 (when (or (stringp family) (eq family 'unspecified))
730 (internal-set-lisp-face-attribute face :family (purecopy family)
731 where))
732 (when (or (stringp foundry) (eq foundry 'unspecified))
733 (internal-set-lisp-face-attribute face :foundry (purecopy foundry)
734 where)))
735 (while args
736 (unless (memq (car args) '(:family :foundry))
737 (internal-set-lisp-face-attribute face (car args)
738 (purecopy (cadr args))
739 where))
740 (setq args (cddr args)))))
742 (defun make-face-bold (face &optional frame _noerror)
743 "Make the font of FACE be bold, if possible.
744 FRAME nil or not specified means change face on all frames.
745 Argument NOERROR is ignored and retained for compatibility.
746 Use `set-face-attribute' for finer control of the font weight."
747 (interactive (list (read-face-name "Make which face bold")))
748 (set-face-attribute face frame :weight 'bold))
751 (defun make-face-unbold (face &optional frame _noerror)
752 "Make the font of FACE be non-bold, if possible.
753 FRAME nil or not specified means change face on all frames.
754 Argument NOERROR is ignored and retained for compatibility."
755 (interactive (list (read-face-name "Make which face non-bold")))
756 (set-face-attribute face frame :weight 'normal))
759 (defun make-face-italic (face &optional frame _noerror)
760 "Make the font of FACE be italic, if possible.
761 FRAME nil or not specified means change face on all frames.
762 Argument NOERROR is ignored and retained for compatibility.
763 Use `set-face-attribute' for finer control of the font slant."
764 (interactive (list (read-face-name "Make which face italic")))
765 (set-face-attribute face frame :slant 'italic))
768 (defun make-face-unitalic (face &optional frame _noerror)
769 "Make the font of FACE be non-italic, if possible.
770 FRAME nil or not specified means change face on all frames.
771 Argument NOERROR is ignored and retained for compatibility."
772 (interactive (list (read-face-name "Make which face non-italic")))
773 (set-face-attribute face frame :slant 'normal))
776 (defun make-face-bold-italic (face &optional frame _noerror)
777 "Make the font of FACE be bold and italic, if possible.
778 FRAME nil or not specified means change face on all frames.
779 Argument NOERROR is ignored and retained for compatibility.
780 Use `set-face-attribute' for finer control of font weight and slant."
781 (interactive (list (read-face-name "Make which face bold-italic")))
782 (set-face-attribute face frame :weight 'bold :slant 'italic))
785 (defun set-face-font (face font &optional frame)
786 "Change font-related attributes of FACE to those of FONT (a string).
787 FRAME nil or not specified means change face on all frames.
788 This sets the attributes `:family', `:foundry', `:width',
789 `:height', `:weight', and `:slant'. When called interactively,
790 prompt for the face and font."
791 (interactive (read-face-and-attribute :font))
792 (set-face-attribute face frame :font font))
795 ;; Implementation note: Emulating gray background colors with a
796 ;; stipple pattern is now part of the face realization process, and is
797 ;; done in C depending on the frame on which the face is realized.
799 (defun set-face-background (face color &optional frame)
800 "Change the background color of face FACE to COLOR (a string).
801 FRAME nil or not specified means change face on all frames.
802 COLOR can be a system-defined color name (see `list-colors-display')
803 or a hex spec of the form #RRGGBB.
804 When called interactively, prompts for the face and color."
805 (interactive (read-face-and-attribute :background))
806 (set-face-attribute face frame :background (or color 'unspecified)))
809 (defun set-face-foreground (face color &optional frame)
810 "Change the foreground color of face FACE to COLOR (a string).
811 FRAME nil or not specified means change face on all frames.
812 COLOR can be a system-defined color name (see `list-colors-display')
813 or a hex spec of the form #RRGGBB.
814 When called interactively, prompts for the face and color."
815 (interactive (read-face-and-attribute :foreground))
816 (set-face-attribute face frame :foreground (or color 'unspecified)))
819 (defun set-face-stipple (face stipple &optional frame)
820 "Change the stipple pixmap of face FACE to STIPPLE.
821 FRAME nil or not specified means change face on all frames.
822 STIPPLE should be a string, the name of a file of pixmap data.
823 The directories listed in the `x-bitmap-file-path' variable are searched.
825 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
826 where WIDTH and HEIGHT are the size in pixels,
827 and DATA is a string, containing the raw bits of the bitmap."
828 (interactive (read-face-and-attribute :stipple))
829 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
832 (defun set-face-underline-p (face underline &optional frame)
833 "Specify whether face FACE is underlined.
834 UNDERLINE nil means FACE explicitly doesn't underline.
835 UNDERLINE non-nil means FACE explicitly does underlining
836 with the same of the foreground color.
837 If UNDERLINE is a string, underline with the color named UNDERLINE.
838 FRAME nil or not specified means change face on all frames.
839 Use `set-face-attribute' to ``unspecify'' underlining."
840 (interactive
841 (let ((list (read-face-and-attribute :underline)))
842 (list (car list) (eq (car (cdr list)) t))))
843 (set-face-attribute face frame :underline underline))
845 (define-obsolete-function-alias 'set-face-underline
846 'set-face-underline-p "22.1")
849 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
850 "Specify whether face FACE is in inverse video.
851 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
852 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
853 FRAME nil or not specified means change face on all frames.
854 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
855 (interactive
856 (let ((list (read-face-and-attribute :inverse-video)))
857 (list (car list) (eq (car (cdr list)) t))))
858 (set-face-attribute face frame :inverse-video inverse-video-p))
861 (defun set-face-bold-p (face bold-p &optional frame)
862 "Specify whether face FACE is bold.
863 BOLD-P non-nil means FACE should explicitly display bold.
864 BOLD-P nil means FACE should explicitly display non-bold.
865 FRAME nil or not specified means change face on all frames.
866 Use `set-face-attribute' or `modify-face' for finer control."
867 (if (null bold-p)
868 (make-face-unbold face frame)
869 (make-face-bold face frame)))
872 (defun set-face-italic-p (face italic-p &optional frame)
873 "Specify whether face FACE is italic.
874 ITALIC-P non-nil means FACE should explicitly display italic.
875 ITALIC-P nil means FACE should explicitly display non-italic.
876 FRAME nil or not specified means change face on all frames.
877 Use `set-face-attribute' or `modify-face' for finer control."
878 (if (null italic-p)
879 (make-face-unitalic face frame)
880 (make-face-italic face frame)))
883 (defalias 'set-face-background-pixmap 'set-face-stipple)
886 (defun invert-face (face &optional frame)
887 "Swap the foreground and background colors of FACE.
888 If FRAME is omitted or nil, it means change face on all frames.
889 If FACE specifies neither foreground nor background color,
890 set its foreground and background to the background and foreground
891 of the default face. Value is FACE."
892 (interactive (list (read-face-name "Invert face")))
893 (let ((fg (face-attribute face :foreground frame))
894 (bg (face-attribute face :background frame)))
895 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
896 (set-face-attribute face frame :foreground bg :background fg)
897 (set-face-attribute face frame
898 :foreground
899 (face-attribute 'default :background frame)
900 :background
901 (face-attribute 'default :foreground frame))))
902 face)
905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
906 ;;; Interactively modifying faces.
907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
909 (defun read-face-name (prompt &optional default multiple)
910 "Read a face, defaulting to the face or faces on the char after point.
911 If it has the property `read-face-name', that overrides the `face' property.
912 PROMPT should be a string that describes what the caller will do with the face;
913 it should not end in a space.
914 The optional argument DEFAULT provides the value to display in the
915 minibuffer prompt that is returned if the user just types RET
916 unless DEFAULT is a string (in which case nil is returned).
917 If MULTIPLE is non-nil, return a list of faces (possibly only one).
918 Otherwise, return a single face."
919 (let ((faceprop (or (get-char-property (point) 'read-face-name)
920 (get-char-property (point) 'face)))
921 (aliasfaces nil)
922 (nonaliasfaces nil)
923 faces)
924 ;; Try to get a face name from the buffer.
925 (if (memq (intern-soft (thing-at-point 'symbol)) (face-list))
926 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
927 ;; Add the named faces that the `face' property uses.
928 (if (and (listp faceprop)
929 ;; Don't treat an attribute spec as a list of faces.
930 (not (keywordp (car faceprop)))
931 (not (memq (car faceprop) '(foreground-color background-color))))
932 (dolist (f faceprop)
933 (if (symbolp f)
934 (push f faces)))
935 (if (symbolp faceprop)
936 (push faceprop faces)))
937 (delete-dups faces)
939 ;; Build up the completion tables.
940 (mapatoms (lambda (s)
941 (if (custom-facep s)
942 (if (get s 'face-alias)
943 (push (symbol-name s) aliasfaces)
944 (push (symbol-name s) nonaliasfaces)))))
946 ;; If we only want one, and the default is more than one,
947 ;; discard the unwanted ones now.
948 (unless multiple
949 (if faces
950 (setq faces (list (car faces)))))
951 (require 'crm)
952 (let* ((input
953 ;; Read the input.
954 (completing-read-multiple
955 (if (or faces default)
956 (format "%s (default `%s'): " prompt
957 (if faces (mapconcat 'symbol-name faces ",")
958 default))
959 (format "%s: " prompt))
960 (completion-table-in-turn nonaliasfaces aliasfaces)
961 nil t nil 'face-name-history
962 (if faces (mapconcat 'symbol-name faces ","))))
963 ;; Canonicalize the output.
964 (output
965 (cond ((or (equal input "") (equal input '("")))
966 (or faces (unless (stringp default) default)))
967 ((stringp input)
968 (mapcar 'intern (split-string input ", *" t)))
969 ((listp input)
970 (mapcar 'intern input))
971 (input))))
972 ;; Return either a list of faces or just one face.
973 (if multiple
974 output
975 (car output)))))
977 ;; Not defined without X, but behind window-system test.
978 (defvar x-bitmap-file-path)
980 (defun face-valid-attribute-values (attribute &optional frame)
981 "Return valid values for face attribute ATTRIBUTE.
982 The optional argument FRAME is used to determine available fonts
983 and colors. If it is nil or not specified, the selected frame is used.
984 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
985 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
986 an integer value."
987 (let ((valid
988 (case attribute
989 (:family
990 (if (window-system frame)
991 (mapcar (lambda (x) (cons x x))
992 (font-family-list))
993 ;; Only one font on TTYs.
994 (list (cons "default" "default"))))
995 (:foundry
996 (list nil))
997 (:width
998 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
999 font-width-table))
1000 (:weight
1001 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1002 font-weight-table))
1003 (:slant
1004 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1005 font-slant-table))
1006 (:inverse-video
1007 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1008 (internal-lisp-face-attribute-values attribute)))
1009 ((:underline :overline :strike-through :box)
1010 (if (window-system frame)
1011 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
1012 (internal-lisp-face-attribute-values attribute))
1013 (mapcar #'(lambda (c) (cons c c))
1014 (defined-colors frame)))
1015 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1016 (internal-lisp-face-attribute-values attribute))))
1017 ((:foreground :background)
1018 (mapcar #'(lambda (c) (cons c c))
1019 (defined-colors frame)))
1020 ((:height)
1021 'integerp)
1022 (:stipple
1023 (and (memq (window-system frame) '(x ns)) ; No stipple on w32
1024 (mapcar #'list
1025 (apply #'nconc
1026 (mapcar (lambda (dir)
1027 (and (file-readable-p dir)
1028 (file-directory-p dir)
1029 (directory-files dir)))
1030 x-bitmap-file-path)))))
1031 (:inherit
1032 (cons '("none" . nil)
1033 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1034 (face-list))))
1036 (error "Internal error")))))
1037 (if (and (listp valid) (not (memq attribute '(:inherit))))
1038 (nconc (list (cons "unspecified" 'unspecified)) valid)
1039 valid)))
1042 (defconst face-attribute-name-alist
1043 '((:family . "font family")
1044 (:foundry . "font foundry")
1045 (:width . "character set width")
1046 (:height . "height in 1/10 pt")
1047 (:weight . "weight")
1048 (:slant . "slant")
1049 (:underline . "underline")
1050 (:overline . "overline")
1051 (:strike-through . "strike-through")
1052 (:box . "box")
1053 (:inverse-video . "inverse-video display")
1054 (:foreground . "foreground color")
1055 (:background . "background color")
1056 (:stipple . "background stipple")
1057 (:inherit . "inheritance"))
1058 "An alist of descriptive names for face attributes.
1059 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1060 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1061 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1064 (defun face-descriptive-attribute-name (attribute)
1065 "Return a descriptive name for ATTRIBUTE."
1066 (cdr (assq attribute face-attribute-name-alist)))
1069 (defun face-read-string (face default name &optional completion-alist)
1070 "Interactively read a face attribute string value.
1071 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1072 default string to return if no new value is entered. NAME is a
1073 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1074 alist of valid values, if non-nil.
1076 Entering nothing accepts the default string DEFAULT.
1077 Value is the new attribute value."
1078 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1079 ;; each word in a string separately).
1080 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1081 (let* ((completion-ignore-case t)
1082 (value (completing-read
1083 (if default
1084 (format "%s for face `%s' (default %s): "
1085 name face default)
1086 (format "%s for face `%s': " name face))
1087 completion-alist nil nil nil nil default)))
1088 (if (equal value "") default value)))
1091 (defun face-read-integer (face default name)
1092 "Interactively read an integer face attribute value.
1093 FACE is the face whose attribute is read. DEFAULT is the default
1094 value to return if no new value is entered. NAME is a descriptive
1095 name of the attribute for prompting. Value is the new attribute value."
1096 (let ((new-value
1097 (face-read-string face
1098 (format "%s" default)
1099 name
1100 (list (cons "unspecified" 'unspecified)))))
1101 (cond ((equal new-value "unspecified")
1102 'unspecified)
1103 ((member new-value '("unspecified-fg" "unspecified-bg"))
1104 new-value)
1106 (string-to-number new-value)))))
1109 (defun read-face-attribute (face attribute &optional frame)
1110 "Interactively read a new value for FACE's ATTRIBUTE.
1111 Optional argument FRAME nil or unspecified means read an attribute value
1112 of a global face. Value is the new attribute value."
1113 (let* ((old-value (face-attribute face attribute frame))
1114 (attribute-name (face-descriptive-attribute-name attribute))
1115 (valid (face-valid-attribute-values attribute frame))
1116 new-value)
1117 ;; Represent complex attribute values as strings by printing them
1118 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1119 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1120 ;; SHADOW)'.
1121 (when (and (or (eq attribute :stipple)
1122 (eq attribute :box))
1123 (or (consp old-value)
1124 (vectorp old-value)))
1125 (setq old-value (prin1-to-string old-value)))
1126 (cond ((listp valid)
1127 (let ((default
1128 (or (car (rassoc old-value valid))
1129 (format "%s" old-value))))
1130 (setq new-value
1131 (face-read-string face default attribute-name valid))
1132 (if (equal new-value default)
1133 ;; Nothing changed, so don't bother with all the stuff
1134 ;; below. In particular, this avoids a non-tty color
1135 ;; from being canonicalized for a tty when the user
1136 ;; just uses the default.
1137 (setq new-value old-value)
1138 ;; Terminal frames can support colors that don't appear
1139 ;; explicitly in VALID, using color approximation code
1140 ;; in tty-colors.el.
1141 (when (and (memq attribute '(:foreground :background))
1142 (not (memq (window-system frame) '(x w32 ns)))
1143 (not (member new-value
1144 '("unspecified"
1145 "unspecified-fg" "unspecified-bg"))))
1146 (setq new-value (car (tty-color-desc new-value frame))))
1147 (when (assoc new-value valid)
1148 (setq new-value (cdr (assoc new-value valid)))))))
1149 ((eq valid 'integerp)
1150 (setq new-value (face-read-integer face old-value attribute-name)))
1151 (t (error "Internal error")))
1152 ;; Convert stipple and box value text we read back to a list or
1153 ;; vector if it looks like one. This makes the assumption that a
1154 ;; pixmap file name won't start with an open-paren.
1155 (when (and (or (eq attribute :stipple)
1156 (eq attribute :box))
1157 (stringp new-value)
1158 (string-match "^[[(]" new-value))
1159 (setq new-value (read new-value)))
1160 new-value))
1162 (declare-function fontset-list "fontset.c" ())
1163 (declare-function x-list-fonts "xfaces.c"
1164 (pattern &optional face frame maximum width))
1166 (defun read-face-font (face &optional frame)
1167 "Read the name of a font for FACE on FRAME.
1168 If optional argument FRAME is nil or omitted, use the selected frame."
1169 (let ((completion-ignore-case t))
1170 (completing-read (format "Set font attributes of face `%s' from font: " face)
1171 (append (fontset-list) (x-list-fonts "*" nil frame)))))
1174 (defun read-all-face-attributes (face &optional frame)
1175 "Interactively read all attributes for FACE.
1176 If optional argument FRAME is nil or omitted, use the selected frame.
1177 Value is a property list of attribute names and new values."
1178 (let (result)
1179 (dolist (attribute face-attribute-name-alist result)
1180 (setq result (cons (car attribute)
1181 (cons (read-face-attribute face (car attribute) frame)
1182 result))))))
1184 (defun modify-face (&optional face foreground background stipple
1185 bold-p italic-p underline inverse-p frame)
1186 "Modify attributes of faces interactively.
1187 If optional argument FRAME is nil or omitted, modify the face used
1188 for newly created frame, i.e. the global face.
1189 For non-interactive use, `set-face-attribute' is preferred.
1190 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1191 and the face and its settings are obtained by querying the user."
1192 (interactive)
1193 (if face
1194 (set-face-attribute face frame
1195 :foreground (or foreground 'unspecified)
1196 :background (or background 'unspecified)
1197 :stipple stipple
1198 :weight (if bold-p 'bold 'normal)
1199 :slant (if italic-p 'italic 'normal)
1200 :underline underline
1201 :inverse-video inverse-p)
1202 (setq face (read-face-name "Modify face"))
1203 (apply #'set-face-attribute face frame
1204 (read-all-face-attributes face frame))))
1206 (defun read-face-and-attribute (attribute &optional frame)
1207 "Read face name and face attribute value.
1208 ATTRIBUTE is the attribute whose new value is read.
1209 FRAME nil or unspecified means read attribute value of global face.
1210 Value is a list (FACE NEW-VALUE) where FACE is the face read
1211 \(a symbol), and NEW-VALUE is value read."
1212 (cond ((eq attribute :font)
1213 (let* ((prompt "Set font-related attributes of face")
1214 (face (read-face-name prompt))
1215 (font (read-face-font face frame)))
1216 (list face font)))
1218 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1219 (prompt (format "Set %s of face" attribute-name))
1220 (face (read-face-name prompt))
1221 (new-value (read-face-attribute face attribute frame)))
1222 (list face new-value)))))
1226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1227 ;;; Listing faces.
1228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1230 (defconst list-faces-sample-text
1231 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1232 "Text string to display as the sample text for `list-faces-display'.")
1235 ;; The name list-faces would be more consistent, but let's avoid a
1236 ;; conflict with Lucid, which uses that name differently.
1238 (defvar help-xref-stack)
1239 (defun list-faces-display (&optional regexp)
1240 "List all faces, using the same sample text in each.
1241 The sample text is a string that comes from the variable
1242 `list-faces-sample-text'.
1244 If REGEXP is non-nil, list only those faces with names matching
1245 this regular expression. When called interactively with a prefix
1246 arg, prompt for a regular expression."
1247 (interactive (list (and current-prefix-arg
1248 (read-regexp "List faces matching regexp"))))
1249 (let ((all-faces (zerop (length regexp)))
1250 (frame (selected-frame))
1251 (max-length 0)
1252 faces line-format
1253 disp-frame window face-name)
1254 ;; We filter and take the max length in one pass
1255 (setq faces
1256 (delq nil
1257 (mapcar (lambda (f)
1258 (let ((s (symbol-name f)))
1259 (when (or all-faces (string-match regexp s))
1260 (setq max-length (max (length s) max-length))
1261 f)))
1262 (sort (face-list) #'string-lessp))))
1263 (unless faces
1264 (error "No faces matching \"%s\"" regexp))
1265 (setq max-length (1+ max-length)
1266 line-format (format "%%-%ds" max-length))
1267 (with-help-window "*Faces*"
1268 (with-current-buffer standard-output
1269 (setq truncate-lines t)
1270 (insert
1271 (substitute-command-keys
1272 (concat
1273 "\\<help-mode-map>Use "
1274 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1275 "\\[help-follow] on a face name to customize it\n"
1276 "or on its sample text for a description of the face.\n\n")))
1277 (setq help-xref-stack nil)
1278 (dolist (face faces)
1279 (setq face-name (symbol-name face))
1280 (insert (format line-format face-name))
1281 ;; Hyperlink to a customization buffer for the face. Using
1282 ;; the help xref mechanism may not be the best way.
1283 (save-excursion
1284 (save-match-data
1285 (search-backward face-name)
1286 (setq help-xref-stack-item `(list-faces-display ,regexp))
1287 (help-xref-button 0 'help-customize-face face)))
1288 (let ((beg (point))
1289 (line-beg (line-beginning-position)))
1290 (insert list-faces-sample-text)
1291 ;; Hyperlink to a help buffer for the face.
1292 (save-excursion
1293 (save-match-data
1294 (search-backward list-faces-sample-text)
1295 (help-xref-button 0 'help-face face)))
1296 (insert "\n")
1297 (put-text-property beg (1- (point)) 'face face)
1298 ;; Make all face commands default to the proper face
1299 ;; anywhere in the line.
1300 (put-text-property line-beg (1- (point)) 'read-face-name face)
1301 ;; If the sample text has multiple lines, line up all of them.
1302 (goto-char beg)
1303 (forward-line 1)
1304 (while (not (eobp))
1305 (insert-char ?\s max-length)
1306 (forward-line 1))))
1307 (goto-char (point-min))))
1308 ;; If the *Faces* buffer appears in a different frame,
1309 ;; copy all the face definitions from FRAME,
1310 ;; so that the display will reflect the frame that was selected.
1311 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1312 (setq disp-frame (if window (window-frame window)
1313 (car (frame-list))))
1314 (or (eq frame disp-frame)
1315 (let ((faces (face-list)))
1316 (while faces
1317 (copy-face (car faces) (car faces) frame disp-frame)
1318 (setq faces (cdr faces)))))))
1321 (defun describe-face (face &optional frame)
1322 "Display the properties of face FACE on FRAME.
1323 Interactively, FACE defaults to the faces of the character after point
1324 and FRAME defaults to the selected frame.
1326 If the optional argument FRAME is given, report on face FACE in that frame.
1327 If FRAME is t, report on the defaults for face FACE (for new frames).
1328 If FRAME is omitted or nil, use the selected frame."
1329 (interactive (list (read-face-name "Describe face" 'default t)))
1330 (let* ((attrs '((:family . "Family")
1331 (:foundry . "Foundry")
1332 (:width . "Width")
1333 (:height . "Height")
1334 (:weight . "Weight")
1335 (:slant . "Slant")
1336 (:foreground . "Foreground")
1337 (:background . "Background")
1338 (:underline . "Underline")
1339 (:overline . "Overline")
1340 (:strike-through . "Strike-through")
1341 (:box . "Box")
1342 (:inverse-video . "Inverse")
1343 (:stipple . "Stipple")
1344 (:font . "Font")
1345 (:fontset . "Fontset")
1346 (:inherit . "Inherit")))
1347 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1348 attrs))))
1349 (help-setup-xref (list #'describe-face face)
1350 (called-interactively-p 'interactive))
1351 (unless face
1352 (setq face 'default))
1353 (if (not (listp face))
1354 (setq face (list face)))
1355 (with-help-window (help-buffer)
1356 (with-current-buffer standard-output
1357 (dolist (f face)
1358 (if (stringp f) (setq f (intern f)))
1359 ;; We may get called for anonymous faces (i.e., faces
1360 ;; expressed using prop-value plists). Those can't be
1361 ;; usefully customized, so ignore them.
1362 (when (symbolp f)
1363 (insert "Face: " (symbol-name f))
1364 (if (not (facep f))
1365 (insert " undefined face.\n")
1366 (let ((customize-label "customize this face")
1367 file-name)
1368 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1369 (princ (concat " (" customize-label ")\n"))
1370 ;; FIXME not sure how much of this belongs here, and
1371 ;; how much in `face-documentation'. The latter is
1372 ;; not used much, but needs to return nil for
1373 ;; undocumented faces.
1374 (let ((alias (get f 'face-alias))
1375 (face f)
1376 obsolete)
1377 (when alias
1378 (setq face alias)
1379 (insert
1380 (format "\n %s is an alias for the face `%s'.\n%s"
1381 f alias
1382 (if (setq obsolete (get f 'obsolete-face))
1383 (format " This face is obsolete%s; use `%s' instead.\n"
1384 (if (stringp obsolete)
1385 (format " since %s" obsolete)
1387 alias)
1388 ""))))
1389 (insert "\nDocumentation:\n"
1390 (or (face-documentation face)
1391 "Not documented as a face.")
1392 "\n\n"))
1393 (with-current-buffer standard-output
1394 (save-excursion
1395 (re-search-backward
1396 (concat "\\(" customize-label "\\)") nil t)
1397 (help-xref-button 1 'help-customize-face f)))
1398 (setq file-name (find-lisp-object-file-name f 'defface))
1399 (when file-name
1400 (princ "Defined in `")
1401 (princ (file-name-nondirectory file-name))
1402 (princ "'")
1403 ;; Make a hyperlink to the library.
1404 (save-excursion
1405 (re-search-backward "`\\([^`']+\\)'" nil t)
1406 (help-xref-button 1 'help-face-def f file-name))
1407 (princ ".")
1408 (terpri)
1409 (terpri))
1410 (dolist (a attrs)
1411 (let ((attr (face-attribute f (car a) frame)))
1412 (insert (make-string (- max-width (length (cdr a))) ?\s)
1413 (cdr a) ": " (format "%s" attr))
1414 (if (and (eq (car a) :inherit)
1415 (not (eq attr 'unspecified)))
1416 ;; Make a hyperlink to the parent face.
1417 (save-excursion
1418 (re-search-backward ": \\([^:]+\\)" nil t)
1419 (help-xref-button 1 'help-face attr)))
1420 (insert "\n")))))
1421 (terpri)))))))
1424 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1425 ;;; Face specifications (defface).
1426 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1428 ;; Parameter FRAME Is kept for call compatibility to with previous
1429 ;; face implementation.
1431 (defun face-attr-construct (face &optional _frame)
1432 "Return a `defface'-style attribute list for FACE.
1433 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1434 face attributes of FACE where ATTRIBUTE is the attribute name and
1435 VALUE is the specified value of that attribute.
1436 Argument FRAME is ignored and retained for compatibility."
1437 (let (result)
1438 (dolist (entry face-attribute-name-alist result)
1439 (let* ((attribute (car entry))
1440 (value (face-attribute face attribute)))
1441 (unless (eq value 'unspecified)
1442 (setq result (nconc (list attribute value) result)))))))
1445 (defun face-spec-set-match-display (display frame)
1446 "Non-nil if DISPLAY matches FRAME.
1447 DISPLAY is part of a spec such as can be used in `defface'.
1448 If FRAME is nil, the current FRAME is used."
1449 (let* ((conjuncts display)
1450 conjunct req options
1451 ;; t means we have succeeded against all the conjuncts in
1452 ;; DISPLAY that have been tested so far.
1453 (match t))
1454 (if (eq conjuncts t)
1455 (setq conjuncts nil))
1456 (while (and conjuncts match)
1457 (setq conjunct (car conjuncts)
1458 conjuncts (cdr conjuncts)
1459 req (car conjunct)
1460 options (cdr conjunct)
1461 match (cond ((eq req 'type)
1462 (or (memq (window-system frame) options)
1463 (and (memq 'graphic options)
1464 (memq (window-system frame) '(x w32 ns)))
1465 ;; FIXME: This should be revisited to use
1466 ;; display-graphic-p, provided that the
1467 ;; color selection depends on the number
1468 ;; of supported colors, and all defface's
1469 ;; are changed to look at number of colors
1470 ;; instead of (type graphic) etc.
1471 (if (null (window-system frame))
1472 (memq 'tty options)
1473 (or (and (memq 'motif options)
1474 (featurep 'motif))
1475 (and (memq 'gtk options)
1476 (featurep 'gtk))
1477 (and (memq 'lucid options)
1478 (featurep 'x-toolkit)
1479 (not (featurep 'motif))
1480 (not (featurep 'gtk)))
1481 (and (memq 'x-toolkit options)
1482 (featurep 'x-toolkit))))))
1483 ((eq req 'min-colors)
1484 (>= (display-color-cells frame) (car options)))
1485 ((eq req 'class)
1486 (memq (frame-parameter frame 'display-type) options))
1487 ((eq req 'background)
1488 (memq (frame-parameter frame 'background-mode)
1489 options))
1490 ((eq req 'supports)
1491 (display-supports-face-attributes-p options frame))
1492 (t (error "Unknown req `%S' with options `%S'"
1493 req options)))))
1494 match))
1497 (defun face-spec-choose (spec &optional frame)
1498 "Choose the proper attributes for FRAME, out of SPEC.
1499 If SPEC is nil, return nil."
1500 (unless frame
1501 (setq frame (selected-frame)))
1502 (let ((tail spec)
1503 result defaults)
1504 (while tail
1505 (let* ((entry (pop tail))
1506 (display (car entry))
1507 (attrs (cdr entry))
1508 thisval)
1509 ;; Get the attributes as actually specified by this alternative.
1510 (setq thisval
1511 (if (null (cdr attrs)) ;; was (listp (car attrs))
1512 ;; Old-style entry, the attribute list is the
1513 ;; first element.
1514 (car attrs)
1515 attrs))
1517 ;; If the condition is `default', that sets the default
1518 ;; for following conditions.
1519 (if (eq display 'default)
1520 (setq defaults thisval)
1521 ;; Otherwise, if it matches, use it.
1522 (when (face-spec-set-match-display display frame)
1523 (setq result thisval)
1524 (setq tail nil)))))
1525 (if defaults (append result defaults) result)))
1528 (defun face-spec-reset-face (face &optional frame)
1529 "Reset all attributes of FACE on FRAME to unspecified."
1530 (apply 'set-face-attribute face frame
1531 (if (eq face 'default)
1532 ;; For the default face, avoid making any attribute
1533 ;; unspecified. Instead, set attributes to default values
1534 ;; (see also realize_default_face in xfaces.c).
1535 (append
1536 '(:underline nil :overline nil :strike-through nil
1537 :box nil :inverse-video nil :stipple nil :inherit nil)
1538 ;; `display-graphic-p' is unavailable when running
1539 ;; temacs, prior to loading frame.el.
1540 (unless (and (fboundp 'display-graphic-p)
1541 (display-graphic-p frame))
1542 '(:family "default" :foundry "default" :width normal
1543 :height 1 :weight normal :slant normal
1544 :foreground "unspecified-fg"
1545 :background "unspecified-bg")))
1546 ;; For all other faces, unspecify all attributes.
1547 (apply 'append
1548 (mapcar (lambda (x) (list (car x) 'unspecified))
1549 face-attribute-name-alist)))))
1551 (defun face-spec-set (face spec &optional for-defface)
1552 "Set and apply the face spec for FACE.
1553 If the optional argument FOR-DEFFACE is omitted or nil, set the
1554 overriding spec to SPEC, recording it in the `face-override-spec'
1555 property of FACE. See `defface' for the format of SPEC.
1557 If FOR-DEFFACE is non-nil, set the base spec (the one set by
1558 `defface' and Custom). In this case, SPEC is ignored; the caller
1559 is responsible for putting the face spec in the `saved-face',
1560 `customized-face', or `face-defface-spec', as appropriate.
1562 The appearance of FACE is controlled by the base spec, by any
1563 custom theme specs on top of that, and by the overriding spec on
1564 top of all the rest."
1565 (if for-defface
1566 ;; When we reset the face based on its custom spec, then it is
1567 ;; unmodified as far as Custom is concerned.
1568 (put (or (get face 'face-alias) face) 'face-modified nil)
1569 ;; When we change a face based on a spec from outside custom,
1570 ;; record it for future frames.
1571 (put (or (get face 'face-alias) face) 'face-override-spec spec))
1572 ;; Reset each frame according to the rules implied by all its specs.
1573 (dolist (frame (frame-list))
1574 (face-spec-recalc face frame)))
1576 (defun face-spec-recalc (face frame)
1577 "Reset the face attributes of FACE on FRAME according to its specs.
1578 This applies the defface/custom spec first, then the custom theme specs,
1579 then the override spec."
1580 (face-spec-reset-face face frame)
1581 (let ((face-sym (or (get face 'face-alias) face)))
1582 (or (get face 'customized-face)
1583 (get face 'saved-face)
1584 (face-spec-set-2 face frame (face-default-spec face)))
1585 (let ((theme-faces (reverse (get face-sym 'theme-face))))
1586 (dolist (spec theme-faces)
1587 (face-spec-set-2 face frame (cadr spec))))
1588 (face-spec-set-2 face frame (get face-sym 'face-override-spec))))
1590 (defun face-spec-set-2 (face frame spec)
1591 "Set the face attributes of FACE on FRAME according to SPEC."
1592 (let* ((spec (face-spec-choose spec frame))
1593 attrs)
1594 (while spec
1595 (when (assq (car spec) face-x-resources)
1596 (push (car spec) attrs)
1597 (push (cadr spec) attrs))
1598 (setq spec (cddr spec)))
1599 (apply 'set-face-attribute face frame (nreverse attrs))))
1601 (defun face-attr-match-p (face attrs &optional frame)
1602 "Return t if attributes of FACE match values in plist ATTRS.
1603 Optional parameter FRAME is the frame whose definition of FACE
1604 is used. If nil or omitted, use the selected frame."
1605 (unless frame
1606 (setq frame (selected-frame)))
1607 (let* ((list face-attribute-name-alist)
1608 (match t)
1609 (bold (and (plist-member attrs :bold)
1610 (not (plist-member attrs :weight))))
1611 (italic (and (plist-member attrs :italic)
1612 (not (plist-member attrs :slant))))
1613 (plist (if (or bold italic)
1614 (copy-sequence attrs)
1615 attrs)))
1616 ;; Handle the Emacs 20 :bold and :italic properties.
1617 (if bold
1618 (plist-put plist :weight (if bold 'bold 'normal)))
1619 (if italic
1620 (plist-put plist :slant (if italic 'italic 'normal)))
1621 (while (and match list)
1622 (let* ((attr (caar list))
1623 (specified-value
1624 (if (plist-member plist attr)
1625 (plist-get plist attr)
1626 'unspecified))
1627 (value-now (face-attribute face attr frame)))
1628 (setq match (equal specified-value value-now))
1629 (setq list (cdr list))))
1630 match))
1632 (defsubst face-spec-match-p (face spec &optional frame)
1633 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1634 (face-attr-match-p face (face-spec-choose spec frame) frame))
1636 (defsubst face-default-spec (face)
1637 "Return the default face-spec for FACE, ignoring any user customization.
1638 If there is no default for FACE, return nil."
1639 (get face 'face-defface-spec))
1641 (defsubst face-user-default-spec (face)
1642 "Return the user's customized face-spec for FACE, or the default if none.
1643 If there is neither a user setting nor a default for FACE, return nil."
1644 (or (get face 'customized-face)
1645 (get face 'saved-face)
1646 (face-default-spec face)))
1649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1650 ;;; Frame-type independent color support.
1651 ;;; We keep the old x-* names as aliases for back-compatibility.
1652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1654 (defun defined-colors (&optional frame)
1655 "Return a list of colors supported for a particular frame.
1656 The argument FRAME specifies which frame to try.
1657 The value may be different for frames on different display types.
1658 If FRAME doesn't support colors, the value is nil.
1659 If FRAME is nil, that stands for the selected frame."
1660 (if (memq (framep (or frame (selected-frame))) '(x w32 ns))
1661 (xw-defined-colors frame)
1662 (mapcar 'car (tty-color-alist frame))))
1663 (defalias 'x-defined-colors 'defined-colors)
1665 (declare-function xw-color-defined-p "xfns.c" (color &optional frame))
1667 (defun color-defined-p (color &optional frame)
1668 "Return non-nil if color COLOR is supported on frame FRAME.
1669 If FRAME is omitted or nil, use the selected frame.
1670 If COLOR is the symbol `unspecified' or one of the strings
1671 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1672 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1674 (if (member (framep (or frame (selected-frame))) '(x w32 ns))
1675 (xw-color-defined-p color frame)
1676 (numberp (tty-color-translate color frame)))))
1677 (defalias 'x-color-defined-p 'color-defined-p)
1679 (declare-function xw-color-values "xfns.c" (color &optional frame))
1681 (defun color-values (color &optional frame)
1682 "Return a description of the color named COLOR on frame FRAME.
1683 COLOR should be a string naming a color (e.g. \"white\"), or a
1684 string specifying a color's RGB components (e.g. \"#ff12ec\").
1686 Return a list of three integers, (RED GREEN BLUE), each between 0
1687 and either 65280 or 65535 (the maximum depends on the system).
1688 Use `color-name-to-rgb' if you want RGB floating-point values
1689 normalized to 1.0.
1691 If FRAME is omitted or nil, use the selected frame.
1692 If FRAME cannot display COLOR, the value is nil.
1694 COLOR can also be the symbol `unspecified' or one of the strings
1695 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1696 return value is nil."
1697 (cond
1698 ((member color '(unspecified "unspecified-fg" "unspecified-bg"))
1699 nil)
1700 ((memq (framep (or frame (selected-frame))) '(x w32 ns))
1701 (xw-color-values color frame))
1703 (tty-color-values color frame))))
1705 (defalias 'x-color-values 'color-values)
1707 (declare-function xw-display-color-p "xfns.c" (&optional terminal))
1709 (defun display-color-p (&optional display)
1710 "Return t if DISPLAY supports color.
1711 The optional argument DISPLAY specifies which display to ask about.
1712 DISPLAY should be either a frame or a display name (a string).
1713 If omitted or nil, that stands for the selected frame's display."
1714 (if (memq (framep-on-display display) '(x w32 ns))
1715 (xw-display-color-p display)
1716 (tty-display-color-p display)))
1717 (defalias 'x-display-color-p 'display-color-p)
1719 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
1721 (defun display-grayscale-p (&optional display)
1722 "Return non-nil if frames on DISPLAY can display shades of gray."
1723 (let ((frame-type (framep-on-display display)))
1724 (cond
1725 ((memq frame-type '(x w32 ns))
1726 (x-display-grayscale-p display))
1728 (> (tty-color-gray-shades display) 2)))))
1730 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg)
1731 "Read a color name or RGB triplet.
1732 Completion is available for color names, but not for RGB triplets.
1734 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1735 components can have one to four digits, but all three components
1736 must have the same number of digits. Each digit is a hex value
1737 between 0 and F; either upper case or lower case for A through F
1738 are acceptable.
1740 In addition to standard color names and RGB hex values, the
1741 following are available as color candidates. In each case, the
1742 corresponding color is used.
1744 * `foreground at point' - foreground under the cursor
1745 * `background at point' - background under the cursor
1747 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1749 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1750 convert an input color name to an RGB hex string. Return the RGB
1751 hex string.
1753 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1754 to enter an empty color name (the empty string).
1756 Interactively, or with optional arg MSG non-nil, print the
1757 resulting color name in the echo area."
1758 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1759 (let* ((completion-ignore-case t)
1760 (colors (or facemenu-color-alist
1761 (append '("foreground at point" "background at point")
1762 (if allow-empty-name '(""))
1763 (defined-colors))))
1764 (color (completing-read
1765 (or prompt "Color (name or #RGB triplet): ")
1766 ;; Completing function for reading colors, accepting
1767 ;; both color names and RGB triplets.
1768 (lambda (string pred flag)
1769 (cond
1770 ((null flag) ; Try completion.
1771 (or (try-completion string colors pred)
1772 (if (color-defined-p string)
1773 string)))
1774 ((eq flag t) ; List all completions.
1775 (or (all-completions string colors pred)
1776 (if (color-defined-p string)
1777 (list string))))
1778 ((eq flag 'lambda) ; Test completion.
1779 (or (memq string colors)
1780 (color-defined-p string)))))
1781 nil t)))
1783 ;; Process named colors.
1784 (when (member color colors)
1785 (cond ((string-equal color "foreground at point")
1786 (setq color (foreground-color-at-point)))
1787 ((string-equal color "background at point")
1788 (setq color (background-color-at-point))))
1789 (when (and convert-to-RGB
1790 (not (string-equal color "")))
1791 (let ((components (x-color-values color)))
1792 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1793 (setq color (format "#%04X%04X%04X"
1794 (logand 65535 (nth 0 components))
1795 (logand 65535 (nth 1 components))
1796 (logand 65535 (nth 2 components))))))))
1797 (when msg (message "Color: `%s'" color))
1798 color))
1801 (defun face-at-point ()
1802 "Return the face of the character after point.
1803 If it has more than one face, return the first one.
1804 Return nil if it has no specified face."
1805 (let* ((faceprop (or (get-char-property (point) 'read-face-name)
1806 (get-char-property (point) 'face)
1807 'default))
1808 (face (cond ((symbolp faceprop) faceprop)
1809 ;; List of faces (don't treat an attribute spec).
1810 ;; Just use the first face.
1811 ((and (consp faceprop) (not (keywordp (car faceprop)))
1812 (not (memq (car faceprop)
1813 '(foreground-color background-color))))
1814 (car faceprop))
1815 (t nil)))) ; Invalid face value.
1816 (if (facep face) face nil)))
1818 (defun foreground-color-at-point ()
1819 "Return the foreground color of the character after point."
1820 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1821 ;; Need also pick up any face properties that are not associated with named faces.
1822 (let ((face (or (face-at-point)
1823 (get-char-property (point) 'read-face-name)
1824 (get-char-property (point) 'face))))
1825 (cond ((and face (symbolp face))
1826 (let ((value (face-foreground face nil 'default)))
1827 (if (member value '("unspecified-fg" "unspecified-bg"))
1829 value)))
1830 ((consp face)
1831 (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face)))
1832 ((memq ':foreground face) (cadr (memq ':foreground face)))))
1833 (t nil)))) ; Invalid face value.
1835 (defun background-color-at-point ()
1836 "Return the background color of the character after point."
1837 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1838 ;; Need also pick up any face properties that are not associated with named faces.
1839 (let ((face (or (face-at-point)
1840 (get-char-property (point) 'read-face-name)
1841 (get-char-property (point) 'face))))
1842 (cond ((and face (symbolp face))
1843 (let ((value (face-background face nil 'default)))
1844 (if (member value '("unspecified-fg" "unspecified-bg"))
1846 value)))
1847 ((consp face)
1848 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1849 ((memq ':background face) (cadr (memq ':background face)))))
1850 (t nil)))) ; Invalid face value.
1853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1854 ;;; Frame creation.
1855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1857 (declare-function x-parse-geometry "frame.c" (string))
1859 (defun x-handle-named-frame-geometry (parameters)
1860 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1861 Value is the new parameter list."
1862 ;; Note that `x-resource-name' has a global meaning.
1863 (let ((x-resource-name (cdr (assq 'name parameters))))
1864 (when x-resource-name
1865 ;; Before checking X resources, we must have an X connection.
1866 (or (window-system)
1867 (x-display-list)
1868 (x-open-connection (or (cdr (assq 'display parameters))
1869 x-display-name)))
1870 (let (res-geometry parsed)
1871 (and (setq res-geometry (x-get-resource "geometry" "Geometry"))
1872 (setq parsed (x-parse-geometry res-geometry))
1873 (setq parameters
1874 (append parameters parsed
1875 ;; If the resource specifies a position,
1876 ;; take note of that.
1877 (if (or (assq 'top parsed) (assq 'left parsed))
1878 '((user-position . t) (user-size . t)))))))))
1879 parameters)
1882 (defun x-handle-reverse-video (frame parameters)
1883 "Handle the reverse-video frame parameter and X resource.
1884 `x-create-frame' does not handle this one."
1885 (when (cdr (or (assq 'reverse parameters)
1886 (let ((resource (x-get-resource "reverseVideo"
1887 "ReverseVideo")))
1888 (if resource
1889 (cons nil (member (downcase resource)
1890 '("on" "true")))))))
1891 (let* ((params (frame-parameters frame))
1892 (bg (cdr (assq 'foreground-color params)))
1893 (fg (cdr (assq 'background-color params))))
1894 (modify-frame-parameters frame
1895 (list (cons 'foreground-color fg)
1896 (cons 'background-color bg)))
1897 (if (equal bg (cdr (assq 'border-color params)))
1898 (modify-frame-parameters frame
1899 (list (cons 'border-color fg))))
1900 (if (equal bg (cdr (assq 'mouse-color params)))
1901 (modify-frame-parameters frame
1902 (list (cons 'mouse-color fg))))
1903 (if (equal bg (cdr (assq 'cursor-color params)))
1904 (modify-frame-parameters frame
1905 (list (cons 'cursor-color fg)))))))
1907 (declare-function x-create-frame "xfns.c" (parms))
1908 (declare-function x-setup-function-keys "term/common-win" (frame))
1910 (defun x-create-frame-with-faces (&optional parameters)
1911 "Create and return a frame with frame parameters PARAMETERS.
1912 If PARAMETERS specify a frame name, handle X geometry resources
1913 for that name. If PARAMETERS includes a `reverse' parameter, or
1914 the X resource ``reverseVideo'' is present, handle that."
1915 (setq parameters (x-handle-named-frame-geometry parameters))
1916 (let* ((params (copy-tree parameters))
1917 (visibility-spec (assq 'visibility parameters))
1918 (delayed-params '(foreground-color background-color font
1919 border-color cursor-color mouse-color
1920 visibility scroll-bar-foreground
1921 scroll-bar-background))
1922 frame success)
1923 (dolist (param delayed-params)
1924 (setq params (assq-delete-all param params)))
1925 (setq frame (x-create-frame `((visibility . nil) . ,params)))
1926 (unwind-protect
1927 (progn
1928 (x-setup-function-keys frame)
1929 (x-handle-reverse-video frame parameters)
1930 (frame-set-background-mode frame t)
1931 (face-set-after-frame-default frame parameters)
1932 (if (null visibility-spec)
1933 (make-frame-visible frame)
1934 (modify-frame-parameters frame (list visibility-spec)))
1935 (setq success t))
1936 (unless success
1937 (delete-frame frame)))
1938 frame))
1940 (defun face-set-after-frame-default (frame &optional parameters)
1941 "Initialize the frame-local faces of FRAME.
1942 Calculate the face definitions using the face specs, custom theme
1943 settings, X resources, and `face-new-frame-defaults'.
1944 Finally, apply any relevant face attributes found amongst the
1945 frame parameters in PARAMETERS."
1946 (let ((window-system-p (memq (window-system frame) '(x w32))))
1947 ;; The `reverse' is so that `default' goes first.
1948 (dolist (face (nreverse (face-list)))
1949 (condition-case ()
1950 (progn
1951 ;; Initialize faces from face spec and custom theme.
1952 (face-spec-recalc face frame)
1953 ;; X resources for the default face are applied during
1954 ;; `x-create-frame'.
1955 (and (not (eq face 'default)) window-system-p
1956 (make-face-x-resource-internal face frame))
1957 ;; Apply attributes specified by face-new-frame-defaults
1958 (internal-merge-in-global-face face frame))
1959 ;; Don't let invalid specs prevent frame creation.
1960 (error nil))))
1962 ;; Apply attributes specified by frame parameters.
1963 (let ((face-params '((foreground-color default :foreground)
1964 (background-color default :background)
1965 (font default :font)
1966 (border-color border :background)
1967 (cursor-color cursor :background)
1968 (scroll-bar-foreground scroll-bar :foreground)
1969 (scroll-bar-background scroll-bar :background)
1970 (mouse-color mouse :background))))
1971 (dolist (param face-params)
1972 (let* ((param-name (nth 0 param))
1973 (value (cdr (assq param-name parameters))))
1974 (if value
1975 (set-face-attribute (nth 1 param) frame
1976 (nth 2 param) value))))))
1978 (defun tty-handle-reverse-video (frame parameters)
1979 "Handle the reverse-video frame parameter for terminal frames."
1980 (when (cdr (assq 'reverse parameters))
1981 (let* ((params (frame-parameters frame))
1982 (bg (cdr (assq 'foreground-color params)))
1983 (fg (cdr (assq 'background-color params))))
1984 (modify-frame-parameters frame
1985 (list (cons 'foreground-color fg)
1986 (cons 'background-color bg)))
1987 (if (equal bg (cdr (assq 'mouse-color params)))
1988 (modify-frame-parameters frame
1989 (list (cons 'mouse-color fg))))
1990 (if (equal bg (cdr (assq 'cursor-color params)))
1991 (modify-frame-parameters frame
1992 (list (cons 'cursor-color fg)))))))
1995 (defun tty-create-frame-with-faces (&optional parameters)
1996 "Create and return a frame from optional frame parameters PARAMETERS.
1997 If PARAMETERS contains a `reverse' parameter, handle that."
1998 (let ((frame (make-terminal-frame parameters))
1999 success)
2000 (unwind-protect
2001 (with-selected-frame frame
2002 (tty-handle-reverse-video frame (frame-parameters frame))
2004 (unless (terminal-parameter frame 'terminal-initted)
2005 (set-terminal-parameter frame 'terminal-initted t)
2006 (set-locale-environment nil frame)
2007 (tty-run-terminal-initialization frame))
2008 (frame-set-background-mode frame t)
2009 (face-set-after-frame-default frame parameters)
2010 (setq success t))
2011 (unless success
2012 (delete-frame frame)))
2013 frame))
2015 (defun tty-find-type (pred type)
2016 "Return the longest prefix of TYPE to which PRED returns non-nil.
2017 TYPE should be a tty type name such as \"xterm-16color\".
2019 The function tries only those prefixes that are followed by a
2020 dash or underscore in the original type name, like \"xterm\" in
2021 the above example."
2022 (let (hyphend)
2023 (while (and type
2024 (not (funcall pred type)))
2025 ;; Strip off last hyphen and what follows, then try again
2026 (setq type
2027 (if (setq hyphend (string-match "[-_][^-_]+$" type))
2028 (substring type 0 hyphend)
2029 nil))))
2030 type)
2032 (defun tty-run-terminal-initialization (frame &optional type)
2033 "Run the special initialization code for the terminal type of FRAME.
2034 The optional TYPE parameter may be used to override the autodetected
2035 terminal type to a different value."
2036 (setq type (or type (tty-type frame)))
2037 ;; Load library for our terminal type.
2038 ;; User init file can set term-file-prefix to nil to prevent this.
2039 (with-selected-frame frame
2040 (unless (null term-file-prefix)
2041 (let* (term-init-func)
2042 ;; First, load the terminal initialization file, if it is
2043 ;; available and it hasn't been loaded already.
2044 (tty-find-type #'(lambda (type)
2045 (let ((file (locate-library (concat term-file-prefix type))))
2046 (and file
2047 (or (assoc file load-history)
2048 (load file t t)))))
2049 type)
2050 ;; Next, try to find a matching initialization function, and call it.
2051 (tty-find-type #'(lambda (type)
2052 (fboundp (setq term-init-func
2053 (intern (concat "terminal-init-" type)))))
2054 type)
2055 (when (fboundp term-init-func)
2056 (funcall term-init-func))
2057 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
2059 ;; Called from C function init_display to initialize faces of the
2060 ;; dumped terminal frame on startup.
2062 (defun tty-set-up-initial-frame-faces ()
2063 (let ((frame (selected-frame)))
2064 (frame-set-background-mode frame t)
2065 (face-set-after-frame-default frame)))
2069 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2070 ;;; Standard faces.
2071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2073 (defgroup basic-faces nil
2074 "The standard faces of Emacs."
2075 :group 'faces)
2077 (defface default
2078 '((t nil)) ; If this were nil, face-defface-spec would not be set.
2079 "Basic default face."
2080 :group 'basic-faces)
2082 (defface bold
2083 '((t :weight bold))
2084 "Basic bold face."
2085 :group 'basic-faces)
2087 (defface italic
2088 '((((supports :slant italic))
2089 :slant italic)
2090 (((supports :underline t))
2091 :underline t)
2093 ;; Default to italic, even if it doesn't appear to be supported,
2094 ;; because in some cases the display engine will do its own
2095 ;; workaround (to `dim' on ttys).
2096 :slant italic))
2097 "Basic italic face."
2098 :group 'basic-faces)
2100 (defface bold-italic
2101 '((t :weight bold :slant italic))
2102 "Basic bold-italic face."
2103 :group 'basic-faces)
2105 (defface underline
2106 '((((supports :underline t))
2107 :underline t)
2108 (((supports :weight bold))
2109 :weight bold)
2110 (t :underline t))
2111 "Basic underlined face."
2112 :group 'basic-faces)
2114 (defface fixed-pitch
2115 '((t :family "Monospace"))
2116 "The basic fixed-pitch face."
2117 :group 'basic-faces)
2119 (defface variable-pitch
2120 '((t :family "Sans Serif"))
2121 "The basic variable-pitch face."
2122 :group 'basic-faces)
2124 (defface shadow
2125 '((((class color grayscale) (min-colors 88) (background light))
2126 :foreground "grey50")
2127 (((class color grayscale) (min-colors 88) (background dark))
2128 :foreground "grey70")
2129 (((class color) (min-colors 8) (background light))
2130 :foreground "green")
2131 (((class color) (min-colors 8) (background dark))
2132 :foreground "yellow"))
2133 "Basic face for shadowed text."
2134 :group 'basic-faces
2135 :version "22.1")
2137 (defface link
2138 '((((class color) (min-colors 88) (background light))
2139 :foreground "RoyalBlue3" :underline t)
2140 (((class color) (background light))
2141 :foreground "blue" :underline t)
2142 (((class color) (min-colors 88) (background dark))
2143 :foreground "cyan1" :underline t)
2144 (((class color) (background dark))
2145 :foreground "cyan" :underline t)
2146 (t :inherit underline))
2147 "Basic face for unvisited links."
2148 :group 'basic-faces
2149 :version "22.1")
2151 (defface link-visited
2152 '((default :inherit link)
2153 (((class color) (background light)) :foreground "magenta4")
2154 (((class color) (background dark)) :foreground "violet"))
2155 "Basic face for visited links."
2156 :group 'basic-faces
2157 :version "22.1")
2159 (defface highlight
2160 '((((class color) (min-colors 88) (background light))
2161 :background "darkseagreen2")
2162 (((class color) (min-colors 88) (background dark))
2163 :background "darkolivegreen")
2164 (((class color) (min-colors 16) (background light))
2165 :background "darkseagreen2")
2166 (((class color) (min-colors 16) (background dark))
2167 :background "darkolivegreen")
2168 (((class color) (min-colors 8))
2169 :background "green" :foreground "black")
2170 (t :inverse-video t))
2171 "Basic face for highlighting."
2172 :group 'basic-faces)
2174 ;; Region face: under NS, default to the system-defined selection
2175 ;; color (optimized for the fixed white background of other apps),
2176 ;; if background is light.
2177 (defface region
2178 '((((class color) (min-colors 88) (background dark))
2179 :background "blue3")
2180 (((class color) (min-colors 88) (background light) (type gtk))
2181 :foreground "gtk_selection_fg_color"
2182 :background "gtk_selection_bg_color")
2183 (((class color) (min-colors 88) (background light) (type ns))
2184 :background "ns_selection_color")
2185 (((class color) (min-colors 88) (background light))
2186 :background "lightgoldenrod2")
2187 (((class color) (min-colors 16) (background dark))
2188 :background "blue3")
2189 (((class color) (min-colors 16) (background light))
2190 :background "lightgoldenrod2")
2191 (((class color) (min-colors 8))
2192 :background "blue" :foreground "white")
2193 (((type tty) (class mono))
2194 :inverse-video t)
2195 (t :background "gray"))
2196 "Basic face for highlighting the region."
2197 :version "21.1"
2198 :group 'basic-faces)
2200 (defface secondary-selection
2201 '((((class color) (min-colors 88) (background light))
2202 :background "yellow1")
2203 (((class color) (min-colors 88) (background dark))
2204 :background "SkyBlue4")
2205 (((class color) (min-colors 16) (background light))
2206 :background "yellow")
2207 (((class color) (min-colors 16) (background dark))
2208 :background "SkyBlue4")
2209 (((class color) (min-colors 8))
2210 :background "cyan" :foreground "black")
2211 (t :inverse-video t))
2212 "Basic face for displaying the secondary selection."
2213 :group 'basic-faces)
2215 (defface trailing-whitespace
2216 '((((class color) (background light))
2217 :background "red1")
2218 (((class color) (background dark))
2219 :background "red1")
2220 (t :inverse-video t))
2221 "Basic face for highlighting trailing whitespace."
2222 :version "21.1"
2223 :group 'whitespace-faces ; like `show-trailing-whitespace'
2224 :group 'basic-faces)
2226 (defface escape-glyph
2227 '((((background dark)) :foreground "cyan")
2228 ;; See the comment in minibuffer-prompt for
2229 ;; the reason not to use blue on MS-DOS.
2230 (((type pc)) :foreground "magenta")
2231 ;; red4 is too dark, but some say blue is too loud.
2232 ;; brown seems to work ok. -- rms.
2233 (t :foreground "brown"))
2234 "Face for characters displayed as sequences using `^' or `\\'."
2235 :group 'basic-faces
2236 :version "22.1")
2238 (defface nobreak-space
2239 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2240 (((class color) (min-colors 8)) :background "magenta")
2241 (t :inverse-video t))
2242 "Face for displaying nobreak space."
2243 :group 'basic-faces
2244 :version "22.1")
2246 (defgroup mode-line-faces nil
2247 "Faces used in the mode line."
2248 :group 'mode-line
2249 :group 'faces
2250 :version "22.1")
2252 (defface mode-line
2253 '((((class color) (min-colors 88))
2254 :box (:line-width -1 :style released-button)
2255 :background "grey75" :foreground "black")
2257 :inverse-video t))
2258 "Basic mode line face for selected window."
2259 :version "21.1"
2260 :group 'mode-line-faces
2261 :group 'basic-faces)
2262 ;; No need to define aliases of this form for new faces.
2263 (define-obsolete-face-alias 'modeline 'mode-line "21.1")
2265 (defface mode-line-inactive
2266 '((default
2267 :inherit mode-line)
2268 (((class color) (min-colors 88) (background light))
2269 :weight light
2270 :box (:line-width -1 :color "grey75" :style nil)
2271 :foreground "grey20" :background "grey90")
2272 (((class color) (min-colors 88) (background dark) )
2273 :weight light
2274 :box (:line-width -1 :color "grey40" :style nil)
2275 :foreground "grey80" :background "grey30"))
2276 "Basic mode line face for non-selected windows."
2277 :version "22.1"
2278 :group 'mode-line-faces
2279 :group 'basic-faces)
2280 (define-obsolete-face-alias 'modeline-inactive 'mode-line-inactive "22.1")
2282 (defface mode-line-highlight
2283 '((((class color) (min-colors 88))
2284 :box (:line-width 2 :color "grey40" :style released-button))
2286 :inherit highlight))
2287 "Basic mode line face for highlighting."
2288 :version "22.1"
2289 :group 'mode-line-faces
2290 :group 'basic-faces)
2291 (define-obsolete-face-alias 'modeline-highlight 'mode-line-highlight "22.1")
2293 (defface mode-line-emphasis
2294 '((t (:weight bold)))
2295 "Face used to emphasize certain mode line features.
2296 Use the face `mode-line-highlight' for features that can be selected."
2297 :version "23.1"
2298 :group 'mode-line-faces
2299 :group 'basic-faces)
2301 (defface mode-line-buffer-id
2302 '((t (:weight bold)))
2303 "Face used for buffer identification parts of the mode line."
2304 :version "22.1"
2305 :group 'mode-line-faces
2306 :group 'basic-faces)
2307 (define-obsolete-face-alias 'modeline-buffer-id 'mode-line-buffer-id "22.1")
2309 (defface header-line
2310 '((default
2311 :inherit mode-line)
2312 (((type tty))
2313 ;; This used to be `:inverse-video t', but that doesn't look very
2314 ;; good when combined with inverse-video mode-lines and multiple
2315 ;; windows. Underlining looks better, and is more consistent with
2316 ;; the window-system face variants, which deemphasize the
2317 ;; header-line in relation to the mode-line face. If a terminal
2318 ;; can't underline, then the header-line will end up without any
2319 ;; highlighting; this may be too confusing in general, although it
2320 ;; happens to look good with the only current use of header-lines,
2321 ;; the info browser. XXX
2322 :inverse-video nil ;Override the value inherited from mode-line.
2323 :underline t)
2324 (((class color grayscale) (background light))
2325 :background "grey90" :foreground "grey20"
2326 :box nil)
2327 (((class color grayscale) (background dark))
2328 :background "grey20" :foreground "grey90"
2329 :box nil)
2330 (((class mono) (background light))
2331 :background "white" :foreground "black"
2332 :inverse-video nil
2333 :box nil
2334 :underline t)
2335 (((class mono) (background dark))
2336 :background "black" :foreground "white"
2337 :inverse-video nil
2338 :box nil
2339 :underline t))
2340 "Basic header-line face."
2341 :version "21.1"
2342 :group 'basic-faces)
2344 (defface vertical-border
2345 '((((type tty)) :inherit mode-line-inactive))
2346 "Face used for vertical window dividers on ttys."
2347 :version "22.1"
2348 :group 'basic-faces)
2350 (defface minibuffer-prompt
2351 '((((background dark)) :foreground "cyan")
2352 ;; Don't use blue because many users of the MS-DOS port customize
2353 ;; their foreground color to be blue.
2354 (((type pc)) :foreground "magenta")
2355 (t :foreground "medium blue"))
2356 "Face for minibuffer prompts.
2357 By default, Emacs automatically adds this face to the value of
2358 `minibuffer-prompt-properties', which is a list of text properties
2359 used to display the prompt text."
2360 :version "22.1"
2361 :group 'basic-faces)
2363 (setq minibuffer-prompt-properties
2364 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2366 (defface fringe
2367 '((((class color) (background light))
2368 :background "grey95")
2369 (((class color) (background dark))
2370 :background "grey10")
2372 :background "gray"))
2373 "Basic face for the fringes to the left and right of windows under X."
2374 :version "21.1"
2375 :group 'frames
2376 :group 'basic-faces)
2378 (defface scroll-bar '((t nil))
2379 "Basic face for the scroll bar colors under X."
2380 :version "21.1"
2381 :group 'frames
2382 :group 'basic-faces)
2384 (defface border '((t nil))
2385 "Basic face for the frame border under X."
2386 :version "21.1"
2387 :group 'frames
2388 :group 'basic-faces)
2390 (defface cursor
2391 '((((background light)) :background "black")
2392 (((background dark)) :background "white"))
2393 "Basic face for the cursor color under X.
2394 Currently, only the `:background' attribute is meaningful; all
2395 other attributes are ignored. The cursor foreground color is
2396 taken from the background color of the underlying text.
2398 Note: Other faces cannot inherit from the cursor face."
2399 :version "21.1"
2400 :group 'cursor
2401 :group 'basic-faces)
2403 (put 'cursor 'face-no-inherit t)
2405 (defface mouse '((t nil))
2406 "Basic face for the mouse color under X."
2407 :version "21.1"
2408 :group 'mouse
2409 :group 'basic-faces)
2411 (defface tool-bar
2412 '((default
2413 :box (:line-width 1 :style released-button)
2414 :foreground "black")
2415 (((type x w32 ns) (class color))
2416 :background "grey75")
2417 (((type x) (class mono))
2418 :background "grey"))
2419 "Basic tool-bar face."
2420 :version "21.1"
2421 :group 'basic-faces)
2423 (defface menu
2424 '((((type tty))
2425 :inverse-video t)
2426 (((type x-toolkit))
2429 :inverse-video t))
2430 "Basic face for the font and colors of the menu bar and popup menus."
2431 :version "21.1"
2432 :group 'menu
2433 :group 'basic-faces)
2435 (defface help-argument-name '((((supports :slant italic)) :inherit italic))
2436 "Face to highlight argument names in *Help* buffers."
2437 :group 'help)
2439 (defface glyphless-char
2440 '((((type tty)) :inherit underline)
2441 (((type pc)) :inherit escape-glyph)
2442 (t :height 0.6))
2443 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2444 It is used for characters of no fonts too."
2445 :version "24.1"
2446 :group 'basic-faces)
2448 (defface error
2449 '((default :weight bold)
2450 (((class color) (min-colors 88) (background light)) :foreground "Red1")
2451 (((class color) (min-colors 88) (background dark)) :foreground "Pink")
2452 (((class color) (min-colors 16) (background light)) :foreground "Red1")
2453 (((class color) (min-colors 16) (background dark)) :foreground "Pink")
2454 (((class color) (min-colors 8)) :foreground "red")
2455 (t :inverse-video t))
2456 "Basic face used to highlight errors and to denote failure."
2457 :version "24.1"
2458 :group 'basic-faces)
2460 (defface warning
2461 '((default :weight bold)
2462 (((class color) (min-colors 16)) :foreground "DarkOrange")
2463 (((class color)) :foreground "yellow"))
2464 "Basic face used to highlight warnings."
2465 :version "24.1"
2466 :group 'basic-faces)
2468 (defface success
2469 '((default :weight bold)
2470 (((class color) (min-colors 16) (background light)) :foreground "ForestGreen")
2471 (((class color) (min-colors 88) (background dark)) :foreground "Green1")
2472 (((class color) (min-colors 16) (background dark)) :foreground "Green")
2473 (((class color)) :foreground "green"))
2474 "Basic face used to indicate successful operation."
2475 :version "24.1"
2476 :group 'basic-faces)
2479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2480 ;;; Manipulating font names.
2481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2483 ;; This is here for compatibility with Emacs 20.2. For example,
2484 ;; international/fontset.el uses x-resolve-font-name. The following
2485 ;; functions are not used in the face implementation itself.
2487 (defvar x-font-regexp nil)
2488 (defvar x-font-regexp-head nil)
2489 (defvar x-font-regexp-weight nil)
2490 (defvar x-font-regexp-slant nil)
2492 (defconst x-font-regexp-weight-subnum 1)
2493 (defconst x-font-regexp-slant-subnum 2)
2494 (defconst x-font-regexp-swidth-subnum 3)
2495 (defconst x-font-regexp-adstyle-subnum 4)
2497 ;;; Regexps matching font names in "Host Portable Character Representation."
2499 (let ((- "[-?]")
2500 (foundry "[^-]+")
2501 (family "[^-]+")
2502 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2503 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2504 (weight\? "\\([^-]*\\)") ; 1
2505 (slant "\\([ior]\\)") ; 2
2506 ; (slant\? "\\([ior?*]?\\)") ; 2
2507 (slant\? "\\([^-]?\\)") ; 2
2508 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2509 (swidth "\\([^-]*\\)") ; 3
2510 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2511 (adstyle "\\([^-]*\\)") ; 4
2512 (pixelsize "[0-9]+")
2513 (pointsize "[0-9][0-9]+")
2514 (resx "[0-9][0-9]+")
2515 (resy "[0-9][0-9]+")
2516 (spacing "[cmp?*]")
2517 (avgwidth "[0-9]+")
2518 (registry "[^-]+")
2519 (encoding "[^-]+")
2521 (setq x-font-regexp
2522 (purecopy (concat "\\`\\*?[-?*]"
2523 foundry - family - weight\? - slant\? - swidth - adstyle -
2524 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2525 registry - encoding "\\*?\\'"
2527 (setq x-font-regexp-head
2528 (purecopy (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2529 "\\([-*?]\\|\\'\\)")))
2530 (setq x-font-regexp-slant (purecopy (concat - slant -)))
2531 (setq x-font-regexp-weight (purecopy (concat - weight -)))
2532 nil)
2535 (defun x-resolve-font-name (pattern &optional face frame)
2536 "Return a font name matching PATTERN.
2537 All wildcards in PATTERN are instantiated.
2538 If PATTERN is nil, return the name of the frame's base font, which never
2539 contains wildcards.
2540 Given optional arguments FACE and FRAME, return a font which is
2541 also the same size as FACE on FRAME, or fail."
2542 (or (symbolp face)
2543 (setq face (face-name face)))
2544 (and (eq frame t)
2545 (setq frame nil))
2546 (if pattern
2547 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2548 (let ((fonts (x-list-fonts pattern face frame 1)))
2549 (or fonts
2550 (if face
2551 (if (string-match "\\*" pattern)
2552 (if (null (face-font face))
2553 (error "No matching fonts are the same height as the frame default font")
2554 (error "No matching fonts are the same height as face `%s'" face))
2555 (if (null (face-font face))
2556 (error "Height of font `%s' doesn't match the frame default font"
2557 pattern)
2558 (error "Height of font `%s' doesn't match face `%s'"
2559 pattern face)))
2560 (error "No fonts match `%s'" pattern)))
2561 (car fonts))
2562 (cdr (assq 'font (frame-parameters (selected-frame))))))
2564 (provide 'faces)
2566 ;;; faces.el ends here