* desktop.el (desktop-read): Use user-emacs-directory if desktop-path is nil.
[emacs.git] / lisp / faces.el
blob40b45187f6c8e87ef554286f7afa39044faf6325
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.
627 If VALUE is t, underline with foreground color of the face.
628 If VALUE is a string, underline with that color.
629 If VALUE is nil, explicitly don't underline.
631 Otherwise, VALUE must be a property list of the form:
633 `(:color COLOR :style STYLE)'.
635 COLOR can be a either a color name string or `foreground-color'.
636 STYLE can be either `line' or `wave'.
637 If a keyword/value pair is missing from the property list, a
638 default value will be used for the value.
639 The default value of COLOR is the foreground color of the face.
640 The default value of STYLE is `line'.
642 `:overline'
644 VALUE specifies whether characters in FACE should be overlined. If
645 VALUE is t, overline with foreground color of the face. If VALUE is a
646 string, overline with that color. If VALUE is nil, explicitly don't
647 overline.
649 `:strike-through'
651 VALUE specifies whether characters in FACE should be drawn with a line
652 striking through them. If VALUE is t, use the foreground color of the
653 face. If VALUE is a string, strike-through with that color. If VALUE
654 is nil, explicitly don't strike through.
656 `:box'
658 VALUE specifies whether characters in FACE should have a box drawn
659 around them. If VALUE is nil, explicitly don't draw boxes. If
660 VALUE is t, draw a box with lines of width 1 in the foreground color
661 of the face. If VALUE is a string, the string must be a color name,
662 and the box is drawn in that color with a line width of 1. Otherwise,
663 VALUE must be a property list of the form `(:line-width WIDTH
664 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
665 the property list, a default value will be used for the value, as
666 specified below. WIDTH specifies the width of the lines to draw; it
667 defaults to 1. If WIDTH is negative, the absolute value is the width
668 of the lines, and draw top/bottom lines inside the characters area,
669 not around it. COLOR is the name of the color to draw in, default is
670 the foreground color of the face for simple boxes, and the background
671 color of the face for 3D boxes. STYLE specifies whether a 3D box
672 should be draw. If STYLE is `released-button', draw a box looking
673 like a released 3D button. If STYLE is `pressed-button' draw a box
674 that appears like a pressed button. If STYLE is nil, the default if
675 the property list doesn't contain a style specification, draw a 2D
676 box.
678 `:inverse-video'
680 VALUE specifies whether characters in FACE should be displayed in
681 inverse video. VALUE must be one of t or nil.
683 `:stipple'
685 If VALUE is a string, it must be the name of a file of pixmap data.
686 The directories listed in the `x-bitmap-file-path' variable are
687 searched. Alternatively, VALUE may be a list of the form (WIDTH
688 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
689 is a string containing the raw bits of the bitmap. VALUE nil means
690 explicitly don't use a stipple pattern.
692 For convenience, attributes `:family', `:foundry', `:width',
693 `:height', `:weight', and `:slant' may also be set in one step
694 from an X font name:
696 `:font'
698 Set font-related face attributes from VALUE. VALUE must be a
699 valid font name or font object. Setting this attribute will also
700 set the `:family', `:foundry', `:width', `:height', `:weight',
701 and `:slant' attributes.
703 `:inherit'
705 VALUE is the name of a face from which to inherit attributes, or
706 a list of face names. Attributes from inherited faces are merged
707 into the face like an underlying face would be, with higher
708 priority than underlying faces.
710 For backward compatibility, the keywords `:bold' and `:italic'
711 can be used to specify weight and slant respectively. This usage
712 is considered obsolete. For these two keywords, the VALUE must
713 be either t or nil. A value of t for `:bold' is equivalent to
714 setting `:weight' to `bold', and a value of t for `:italic' is
715 equivalent to setting `:slant' to `italic'. But if `:weight' is
716 specified in the face spec, `:bold' is ignored, and if `:slant'
717 is specified, `:italic' is ignored."
718 (setq args (purecopy args))
719 (let ((where (if (null frame) 0 frame))
720 (spec args)
721 family foundry)
722 ;; If we set the new-frame defaults, this face is modified outside Custom.
723 (if (memq where '(0 t))
724 (put (or (get face 'face-alias) face) 'face-modified t))
725 ;; If family and/or foundry are specified, set it first. Certain
726 ;; face attributes, e.g. :weight semi-condensed, are not supported
727 ;; in every font. See bug#1127.
728 (while spec
729 (cond ((eq (car spec) :family)
730 (setq family (cadr spec)))
731 ((eq (car spec) :foundry)
732 (setq foundry (cadr spec))))
733 (setq spec (cddr spec)))
734 (when (or family foundry)
735 (when (and (stringp family)
736 (string-match "\\([^-]*\\)-\\([^-]*\\)" family))
737 (unless foundry
738 (setq foundry (match-string 1 family)))
739 (setq family (match-string 2 family)))
740 (when (or (stringp family) (eq family 'unspecified))
741 (internal-set-lisp-face-attribute face :family (purecopy family)
742 where))
743 (when (or (stringp foundry) (eq foundry 'unspecified))
744 (internal-set-lisp-face-attribute face :foundry (purecopy foundry)
745 where)))
746 (while args
747 (unless (memq (car args) '(:family :foundry))
748 (internal-set-lisp-face-attribute face (car args)
749 (purecopy (cadr args))
750 where))
751 (setq args (cddr args)))))
753 (defun make-face-bold (face &optional frame _noerror)
754 "Make the font of FACE be bold, if possible.
755 FRAME nil or not specified means change face on all frames.
756 Argument NOERROR is ignored and retained for compatibility.
757 Use `set-face-attribute' for finer control of the font weight."
758 (interactive (list (read-face-name "Make which face bold")))
759 (set-face-attribute face frame :weight 'bold))
762 (defun make-face-unbold (face &optional frame _noerror)
763 "Make the font of FACE be non-bold, if possible.
764 FRAME nil or not specified means change face on all frames.
765 Argument NOERROR is ignored and retained for compatibility."
766 (interactive (list (read-face-name "Make which face non-bold")))
767 (set-face-attribute face frame :weight 'normal))
770 (defun make-face-italic (face &optional frame _noerror)
771 "Make the font of FACE be italic, if possible.
772 FRAME nil or not specified means change face on all frames.
773 Argument NOERROR is ignored and retained for compatibility.
774 Use `set-face-attribute' for finer control of the font slant."
775 (interactive (list (read-face-name "Make which face italic")))
776 (set-face-attribute face frame :slant 'italic))
779 (defun make-face-unitalic (face &optional frame _noerror)
780 "Make the font of FACE be non-italic, if possible.
781 FRAME nil or not specified means change face on all frames.
782 Argument NOERROR is ignored and retained for compatibility."
783 (interactive (list (read-face-name "Make which face non-italic")))
784 (set-face-attribute face frame :slant 'normal))
787 (defun make-face-bold-italic (face &optional frame _noerror)
788 "Make the font of FACE be bold and italic, if possible.
789 FRAME nil or not specified means change face on all frames.
790 Argument NOERROR is ignored and retained for compatibility.
791 Use `set-face-attribute' for finer control of font weight and slant."
792 (interactive (list (read-face-name "Make which face bold-italic")))
793 (set-face-attribute face frame :weight 'bold :slant 'italic))
796 (defun set-face-font (face font &optional frame)
797 "Change font-related attributes of FACE to those of FONT (a string).
798 FRAME nil or not specified means change face on all frames.
799 This sets the attributes `:family', `:foundry', `:width',
800 `:height', `:weight', and `:slant'. When called interactively,
801 prompt for the face and font."
802 (interactive (read-face-and-attribute :font))
803 (set-face-attribute face frame :font font))
806 ;; Implementation note: Emulating gray background colors with a
807 ;; stipple pattern is now part of the face realization process, and is
808 ;; done in C depending on the frame on which the face is realized.
810 (defun set-face-background (face color &optional frame)
811 "Change the background color of face FACE to COLOR (a string).
812 FRAME nil or not specified means change face on all frames.
813 COLOR can be a system-defined color name (see `list-colors-display')
814 or a hex spec of the form #RRGGBB.
815 When called interactively, prompts for the face and color."
816 (interactive (read-face-and-attribute :background))
817 (set-face-attribute face frame :background (or color 'unspecified)))
820 (defun set-face-foreground (face color &optional frame)
821 "Change the foreground color of face FACE to COLOR (a string).
822 FRAME nil or not specified means change face on all frames.
823 COLOR can be a system-defined color name (see `list-colors-display')
824 or a hex spec of the form #RRGGBB.
825 When called interactively, prompts for the face and color."
826 (interactive (read-face-and-attribute :foreground))
827 (set-face-attribute face frame :foreground (or color 'unspecified)))
830 (defun set-face-stipple (face stipple &optional frame)
831 "Change the stipple pixmap of face FACE to STIPPLE.
832 FRAME nil or not specified means change face on all frames.
833 STIPPLE should be a string, the name of a file of pixmap data.
834 The directories listed in the `x-bitmap-file-path' variable are searched.
836 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
837 where WIDTH and HEIGHT are the size in pixels,
838 and DATA is a string, containing the raw bits of the bitmap."
839 (interactive (read-face-and-attribute :stipple))
840 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
843 (defun set-face-underline-p (face underline &optional frame)
844 "Specify whether face FACE is underlined.
845 UNDERLINE nil means FACE explicitly doesn't underline.
846 UNDERLINE non-nil means FACE explicitly does underlining
847 with the same of the foreground color.
848 If UNDERLINE is a string, underline with the color named UNDERLINE.
849 FRAME nil or not specified means change face on all frames.
850 Use `set-face-attribute' to ``unspecify'' underlining."
851 (interactive
852 (let ((list (read-face-and-attribute :underline)))
853 (list (car list) (eq (car (cdr list)) t))))
854 (set-face-attribute face frame :underline underline))
856 (define-obsolete-function-alias 'set-face-underline
857 'set-face-underline-p "22.1")
860 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
861 "Specify whether face FACE is in inverse video.
862 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
863 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
864 FRAME nil or not specified means change face on all frames.
865 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
866 (interactive
867 (let ((list (read-face-and-attribute :inverse-video)))
868 (list (car list) (eq (car (cdr list)) t))))
869 (set-face-attribute face frame :inverse-video inverse-video-p))
872 (defun set-face-bold-p (face bold-p &optional frame)
873 "Specify whether face FACE is bold.
874 BOLD-P non-nil means FACE should explicitly display bold.
875 BOLD-P nil means FACE should explicitly display non-bold.
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 bold-p)
879 (make-face-unbold face frame)
880 (make-face-bold face frame)))
883 (defun set-face-italic-p (face italic-p &optional frame)
884 "Specify whether face FACE is italic.
885 ITALIC-P non-nil means FACE should explicitly display italic.
886 ITALIC-P nil means FACE should explicitly display non-italic.
887 FRAME nil or not specified means change face on all frames.
888 Use `set-face-attribute' or `modify-face' for finer control."
889 (if (null italic-p)
890 (make-face-unitalic face frame)
891 (make-face-italic face frame)))
894 (defalias 'set-face-background-pixmap 'set-face-stipple)
897 (defun invert-face (face &optional frame)
898 "Swap the foreground and background colors of FACE.
899 If FRAME is omitted or nil, it means change face on all frames.
900 If FACE specifies neither foreground nor background color,
901 set its foreground and background to the background and foreground
902 of the default face. Value is FACE."
903 (interactive (list (read-face-name "Invert face")))
904 (let ((fg (face-attribute face :foreground frame))
905 (bg (face-attribute face :background frame)))
906 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
907 (set-face-attribute face frame :foreground bg :background fg)
908 (set-face-attribute face frame
909 :foreground
910 (face-attribute 'default :background frame)
911 :background
912 (face-attribute 'default :foreground frame))))
913 face)
916 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917 ;;; Interactively modifying faces.
918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
920 (defun read-face-name (prompt &optional default multiple)
921 "Read a face, defaulting to the face or faces on the char after point.
922 If it has the property `read-face-name', that overrides the `face' property.
923 PROMPT should be a string that describes what the caller will do with the face;
924 it should not end in a space.
925 The optional argument DEFAULT provides the value to display in the
926 minibuffer prompt that is returned if the user just types RET
927 unless DEFAULT is a string (in which case nil is returned).
928 If MULTIPLE is non-nil, return a list of faces (possibly only one).
929 Otherwise, return a single face."
930 (let ((faceprop (or (get-char-property (point) 'read-face-name)
931 (get-char-property (point) 'face)))
932 (aliasfaces nil)
933 (nonaliasfaces nil)
934 faces)
935 ;; Try to get a face name from the buffer.
936 (if (memq (intern-soft (thing-at-point 'symbol)) (face-list))
937 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
938 ;; Add the named faces that the `face' property uses.
939 (if (and (listp faceprop)
940 ;; Don't treat an attribute spec as a list of faces.
941 (not (keywordp (car faceprop)))
942 (not (memq (car faceprop) '(foreground-color background-color))))
943 (dolist (f faceprop)
944 (if (symbolp f)
945 (push f faces)))
946 (if (symbolp faceprop)
947 (push faceprop faces)))
948 (delete-dups faces)
950 ;; Build up the completion tables.
951 (mapatoms (lambda (s)
952 (if (custom-facep s)
953 (if (get s 'face-alias)
954 (push (symbol-name s) aliasfaces)
955 (push (symbol-name s) nonaliasfaces)))))
957 ;; If we only want one, and the default is more than one,
958 ;; discard the unwanted ones now.
959 (unless multiple
960 (if faces
961 (setq faces (list (car faces)))))
962 (require 'crm)
963 (let* ((input
964 ;; Read the input.
965 (completing-read-multiple
966 (if (or faces default)
967 (format "%s (default `%s'): " prompt
968 (if faces (mapconcat 'symbol-name faces ",")
969 default))
970 (format "%s: " prompt))
971 (completion-table-in-turn nonaliasfaces aliasfaces)
972 nil t nil 'face-name-history
973 (if faces (mapconcat 'symbol-name faces ","))))
974 ;; Canonicalize the output.
975 (output
976 (cond ((or (equal input "") (equal input '("")))
977 (or faces (unless (stringp default) default)))
978 ((stringp input)
979 (mapcar 'intern (split-string input ", *" t)))
980 ((listp input)
981 (mapcar 'intern input))
982 (input))))
983 ;; Return either a list of faces or just one face.
984 (if multiple
985 output
986 (car output)))))
988 ;; Not defined without X, but behind window-system test.
989 (defvar x-bitmap-file-path)
991 (defun face-valid-attribute-values (attribute &optional frame)
992 "Return valid values for face attribute ATTRIBUTE.
993 The optional argument FRAME is used to determine available fonts
994 and colors. If it is nil or not specified, the selected frame is used.
995 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
996 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
997 an integer value."
998 (let ((valid
999 (case attribute
1000 (:family
1001 (if (window-system frame)
1002 (mapcar (lambda (x) (cons x x))
1003 (font-family-list))
1004 ;; Only one font on TTYs.
1005 (list (cons "default" "default"))))
1006 (:foundry
1007 (list nil))
1008 (:width
1009 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1010 font-width-table))
1011 (:weight
1012 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1013 font-weight-table))
1014 (:slant
1015 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1016 font-slant-table))
1017 (:inverse-video
1018 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1019 (internal-lisp-face-attribute-values attribute)))
1020 ((:underline :overline :strike-through :box)
1021 (if (window-system frame)
1022 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
1023 (internal-lisp-face-attribute-values attribute))
1024 (mapcar #'(lambda (c) (cons c c))
1025 (defined-colors frame)))
1026 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1027 (internal-lisp-face-attribute-values attribute))))
1028 ((:foreground :background)
1029 (mapcar #'(lambda (c) (cons c c))
1030 (defined-colors frame)))
1031 ((:height)
1032 'integerp)
1033 (:stipple
1034 (and (memq (window-system frame) '(x ns)) ; No stipple on w32
1035 (mapcar #'list
1036 (apply #'nconc
1037 (mapcar (lambda (dir)
1038 (and (file-readable-p dir)
1039 (file-directory-p dir)
1040 (directory-files dir)))
1041 x-bitmap-file-path)))))
1042 (:inherit
1043 (cons '("none" . nil)
1044 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1045 (face-list))))
1047 (error "Internal error")))))
1048 (if (and (listp valid) (not (memq attribute '(:inherit))))
1049 (nconc (list (cons "unspecified" 'unspecified)) valid)
1050 valid)))
1053 (defconst face-attribute-name-alist
1054 '((:family . "font family")
1055 (:foundry . "font foundry")
1056 (:width . "character set width")
1057 (:height . "height in 1/10 pt")
1058 (:weight . "weight")
1059 (:slant . "slant")
1060 (:underline . "underline")
1061 (:overline . "overline")
1062 (:strike-through . "strike-through")
1063 (:box . "box")
1064 (:inverse-video . "inverse-video display")
1065 (:foreground . "foreground color")
1066 (:background . "background color")
1067 (:stipple . "background stipple")
1068 (:inherit . "inheritance"))
1069 "An alist of descriptive names for face attributes.
1070 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1071 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1072 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1075 (defun face-descriptive-attribute-name (attribute)
1076 "Return a descriptive name for ATTRIBUTE."
1077 (cdr (assq attribute face-attribute-name-alist)))
1080 (defun face-read-string (face default name &optional completion-alist)
1081 "Interactively read a face attribute string value.
1082 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1083 default string to return if no new value is entered. NAME is a
1084 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1085 alist of valid values, if non-nil.
1087 Entering nothing accepts the default string DEFAULT.
1088 Value is the new attribute value."
1089 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1090 ;; each word in a string separately).
1091 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1092 (let* ((completion-ignore-case t)
1093 (value (completing-read
1094 (if default
1095 (format "%s for face `%s' (default %s): "
1096 name face default)
1097 (format "%s for face `%s': " name face))
1098 completion-alist nil nil nil nil default)))
1099 (if (equal value "") default value)))
1102 (defun face-read-integer (face default name)
1103 "Interactively read an integer face attribute value.
1104 FACE is the face whose attribute is read. DEFAULT is the default
1105 value to return if no new value is entered. NAME is a descriptive
1106 name of the attribute for prompting. Value is the new attribute value."
1107 (let ((new-value
1108 (face-read-string face
1109 (format "%s" default)
1110 name
1111 (list (cons "unspecified" 'unspecified)))))
1112 (cond ((equal new-value "unspecified")
1113 'unspecified)
1114 ((member new-value '("unspecified-fg" "unspecified-bg"))
1115 new-value)
1117 (string-to-number new-value)))))
1120 (defun read-face-attribute (face attribute &optional frame)
1121 "Interactively read a new value for FACE's ATTRIBUTE.
1122 Optional argument FRAME nil or unspecified means read an attribute value
1123 of a global face. Value is the new attribute value."
1124 (let* ((old-value (face-attribute face attribute frame))
1125 (attribute-name (face-descriptive-attribute-name attribute))
1126 (valid (face-valid-attribute-values attribute frame))
1127 new-value)
1128 ;; Represent complex attribute values as strings by printing them
1129 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1130 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1131 ;; SHADOW)'.
1132 (when (and (or (eq attribute :stipple)
1133 (eq attribute :box))
1134 (or (consp old-value)
1135 (vectorp old-value)))
1136 (setq old-value (prin1-to-string old-value)))
1137 (cond ((listp valid)
1138 (let ((default
1139 (or (car (rassoc old-value valid))
1140 (format "%s" old-value))))
1141 (setq new-value
1142 (face-read-string face default attribute-name valid))
1143 (if (equal new-value default)
1144 ;; Nothing changed, so don't bother with all the stuff
1145 ;; below. In particular, this avoids a non-tty color
1146 ;; from being canonicalized for a tty when the user
1147 ;; just uses the default.
1148 (setq new-value old-value)
1149 ;; Terminal frames can support colors that don't appear
1150 ;; explicitly in VALID, using color approximation code
1151 ;; in tty-colors.el.
1152 (when (and (memq attribute '(:foreground :background))
1153 (not (memq (window-system frame) '(x w32 ns)))
1154 (not (member new-value
1155 '("unspecified"
1156 "unspecified-fg" "unspecified-bg"))))
1157 (setq new-value (car (tty-color-desc new-value frame))))
1158 (when (assoc new-value valid)
1159 (setq new-value (cdr (assoc new-value valid)))))))
1160 ((eq valid 'integerp)
1161 (setq new-value (face-read-integer face old-value attribute-name)))
1162 (t (error "Internal error")))
1163 ;; Convert stipple and box value text we read back to a list or
1164 ;; vector if it looks like one. This makes the assumption that a
1165 ;; pixmap file name won't start with an open-paren.
1166 (when (and (or (eq attribute :stipple)
1167 (eq attribute :box))
1168 (stringp new-value)
1169 (string-match "^[[(]" new-value))
1170 (setq new-value (read new-value)))
1171 new-value))
1173 (declare-function fontset-list "fontset.c" ())
1174 (declare-function x-list-fonts "xfaces.c"
1175 (pattern &optional face frame maximum width))
1177 (defun read-face-font (face &optional frame)
1178 "Read the name of a font for FACE on FRAME.
1179 If optional argument FRAME is nil or omitted, use the selected frame."
1180 (let ((completion-ignore-case t))
1181 (completing-read (format "Set font attributes of face `%s' from font: " face)
1182 (append (fontset-list) (x-list-fonts "*" nil frame)))))
1185 (defun read-all-face-attributes (face &optional frame)
1186 "Interactively read all attributes for FACE.
1187 If optional argument FRAME is nil or omitted, use the selected frame.
1188 Value is a property list of attribute names and new values."
1189 (let (result)
1190 (dolist (attribute face-attribute-name-alist result)
1191 (setq result (cons (car attribute)
1192 (cons (read-face-attribute face (car attribute) frame)
1193 result))))))
1195 (defun modify-face (&optional face foreground background stipple
1196 bold-p italic-p underline inverse-p frame)
1197 "Modify attributes of faces interactively.
1198 If optional argument FRAME is nil or omitted, modify the face used
1199 for newly created frame, i.e. the global face.
1200 For non-interactive use, `set-face-attribute' is preferred.
1201 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1202 and the face and its settings are obtained by querying the user."
1203 (interactive)
1204 (if face
1205 (set-face-attribute face frame
1206 :foreground (or foreground 'unspecified)
1207 :background (or background 'unspecified)
1208 :stipple stipple
1209 :weight (if bold-p 'bold 'normal)
1210 :slant (if italic-p 'italic 'normal)
1211 :underline underline
1212 :inverse-video inverse-p)
1213 (setq face (read-face-name "Modify face"))
1214 (apply #'set-face-attribute face frame
1215 (read-all-face-attributes face frame))))
1217 (defun read-face-and-attribute (attribute &optional frame)
1218 "Read face name and face attribute value.
1219 ATTRIBUTE is the attribute whose new value is read.
1220 FRAME nil or unspecified means read attribute value of global face.
1221 Value is a list (FACE NEW-VALUE) where FACE is the face read
1222 \(a symbol), and NEW-VALUE is value read."
1223 (cond ((eq attribute :font)
1224 (let* ((prompt "Set font-related attributes of face")
1225 (face (read-face-name prompt))
1226 (font (read-face-font face frame)))
1227 (list face font)))
1229 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1230 (prompt (format "Set %s of face" attribute-name))
1231 (face (read-face-name prompt))
1232 (new-value (read-face-attribute face attribute frame)))
1233 (list face new-value)))))
1237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1238 ;;; Listing faces.
1239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1241 (defconst list-faces-sample-text
1242 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1243 "Text string to display as the sample text for `list-faces-display'.")
1246 ;; The name list-faces would be more consistent, but let's avoid a
1247 ;; conflict with Lucid, which uses that name differently.
1249 (defvar help-xref-stack)
1250 (defun list-faces-display (&optional regexp)
1251 "List all faces, using the same sample text in each.
1252 The sample text is a string that comes from the variable
1253 `list-faces-sample-text'.
1255 If REGEXP is non-nil, list only those faces with names matching
1256 this regular expression. When called interactively with a prefix
1257 arg, prompt for a regular expression."
1258 (interactive (list (and current-prefix-arg
1259 (read-regexp "List faces matching regexp"))))
1260 (let ((all-faces (zerop (length regexp)))
1261 (frame (selected-frame))
1262 (max-length 0)
1263 faces line-format
1264 disp-frame window face-name)
1265 ;; We filter and take the max length in one pass
1266 (setq faces
1267 (delq nil
1268 (mapcar (lambda (f)
1269 (let ((s (symbol-name f)))
1270 (when (or all-faces (string-match regexp s))
1271 (setq max-length (max (length s) max-length))
1272 f)))
1273 (sort (face-list) #'string-lessp))))
1274 (unless faces
1275 (error "No faces matching \"%s\"" regexp))
1276 (setq max-length (1+ max-length)
1277 line-format (format "%%-%ds" max-length))
1278 (with-help-window "*Faces*"
1279 (with-current-buffer standard-output
1280 (setq truncate-lines t)
1281 (insert
1282 (substitute-command-keys
1283 (concat
1284 "\\<help-mode-map>Use "
1285 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1286 "\\[help-follow] on a face name to customize it\n"
1287 "or on its sample text for a description of the face.\n\n")))
1288 (setq help-xref-stack nil)
1289 (dolist (face faces)
1290 (setq face-name (symbol-name face))
1291 (insert (format line-format face-name))
1292 ;; Hyperlink to a customization buffer for the face. Using
1293 ;; the help xref mechanism may not be the best way.
1294 (save-excursion
1295 (save-match-data
1296 (search-backward face-name)
1297 (setq help-xref-stack-item `(list-faces-display ,regexp))
1298 (help-xref-button 0 'help-customize-face face)))
1299 (let ((beg (point))
1300 (line-beg (line-beginning-position)))
1301 (insert list-faces-sample-text)
1302 ;; Hyperlink to a help buffer for the face.
1303 (save-excursion
1304 (save-match-data
1305 (search-backward list-faces-sample-text)
1306 (help-xref-button 0 'help-face face)))
1307 (insert "\n")
1308 (put-text-property beg (1- (point)) 'face face)
1309 ;; Make all face commands default to the proper face
1310 ;; anywhere in the line.
1311 (put-text-property line-beg (1- (point)) 'read-face-name face)
1312 ;; If the sample text has multiple lines, line up all of them.
1313 (goto-char beg)
1314 (forward-line 1)
1315 (while (not (eobp))
1316 (insert-char ?\s max-length)
1317 (forward-line 1))))
1318 (goto-char (point-min))))
1319 ;; If the *Faces* buffer appears in a different frame,
1320 ;; copy all the face definitions from FRAME,
1321 ;; so that the display will reflect the frame that was selected.
1322 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1323 (setq disp-frame (if window (window-frame window)
1324 (car (frame-list))))
1325 (or (eq frame disp-frame)
1326 (let ((faces (face-list)))
1327 (while faces
1328 (copy-face (car faces) (car faces) frame disp-frame)
1329 (setq faces (cdr faces)))))))
1332 (defun describe-face (face &optional frame)
1333 "Display the properties of face FACE on FRAME.
1334 Interactively, FACE defaults to the faces of the character after point
1335 and FRAME defaults to the selected frame.
1337 If the optional argument FRAME is given, report on face FACE in that frame.
1338 If FRAME is t, report on the defaults for face FACE (for new frames).
1339 If FRAME is omitted or nil, use the selected frame."
1340 (interactive (list (read-face-name "Describe face" 'default t)))
1341 (let* ((attrs '((:family . "Family")
1342 (:foundry . "Foundry")
1343 (:width . "Width")
1344 (:height . "Height")
1345 (:weight . "Weight")
1346 (:slant . "Slant")
1347 (:foreground . "Foreground")
1348 (:background . "Background")
1349 (:underline . "Underline")
1350 (:overline . "Overline")
1351 (:strike-through . "Strike-through")
1352 (:box . "Box")
1353 (:inverse-video . "Inverse")
1354 (:stipple . "Stipple")
1355 (:font . "Font")
1356 (:fontset . "Fontset")
1357 (:inherit . "Inherit")))
1358 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1359 attrs))))
1360 (help-setup-xref (list #'describe-face face)
1361 (called-interactively-p 'interactive))
1362 (unless face
1363 (setq face 'default))
1364 (if (not (listp face))
1365 (setq face (list face)))
1366 (with-help-window (help-buffer)
1367 (with-current-buffer standard-output
1368 (dolist (f face)
1369 (if (stringp f) (setq f (intern f)))
1370 ;; We may get called for anonymous faces (i.e., faces
1371 ;; expressed using prop-value plists). Those can't be
1372 ;; usefully customized, so ignore them.
1373 (when (symbolp f)
1374 (insert "Face: " (symbol-name f))
1375 (if (not (facep f))
1376 (insert " undefined face.\n")
1377 (let ((customize-label "customize this face")
1378 file-name)
1379 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1380 (princ (concat " (" customize-label ")\n"))
1381 ;; FIXME not sure how much of this belongs here, and
1382 ;; how much in `face-documentation'. The latter is
1383 ;; not used much, but needs to return nil for
1384 ;; undocumented faces.
1385 (let ((alias (get f 'face-alias))
1386 (face f)
1387 obsolete)
1388 (when alias
1389 (setq face alias)
1390 (insert
1391 (format "\n %s is an alias for the face `%s'.\n%s"
1392 f alias
1393 (if (setq obsolete (get f 'obsolete-face))
1394 (format " This face is obsolete%s; use `%s' instead.\n"
1395 (if (stringp obsolete)
1396 (format " since %s" obsolete)
1398 alias)
1399 ""))))
1400 (insert "\nDocumentation:\n"
1401 (or (face-documentation face)
1402 "Not documented as a face.")
1403 "\n\n"))
1404 (with-current-buffer standard-output
1405 (save-excursion
1406 (re-search-backward
1407 (concat "\\(" customize-label "\\)") nil t)
1408 (help-xref-button 1 'help-customize-face f)))
1409 (setq file-name (find-lisp-object-file-name f 'defface))
1410 (when file-name
1411 (princ "Defined in `")
1412 (princ (file-name-nondirectory file-name))
1413 (princ "'")
1414 ;; Make a hyperlink to the library.
1415 (save-excursion
1416 (re-search-backward "`\\([^`']+\\)'" nil t)
1417 (help-xref-button 1 'help-face-def f file-name))
1418 (princ ".")
1419 (terpri)
1420 (terpri))
1421 (dolist (a attrs)
1422 (let ((attr (face-attribute f (car a) frame)))
1423 (insert (make-string (- max-width (length (cdr a))) ?\s)
1424 (cdr a) ": " (format "%s" attr))
1425 (if (and (eq (car a) :inherit)
1426 (not (eq attr 'unspecified)))
1427 ;; Make a hyperlink to the parent face.
1428 (save-excursion
1429 (re-search-backward ": \\([^:]+\\)" nil t)
1430 (help-xref-button 1 'help-face attr)))
1431 (insert "\n")))))
1432 (terpri)))))))
1435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1436 ;;; Face specifications (defface).
1437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1439 ;; Parameter FRAME Is kept for call compatibility to with previous
1440 ;; face implementation.
1442 (defun face-attr-construct (face &optional _frame)
1443 "Return a `defface'-style attribute list for FACE.
1444 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1445 face attributes of FACE where ATTRIBUTE is the attribute name and
1446 VALUE is the specified value of that attribute.
1447 Argument FRAME is ignored and retained for compatibility."
1448 (let (result)
1449 (dolist (entry face-attribute-name-alist result)
1450 (let* ((attribute (car entry))
1451 (value (face-attribute face attribute)))
1452 (unless (eq value 'unspecified)
1453 (setq result (nconc (list attribute value) result)))))))
1456 (defun face-spec-set-match-display (display frame)
1457 "Non-nil if DISPLAY matches FRAME.
1458 DISPLAY is part of a spec such as can be used in `defface'.
1459 If FRAME is nil, the current FRAME is used."
1460 (let* ((conjuncts display)
1461 conjunct req options
1462 ;; t means we have succeeded against all the conjuncts in
1463 ;; DISPLAY that have been tested so far.
1464 (match t))
1465 (if (eq conjuncts t)
1466 (setq conjuncts nil))
1467 (while (and conjuncts match)
1468 (setq conjunct (car conjuncts)
1469 conjuncts (cdr conjuncts)
1470 req (car conjunct)
1471 options (cdr conjunct)
1472 match (cond ((eq req 'type)
1473 (or (memq (window-system frame) options)
1474 (and (memq 'graphic options)
1475 (memq (window-system frame) '(x w32 ns)))
1476 ;; FIXME: This should be revisited to use
1477 ;; display-graphic-p, provided that the
1478 ;; color selection depends on the number
1479 ;; of supported colors, and all defface's
1480 ;; are changed to look at number of colors
1481 ;; instead of (type graphic) etc.
1482 (if (null (window-system frame))
1483 (memq 'tty options)
1484 (or (and (memq 'motif options)
1485 (featurep 'motif))
1486 (and (memq 'gtk options)
1487 (featurep 'gtk))
1488 (and (memq 'lucid options)
1489 (featurep 'x-toolkit)
1490 (not (featurep 'motif))
1491 (not (featurep 'gtk)))
1492 (and (memq 'x-toolkit options)
1493 (featurep 'x-toolkit))))))
1494 ((eq req 'min-colors)
1495 (>= (display-color-cells frame) (car options)))
1496 ((eq req 'class)
1497 (memq (frame-parameter frame 'display-type) options))
1498 ((eq req 'background)
1499 (memq (frame-parameter frame 'background-mode)
1500 options))
1501 ((eq req 'supports)
1502 (display-supports-face-attributes-p options frame))
1503 (t (error "Unknown req `%S' with options `%S'"
1504 req options)))))
1505 match))
1508 (defun face-spec-choose (spec &optional frame)
1509 "Choose the proper attributes for FRAME, out of SPEC.
1510 If SPEC is nil, return nil."
1511 (unless frame
1512 (setq frame (selected-frame)))
1513 (let ((tail spec)
1514 result defaults)
1515 (while tail
1516 (let* ((entry (pop tail))
1517 (display (car entry))
1518 (attrs (cdr entry))
1519 thisval)
1520 ;; Get the attributes as actually specified by this alternative.
1521 (setq thisval
1522 (if (null (cdr attrs)) ;; was (listp (car attrs))
1523 ;; Old-style entry, the attribute list is the
1524 ;; first element.
1525 (car attrs)
1526 attrs))
1528 ;; If the condition is `default', that sets the default
1529 ;; for following conditions.
1530 (if (eq display 'default)
1531 (setq defaults thisval)
1532 ;; Otherwise, if it matches, use it.
1533 (when (face-spec-set-match-display display frame)
1534 (setq result thisval)
1535 (setq tail nil)))))
1536 (if defaults (append result defaults) result)))
1539 (defun face-spec-reset-face (face &optional frame)
1540 "Reset all attributes of FACE on FRAME to unspecified."
1541 (apply 'set-face-attribute face frame
1542 (if (eq face 'default)
1543 ;; For the default face, avoid making any attribute
1544 ;; unspecified. Instead, set attributes to default values
1545 ;; (see also realize_default_face in xfaces.c).
1546 (append
1547 '(:underline nil :overline nil :strike-through nil
1548 :box nil :inverse-video nil :stipple nil :inherit nil)
1549 ;; `display-graphic-p' is unavailable when running
1550 ;; temacs, prior to loading frame.el.
1551 (unless (and (fboundp 'display-graphic-p)
1552 (display-graphic-p frame))
1553 '(:family "default" :foundry "default" :width normal
1554 :height 1 :weight normal :slant normal
1555 :foreground "unspecified-fg"
1556 :background "unspecified-bg")))
1557 ;; For all other faces, unspecify all attributes.
1558 (apply 'append
1559 (mapcar (lambda (x) (list (car x) 'unspecified))
1560 face-attribute-name-alist)))))
1562 (defun face-spec-set (face spec &optional for-defface)
1563 "Set and apply the face spec for FACE.
1564 If the optional argument FOR-DEFFACE is omitted or nil, set the
1565 overriding spec to SPEC, recording it in the `face-override-spec'
1566 property of FACE. See `defface' for the format of SPEC.
1568 If FOR-DEFFACE is non-nil, set the base spec (the one set by
1569 `defface' and Custom). In this case, SPEC is ignored; the caller
1570 is responsible for putting the face spec in the `saved-face',
1571 `customized-face', or `face-defface-spec', as appropriate.
1573 The appearance of FACE is controlled by the base spec, by any
1574 custom theme specs on top of that, and by the overriding spec on
1575 top of all the rest."
1576 (if for-defface
1577 ;; When we reset the face based on its custom spec, then it is
1578 ;; unmodified as far as Custom is concerned.
1579 (put (or (get face 'face-alias) face) 'face-modified nil)
1580 ;; When we change a face based on a spec from outside custom,
1581 ;; record it for future frames.
1582 (put (or (get face 'face-alias) face) 'face-override-spec spec))
1583 ;; Reset each frame according to the rules implied by all its specs.
1584 (dolist (frame (frame-list))
1585 (face-spec-recalc face frame)))
1587 (defun face-spec-recalc (face frame)
1588 "Reset the face attributes of FACE on FRAME according to its specs.
1589 This applies the defface/custom spec first, then the custom theme specs,
1590 then the override spec."
1591 (face-spec-reset-face face frame)
1592 (let ((face-sym (or (get face 'face-alias) face)))
1593 (or (get face 'customized-face)
1594 (get face 'saved-face)
1595 (face-spec-set-2 face frame (face-default-spec face)))
1596 (let ((theme-faces (reverse (get face-sym 'theme-face))))
1597 (dolist (spec theme-faces)
1598 (face-spec-set-2 face frame (cadr spec))))
1599 (face-spec-set-2 face frame (get face-sym 'face-override-spec))))
1601 (defun face-spec-set-2 (face frame spec)
1602 "Set the face attributes of FACE on FRAME according to SPEC."
1603 (let* ((spec (face-spec-choose spec frame))
1604 attrs)
1605 (while spec
1606 (when (assq (car spec) face-x-resources)
1607 (push (car spec) attrs)
1608 (push (cadr spec) attrs))
1609 (setq spec (cddr spec)))
1610 (apply 'set-face-attribute face frame (nreverse attrs))))
1612 (defun face-attr-match-p (face attrs &optional frame)
1613 "Return t if attributes of FACE match values in plist ATTRS.
1614 Optional parameter FRAME is the frame whose definition of FACE
1615 is used. If nil or omitted, use the selected frame."
1616 (unless frame
1617 (setq frame (selected-frame)))
1618 (let* ((list face-attribute-name-alist)
1619 (match t)
1620 (bold (and (plist-member attrs :bold)
1621 (not (plist-member attrs :weight))))
1622 (italic (and (plist-member attrs :italic)
1623 (not (plist-member attrs :slant))))
1624 (plist (if (or bold italic)
1625 (copy-sequence attrs)
1626 attrs)))
1627 ;; Handle the Emacs 20 :bold and :italic properties.
1628 (if bold
1629 (plist-put plist :weight (if bold 'bold 'normal)))
1630 (if italic
1631 (plist-put plist :slant (if italic 'italic 'normal)))
1632 (while (and match list)
1633 (let* ((attr (caar list))
1634 (specified-value
1635 (if (plist-member plist attr)
1636 (plist-get plist attr)
1637 'unspecified))
1638 (value-now (face-attribute face attr frame)))
1639 (setq match (equal specified-value value-now))
1640 (setq list (cdr list))))
1641 match))
1643 (defsubst face-spec-match-p (face spec &optional frame)
1644 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1645 (face-attr-match-p face (face-spec-choose spec frame) frame))
1647 (defsubst face-default-spec (face)
1648 "Return the default face-spec for FACE, ignoring any user customization.
1649 If there is no default for FACE, return nil."
1650 (get face 'face-defface-spec))
1652 (defsubst face-user-default-spec (face)
1653 "Return the user's customized face-spec for FACE, or the default if none.
1654 If there is neither a user setting nor a default for FACE, return nil."
1655 (or (get face 'customized-face)
1656 (get face 'saved-face)
1657 (face-default-spec face)))
1660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1661 ;;; Frame-type independent color support.
1662 ;;; We keep the old x-* names as aliases for back-compatibility.
1663 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1665 (defun defined-colors (&optional frame)
1666 "Return a list of colors supported for a particular frame.
1667 The argument FRAME specifies which frame to try.
1668 The value may be different for frames on different display types.
1669 If FRAME doesn't support colors, the value is nil.
1670 If FRAME is nil, that stands for the selected frame."
1671 (if (memq (framep (or frame (selected-frame))) '(x w32 ns))
1672 (xw-defined-colors frame)
1673 (mapcar 'car (tty-color-alist frame))))
1674 (defalias 'x-defined-colors 'defined-colors)
1676 (declare-function xw-color-defined-p "xfns.c" (color &optional frame))
1678 (defun color-defined-p (color &optional frame)
1679 "Return non-nil if color COLOR is supported on frame FRAME.
1680 If FRAME is omitted or nil, use the selected frame.
1681 If COLOR is the symbol `unspecified' or one of the strings
1682 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1683 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1685 (if (member (framep (or frame (selected-frame))) '(x w32 ns))
1686 (xw-color-defined-p color frame)
1687 (numberp (tty-color-translate color frame)))))
1688 (defalias 'x-color-defined-p 'color-defined-p)
1690 (declare-function xw-color-values "xfns.c" (color &optional frame))
1692 (defun color-values (color &optional frame)
1693 "Return a description of the color named COLOR on frame FRAME.
1694 COLOR should be a string naming a color (e.g. \"white\"), or a
1695 string specifying a color's RGB components (e.g. \"#ff12ec\").
1697 Return a list of three integers, (RED GREEN BLUE), each between 0
1698 and either 65280 or 65535 (the maximum depends on the system).
1699 Use `color-name-to-rgb' if you want RGB floating-point values
1700 normalized to 1.0.
1702 If FRAME is omitted or nil, use the selected frame.
1703 If FRAME cannot display COLOR, the value is nil.
1705 COLOR can also be the symbol `unspecified' or one of the strings
1706 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1707 return value is nil."
1708 (cond
1709 ((member color '(unspecified "unspecified-fg" "unspecified-bg"))
1710 nil)
1711 ((memq (framep (or frame (selected-frame))) '(x w32 ns))
1712 (xw-color-values color frame))
1714 (tty-color-values color frame))))
1716 (defalias 'x-color-values 'color-values)
1718 (declare-function xw-display-color-p "xfns.c" (&optional terminal))
1720 (defun display-color-p (&optional display)
1721 "Return t if DISPLAY supports color.
1722 The optional argument DISPLAY specifies which display to ask about.
1723 DISPLAY should be either a frame or a display name (a string).
1724 If omitted or nil, that stands for the selected frame's display."
1725 (if (memq (framep-on-display display) '(x w32 ns))
1726 (xw-display-color-p display)
1727 (tty-display-color-p display)))
1728 (defalias 'x-display-color-p 'display-color-p)
1730 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
1732 (defun display-grayscale-p (&optional display)
1733 "Return non-nil if frames on DISPLAY can display shades of gray."
1734 (let ((frame-type (framep-on-display display)))
1735 (cond
1736 ((memq frame-type '(x w32 ns))
1737 (x-display-grayscale-p display))
1739 (> (tty-color-gray-shades display) 2)))))
1741 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg)
1742 "Read a color name or RGB triplet.
1743 Completion is available for color names, but not for RGB triplets.
1745 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1746 components can have one to four digits, but all three components
1747 must have the same number of digits. Each digit is a hex value
1748 between 0 and F; either upper case or lower case for A through F
1749 are acceptable.
1751 In addition to standard color names and RGB hex values, the
1752 following are available as color candidates. In each case, the
1753 corresponding color is used.
1755 * `foreground at point' - foreground under the cursor
1756 * `background at point' - background under the cursor
1758 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1760 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1761 convert an input color name to an RGB hex string. Return the RGB
1762 hex string.
1764 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1765 to enter an empty color name (the empty string).
1767 Interactively, or with optional arg MSG non-nil, print the
1768 resulting color name in the echo area."
1769 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1770 (let* ((completion-ignore-case t)
1771 (colors (or facemenu-color-alist
1772 (append '("foreground at point" "background at point")
1773 (if allow-empty-name '(""))
1774 (defined-colors))))
1775 (color (completing-read
1776 (or prompt "Color (name or #RGB triplet): ")
1777 ;; Completing function for reading colors, accepting
1778 ;; both color names and RGB triplets.
1779 (lambda (string pred flag)
1780 (cond
1781 ((null flag) ; Try completion.
1782 (or (try-completion string colors pred)
1783 (if (color-defined-p string)
1784 string)))
1785 ((eq flag t) ; List all completions.
1786 (or (all-completions string colors pred)
1787 (if (color-defined-p string)
1788 (list string))))
1789 ((eq flag 'lambda) ; Test completion.
1790 (or (memq string colors)
1791 (color-defined-p string)))))
1792 nil t)))
1794 ;; Process named colors.
1795 (when (member color colors)
1796 (cond ((string-equal color "foreground at point")
1797 (setq color (foreground-color-at-point)))
1798 ((string-equal color "background at point")
1799 (setq color (background-color-at-point))))
1800 (when (and convert-to-RGB
1801 (not (string-equal color "")))
1802 (let ((components (x-color-values color)))
1803 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1804 (setq color (format "#%04X%04X%04X"
1805 (logand 65535 (nth 0 components))
1806 (logand 65535 (nth 1 components))
1807 (logand 65535 (nth 2 components))))))))
1808 (when msg (message "Color: `%s'" color))
1809 color))
1812 (defun face-at-point ()
1813 "Return the face of the character after point.
1814 If it has more than one face, return the first one.
1815 Return nil if it has no specified face."
1816 (let* ((faceprop (or (get-char-property (point) 'read-face-name)
1817 (get-char-property (point) 'face)
1818 'default))
1819 (face (cond ((symbolp faceprop) faceprop)
1820 ;; List of faces (don't treat an attribute spec).
1821 ;; Just use the first face.
1822 ((and (consp faceprop) (not (keywordp (car faceprop)))
1823 (not (memq (car faceprop)
1824 '(foreground-color background-color))))
1825 (car faceprop))
1826 (t nil)))) ; Invalid face value.
1827 (if (facep face) face nil)))
1829 (defun foreground-color-at-point ()
1830 "Return the foreground color of the character after point."
1831 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1832 ;; Need also pick up any face properties that are not associated with named faces.
1833 (let ((face (or (face-at-point)
1834 (get-char-property (point) 'read-face-name)
1835 (get-char-property (point) 'face))))
1836 (cond ((and face (symbolp face))
1837 (let ((value (face-foreground face nil 'default)))
1838 (if (member value '("unspecified-fg" "unspecified-bg"))
1840 value)))
1841 ((consp face)
1842 (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face)))
1843 ((memq ':foreground face) (cadr (memq ':foreground face)))))
1844 (t nil)))) ; Invalid face value.
1846 (defun background-color-at-point ()
1847 "Return the background color of the character after point."
1848 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1849 ;; Need also pick up any face properties that are not associated with named faces.
1850 (let ((face (or (face-at-point)
1851 (get-char-property (point) 'read-face-name)
1852 (get-char-property (point) 'face))))
1853 (cond ((and face (symbolp face))
1854 (let ((value (face-background face nil 'default)))
1855 (if (member value '("unspecified-fg" "unspecified-bg"))
1857 value)))
1858 ((consp face)
1859 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1860 ((memq ':background face) (cadr (memq ':background face)))))
1861 (t nil)))) ; Invalid face value.
1864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1865 ;;; Frame creation.
1866 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1868 (declare-function x-parse-geometry "frame.c" (string))
1870 (defun x-handle-named-frame-geometry (parameters)
1871 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1872 Value is the new parameter list."
1873 ;; Note that `x-resource-name' has a global meaning.
1874 (let ((x-resource-name (cdr (assq 'name parameters))))
1875 (when x-resource-name
1876 ;; Before checking X resources, we must have an X connection.
1877 (or (window-system)
1878 (x-display-list)
1879 (x-open-connection (or (cdr (assq 'display parameters))
1880 x-display-name)))
1881 (let (res-geometry parsed)
1882 (and (setq res-geometry (x-get-resource "geometry" "Geometry"))
1883 (setq parsed (x-parse-geometry res-geometry))
1884 (setq parameters
1885 (append parameters parsed
1886 ;; If the resource specifies a position,
1887 ;; take note of that.
1888 (if (or (assq 'top parsed) (assq 'left parsed))
1889 '((user-position . t) (user-size . t)))))))))
1890 parameters)
1893 (defun x-handle-reverse-video (frame parameters)
1894 "Handle the reverse-video frame parameter and X resource.
1895 `x-create-frame' does not handle this one."
1896 (when (cdr (or (assq 'reverse parameters)
1897 (let ((resource (x-get-resource "reverseVideo"
1898 "ReverseVideo")))
1899 (if resource
1900 (cons nil (member (downcase resource)
1901 '("on" "true")))))))
1902 (let* ((params (frame-parameters frame))
1903 (bg (cdr (assq 'foreground-color params)))
1904 (fg (cdr (assq 'background-color params))))
1905 (modify-frame-parameters frame
1906 (list (cons 'foreground-color fg)
1907 (cons 'background-color bg)))
1908 (if (equal bg (cdr (assq 'border-color params)))
1909 (modify-frame-parameters frame
1910 (list (cons 'border-color fg))))
1911 (if (equal bg (cdr (assq 'mouse-color params)))
1912 (modify-frame-parameters frame
1913 (list (cons 'mouse-color fg))))
1914 (if (equal bg (cdr (assq 'cursor-color params)))
1915 (modify-frame-parameters frame
1916 (list (cons 'cursor-color fg)))))))
1918 (declare-function x-create-frame "xfns.c" (parms))
1919 (declare-function x-setup-function-keys "term/common-win" (frame))
1921 (defun x-create-frame-with-faces (&optional parameters)
1922 "Create and return a frame with frame parameters PARAMETERS.
1923 If PARAMETERS specify a frame name, handle X geometry resources
1924 for that name. If PARAMETERS includes a `reverse' parameter, or
1925 the X resource ``reverseVideo'' is present, handle that."
1926 (setq parameters (x-handle-named-frame-geometry parameters))
1927 (let* ((params (copy-tree parameters))
1928 (visibility-spec (assq 'visibility parameters))
1929 (delayed-params '(foreground-color background-color font
1930 border-color cursor-color mouse-color
1931 visibility scroll-bar-foreground
1932 scroll-bar-background))
1933 frame success)
1934 (dolist (param delayed-params)
1935 (setq params (assq-delete-all param params)))
1936 (setq frame (x-create-frame `((visibility . nil) . ,params)))
1937 (unwind-protect
1938 (progn
1939 (x-setup-function-keys frame)
1940 (x-handle-reverse-video frame parameters)
1941 (frame-set-background-mode frame t)
1942 (face-set-after-frame-default frame parameters)
1943 (if (null visibility-spec)
1944 (make-frame-visible frame)
1945 (modify-frame-parameters frame (list visibility-spec)))
1946 (setq success t))
1947 (unless success
1948 (delete-frame frame)))
1949 frame))
1951 (defun face-set-after-frame-default (frame &optional parameters)
1952 "Initialize the frame-local faces of FRAME.
1953 Calculate the face definitions using the face specs, custom theme
1954 settings, X resources, and `face-new-frame-defaults'.
1955 Finally, apply any relevant face attributes found amongst the
1956 frame parameters in PARAMETERS."
1957 (let ((window-system-p (memq (window-system frame) '(x w32))))
1958 ;; The `reverse' is so that `default' goes first.
1959 (dolist (face (nreverse (face-list)))
1960 (condition-case ()
1961 (progn
1962 ;; Initialize faces from face spec and custom theme.
1963 (face-spec-recalc face frame)
1964 ;; X resources for the default face are applied during
1965 ;; `x-create-frame'.
1966 (and (not (eq face 'default)) window-system-p
1967 (make-face-x-resource-internal face frame))
1968 ;; Apply attributes specified by face-new-frame-defaults
1969 (internal-merge-in-global-face face frame))
1970 ;; Don't let invalid specs prevent frame creation.
1971 (error nil))))
1973 ;; Apply attributes specified by frame parameters.
1974 (let ((face-params '((foreground-color default :foreground)
1975 (background-color default :background)
1976 (font default :font)
1977 (border-color border :background)
1978 (cursor-color cursor :background)
1979 (scroll-bar-foreground scroll-bar :foreground)
1980 (scroll-bar-background scroll-bar :background)
1981 (mouse-color mouse :background))))
1982 (dolist (param face-params)
1983 (let* ((param-name (nth 0 param))
1984 (value (cdr (assq param-name parameters))))
1985 (if value
1986 (set-face-attribute (nth 1 param) frame
1987 (nth 2 param) value))))))
1989 (defun tty-handle-reverse-video (frame parameters)
1990 "Handle the reverse-video frame parameter for terminal frames."
1991 (when (cdr (assq 'reverse parameters))
1992 (let* ((params (frame-parameters frame))
1993 (bg (cdr (assq 'foreground-color params)))
1994 (fg (cdr (assq 'background-color params))))
1995 (modify-frame-parameters frame
1996 (list (cons 'foreground-color fg)
1997 (cons 'background-color bg)))
1998 (if (equal bg (cdr (assq 'mouse-color params)))
1999 (modify-frame-parameters frame
2000 (list (cons 'mouse-color fg))))
2001 (if (equal bg (cdr (assq 'cursor-color params)))
2002 (modify-frame-parameters frame
2003 (list (cons 'cursor-color fg)))))))
2006 (defun tty-create-frame-with-faces (&optional parameters)
2007 "Create and return a frame from optional frame parameters PARAMETERS.
2008 If PARAMETERS contains a `reverse' parameter, handle that."
2009 (let ((frame (make-terminal-frame parameters))
2010 success)
2011 (unwind-protect
2012 (with-selected-frame frame
2013 (tty-handle-reverse-video frame (frame-parameters frame))
2015 (unless (terminal-parameter frame 'terminal-initted)
2016 (set-terminal-parameter frame 'terminal-initted t)
2017 (set-locale-environment nil frame)
2018 (tty-run-terminal-initialization frame))
2019 (frame-set-background-mode frame t)
2020 (face-set-after-frame-default frame parameters)
2021 (setq success t))
2022 (unless success
2023 (delete-frame frame)))
2024 frame))
2026 (defun tty-find-type (pred type)
2027 "Return the longest prefix of TYPE to which PRED returns non-nil.
2028 TYPE should be a tty type name such as \"xterm-16color\".
2030 The function tries only those prefixes that are followed by a
2031 dash or underscore in the original type name, like \"xterm\" in
2032 the above example."
2033 (let (hyphend)
2034 (while (and type
2035 (not (funcall pred type)))
2036 ;; Strip off last hyphen and what follows, then try again
2037 (setq type
2038 (if (setq hyphend (string-match "[-_][^-_]+$" type))
2039 (substring type 0 hyphend)
2040 nil))))
2041 type)
2043 (defun tty-run-terminal-initialization (frame &optional type)
2044 "Run the special initialization code for the terminal type of FRAME.
2045 The optional TYPE parameter may be used to override the autodetected
2046 terminal type to a different value."
2047 (setq type (or type (tty-type frame)))
2048 ;; Load library for our terminal type.
2049 ;; User init file can set term-file-prefix to nil to prevent this.
2050 (with-selected-frame frame
2051 (unless (null term-file-prefix)
2052 (let* (term-init-func)
2053 ;; First, load the terminal initialization file, if it is
2054 ;; available and it hasn't been loaded already.
2055 (tty-find-type #'(lambda (type)
2056 (let ((file (locate-library (concat term-file-prefix type))))
2057 (and file
2058 (or (assoc file load-history)
2059 (load file t t)))))
2060 type)
2061 ;; Next, try to find a matching initialization function, and call it.
2062 (tty-find-type #'(lambda (type)
2063 (fboundp (setq term-init-func
2064 (intern (concat "terminal-init-" type)))))
2065 type)
2066 (when (fboundp term-init-func)
2067 (funcall term-init-func))
2068 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
2070 ;; Called from C function init_display to initialize faces of the
2071 ;; dumped terminal frame on startup.
2073 (defun tty-set-up-initial-frame-faces ()
2074 (let ((frame (selected-frame)))
2075 (frame-set-background-mode frame t)
2076 (face-set-after-frame-default frame)))
2080 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2081 ;;; Standard faces.
2082 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2084 (defgroup basic-faces nil
2085 "The standard faces of Emacs."
2086 :group 'faces)
2088 (defface default
2089 '((t nil)) ; If this were nil, face-defface-spec would not be set.
2090 "Basic default face."
2091 :group 'basic-faces)
2093 (defface bold
2094 '((t :weight bold))
2095 "Basic bold face."
2096 :group 'basic-faces)
2098 (defface italic
2099 '((((supports :slant italic))
2100 :slant italic)
2101 (((supports :underline t))
2102 :underline t)
2104 ;; Default to italic, even if it doesn't appear to be supported,
2105 ;; because in some cases the display engine will do its own
2106 ;; workaround (to `dim' on ttys).
2107 :slant italic))
2108 "Basic italic face."
2109 :group 'basic-faces)
2111 (defface bold-italic
2112 '((t :weight bold :slant italic))
2113 "Basic bold-italic face."
2114 :group 'basic-faces)
2116 (defface underline
2117 '((((supports :underline t))
2118 :underline t)
2119 (((supports :weight bold))
2120 :weight bold)
2121 (t :underline t))
2122 "Basic underlined face."
2123 :group 'basic-faces)
2125 (defface fixed-pitch
2126 '((t :family "Monospace"))
2127 "The basic fixed-pitch face."
2128 :group 'basic-faces)
2130 (defface variable-pitch
2131 '((t :family "Sans Serif"))
2132 "The basic variable-pitch face."
2133 :group 'basic-faces)
2135 (defface shadow
2136 '((((class color grayscale) (min-colors 88) (background light))
2137 :foreground "grey50")
2138 (((class color grayscale) (min-colors 88) (background dark))
2139 :foreground "grey70")
2140 (((class color) (min-colors 8) (background light))
2141 :foreground "green")
2142 (((class color) (min-colors 8) (background dark))
2143 :foreground "yellow"))
2144 "Basic face for shadowed text."
2145 :group 'basic-faces
2146 :version "22.1")
2148 (defface link
2149 '((((class color) (min-colors 88) (background light))
2150 :foreground "RoyalBlue3" :underline t)
2151 (((class color) (background light))
2152 :foreground "blue" :underline t)
2153 (((class color) (min-colors 88) (background dark))
2154 :foreground "cyan1" :underline t)
2155 (((class color) (background dark))
2156 :foreground "cyan" :underline t)
2157 (t :inherit underline))
2158 "Basic face for unvisited links."
2159 :group 'basic-faces
2160 :version "22.1")
2162 (defface link-visited
2163 '((default :inherit link)
2164 (((class color) (background light)) :foreground "magenta4")
2165 (((class color) (background dark)) :foreground "violet"))
2166 "Basic face for visited links."
2167 :group 'basic-faces
2168 :version "22.1")
2170 (defface highlight
2171 '((((class color) (min-colors 88) (background light))
2172 :background "darkseagreen2")
2173 (((class color) (min-colors 88) (background dark))
2174 :background "darkolivegreen")
2175 (((class color) (min-colors 16) (background light))
2176 :background "darkseagreen2")
2177 (((class color) (min-colors 16) (background dark))
2178 :background "darkolivegreen")
2179 (((class color) (min-colors 8))
2180 :background "green" :foreground "black")
2181 (t :inverse-video t))
2182 "Basic face for highlighting."
2183 :group 'basic-faces)
2185 ;; Region face: under NS, default to the system-defined selection
2186 ;; color (optimized for the fixed white background of other apps),
2187 ;; if background is light.
2188 (defface region
2189 '((((class color) (min-colors 88) (background dark))
2190 :background "blue3")
2191 (((class color) (min-colors 88) (background light) (type gtk))
2192 :foreground "gtk_selection_fg_color"
2193 :background "gtk_selection_bg_color")
2194 (((class color) (min-colors 88) (background light) (type ns))
2195 :background "ns_selection_color")
2196 (((class color) (min-colors 88) (background light))
2197 :background "lightgoldenrod2")
2198 (((class color) (min-colors 16) (background dark))
2199 :background "blue3")
2200 (((class color) (min-colors 16) (background light))
2201 :background "lightgoldenrod2")
2202 (((class color) (min-colors 8))
2203 :background "blue" :foreground "white")
2204 (((type tty) (class mono))
2205 :inverse-video t)
2206 (t :background "gray"))
2207 "Basic face for highlighting the region."
2208 :version "21.1"
2209 :group 'basic-faces)
2211 (defface secondary-selection
2212 '((((class color) (min-colors 88) (background light))
2213 :background "yellow1")
2214 (((class color) (min-colors 88) (background dark))
2215 :background "SkyBlue4")
2216 (((class color) (min-colors 16) (background light))
2217 :background "yellow")
2218 (((class color) (min-colors 16) (background dark))
2219 :background "SkyBlue4")
2220 (((class color) (min-colors 8))
2221 :background "cyan" :foreground "black")
2222 (t :inverse-video t))
2223 "Basic face for displaying the secondary selection."
2224 :group 'basic-faces)
2226 (defface trailing-whitespace
2227 '((((class color) (background light))
2228 :background "red1")
2229 (((class color) (background dark))
2230 :background "red1")
2231 (t :inverse-video t))
2232 "Basic face for highlighting trailing whitespace."
2233 :version "21.1"
2234 :group 'whitespace-faces ; like `show-trailing-whitespace'
2235 :group 'basic-faces)
2237 (defface escape-glyph
2238 '((((background dark)) :foreground "cyan")
2239 ;; See the comment in minibuffer-prompt for
2240 ;; the reason not to use blue on MS-DOS.
2241 (((type pc)) :foreground "magenta")
2242 ;; red4 is too dark, but some say blue is too loud.
2243 ;; brown seems to work ok. -- rms.
2244 (t :foreground "brown"))
2245 "Face for characters displayed as sequences using `^' or `\\'."
2246 :group 'basic-faces
2247 :version "22.1")
2249 (defface nobreak-space
2250 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2251 (((class color) (min-colors 8)) :background "magenta")
2252 (t :inverse-video t))
2253 "Face for displaying nobreak space."
2254 :group 'basic-faces
2255 :version "22.1")
2257 (defgroup mode-line-faces nil
2258 "Faces used in the mode line."
2259 :group 'mode-line
2260 :group 'faces
2261 :version "22.1")
2263 (defface mode-line
2264 '((((class color) (min-colors 88))
2265 :box (:line-width -1 :style released-button)
2266 :background "grey75" :foreground "black")
2268 :inverse-video t))
2269 "Basic mode line face for selected window."
2270 :version "21.1"
2271 :group 'mode-line-faces
2272 :group 'basic-faces)
2273 ;; No need to define aliases of this form for new faces.
2274 (define-obsolete-face-alias 'modeline 'mode-line "21.1")
2276 (defface mode-line-inactive
2277 '((default
2278 :inherit mode-line)
2279 (((class color) (min-colors 88) (background light))
2280 :weight light
2281 :box (:line-width -1 :color "grey75" :style nil)
2282 :foreground "grey20" :background "grey90")
2283 (((class color) (min-colors 88) (background dark) )
2284 :weight light
2285 :box (:line-width -1 :color "grey40" :style nil)
2286 :foreground "grey80" :background "grey30"))
2287 "Basic mode line face for non-selected windows."
2288 :version "22.1"
2289 :group 'mode-line-faces
2290 :group 'basic-faces)
2291 (define-obsolete-face-alias 'modeline-inactive 'mode-line-inactive "22.1")
2293 (defface mode-line-highlight
2294 '((((class color) (min-colors 88))
2295 :box (:line-width 2 :color "grey40" :style released-button))
2297 :inherit highlight))
2298 "Basic mode line face for highlighting."
2299 :version "22.1"
2300 :group 'mode-line-faces
2301 :group 'basic-faces)
2302 (define-obsolete-face-alias 'modeline-highlight 'mode-line-highlight "22.1")
2304 (defface mode-line-emphasis
2305 '((t (:weight bold)))
2306 "Face used to emphasize certain mode line features.
2307 Use the face `mode-line-highlight' for features that can be selected."
2308 :version "23.1"
2309 :group 'mode-line-faces
2310 :group 'basic-faces)
2312 (defface mode-line-buffer-id
2313 '((t (:weight bold)))
2314 "Face used for buffer identification parts of the mode line."
2315 :version "22.1"
2316 :group 'mode-line-faces
2317 :group 'basic-faces)
2318 (define-obsolete-face-alias 'modeline-buffer-id 'mode-line-buffer-id "22.1")
2320 (defface header-line
2321 '((default
2322 :inherit mode-line)
2323 (((type tty))
2324 ;; This used to be `:inverse-video t', but that doesn't look very
2325 ;; good when combined with inverse-video mode-lines and multiple
2326 ;; windows. Underlining looks better, and is more consistent with
2327 ;; the window-system face variants, which deemphasize the
2328 ;; header-line in relation to the mode-line face. If a terminal
2329 ;; can't underline, then the header-line will end up without any
2330 ;; highlighting; this may be too confusing in general, although it
2331 ;; happens to look good with the only current use of header-lines,
2332 ;; the info browser. XXX
2333 :inverse-video nil ;Override the value inherited from mode-line.
2334 :underline t)
2335 (((class color grayscale) (background light))
2336 :background "grey90" :foreground "grey20"
2337 :box nil)
2338 (((class color grayscale) (background dark))
2339 :background "grey20" :foreground "grey90"
2340 :box nil)
2341 (((class mono) (background light))
2342 :background "white" :foreground "black"
2343 :inverse-video nil
2344 :box nil
2345 :underline t)
2346 (((class mono) (background dark))
2347 :background "black" :foreground "white"
2348 :inverse-video nil
2349 :box nil
2350 :underline t))
2351 "Basic header-line face."
2352 :version "21.1"
2353 :group 'basic-faces)
2355 (defface vertical-border
2356 '((((type tty)) :inherit mode-line-inactive))
2357 "Face used for vertical window dividers on ttys."
2358 :version "22.1"
2359 :group 'basic-faces)
2361 (defface minibuffer-prompt
2362 '((((background dark)) :foreground "cyan")
2363 ;; Don't use blue because many users of the MS-DOS port customize
2364 ;; their foreground color to be blue.
2365 (((type pc)) :foreground "magenta")
2366 (t :foreground "medium blue"))
2367 "Face for minibuffer prompts.
2368 By default, Emacs automatically adds this face to the value of
2369 `minibuffer-prompt-properties', which is a list of text properties
2370 used to display the prompt text."
2371 :version "22.1"
2372 :group 'basic-faces)
2374 (setq minibuffer-prompt-properties
2375 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2377 (defface fringe
2378 '((((class color) (background light))
2379 :background "grey95")
2380 (((class color) (background dark))
2381 :background "grey10")
2383 :background "gray"))
2384 "Basic face for the fringes to the left and right of windows under X."
2385 :version "21.1"
2386 :group 'frames
2387 :group 'basic-faces)
2389 (defface scroll-bar '((t nil))
2390 "Basic face for the scroll bar colors under X."
2391 :version "21.1"
2392 :group 'frames
2393 :group 'basic-faces)
2395 (defface border '((t nil))
2396 "Basic face for the frame border under X."
2397 :version "21.1"
2398 :group 'frames
2399 :group 'basic-faces)
2401 (defface cursor
2402 '((((background light)) :background "black")
2403 (((background dark)) :background "white"))
2404 "Basic face for the cursor color under X.
2405 Currently, only the `:background' attribute is meaningful; all
2406 other attributes are ignored. The cursor foreground color is
2407 taken from the background color of the underlying text.
2409 Note: Other faces cannot inherit from the cursor face."
2410 :version "21.1"
2411 :group 'cursor
2412 :group 'basic-faces)
2414 (put 'cursor 'face-no-inherit t)
2416 (defface mouse '((t nil))
2417 "Basic face for the mouse color under X."
2418 :version "21.1"
2419 :group 'mouse
2420 :group 'basic-faces)
2422 (defface tool-bar
2423 '((default
2424 :box (:line-width 1 :style released-button)
2425 :foreground "black")
2426 (((type x w32 ns) (class color))
2427 :background "grey75")
2428 (((type x) (class mono))
2429 :background "grey"))
2430 "Basic tool-bar face."
2431 :version "21.1"
2432 :group 'basic-faces)
2434 (defface menu
2435 '((((type tty))
2436 :inverse-video t)
2437 (((type x-toolkit))
2440 :inverse-video t))
2441 "Basic face for the font and colors of the menu bar and popup menus."
2442 :version "21.1"
2443 :group 'menu
2444 :group 'basic-faces)
2446 (defface help-argument-name '((((supports :slant italic)) :inherit italic))
2447 "Face to highlight argument names in *Help* buffers."
2448 :group 'help)
2450 (defface glyphless-char
2451 '((((type tty)) :inherit underline)
2452 (((type pc)) :inherit escape-glyph)
2453 (t :height 0.6))
2454 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2455 It is used for characters of no fonts too."
2456 :version "24.1"
2457 :group 'basic-faces)
2459 (defface error
2460 '((default :weight bold)
2461 (((class color) (min-colors 88) (background light)) :foreground "Red1")
2462 (((class color) (min-colors 88) (background dark)) :foreground "Pink")
2463 (((class color) (min-colors 16) (background light)) :foreground "Red1")
2464 (((class color) (min-colors 16) (background dark)) :foreground "Pink")
2465 (((class color) (min-colors 8)) :foreground "red")
2466 (t :inverse-video t))
2467 "Basic face used to highlight errors and to denote failure."
2468 :version "24.1"
2469 :group 'basic-faces)
2471 (defface warning
2472 '((default :weight bold)
2473 (((class color) (min-colors 16)) :foreground "DarkOrange")
2474 (((class color)) :foreground "yellow"))
2475 "Basic face used to highlight warnings."
2476 :version "24.1"
2477 :group 'basic-faces)
2479 (defface success
2480 '((default :weight bold)
2481 (((class color) (min-colors 16) (background light)) :foreground "ForestGreen")
2482 (((class color) (min-colors 88) (background dark)) :foreground "Green1")
2483 (((class color) (min-colors 16) (background dark)) :foreground "Green")
2484 (((class color)) :foreground "green"))
2485 "Basic face used to indicate successful operation."
2486 :version "24.1"
2487 :group 'basic-faces)
2490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2491 ;;; Manipulating font names.
2492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2494 ;; This is here for compatibility with Emacs 20.2. For example,
2495 ;; international/fontset.el uses x-resolve-font-name. The following
2496 ;; functions are not used in the face implementation itself.
2498 (defvar x-font-regexp nil)
2499 (defvar x-font-regexp-head nil)
2500 (defvar x-font-regexp-weight nil)
2501 (defvar x-font-regexp-slant nil)
2503 (defconst x-font-regexp-weight-subnum 1)
2504 (defconst x-font-regexp-slant-subnum 2)
2505 (defconst x-font-regexp-swidth-subnum 3)
2506 (defconst x-font-regexp-adstyle-subnum 4)
2508 ;;; Regexps matching font names in "Host Portable Character Representation."
2510 (let ((- "[-?]")
2511 (foundry "[^-]+")
2512 (family "[^-]+")
2513 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2514 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2515 (weight\? "\\([^-]*\\)") ; 1
2516 (slant "\\([ior]\\)") ; 2
2517 ; (slant\? "\\([ior?*]?\\)") ; 2
2518 (slant\? "\\([^-]?\\)") ; 2
2519 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2520 (swidth "\\([^-]*\\)") ; 3
2521 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2522 (adstyle "\\([^-]*\\)") ; 4
2523 (pixelsize "[0-9]+")
2524 (pointsize "[0-9][0-9]+")
2525 (resx "[0-9][0-9]+")
2526 (resy "[0-9][0-9]+")
2527 (spacing "[cmp?*]")
2528 (avgwidth "[0-9]+")
2529 (registry "[^-]+")
2530 (encoding "[^-]+")
2532 (setq x-font-regexp
2533 (purecopy (concat "\\`\\*?[-?*]"
2534 foundry - family - weight\? - slant\? - swidth - adstyle -
2535 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2536 registry - encoding "\\*?\\'"
2538 (setq x-font-regexp-head
2539 (purecopy (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2540 "\\([-*?]\\|\\'\\)")))
2541 (setq x-font-regexp-slant (purecopy (concat - slant -)))
2542 (setq x-font-regexp-weight (purecopy (concat - weight -)))
2543 nil)
2546 (defun x-resolve-font-name (pattern &optional face frame)
2547 "Return a font name matching PATTERN.
2548 All wildcards in PATTERN are instantiated.
2549 If PATTERN is nil, return the name of the frame's base font, which never
2550 contains wildcards.
2551 Given optional arguments FACE and FRAME, return a font which is
2552 also the same size as FACE on FRAME, or fail."
2553 (or (symbolp face)
2554 (setq face (face-name face)))
2555 (and (eq frame t)
2556 (setq frame nil))
2557 (if pattern
2558 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2559 (let ((fonts (x-list-fonts pattern face frame 1)))
2560 (or fonts
2561 (if face
2562 (if (string-match "\\*" pattern)
2563 (if (null (face-font face))
2564 (error "No matching fonts are the same height as the frame default font")
2565 (error "No matching fonts are the same height as face `%s'" face))
2566 (if (null (face-font face))
2567 (error "Height of font `%s' doesn't match the frame default font"
2568 pattern)
2569 (error "Height of font `%s' doesn't match face `%s'"
2570 pattern face)))
2571 (error "No fonts match `%s'" pattern)))
2572 (car fonts))
2573 (cdr (assq 'font (frame-parameters (selected-frame))))))
2575 (provide 'faces)
2577 ;;; faces.el ends here