fix xfree bug in run_thread
[emacs.git] / lisp / faces.el
blob0a3f055132503ff257cf3eaa6fd34110bd828479
1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992-1996, 1998-2013 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 (defcustom term-file-prefix (purecopy "term/")
29 "If non-nil, Emacs startup performs terminal-specific initialization.
30 It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
32 You may set this variable to nil in your init file if you do not wish
33 the terminal-initialization file to be loaded."
34 :type '(choice (const :tag "No terminal-specific initialization" nil)
35 (string :tag "Name of directory with term files"))
36 :group 'terminals)
38 (declare-function xw-defined-colors "term/common-win" (&optional frame))
40 (defvar help-xref-stack-item)
42 (defvar face-name-history nil
43 "History list for some commands that read face names.
44 Maximum length of the history list is determined by the value
45 of `history-length', which see.")
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 ;;; Font selection.
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 (defgroup font-selection nil
53 "Influencing face font selection."
54 :group 'faces)
57 (defcustom face-font-selection-order
58 '(:width :height :weight :slant)
59 "A list specifying how face font selection chooses fonts.
60 Each of the four symbols `:width', `:height', `:weight', and `:slant'
61 must appear once in the list, and the list must not contain any other
62 elements. Font selection first tries to find a best matching font
63 for those face attributes that appear before in the list. For
64 example, if `:slant' appears before `:height', font selection first
65 tries to find a font with a suitable slant, even if this results in
66 a font height that isn't optimal."
67 :tag "Font selection order"
68 :type '(list symbol symbol symbol symbol)
69 :group 'font-selection
70 :set #'(lambda (symbol value)
71 (set-default symbol value)
72 (internal-set-font-selection-order value)))
75 ;; In the absence of Fontconfig support, Monospace and Sans Serif are
76 ;; unavailable, and we fall back on the courier and helv families,
77 ;; which are generally available.
78 (defcustom face-font-family-alternatives
79 (mapcar (lambda (arg) (mapcar 'purecopy arg))
80 '(("Monospace" "courier" "fixed")
81 ("courier" "CMU Typewriter Text" "fixed")
82 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
83 ("helv" "helvetica" "arial" "fixed")))
84 "Alist of alternative font family names.
85 Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
86 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
87 ALTERNATIVE2 etc."
88 :tag "Alternative font families to try"
89 :type '(repeat (repeat string))
90 :group 'font-selection
91 :set #'(lambda (symbol value)
92 (set-default symbol value)
93 (internal-set-alternative-font-family-alist value)))
96 ;; This is defined originally in xfaces.c.
97 (defcustom face-font-registry-alternatives
98 (mapcar (lambda (arg) (mapcar 'purecopy arg))
99 (if (featurep 'w32)
100 '(("iso8859-1" "ms-oemlatin")
101 ("gb2312.1980" "gb2312" "gbk" "gb18030")
102 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
103 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
104 ("muletibetan-2" "muletibetan-0"))
105 '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
106 ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
107 ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
108 ("muletibetan-2" "muletibetan-0"))))
109 "Alist of alternative font registry names.
110 Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
111 If fonts of registry REGISTRY can be loaded, font selection
112 tries to find a best matching font among all fonts of registry
113 REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
114 :tag "Alternative font registries to try"
115 :type '(repeat (repeat string))
116 :version "21.1"
117 :group 'font-selection
118 :set #'(lambda (symbol value)
119 (set-default symbol value)
120 (internal-set-alternative-font-registry-alist value)))
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124 ;;; Creation, copying.
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128 (defun face-list ()
129 "Return a list of all defined faces."
130 (mapcar #'car face-new-frame-defaults))
132 (defun make-face (face &optional no-init-from-resources)
133 "Define a new face with name FACE, a symbol.
134 Do not call this directly from Lisp code; use `defface' instead.
136 If NO-INIT-FROM-RESOURCES is non-nil, don't initialize face
137 attributes from X resources. If FACE is already known as a face,
138 leave it unmodified. Return FACE."
139 (interactive (list (read-from-minibuffer
140 "Make face: " nil nil t 'face-name-history)))
141 (unless (facep face)
142 ;; Make frame-local faces (this also makes the global one).
143 (dolist (frame (frame-list))
144 (internal-make-lisp-face face frame))
145 ;; Add the face to the face menu.
146 (when (fboundp 'facemenu-add-new-face)
147 (facemenu-add-new-face face))
148 ;; Define frame-local faces for all frames from X resources.
149 (unless no-init-from-resources
150 (make-face-x-resource-internal face)))
151 face)
153 (defun make-empty-face (face)
154 "Define a new, empty face with name FACE.
155 Do not call this directly from Lisp code; use `defface' instead."
156 (interactive (list (read-from-minibuffer
157 "Make empty face: " nil nil t 'face-name-history)))
158 (make-face face 'no-init-from-resources))
160 (defun copy-face (old-face new-face &optional frame new-frame)
161 "Define a face named NEW-FACE, which is a copy of OLD-FACE.
162 This function does not copy face customization data, so NEW-FACE
163 will not be made customizable. Most Lisp code should not call
164 this function; use `defface' with :inherit instead.
166 If NEW-FACE already exists as a face, modify it to be like
167 OLD-FACE. If NEW-FACE doesn't already exist, create it.
169 If the optional argument FRAME is a frame, change NEW-FACE on
170 FRAME only. If FRAME is t, copy the frame-independent default
171 specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
172 the defaults as well as the faces on each existing frame.
174 If the optional fourth argument NEW-FRAME is given, copy the
175 information from face OLD-FACE on frame FRAME to NEW-FACE on
176 frame NEW-FRAME. In this case, FRAME must not be nil."
177 (let ((inhibit-quit t))
178 (if (null frame)
179 (progn
180 (when new-frame
181 (error "Copying face %s from all frames to one frame"
182 old-face))
183 (make-empty-face new-face)
184 (dolist (frame (frame-list))
185 (copy-face old-face new-face frame))
186 (copy-face old-face new-face t))
187 (make-empty-face new-face)
188 (internal-copy-lisp-face old-face new-face frame new-frame))
189 new-face))
192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
193 ;;; Predicates, type checks.
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 (defun facep (face)
197 "Return non-nil if FACE is a face name; nil otherwise.
198 A face name can be a string or a symbol."
199 (internal-lisp-face-p face))
202 (defun check-face (face)
203 "Signal an error if FACE doesn't name a face.
204 Value is FACE."
205 (unless (facep face)
206 (error "Not a face: %s" face))
207 face)
210 ;; The ID returned is not to be confused with the internally used IDs
211 ;; of realized faces. The ID assigned to Lisp faces is used to
212 ;; support faces in display table entries.
214 (defun face-id (face &optional _frame)
215 "Return the internal ID of face with name FACE.
216 If FACE is a face-alias, return the ID of the target face.
217 The optional argument FRAME is ignored, since the internal face ID
218 of a face name is the same for all frames."
219 (check-face face)
220 (or (get face 'face)
221 (face-id (get face 'face-alias))))
223 (defun face-equal (face1 face2 &optional frame)
224 "Non-nil if faces FACE1 and FACE2 are equal.
225 Faces are considered equal if all their attributes are equal.
226 If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
227 If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
228 If FRAME is omitted or nil, use the selected frame."
229 (internal-lisp-face-equal-p face1 face2 frame))
232 (defun face-differs-from-default-p (face &optional frame)
233 "Return non-nil if FACE displays differently from the default face.
234 If the optional argument FRAME is given, report on face FACE in that frame.
235 If FRAME is t, report on the defaults for face FACE (for new frames).
236 If FRAME is omitted or nil, use the selected frame."
237 (let ((attrs
238 (delq :inherit (mapcar 'car face-attribute-name-alist)))
239 (differs nil))
240 (while (and attrs (not differs))
241 (let* ((attr (pop attrs))
242 (attr-val (face-attribute face attr frame t)))
243 (when (and
244 (not (eq attr-val 'unspecified))
245 (display-supports-face-attributes-p (list attr attr-val)
246 frame))
247 (setq differs attr))))
248 differs))
251 (defun face-nontrivial-p (face &optional frame)
252 "True if face FACE has some non-nil attribute.
253 If the optional argument FRAME is given, report on face FACE in that frame.
254 If FRAME is t, report on the defaults for face FACE (for new frames).
255 If FRAME is omitted or nil, use the selected frame."
256 (not (internal-lisp-face-empty-p face frame)))
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
261 ;;; Setting face attributes from X resources.
262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 (defcustom face-x-resources
265 (mapcar
266 (lambda (arg)
267 ;; FIXME; can we purecopy some of the conses too?
268 (cons (car arg)
269 (cons (purecopy (car (cdr arg))) (purecopy (cdr (cdr arg))))))
270 '((:family (".attributeFamily" . "Face.AttributeFamily"))
271 (:foundry (".attributeFoundry" . "Face.AttributeFoundry"))
272 (:width (".attributeWidth" . "Face.AttributeWidth"))
273 (:height (".attributeHeight" . "Face.AttributeHeight"))
274 (:weight (".attributeWeight" . "Face.AttributeWeight"))
275 (:slant (".attributeSlant" . "Face.AttributeSlant"))
276 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
277 (:background (".attributeBackground" . "Face.AttributeBackground"))
278 (:overline (".attributeOverline" . "Face.AttributeOverline"))
279 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
280 (:box (".attributeBox" . "Face.AttributeBox"))
281 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
282 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
283 (:stipple
284 (".attributeStipple" . "Face.AttributeStipple")
285 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
286 (:bold (".attributeBold" . "Face.AttributeBold"))
287 (:italic (".attributeItalic" . "Face.AttributeItalic"))
288 (:font (".attributeFont" . "Face.AttributeFont"))
289 (:inherit (".attributeInherit" . "Face.AttributeInherit"))))
290 "List of X resources and classes for face attributes.
291 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
292 the name of a face attribute, and each ENTRY is a cons of the form
293 \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
294 X resource class for the attribute."
295 :type '(repeat (cons symbol (repeat (cons string string))))
296 :group 'faces)
299 (declare-function internal-face-x-get-resource "xfaces.c"
300 (resource class &optional frame))
302 (declare-function internal-set-lisp-face-attribute-from-resource "xfaces.c"
303 (face attr value &optional frame))
305 (defun set-face-attribute-from-resource (face attribute resource class frame)
306 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
307 Value is the attribute value specified by the resource, or nil
308 if not present. This function displays a message if the resource
309 specifies an invalid attribute."
310 (let* ((face-name (face-name face))
311 (value (internal-face-x-get-resource (concat face-name resource)
312 class frame)))
313 (when value
314 (condition-case ()
315 (internal-set-lisp-face-attribute-from-resource
316 face attribute (downcase value) frame)
317 (error
318 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
319 face-name frame attribute value))))
320 value))
323 (defun set-face-attributes-from-resources (face frame)
324 "Set attributes of FACE from X resources for FRAME."
325 (when (memq (framep frame) '(x w32))
326 (dolist (definition face-x-resources)
327 (let ((attribute (car definition)))
328 (dolist (entry (cdr definition))
329 (set-face-attribute-from-resource face attribute (car entry)
330 (cdr entry) frame))))))
333 (defun make-face-x-resource-internal (face &optional frame)
334 "Fill frame-local FACE on FRAME from X resources.
335 FRAME nil or not specified means do it for all frames."
336 (if (null frame)
337 (dolist (frame (frame-list))
338 (set-face-attributes-from-resources face frame))
339 (set-face-attributes-from-resources face frame)))
343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
344 ;;; Retrieving face attributes.
345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
347 (defun face-name (face)
348 "Return the name of face FACE."
349 (symbol-name (check-face face)))
352 (defun face-all-attributes (face &optional frame)
353 "Return an alist stating the attributes of FACE.
354 Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
355 If FRAME is omitted or nil the value describes the default attributes,
356 but if you specify FRAME, the value describes the attributes
357 of FACE on FRAME."
358 (mapcar (lambda (pair)
359 (let ((attr (car pair)))
360 (cons attr (face-attribute face attr (or frame t)))))
361 face-attribute-name-alist))
363 (defun face-attribute (face attribute &optional frame inherit)
364 "Return the value of FACE's ATTRIBUTE on FRAME.
365 If the optional argument FRAME is given, report on face FACE in that frame.
366 If FRAME is t, report on the defaults for face FACE (for new frames).
367 If FRAME is omitted or nil, use the selected frame.
369 If INHERIT is nil, only attributes directly defined by FACE are considered,
370 so the return value may be `unspecified', or a relative value.
371 If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
372 faces specified by its `:inherit' attribute; however the return value
373 may still be `unspecified' or relative.
374 If INHERIT is a face or a list of faces, then the result is further merged
375 with that face (or faces), until it becomes specified and absolute.
377 To ensure that the return value is always specified and absolute, use a
378 value of `default' for INHERIT; this will resolve any unspecified or
379 relative values by merging with the `default' face (which is always
380 completely specified)."
381 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
382 (when (and inherit (face-attribute-relative-p attribute value))
383 ;; VALUE is relative, so merge with inherited faces
384 (let ((inh-from (face-attribute face :inherit frame)))
385 (unless (or (null inh-from) (eq inh-from 'unspecified))
386 (condition-case nil
387 (setq value
388 (face-attribute-merged-with attribute value inh-from frame))
389 ;; The `inherit' attribute may point to non existent faces.
390 (error nil)))))
391 (when (and inherit
392 (not (eq inherit t))
393 (face-attribute-relative-p attribute value))
394 ;; We should merge with INHERIT as well
395 (setq value (face-attribute-merged-with attribute value inherit frame)))
396 value))
398 (defun face-attribute-merged-with (attribute value faces &optional frame)
399 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
400 FACES may be either a single face or a list of faces.
401 \[This is an internal function.]"
402 (cond ((not (face-attribute-relative-p attribute value))
403 value)
404 ((null faces)
405 value)
406 ((consp faces)
407 (face-attribute-merged-with
408 attribute
409 (face-attribute-merged-with attribute value (car faces) frame)
410 (cdr faces)
411 frame))
413 (merge-face-attribute attribute
414 value
415 (face-attribute faces attribute frame t)))))
418 (defmacro face-attribute-specified-or (value &rest body)
419 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
420 (let ((temp (make-symbol "value")))
421 `(let ((,temp ,value))
422 (if (not (eq ,temp 'unspecified))
423 ,temp
424 ,@body))))
426 (defun face-foreground (face &optional frame inherit)
427 "Return the foreground color name of FACE, or nil if unspecified.
428 If the optional argument FRAME is given, report on face FACE in that frame.
429 If FRAME is t, report on the defaults for face FACE (for new frames).
430 If FRAME is omitted or nil, use the selected frame.
432 If INHERIT is nil, only a foreground color directly defined by FACE is
433 considered, so the return value may be nil.
434 If INHERIT is t, and FACE doesn't define a foreground color, then any
435 foreground color that FACE inherits through its `:inherit' attribute
436 is considered as well; however the return value may still be nil.
437 If INHERIT is a face or a list of faces, then it is used to try to
438 resolve an unspecified foreground color.
440 To ensure that a valid color is always returned, use a value of
441 `default' for INHERIT; this will resolve any unspecified values by
442 merging with the `default' face (which is always completely specified)."
443 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
444 nil))
446 (defun face-background (face &optional frame inherit)
447 "Return the background color name of FACE, or nil if unspecified.
448 If the optional argument FRAME is given, report on face FACE in that frame.
449 If FRAME is t, report on the defaults for face FACE (for new frames).
450 If FRAME is omitted or nil, use the selected frame.
452 If INHERIT is nil, only a background color directly defined by FACE is
453 considered, so the return value may be nil.
454 If INHERIT is t, and FACE doesn't define a background color, then any
455 background color that FACE inherits through its `:inherit' attribute
456 is considered as well; however the return value may still be nil.
457 If INHERIT is a face or a list of faces, then it is used to try to
458 resolve an unspecified background color.
460 To ensure that a valid color is always returned, use a value of
461 `default' for INHERIT; this will resolve any unspecified values by
462 merging with the `default' face (which is always completely specified)."
463 (face-attribute-specified-or (face-attribute face :background frame inherit)
464 nil))
466 (defun face-stipple (face &optional frame inherit)
467 "Return the stipple pixmap name of FACE, or nil if unspecified.
468 If the optional argument FRAME is given, report on face FACE in that frame.
469 If FRAME is t, report on the defaults for face FACE (for new frames).
470 If FRAME is omitted or nil, use the selected frame.
472 If INHERIT is nil, only a stipple directly defined by FACE is
473 considered, so the return value may be nil.
474 If INHERIT is t, and FACE doesn't define a stipple, then any stipple
475 that FACE inherits through its `:inherit' attribute is considered as
476 well; however the return value may still be nil.
477 If INHERIT is a face or a list of faces, then it is used to try to
478 resolve an unspecified stipple.
480 To ensure that a valid stipple or nil is always returned, use a value of
481 `default' for INHERIT; this will resolve any unspecified values by merging
482 with the `default' face (which is always completely specified)."
483 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
484 nil))
487 (defalias 'face-background-pixmap 'face-stipple)
490 (defun face-underline-p (face &optional frame inherit)
491 "Return non-nil if FACE specifies a non-nil underlining.
492 If the optional argument FRAME is given, report on face FACE in that frame.
493 If FRAME is t, report on the defaults for face FACE (for new frames).
494 If FRAME is omitted or nil, use the selected frame.
495 Optional argument INHERIT is passed to `face-attribute'."
496 (face-attribute-specified-or
497 (face-attribute face :underline frame inherit) nil))
500 (defun face-inverse-video-p (face &optional frame inherit)
501 "Return non-nil if FACE specifies a non-nil inverse-video.
502 If the optional argument FRAME is given, report on face FACE in that frame.
503 If FRAME is t, report on the defaults for face FACE (for new frames).
504 If FRAME is omitted or nil, use the selected frame.
505 Optional argument INHERIT is passed to `face-attribute'."
506 (eq (face-attribute face :inverse-video frame inherit) t))
509 (defun face-bold-p (face &optional frame inherit)
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 Optional argument INHERIT is passed to `face-attribute'.
515 Use `face-attribute' for finer control."
516 (let ((bold (face-attribute face :weight frame inherit)))
517 (memq bold '(semi-bold bold extra-bold ultra-bold))))
520 (defun face-italic-p (face &optional frame inherit)
521 "Return non-nil if the font of FACE is italic on FRAME.
522 If the optional argument FRAME is given, report on face FACE in that frame.
523 If FRAME is t, report on the defaults for face FACE (for new frames).
524 If FRAME is omitted or nil, use the selected frame.
525 Optional argument INHERIT is passed to `face-attribute'.
526 Use `face-attribute' for finer control."
527 (let ((italic (face-attribute face :slant frame inherit)))
528 (memq italic '(italic oblique))))
532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
533 ;;; Face documentation.
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
536 (defun face-documentation (face)
537 "Get the documentation string for FACE.
538 If FACE is a face-alias, get the documentation for the target face."
539 (let ((alias (get face 'face-alias)))
540 (if alias
541 (let ((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 (face-at-point t))))
760 (set-face-attribute face frame :weight 'bold))
763 (defun make-face-unbold (face &optional frame _noerror)
764 "Make the font of FACE be non-bold, if possible.
765 FRAME nil or not specified means change face on all frames.
766 Argument NOERROR is ignored and retained for compatibility."
767 (interactive (list (read-face-name "Make which face non-bold"
768 (face-at-point t))))
769 (set-face-attribute face frame :weight 'normal))
772 (defun make-face-italic (face &optional frame _noerror)
773 "Make the font of FACE be italic, if possible.
774 FRAME nil or not specified means change face on all frames.
775 Argument NOERROR is ignored and retained for compatibility.
776 Use `set-face-attribute' for finer control of the font slant."
777 (interactive (list (read-face-name "Make which face italic"
778 (face-at-point t))))
779 (set-face-attribute face frame :slant 'italic))
782 (defun make-face-unitalic (face &optional frame _noerror)
783 "Make the font of FACE be non-italic, if possible.
784 FRAME nil or not specified means change face on all frames.
785 Argument NOERROR is ignored and retained for compatibility."
786 (interactive (list (read-face-name "Make which face non-italic"
787 (face-at-point t))))
788 (set-face-attribute face frame :slant 'normal))
791 (defun make-face-bold-italic (face &optional frame _noerror)
792 "Make the font of FACE be bold and italic, if possible.
793 FRAME nil or not specified means change face on all frames.
794 Argument NOERROR is ignored and retained for compatibility.
795 Use `set-face-attribute' for finer control of font weight and slant."
796 (interactive (list (read-face-name "Make which face bold-italic"
797 (face-at-point t))))
798 (set-face-attribute face frame :weight 'bold :slant 'italic))
801 (defun set-face-font (face font &optional frame)
802 "Change font-related attributes of FACE to those of FONT (a string).
803 FRAME nil or not specified means change face on all frames.
804 This sets the attributes `:family', `:foundry', `:width',
805 `:height', `:weight', and `:slant'. When called interactively,
806 prompt for the face and font."
807 (interactive (read-face-and-attribute :font))
808 (set-face-attribute face frame :font font))
811 ;; Implementation note: Emulating gray background colors with a
812 ;; stipple pattern is now part of the face realization process, and is
813 ;; done in C depending on the frame on which the face is realized.
815 (defun set-face-background (face color &optional frame)
816 "Change the background color of face FACE to COLOR (a string).
817 FRAME nil or not specified means change face on all frames.
818 COLOR can be a system-defined color name (see `list-colors-display')
819 or a hex spec of the form #RRGGBB.
820 When called interactively, prompts for the face and color."
821 (interactive (read-face-and-attribute :background))
822 (set-face-attribute face frame :background (or color 'unspecified)))
825 (defun set-face-foreground (face color &optional frame)
826 "Change the foreground color of face FACE to COLOR (a string).
827 FRAME nil or not specified means change face on all frames.
828 COLOR can be a system-defined color name (see `list-colors-display')
829 or a hex spec of the form #RRGGBB.
830 When called interactively, prompts for the face and color."
831 (interactive (read-face-and-attribute :foreground))
832 (set-face-attribute face frame :foreground (or color 'unspecified)))
835 (defun set-face-stipple (face stipple &optional frame)
836 "Change the stipple pixmap of face FACE to STIPPLE.
837 FRAME nil or not specified means change face on all frames.
838 STIPPLE should be a string, the name of a file of pixmap data.
839 The directories listed in the `x-bitmap-file-path' variable are searched.
841 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
842 where WIDTH and HEIGHT are the size in pixels,
843 and DATA is a string, containing the raw bits of the bitmap."
844 (interactive (read-face-and-attribute :stipple))
845 (set-face-attribute face frame :stipple (or stipple 'unspecified)))
848 (defun set-face-underline (face underline &optional frame)
849 "Specify whether face FACE is underlined.
850 UNDERLINE nil means FACE explicitly doesn't underline.
851 UNDERLINE t means FACE underlines with its foreground color.
852 If UNDERLINE is a string, underline with that color.
854 UNDERLINE may also be a list of the form (:color COLOR :style STYLE),
855 where COLOR is a string or `foreground-color', and STYLE is either
856 `line' or `wave'. :color may be omitted, which means to use the
857 foreground color. :style may be omitted, which means to use a line.
859 FRAME nil or not specified means change face on all frames.
860 Use `set-face-attribute' to ``unspecify'' underlining."
861 (interactive (read-face-and-attribute :underline))
862 (set-face-attribute face frame :underline underline))
864 (define-obsolete-function-alias 'set-face-underline-p
865 'set-face-underline "24.3")
868 (defun set-face-inverse-video (face inverse-video-p &optional frame)
869 "Specify whether face FACE is in inverse video.
870 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
871 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
872 FRAME nil or not specified means change face on all frames.
873 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
874 (interactive
875 (let ((list (read-face-and-attribute :inverse-video)))
876 (list (car list) (if (cadr list) t))))
877 (set-face-attribute face frame :inverse-video inverse-video-p))
879 (define-obsolete-function-alias 'set-face-inverse-video-p
880 'set-face-inverse-video "24.4")
882 (defun set-face-bold (face bold-p &optional frame)
883 "Specify whether face FACE is bold.
884 BOLD-P non-nil means FACE should explicitly display bold.
885 BOLD-P nil means FACE should explicitly display non-bold.
886 FRAME nil or not specified means change face on all frames.
887 Use `set-face-attribute' or `modify-face' for finer control."
888 (if (null bold-p)
889 (make-face-unbold face frame)
890 (make-face-bold face frame)))
892 (define-obsolete-function-alias 'set-face-bold-p 'set-face-bold "24.4")
895 (defun set-face-italic (face italic-p &optional frame)
896 "Specify whether face FACE is italic.
897 ITALIC-P non-nil means FACE should explicitly display italic.
898 ITALIC-P nil means FACE should explicitly display non-italic.
899 FRAME nil or not specified means change face on all frames.
900 Use `set-face-attribute' or `modify-face' for finer control."
901 (if (null italic-p)
902 (make-face-unitalic face frame)
903 (make-face-italic face frame)))
905 (define-obsolete-function-alias 'set-face-italic-p 'set-face-italic "24.4")
908 (defalias 'set-face-background-pixmap 'set-face-stipple)
911 (defun invert-face (face &optional frame)
912 "Swap the foreground and background colors of FACE.
913 If FRAME is omitted or nil, it means change face on all frames.
914 If FACE specifies neither foreground nor background color,
915 set its foreground and background to the background and foreground
916 of the default face. Value is FACE."
917 (interactive (list (read-face-name "Invert face" (face-at-point t))))
918 (let ((fg (face-attribute face :foreground frame))
919 (bg (face-attribute face :background frame)))
920 (if (not (and (eq fg 'unspecified) (eq bg 'unspecified)))
921 (set-face-attribute face frame :foreground bg :background fg)
922 (set-face-attribute face frame
923 :foreground
924 (face-attribute 'default :background frame)
925 :background
926 (face-attribute 'default :foreground frame))))
927 face)
930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 ;;; Interactively modifying faces.
932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
934 (defvar crm-separator) ; from crm.el
936 (defun read-face-name (prompt &optional default multiple)
937 "Read one or more face names, prompting with PROMPT.
938 PROMPT should not end in a space or a colon.
940 Return DEFAULT if the user enters the empty string.
941 If DEFAULT is non-nil, it should be a single face or a list of face names
942 \(symbols or strings). In the latter case, return the `car' of DEFAULT
943 \(if MULTIPLE is nil, see below), or DEFAULT (if MULTIPLE is non-nil).
945 If MULTIPLE is non-nil, this function uses `completing-read-multiple'
946 to read multiple faces with \"[ \\t]*,[ \\t]*\" as the separator regexp
947 and it returns a list of face names. Otherwise, it reads and returns
948 a single face name."
949 (if (and default (not (stringp default)))
950 (setq default
951 (cond ((symbolp default)
952 (symbol-name default))
953 (multiple
954 (mapconcat (lambda (f) (if (symbolp f) (symbol-name f) f))
955 default ", "))
956 ;; If we only want one, and the default is more than one,
957 ;; discard the unwanted ones.
958 (t (symbol-name (car default))))))
959 (if (and default (not multiple))
960 ;; For compatibility with `completing-read-multiple' use `crm-separator'
961 ;; to define DEFAULT if MULTIPLE is nil.
962 (setq default (car (split-string default crm-separator t))))
964 (let ((prompt (if default
965 (format "%s (default `%s'): " prompt default)
966 (format "%s: " prompt)))
967 aliasfaces nonaliasfaces faces)
968 ;; Build up the completion tables.
969 (mapatoms (lambda (s)
970 (if (facep s)
971 (if (get s 'face-alias)
972 (push (symbol-name s) aliasfaces)
973 (push (symbol-name s) nonaliasfaces)))))
974 (if multiple
975 (progn
976 (dolist (face (completing-read-multiple
977 prompt
978 (completion-table-in-turn nonaliasfaces aliasfaces)
979 nil t nil 'face-name-history default))
980 ;; Ignore elements that are not faces
981 ;; (for example, because DEFAULT was "all faces")
982 (if (facep face) (push (intern face) faces)))
983 (nreverse faces))
984 (let ((face (completing-read
985 prompt
986 (completion-table-in-turn nonaliasfaces aliasfaces)
987 nil t nil 'face-name-history default)))
988 (if (facep face) (intern face))))))
990 ;; Not defined without X, but behind window-system test.
991 (defvar x-bitmap-file-path)
993 (defun face-valid-attribute-values (attribute &optional frame)
994 "Return valid values for face attribute ATTRIBUTE.
995 The optional argument FRAME is used to determine available fonts
996 and colors. If it is nil or not specified, the selected frame is used.
997 Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out
998 of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
999 an integer value."
1000 (let ((valid
1001 (pcase attribute
1002 (`:family
1003 (if (window-system frame)
1004 (mapcar (lambda (x) (cons x x))
1005 (font-family-list))
1006 ;; Only one font on TTYs.
1007 (list (cons "default" "default"))))
1008 (`:foundry
1009 (list nil))
1010 (`:width
1011 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1012 font-width-table))
1013 (`:weight
1014 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1015 font-weight-table))
1016 (`:slant
1017 (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1)))
1018 font-slant-table))
1019 (`:inverse-video
1020 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1021 (internal-lisp-face-attribute-values attribute)))
1022 ((or `:underline `:overline `:strike-through `:box)
1023 (if (window-system frame)
1024 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
1025 (internal-lisp-face-attribute-values attribute))
1026 (mapcar #'(lambda (c) (cons c c))
1027 (defined-colors frame)))
1028 (mapcar #'(lambda (x) (cons (symbol-name x) x))
1029 (internal-lisp-face-attribute-values attribute))))
1030 ((or `:foreground `:background)
1031 (mapcar #'(lambda (c) (cons c c))
1032 (defined-colors frame)))
1033 (`:height
1034 'integerp)
1035 (`:stipple
1036 (and (memq (window-system frame) '(x ns)) ; No stipple on w32
1037 (mapcar #'list
1038 (apply #'nconc
1039 (mapcar (lambda (dir)
1040 (and (file-readable-p dir)
1041 (file-directory-p dir)
1042 (directory-files dir)))
1043 x-bitmap-file-path)))))
1044 (`:inherit
1045 (cons '("none" . nil)
1046 (mapcar #'(lambda (c) (cons (symbol-name c) c))
1047 (face-list))))
1049 (error "Internal error")))))
1050 (if (and (listp valid) (not (memq attribute '(:inherit))))
1051 (nconc (list (cons "unspecified" 'unspecified)) valid)
1052 valid)))
1055 (defconst face-attribute-name-alist
1056 '((:family . "font family")
1057 (:foundry . "font foundry")
1058 (:width . "character set width")
1059 (:height . "height in 1/10 pt")
1060 (:weight . "weight")
1061 (:slant . "slant")
1062 (:underline . "underline")
1063 (:overline . "overline")
1064 (:strike-through . "strike-through")
1065 (:box . "box")
1066 (:inverse-video . "inverse-video display")
1067 (:foreground . "foreground color")
1068 (:background . "background color")
1069 (:stipple . "background stipple")
1070 (:inherit . "inheritance"))
1071 "An alist of descriptive names for face attributes.
1072 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
1073 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
1074 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
1077 (defun face-descriptive-attribute-name (attribute)
1078 "Return a descriptive name for ATTRIBUTE."
1079 (cdr (assq attribute face-attribute-name-alist)))
1082 (defun face-read-string (face default name &optional completion-alist)
1083 "Interactively read a face attribute string value.
1084 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
1085 default string to return if no new value is entered. NAME is a
1086 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
1087 alist of valid values, if non-nil.
1089 Entering nothing accepts the default string DEFAULT.
1090 Value is the new attribute value."
1091 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
1092 ;; each word in a string separately).
1093 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
1094 (let* ((completion-ignore-case t)
1095 (value (completing-read
1096 (if default
1097 (format "%s for face `%s' (default %s): "
1098 name face default)
1099 (format "%s for face `%s': " name face))
1100 completion-alist nil nil nil nil default)))
1101 (if (equal value "") default value)))
1104 (defun face-read-integer (face default name)
1105 "Interactively read an integer face attribute value.
1106 FACE is the face whose attribute is read. DEFAULT is the default
1107 value to return if no new value is entered. NAME is a descriptive
1108 name of the attribute for prompting. Value is the new attribute value."
1109 (let ((new-value
1110 (face-read-string face
1111 (format "%s" default)
1112 name
1113 (list (cons "unspecified" 'unspecified)))))
1114 (cond ((equal new-value "unspecified")
1115 'unspecified)
1116 ((member new-value '("unspecified-fg" "unspecified-bg"))
1117 new-value)
1119 (string-to-number new-value)))))
1122 ;; FIXME this does allow you to enter the list forms of :box,
1123 ;; :stipple, or :underline, because face-valid-attribute-values does
1124 ;; not return those forms.
1125 (defun read-face-attribute (face attribute &optional frame)
1126 "Interactively read a new value for FACE's ATTRIBUTE.
1127 Optional argument FRAME nil or unspecified means read an attribute value
1128 of a global face. Value is the new attribute value."
1129 (let* ((old-value (face-attribute face attribute frame))
1130 (attribute-name (face-descriptive-attribute-name attribute))
1131 (valid (face-valid-attribute-values attribute frame))
1132 new-value)
1133 ;; Represent complex attribute values as strings by printing them
1134 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1135 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1136 ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'.
1137 (and (memq attribute '(:box :stipple :underline))
1138 (or (consp old-value)
1139 (vectorp old-value))
1140 (setq old-value (prin1-to-string old-value)))
1141 (cond ((listp valid)
1142 (let ((default
1143 (or (car (rassoc old-value valid))
1144 (format "%s" old-value))))
1145 (setq new-value
1146 (face-read-string face default attribute-name valid))
1147 (if (equal new-value default)
1148 ;; Nothing changed, so don't bother with all the stuff
1149 ;; below. In particular, this avoids a non-tty color
1150 ;; from being canonicalized for a tty when the user
1151 ;; just uses the default.
1152 (setq new-value old-value)
1153 ;; Terminal frames can support colors that don't appear
1154 ;; explicitly in VALID, using color approximation code
1155 ;; in tty-colors.el.
1156 (when (and (memq attribute '(:foreground :background))
1157 (not (memq (window-system frame) '(x w32 ns)))
1158 (not (member new-value
1159 '("unspecified"
1160 "unspecified-fg" "unspecified-bg"))))
1161 (setq new-value (car (tty-color-desc new-value frame))))
1162 (when (assoc new-value valid)
1163 (setq new-value (cdr (assoc new-value valid)))))))
1164 ((eq valid 'integerp)
1165 (setq new-value (face-read-integer face old-value attribute-name)))
1166 (t (error "Internal error")))
1167 ;; Convert stipple and box value text we read back to a list or
1168 ;; vector if it looks like one. This makes the assumption that a
1169 ;; pixmap file name won't start with an open-paren.
1170 (and (memq attribute '(:stipple :box :underline))
1171 (stringp new-value)
1172 (string-match-p "^[[(]" new-value)
1173 (setq new-value (read new-value)))
1174 new-value))
1176 (declare-function fontset-list "fontset.c" ())
1177 (declare-function x-list-fonts "xfaces.c"
1178 (pattern &optional face frame maximum width))
1180 (defun read-face-font (face &optional frame)
1181 "Read the name of a font for FACE on FRAME.
1182 If optional argument FRAME is nil or omitted, use the selected frame."
1183 (let ((completion-ignore-case t))
1184 (completing-read (format "Set font attributes of face `%s' from font: " face)
1185 (append (fontset-list) (x-list-fonts "*" nil frame)))))
1188 (defun read-all-face-attributes (face &optional frame)
1189 "Interactively read all attributes for FACE.
1190 If optional argument FRAME is nil or omitted, use the selected frame.
1191 Value is a property list of attribute names and new values."
1192 (let (result)
1193 (dolist (attribute face-attribute-name-alist result)
1194 (setq result (cons (car attribute)
1195 (cons (read-face-attribute face (car attribute) frame)
1196 result))))))
1198 (defun modify-face (&optional face foreground background stipple
1199 bold-p italic-p underline inverse-p frame)
1200 "Modify attributes of faces interactively.
1201 If optional argument FRAME is nil or omitted, modify the face used
1202 for newly created frame, i.e. the global face.
1203 For non-interactive use, `set-face-attribute' is preferred.
1204 When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
1205 and the face and its settings are obtained by querying the user."
1206 (interactive)
1207 (if face
1208 (set-face-attribute face frame
1209 :foreground (or foreground 'unspecified)
1210 :background (or background 'unspecified)
1211 :stipple stipple
1212 :weight (if bold-p 'bold 'normal)
1213 :slant (if italic-p 'italic 'normal)
1214 :underline underline
1215 :inverse-video inverse-p)
1216 (setq face (read-face-name "Modify face" (face-at-point t)))
1217 (apply #'set-face-attribute face frame
1218 (read-all-face-attributes face frame))))
1220 (defun read-face-and-attribute (attribute &optional frame)
1221 "Read face name and face attribute value.
1222 ATTRIBUTE is the attribute whose new value is read.
1223 FRAME nil or unspecified means read attribute value of global face.
1224 Value is a list (FACE NEW-VALUE) where FACE is the face read
1225 \(a symbol), and NEW-VALUE is value read."
1226 (cond ((eq attribute :font)
1227 (let* ((prompt "Set font-related attributes of face")
1228 (face (read-face-name prompt (face-at-point t)))
1229 (font (read-face-font face frame)))
1230 (list face font)))
1232 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1233 (prompt (format "Set %s of face" attribute-name))
1234 (face (read-face-name prompt (face-at-point t)))
1235 (new-value (read-face-attribute face attribute frame)))
1236 (list face new-value)))))
1240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1241 ;;; Listing faces.
1242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1244 (defconst list-faces-sample-text
1245 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1246 "Text string to display as the sample text for `list-faces-display'.")
1249 ;; The name list-faces would be more consistent, but let's avoid a
1250 ;; conflict with Lucid, which uses that name differently.
1252 (defvar help-xref-stack)
1253 (defun list-faces-display (&optional regexp)
1254 "List all faces, using the same sample text in each.
1255 The sample text is a string that comes from the variable
1256 `list-faces-sample-text'.
1258 If REGEXP is non-nil, list only those faces with names matching
1259 this regular expression. When called interactively with a prefix
1260 arg, prompt for a regular expression."
1261 (interactive (list (and current-prefix-arg
1262 (read-regexp "List faces matching regexp"))))
1263 (let ((all-faces (zerop (length regexp)))
1264 (frame (selected-frame))
1265 (max-length 0)
1266 faces line-format
1267 disp-frame window face-name)
1268 ;; We filter and take the max length in one pass
1269 (setq faces
1270 (delq nil
1271 (mapcar (lambda (f)
1272 (let ((s (symbol-name f)))
1273 (when (or all-faces (string-match-p regexp s))
1274 (setq max-length (max (length s) max-length))
1275 f)))
1276 (sort (face-list) #'string-lessp))))
1277 (unless faces
1278 (error "No faces matching \"%s\"" regexp))
1279 (setq max-length (1+ max-length)
1280 line-format (format "%%-%ds" max-length))
1281 (with-help-window "*Faces*"
1282 (with-current-buffer standard-output
1283 (setq truncate-lines t)
1284 (insert
1285 (substitute-command-keys
1286 (concat
1287 "\\<help-mode-map>Use "
1288 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1289 "\\[help-follow] on a face name to customize it\n"
1290 "or on its sample text for a description of the face.\n\n")))
1291 (setq help-xref-stack nil)
1292 (dolist (face faces)
1293 (setq face-name (symbol-name face))
1294 (insert (format line-format face-name))
1295 ;; Hyperlink to a customization buffer for the face. Using
1296 ;; the help xref mechanism may not be the best way.
1297 (save-excursion
1298 (save-match-data
1299 (search-backward face-name)
1300 (setq help-xref-stack-item `(list-faces-display ,regexp))
1301 (help-xref-button 0 'help-customize-face face)))
1302 (let ((beg (point))
1303 (line-beg (line-beginning-position)))
1304 (insert list-faces-sample-text)
1305 ;; Hyperlink to a help buffer for the face.
1306 (save-excursion
1307 (save-match-data
1308 (search-backward list-faces-sample-text)
1309 (help-xref-button 0 'help-face face)))
1310 (insert "\n")
1311 (put-text-property beg (1- (point)) 'face face)
1312 ;; Make all face commands default to the proper face
1313 ;; anywhere in the line.
1314 (put-text-property line-beg (1- (point)) 'read-face-name face)
1315 ;; If the sample text has multiple lines, line up all of them.
1316 (goto-char beg)
1317 (forward-line 1)
1318 (while (not (eobp))
1319 (insert-char ?\s max-length)
1320 (forward-line 1))))
1321 (goto-char (point-min))))
1322 ;; If the *Faces* buffer appears in a different frame,
1323 ;; copy all the face definitions from FRAME,
1324 ;; so that the display will reflect the frame that was selected.
1325 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1326 (setq disp-frame (if window (window-frame window)
1327 (car (frame-list))))
1328 (or (eq frame disp-frame)
1329 (dolist (face (face-list))
1330 (copy-face face face frame disp-frame)))))
1333 (defun describe-face (face &optional frame)
1334 "Display the properties of face FACE on FRAME.
1335 Interactively, FACE defaults to the faces of the character after point
1336 and FRAME defaults to the selected frame.
1338 If the optional argument FRAME is given, report on face FACE in that frame.
1339 If FRAME is t, report on the defaults for face FACE (for new frames).
1340 If FRAME is omitted or nil, use the selected frame."
1341 (interactive (list (read-face-name "Describe face"
1342 (or (face-at-point t) 'default)
1343 t)))
1344 (let* ((attrs '((:family . "Family")
1345 (:foundry . "Foundry")
1346 (:width . "Width")
1347 (:height . "Height")
1348 (:weight . "Weight")
1349 (:slant . "Slant")
1350 (:foreground . "Foreground")
1351 (:background . "Background")
1352 (:underline . "Underline")
1353 (:overline . "Overline")
1354 (:strike-through . "Strike-through")
1355 (:box . "Box")
1356 (:inverse-video . "Inverse")
1357 (:stipple . "Stipple")
1358 (:font . "Font")
1359 (:fontset . "Fontset")
1360 (:inherit . "Inherit")))
1361 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1362 attrs))))
1363 (help-setup-xref (list #'describe-face face)
1364 (called-interactively-p 'interactive))
1365 (unless face
1366 (setq face 'default))
1367 (if (not (listp face))
1368 (setq face (list face)))
1369 (with-help-window (help-buffer)
1370 (with-current-buffer standard-output
1371 (dolist (f face)
1372 (if (stringp f) (setq f (intern f)))
1373 ;; We may get called for anonymous faces (i.e., faces
1374 ;; expressed using prop-value plists). Those can't be
1375 ;; usefully customized, so ignore them.
1376 (when (symbolp f)
1377 (insert "Face: " (symbol-name f))
1378 (if (not (facep f))
1379 (insert " undefined face.\n")
1380 (let ((customize-label "customize this face")
1381 file-name)
1382 (insert (concat " (" (propertize "sample" 'font-lock-face f) ")"))
1383 (princ (concat " (" customize-label ")\n"))
1384 ;; FIXME not sure how much of this belongs here, and
1385 ;; how much in `face-documentation'. The latter is
1386 ;; not used much, but needs to return nil for
1387 ;; undocumented faces.
1388 (let ((alias (get f 'face-alias))
1389 (face f)
1390 obsolete)
1391 (when alias
1392 (setq face alias)
1393 (insert
1394 (format "\n %s is an alias for the face `%s'.\n%s"
1395 f alias
1396 (if (setq obsolete (get f 'obsolete-face))
1397 (format " This face is obsolete%s; use `%s' instead.\n"
1398 (if (stringp obsolete)
1399 (format " since %s" obsolete)
1401 alias)
1402 ""))))
1403 (insert "\nDocumentation:\n"
1404 (or (face-documentation face)
1405 "Not documented as a face.")
1406 "\n\n"))
1407 (with-current-buffer standard-output
1408 (save-excursion
1409 (re-search-backward
1410 (concat "\\(" customize-label "\\)") nil t)
1411 (help-xref-button 1 'help-customize-face f)))
1412 (setq file-name (find-lisp-object-file-name f 'defface))
1413 (when file-name
1414 (princ "Defined in `")
1415 (princ (file-name-nondirectory file-name))
1416 (princ "'")
1417 ;; Make a hyperlink to the library.
1418 (save-excursion
1419 (re-search-backward "`\\([^`']+\\)'" nil t)
1420 (help-xref-button 1 'help-face-def f file-name))
1421 (princ ".")
1422 (terpri)
1423 (terpri))
1424 (dolist (a attrs)
1425 (let ((attr (face-attribute f (car a) frame)))
1426 (insert (make-string (- max-width (length (cdr a))) ?\s)
1427 (cdr a) ": " (format "%s" attr))
1428 (if (and (eq (car a) :inherit)
1429 (not (eq attr 'unspecified)))
1430 ;; Make a hyperlink to the parent face.
1431 (save-excursion
1432 (re-search-backward ": \\([^:]+\\)" nil t)
1433 (help-xref-button 1 'help-face attr)))
1434 (insert "\n")))))
1435 (terpri)))))))
1438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1439 ;;; Face specifications (defface).
1440 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1442 ;; Parameter FRAME Is kept for call compatibility to with previous
1443 ;; face implementation.
1445 (defun face-attr-construct (face &optional _frame)
1446 "Return a `defface'-style attribute list for FACE.
1447 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1448 face attributes of FACE where ATTRIBUTE is the attribute name and
1449 VALUE is the specified value of that attribute.
1450 Argument FRAME is ignored and retained for compatibility."
1451 (let (result)
1452 (dolist (entry face-attribute-name-alist result)
1453 (let* ((attribute (car entry))
1454 (value (face-attribute face attribute)))
1455 (unless (eq value 'unspecified)
1456 (setq result (nconc (list attribute value) result)))))))
1459 (defun face-spec-set-match-display (display frame)
1460 "Non-nil if DISPLAY matches FRAME.
1461 DISPLAY is part of a spec such as can be used in `defface'.
1462 If FRAME is nil, the current FRAME is used."
1463 (let* ((conjuncts display)
1464 conjunct req options
1465 ;; t means we have succeeded against all the conjuncts in
1466 ;; DISPLAY that have been tested so far.
1467 (match t))
1468 (if (eq conjuncts t)
1469 (setq conjuncts nil))
1470 (while (and conjuncts match)
1471 (setq conjunct (car conjuncts)
1472 conjuncts (cdr conjuncts)
1473 req (car conjunct)
1474 options (cdr conjunct)
1475 match (cond ((eq req 'type)
1476 (or (memq (window-system frame) options)
1477 (and (memq 'graphic options)
1478 (memq (window-system frame) '(x w32 ns)))
1479 ;; FIXME: This should be revisited to use
1480 ;; display-graphic-p, provided that the
1481 ;; color selection depends on the number
1482 ;; of supported colors, and all defface's
1483 ;; are changed to look at number of colors
1484 ;; instead of (type graphic) etc.
1485 (if (null (window-system frame))
1486 (memq 'tty options)
1487 (or (and (memq 'motif options)
1488 (featurep 'motif))
1489 (and (memq 'gtk options)
1490 (featurep 'gtk))
1491 (and (memq 'lucid options)
1492 (featurep 'x-toolkit)
1493 (not (featurep 'motif))
1494 (not (featurep 'gtk)))
1495 (and (memq 'x-toolkit options)
1496 (featurep 'x-toolkit))))))
1497 ((eq req 'min-colors)
1498 (>= (display-color-cells frame) (car options)))
1499 ((eq req 'class)
1500 (memq (frame-parameter frame 'display-type) options))
1501 ((eq req 'background)
1502 (memq (frame-parameter frame 'background-mode)
1503 options))
1504 ((eq req 'supports)
1505 (display-supports-face-attributes-p options frame))
1506 (t (error "Unknown req `%S' with options `%S'"
1507 req options)))))
1508 match))
1511 (defun face-spec-choose (spec &optional frame)
1512 "Choose the proper attributes for FRAME, out of SPEC.
1513 If SPEC is nil, return nil."
1514 (unless frame
1515 (setq frame (selected-frame)))
1516 (let ((tail spec)
1517 result defaults)
1518 (while tail
1519 (let* ((entry (pop tail))
1520 (display (car entry))
1521 (attrs (cdr entry))
1522 thisval)
1523 ;; Get the attributes as actually specified by this alternative.
1524 (setq thisval
1525 (if (null (cdr attrs)) ;; was (listp (car attrs))
1526 ;; Old-style entry, the attribute list is the
1527 ;; first element.
1528 (car attrs)
1529 attrs))
1531 ;; If the condition is `default', that sets the default
1532 ;; for following conditions.
1533 (if (eq display 'default)
1534 (setq defaults thisval)
1535 ;; Otherwise, if it matches, use it.
1536 (when (face-spec-set-match-display display frame)
1537 (setq result thisval)
1538 (setq tail nil)))))
1539 (if defaults (append result defaults) result)))
1542 (defun face-spec-reset-face (face &optional frame)
1543 "Reset all attributes of FACE on FRAME to unspecified."
1544 (apply 'set-face-attribute face frame
1545 (if (eq face 'default)
1546 ;; For the default face, avoid making any attribute
1547 ;; unspecified. Instead, set attributes to default values
1548 ;; (see also realize_default_face in xfaces.c).
1549 (append
1550 '(:underline nil :overline nil :strike-through nil
1551 :box nil :inverse-video nil :stipple nil :inherit nil)
1552 ;; `display-graphic-p' is unavailable when running
1553 ;; temacs, prior to loading frame.el.
1554 (unless (and (fboundp 'display-graphic-p)
1555 (display-graphic-p frame))
1556 `(:family "default" :foundry "default" :width normal
1557 :height 1 :weight normal :slant normal
1558 :foreground ,(if (frame-parameter nil 'reverse)
1559 "unspecified-bg"
1560 "unspecified-fg")
1561 :background ,(if (frame-parameter nil 'reverse)
1562 "unspecified-fg"
1563 "unspecified-bg"))))
1564 ;; For all other faces, unspecify all attributes.
1565 (apply 'append
1566 (mapcar (lambda (x) (list (car x) 'unspecified))
1567 face-attribute-name-alist)))))
1569 (defun face-spec-set (face spec &optional spec-type)
1570 "Set the face spec SPEC for FACE.
1571 See `defface' for the format of SPEC.
1573 The appearance of each face is controlled by its spec, and by the
1574 internal face attributes (which can be frame-specific and can be
1575 set via `set-face-attribute').
1577 The argument SPEC-TYPE determines which spec to set:
1578 nil or `face-override-spec' means the override spec (which is
1579 usually what you want if calling this function outside of
1580 Custom code);
1581 `customized-face' or `saved-face' means the customized spec or
1582 the saved custom spec;
1583 `face-defface-spec' means the default spec
1584 (usually set only via `defface');
1585 `reset' means to ignore SPEC, but clear the `customized-face'
1586 and `face-override-spec' specs;
1587 Any other value means not to set any spec, but to run the
1588 function for its other effects.
1590 In addition to setting the face spec, this function defines FACE
1591 as a valid face name if it is not already one, and (re)calculates
1592 the face's attributes on existing frames."
1593 (if (get face 'face-alias)
1594 (setq face (get face 'face-alias)))
1595 ;; Save SPEC to the relevant symbol property.
1596 (unless spec-type
1597 (setq spec-type 'face-override-spec))
1598 (if (memq spec-type '(face-defface-spec face-override-spec
1599 customized-face saved-face))
1600 (put face spec-type spec))
1601 (if (memq spec-type '(reset saved-face))
1602 (put face 'customized-face nil))
1603 ;; Setting the face spec via Custom empties out any override spec,
1604 ;; similar to how setting a variable via Custom changes its values.
1605 (if (memq spec-type '(customized-face saved-face reset))
1606 (put face 'face-override-spec nil))
1607 ;; If we reset the face based on its custom spec, it is unmodified
1608 ;; as far as Custom is concerned.
1609 (unless (eq face 'face-override-spec)
1610 (put face 'face-modified nil))
1611 (if (facep face)
1612 ;; If the face already exists, recalculate it.
1613 (dolist (frame (frame-list))
1614 (face-spec-recalc face frame))
1615 ;; Otherwise, initialize it on all frames.
1616 (make-empty-face face)
1617 (let ((value (face-user-default-spec face))
1618 (have-window-system (memq initial-window-system '(x w32 ns))))
1619 (dolist (frame (frame-list))
1620 (face-spec-set-2 face frame value)
1621 (when (memq (window-system frame) '(x w32 ns))
1622 (setq have-window-system t)))
1623 (if have-window-system
1624 (make-face-x-resource-internal face)))))
1626 (defun face-spec-recalc (face frame)
1627 "Reset the face attributes of FACE on FRAME according to its specs.
1628 This applies the defface/custom spec first, then the custom theme specs,
1629 then the override spec."
1630 (while (get face 'face-alias)
1631 (setq face (get face 'face-alias)))
1632 (face-spec-reset-face face frame)
1633 ;; If FACE is customized or themed, set the custom spec from
1634 ;; `theme-face' records, which completely replace the defface spec
1635 ;; rather than inheriting from it.
1636 (let ((theme-faces (get face 'theme-face)))
1637 (if theme-faces
1638 (dolist (spec (reverse theme-faces))
1639 (face-spec-set-2 face frame (cadr spec)))
1640 (face-spec-set-2 face frame (face-default-spec face))))
1641 (face-spec-set-2 face frame (get face 'face-override-spec)))
1643 (defun face-spec-set-2 (face frame spec)
1644 "Set the face attributes of FACE on FRAME according to SPEC."
1645 (let* ((spec (face-spec-choose spec frame))
1646 attrs)
1647 (while spec
1648 (when (assq (car spec) face-x-resources)
1649 (push (car spec) attrs)
1650 (push (cadr spec) attrs))
1651 (setq spec (cddr spec)))
1652 (apply 'set-face-attribute face frame (nreverse attrs))))
1654 (defun face-attr-match-p (face attrs &optional frame)
1655 "Return t if attributes of FACE match values in plist ATTRS.
1656 Optional parameter FRAME is the frame whose definition of FACE
1657 is used. If nil or omitted, use the selected frame."
1658 (unless frame
1659 (setq frame (selected-frame)))
1660 (let* ((list face-attribute-name-alist)
1661 (match t)
1662 (bold (and (plist-member attrs :bold)
1663 (not (plist-member attrs :weight))))
1664 (italic (and (plist-member attrs :italic)
1665 (not (plist-member attrs :slant))))
1666 (plist (if (or bold italic)
1667 (copy-sequence attrs)
1668 attrs)))
1669 ;; Handle the Emacs 20 :bold and :italic properties.
1670 (if bold
1671 (plist-put plist :weight (if bold 'bold 'normal)))
1672 (if italic
1673 (plist-put plist :slant (if italic 'italic 'normal)))
1674 (while (and match list)
1675 (let* ((attr (caar list))
1676 (specified-value
1677 (if (plist-member plist attr)
1678 (plist-get plist attr)
1679 'unspecified))
1680 (value-now (face-attribute face attr frame)))
1681 (setq match (equal specified-value value-now))
1682 (setq list (cdr list))))
1683 match))
1685 (defsubst face-spec-match-p (face spec &optional frame)
1686 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1687 (face-attr-match-p face (face-spec-choose spec frame) frame))
1689 (defsubst face-default-spec (face)
1690 "Return the default face-spec for FACE, ignoring any user customization.
1691 If there is no default for FACE, return nil."
1692 (get face 'face-defface-spec))
1694 (defsubst face-user-default-spec (face)
1695 "Return the user's customized face-spec for FACE, or the default if none.
1696 If there is neither a user setting nor a default for FACE, return nil."
1697 (or (get face 'customized-face)
1698 (get face 'saved-face)
1699 (face-default-spec face)))
1702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1703 ;;; Frame-type independent color support.
1704 ;;; We keep the old x-* names as aliases for back-compatibility.
1705 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1707 (defun defined-colors (&optional frame)
1708 "Return a list of colors supported for a particular frame.
1709 The argument FRAME specifies which frame to try.
1710 The value may be different for frames on different display types.
1711 If FRAME doesn't support colors, the value is nil.
1712 If FRAME is nil, that stands for the selected frame."
1713 (if (memq (framep (or frame (selected-frame))) '(x w32 ns))
1714 (xw-defined-colors frame)
1715 (mapcar 'car (tty-color-alist frame))))
1716 (defalias 'x-defined-colors 'defined-colors)
1718 (declare-function xw-color-defined-p "xfns.c" (color &optional frame))
1720 (defun color-defined-p (color &optional frame)
1721 "Return non-nil if COLOR is supported on frame FRAME.
1722 COLOR should be a string naming a color (e.g. \"white\"), or a
1723 string specifying a color's RGB components (e.g. \"#ff12ec\"), or
1724 the symbol `unspecified'.
1726 This function returns nil if COLOR is the symbol `unspecified',
1727 or one of the strings \"unspecified-fg\" or \"unspecified-bg\".
1729 If FRAME is omitted or nil, use the selected frame."
1730 (unless (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1731 (if (member (framep (or frame (selected-frame))) '(x w32 ns))
1732 (xw-color-defined-p color frame)
1733 (numberp (tty-color-translate color frame)))))
1734 (defalias 'x-color-defined-p 'color-defined-p)
1736 (declare-function xw-color-values "xfns.c" (color &optional frame))
1738 (defun color-values (color &optional frame)
1739 "Return a description of the color named COLOR on frame FRAME.
1740 COLOR should be a string naming a color (e.g. \"white\"), or a
1741 string specifying a color's RGB components (e.g. \"#ff12ec\").
1743 Return a list of three integers, (RED GREEN BLUE), each between 0
1744 and either 65280 or 65535 (the maximum depends on the system).
1745 Use `color-name-to-rgb' if you want RGB floating-point values
1746 normalized to 1.0.
1748 If FRAME is omitted or nil, use the selected frame.
1749 If FRAME cannot display COLOR, the value is nil.
1751 COLOR can also be the symbol `unspecified' or one of the strings
1752 \"unspecified-fg\" or \"unspecified-bg\", in which case the
1753 return value is nil."
1754 (cond
1755 ((member color '(unspecified "unspecified-fg" "unspecified-bg"))
1756 nil)
1757 ((memq (framep (or frame (selected-frame))) '(x w32 ns))
1758 (xw-color-values color frame))
1760 (tty-color-values color frame))))
1762 (defalias 'x-color-values 'color-values)
1764 (declare-function xw-display-color-p "xfns.c" (&optional terminal))
1766 (defun display-color-p (&optional display)
1767 "Return t if DISPLAY supports color.
1768 The optional argument DISPLAY specifies which display to ask about.
1769 DISPLAY should be either a frame or a display name (a string).
1770 If omitted or nil, that stands for the selected frame's display."
1771 (if (memq (framep-on-display display) '(x w32 ns))
1772 (xw-display-color-p display)
1773 (tty-display-color-p display)))
1774 (defalias 'x-display-color-p 'display-color-p)
1776 (declare-function x-display-grayscale-p "xfns.c" (&optional terminal))
1778 (defun display-grayscale-p (&optional display)
1779 "Return non-nil if frames on DISPLAY can display shades of gray."
1780 (let ((frame-type (framep-on-display display)))
1781 (cond
1782 ((memq frame-type '(x w32 ns))
1783 (x-display-grayscale-p display))
1785 (> (tty-color-gray-shades display) 2)))))
1787 (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg)
1788 "Read a color name or RGB triplet.
1789 Completion is available for color names, but not for RGB triplets.
1791 RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B
1792 components can have one to four digits, but all three components
1793 must have the same number of digits. Each digit is a hex value
1794 between 0 and F; either upper case or lower case for A through F
1795 are acceptable.
1797 In addition to standard color names and RGB hex values, the
1798 following are available as color candidates. In each case, the
1799 corresponding color is used.
1801 * `foreground at point' - foreground under the cursor
1802 * `background at point' - background under the cursor
1804 Optional arg PROMPT is the prompt; if nil, use a default prompt.
1806 Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1807 convert an input color name to an RGB hex string. Return the RGB
1808 hex string.
1810 If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1811 to enter an empty color name (the empty string).
1813 Interactively, or with optional arg MSG non-nil, print the
1814 resulting color name in the echo area."
1815 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1816 (let* ((completion-ignore-case t)
1817 (colors (or facemenu-color-alist
1818 (append '("foreground at point" "background at point")
1819 (if allow-empty-name '(""))
1820 (defined-colors))))
1821 (color (completing-read
1822 (or prompt "Color (name or #RGB triplet): ")
1823 ;; Completing function for reading colors, accepting
1824 ;; both color names and RGB triplets.
1825 (lambda (string pred flag)
1826 (cond
1827 ((null flag) ; Try completion.
1828 (or (try-completion string colors pred)
1829 (if (color-defined-p string)
1830 string)))
1831 ((eq flag t) ; List all completions.
1832 (or (all-completions string colors pred)
1833 (if (color-defined-p string)
1834 (list string))))
1835 ((eq flag 'lambda) ; Test completion.
1836 (or (memq string colors)
1837 (color-defined-p string)))))
1838 nil t)))
1840 ;; Process named colors.
1841 (when (member color colors)
1842 (cond ((string-equal color "foreground at point")
1843 (setq color (foreground-color-at-point)))
1844 ((string-equal color "background at point")
1845 (setq color (background-color-at-point))))
1846 (when (and convert-to-RGB
1847 (not (string-equal color "")))
1848 (let ((components (x-color-values color)))
1849 (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1850 (setq color (format "#%04X%04X%04X"
1851 (logand 65535 (nth 0 components))
1852 (logand 65535 (nth 1 components))
1853 (logand 65535 (nth 2 components))))))))
1854 (when msg (message "Color: `%s'" color))
1855 color))
1857 (defun face-at-point (&optional thing multiple)
1858 "Return the face of the character after point.
1859 If it has more than one face, return the first one.
1860 If THING is non-nil try first to get a face name from the buffer.
1861 IF MULTIPLE is non-nil, return a list of all faces.
1862 Return nil if there is no face."
1863 (let (faces)
1864 (if thing
1865 ;; Try to get a face name from the buffer.
1866 (let ((face (intern-soft (thing-at-point 'symbol))))
1867 (if (facep face)
1868 (push face faces))))
1869 ;; Add the named faces that the `read-face-name' or `face' property uses.
1870 (let ((faceprop (or (get-char-property (point) 'read-face-name)
1871 (get-char-property (point) 'face))))
1872 (cond ((facep faceprop)
1873 (push faceprop faces))
1874 ((and (listp faceprop)
1875 ;; Don't treat an attribute spec as a list of faces.
1876 (not (keywordp (car faceprop)))
1877 (not (memq (car faceprop)
1878 '(foreground-color background-color))))
1879 (dolist (face faceprop)
1880 (if (facep face)
1881 (push face faces))))))
1882 (setq faces (delete-dups (nreverse faces)))
1883 (if multiple faces (car faces))))
1885 (defun foreground-color-at-point ()
1886 "Return the foreground color of the character after point."
1887 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1888 ;; Need also pick up any face properties that are not associated with named faces.
1889 (let ((face (or (face-at-point)
1890 (get-char-property (point) 'read-face-name)
1891 (get-char-property (point) 'face))))
1892 (cond ((and face (symbolp face))
1893 (let ((value (face-foreground face nil 'default)))
1894 (if (member value '("unspecified-fg" "unspecified-bg"))
1896 value)))
1897 ((consp face)
1898 (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face)))
1899 ((memq ':foreground face) (cadr (memq ':foreground face)))))
1900 (t nil)))) ; Invalid face value.
1902 (defun background-color-at-point ()
1903 "Return the background color of the character after point."
1904 ;; `face-at-point' alone is not sufficient. It only gets named faces.
1905 ;; Need also pick up any face properties that are not associated with named faces.
1906 (let ((face (or (face-at-point)
1907 (get-char-property (point) 'read-face-name)
1908 (get-char-property (point) 'face))))
1909 (cond ((and face (symbolp face))
1910 (let ((value (face-background face nil 'default)))
1911 (if (member value '("unspecified-fg" "unspecified-bg"))
1913 value)))
1914 ((consp face)
1915 (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
1916 ((memq ':background face) (cadr (memq ':background face)))))
1917 (t nil)))) ; Invalid face value.
1920 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1921 ;;; Frame creation.
1922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1924 (declare-function x-parse-geometry "frame.c" (string))
1925 (defvar x-display-name)
1927 (defun x-handle-named-frame-geometry (parameters)
1928 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1929 Value is the new parameter list."
1930 ;; Note that `x-resource-name' has a global meaning.
1931 (let ((x-resource-name (cdr (assq 'name parameters))))
1932 (when x-resource-name
1933 ;; Before checking X resources, we must have an X connection.
1934 (or (window-system)
1935 (x-display-list)
1936 (x-open-connection (or (cdr (assq 'display parameters))
1937 x-display-name)))
1938 (let (res-geometry parsed)
1939 (and (setq res-geometry (x-get-resource "geometry" "Geometry"))
1940 (setq parsed (x-parse-geometry res-geometry))
1941 (setq parameters
1942 (append parameters parsed
1943 ;; If the resource specifies a position,
1944 ;; take note of that.
1945 (if (or (assq 'top parsed) (assq 'left parsed))
1946 '((user-position . t) (user-size . t)))))))))
1947 parameters)
1950 (defun x-handle-reverse-video (frame parameters)
1951 "Handle the reverse-video frame parameter and X resource.
1952 `x-create-frame' does not handle this one."
1953 (when (cdr (or (assq 'reverse parameters)
1954 (let ((resource (x-get-resource "reverseVideo"
1955 "ReverseVideo")))
1956 (if resource
1957 (cons nil (member (downcase resource)
1958 '("on" "true")))))))
1959 (let* ((params (frame-parameters frame))
1960 (bg (cdr (assq 'foreground-color params)))
1961 (fg (cdr (assq 'background-color params))))
1962 (modify-frame-parameters frame
1963 (list (cons 'foreground-color fg)
1964 (cons 'background-color bg)))
1965 (if (equal bg (cdr (assq 'border-color params)))
1966 (modify-frame-parameters frame
1967 (list (cons 'border-color fg))))
1968 (if (equal bg (cdr (assq 'mouse-color params)))
1969 (modify-frame-parameters frame
1970 (list (cons 'mouse-color fg))))
1971 (if (equal bg (cdr (assq 'cursor-color params)))
1972 (modify-frame-parameters frame
1973 (list (cons 'cursor-color fg)))))))
1975 (declare-function x-create-frame "xfns.c" (parms))
1976 (declare-function x-setup-function-keys "term/common-win" (frame))
1978 (defun x-create-frame-with-faces (&optional parameters)
1979 "Create and return a frame with frame parameters PARAMETERS.
1980 If PARAMETERS specify a frame name, handle X geometry resources
1981 for that name. If PARAMETERS includes a `reverse' parameter, or
1982 the X resource ``reverseVideo'' is present, handle that."
1983 (setq parameters (x-handle-named-frame-geometry parameters))
1984 (let* ((params (copy-tree parameters))
1985 (visibility-spec (assq 'visibility parameters))
1986 (delayed-params '(foreground-color background-color font
1987 border-color cursor-color mouse-color
1988 visibility scroll-bar-foreground
1989 scroll-bar-background))
1990 frame success)
1991 (dolist (param delayed-params)
1992 (setq params (assq-delete-all param params)))
1993 (setq frame (x-create-frame `((visibility . nil) . ,params)))
1994 (unwind-protect
1995 (progn
1996 (x-setup-function-keys frame)
1997 (x-handle-reverse-video frame parameters)
1998 (frame-set-background-mode frame t)
1999 (face-set-after-frame-default frame parameters)
2000 (if (null visibility-spec)
2001 (make-frame-visible frame)
2002 (modify-frame-parameters frame (list visibility-spec)))
2003 (setq success t))
2004 (unless success
2005 (delete-frame frame)))
2006 frame))
2008 (defun face-set-after-frame-default (frame &optional parameters)
2009 "Initialize the frame-local faces of FRAME.
2010 Calculate the face definitions using the face specs, custom theme
2011 settings, X resources, and `face-new-frame-defaults'.
2012 Finally, apply any relevant face attributes found amongst the
2013 frame parameters in PARAMETERS."
2014 (let ((window-system-p (memq (window-system frame) '(x w32))))
2015 ;; The `reverse' is so that `default' goes first.
2016 (dolist (face (nreverse (face-list)))
2017 (condition-case ()
2018 (progn
2019 ;; Initialize faces from face spec and custom theme.
2020 (face-spec-recalc face frame)
2021 ;; X resources for the default face are applied during
2022 ;; `x-create-frame'.
2023 (and (not (eq face 'default)) window-system-p
2024 (make-face-x-resource-internal face frame))
2025 ;; Apply attributes specified by face-new-frame-defaults
2026 (internal-merge-in-global-face face frame))
2027 ;; Don't let invalid specs prevent frame creation.
2028 (error nil))))
2030 ;; Apply attributes specified by frame parameters.
2031 (let ((face-params '((foreground-color default :foreground)
2032 (background-color default :background)
2033 (font default :font)
2034 (border-color border :background)
2035 (cursor-color cursor :background)
2036 (scroll-bar-foreground scroll-bar :foreground)
2037 (scroll-bar-background scroll-bar :background)
2038 (mouse-color mouse :background))))
2039 (dolist (param face-params)
2040 (let* ((param-name (nth 0 param))
2041 (value (cdr (assq param-name parameters))))
2042 (if value
2043 (set-face-attribute (nth 1 param) frame
2044 (nth 2 param) value))))))
2046 (defun tty-handle-reverse-video (frame parameters)
2047 "Handle the reverse-video frame parameter for terminal frames."
2048 (when (cdr (assq 'reverse parameters))
2049 (let* ((params (frame-parameters frame))
2050 (bg (cdr (assq 'foreground-color params)))
2051 (fg (cdr (assq 'background-color params))))
2052 (modify-frame-parameters frame
2053 (list (cons 'foreground-color fg)
2054 (cons 'background-color bg)))
2055 (if (equal bg (cdr (assq 'mouse-color params)))
2056 (modify-frame-parameters frame
2057 (list (cons 'mouse-color fg))))
2058 (if (equal bg (cdr (assq 'cursor-color params)))
2059 (modify-frame-parameters frame
2060 (list (cons 'cursor-color fg)))))))
2063 (defun tty-create-frame-with-faces (&optional parameters)
2064 "Create and return a frame from optional frame parameters PARAMETERS.
2065 If PARAMETERS contains a `reverse' parameter, handle that."
2066 (let ((frame (make-terminal-frame parameters))
2067 success)
2068 (unwind-protect
2069 (with-selected-frame frame
2070 (tty-handle-reverse-video frame (frame-parameters frame))
2072 (unless (terminal-parameter frame 'terminal-initted)
2073 (set-terminal-parameter frame 'terminal-initted t)
2074 (set-locale-environment nil frame)
2075 (tty-run-terminal-initialization frame))
2076 (frame-set-background-mode frame t)
2077 (face-set-after-frame-default frame parameters)
2078 (setq success t))
2079 (unless success
2080 (delete-frame frame)))
2081 frame))
2083 (defun tty-find-type (pred type)
2084 "Return the longest prefix of TYPE to which PRED returns non-nil.
2085 TYPE should be a tty type name such as \"xterm-16color\".
2087 The function tries only those prefixes that are followed by a
2088 dash or underscore in the original type name, like \"xterm\" in
2089 the above example."
2090 (let (hyphend)
2091 (while (and type
2092 (not (funcall pred type)))
2093 ;; Strip off last hyphen and what follows, then try again
2094 (setq type
2095 (if (setq hyphend (string-match-p "[-_][^-_]+$" type))
2096 (substring type 0 hyphend)
2097 nil))))
2098 type)
2100 (defun tty-run-terminal-initialization (frame &optional type)
2101 "Run the special initialization code for the terminal type of FRAME.
2102 The optional TYPE parameter may be used to override the autodetected
2103 terminal type to a different value."
2104 (setq type (or type (tty-type frame)))
2105 ;; Load library for our terminal type.
2106 ;; User init file can set term-file-prefix to nil to prevent this.
2107 (with-selected-frame frame
2108 (unless (null term-file-prefix)
2109 (let* (term-init-func)
2110 ;; First, load the terminal initialization file, if it is
2111 ;; available and it hasn't been loaded already.
2112 (tty-find-type #'(lambda (type)
2113 (let ((file (locate-library (concat term-file-prefix type))))
2114 (and file
2115 (or (assoc file load-history)
2116 (load file t t)))))
2117 type)
2118 ;; Next, try to find a matching initialization function, and call it.
2119 (tty-find-type #'(lambda (type)
2120 (fboundp (setq term-init-func
2121 (intern (concat "terminal-init-" type)))))
2122 type)
2123 (when (fboundp term-init-func)
2124 (funcall term-init-func))
2125 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
2127 ;; Called from C function init_display to initialize faces of the
2128 ;; dumped terminal frame on startup.
2130 (defun tty-set-up-initial-frame-faces ()
2131 (let ((frame (selected-frame)))
2132 (frame-set-background-mode frame t)
2133 (face-set-after-frame-default frame)))
2137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2138 ;;; Standard faces.
2139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2141 (defgroup basic-faces nil
2142 "The standard faces of Emacs."
2143 :group 'faces)
2145 (defface default
2146 '((t nil)) ; If this were nil, face-defface-spec would not be set.
2147 "Basic default face."
2148 :group 'basic-faces)
2150 (defface bold
2151 '((t :weight bold))
2152 "Basic bold face."
2153 :group 'basic-faces)
2155 (defface italic
2156 '((((supports :slant italic))
2157 :slant italic)
2158 (((supports :underline t))
2159 :underline t)
2161 ;; Default to italic, even if it doesn't appear to be supported,
2162 ;; because in some cases the display engine will do its own
2163 ;; workaround (to `dim' on ttys).
2164 :slant italic))
2165 "Basic italic face."
2166 :group 'basic-faces)
2168 (defface bold-italic
2169 '((t :weight bold :slant italic))
2170 "Basic bold-italic face."
2171 :group 'basic-faces)
2173 (defface underline
2174 '((((supports :underline t))
2175 :underline t)
2176 (((supports :weight bold))
2177 :weight bold)
2178 (t :underline t))
2179 "Basic underlined face."
2180 :group 'basic-faces)
2182 (defface fixed-pitch
2183 '((t :family "Monospace"))
2184 "The basic fixed-pitch face."
2185 :group 'basic-faces)
2187 (defface variable-pitch
2188 '((t :family "Sans Serif"))
2189 "The basic variable-pitch face."
2190 :group 'basic-faces)
2192 (defface shadow
2193 '((((class color grayscale) (min-colors 88) (background light))
2194 :foreground "grey50")
2195 (((class color grayscale) (min-colors 88) (background dark))
2196 :foreground "grey70")
2197 (((class color) (min-colors 8) (background light))
2198 :foreground "green")
2199 (((class color) (min-colors 8) (background dark))
2200 :foreground "yellow"))
2201 "Basic face for shadowed text."
2202 :group 'basic-faces
2203 :version "22.1")
2205 (defface link
2206 '((((class color) (min-colors 88) (background light))
2207 :foreground "RoyalBlue3" :underline t)
2208 (((class color) (background light))
2209 :foreground "blue" :underline t)
2210 (((class color) (min-colors 88) (background dark))
2211 :foreground "cyan1" :underline t)
2212 (((class color) (background dark))
2213 :foreground "cyan" :underline t)
2214 (t :inherit underline))
2215 "Basic face for unvisited links."
2216 :group 'basic-faces
2217 :version "22.1")
2219 (defface link-visited
2220 '((default :inherit link)
2221 (((class color) (background light)) :foreground "magenta4")
2222 (((class color) (background dark)) :foreground "violet"))
2223 "Basic face for visited links."
2224 :group 'basic-faces
2225 :version "22.1")
2227 (defface highlight
2228 '((((class color) (min-colors 88) (background light))
2229 :background "darkseagreen2")
2230 (((class color) (min-colors 88) (background dark))
2231 :background "darkolivegreen")
2232 (((class color) (min-colors 16) (background light))
2233 :background "darkseagreen2")
2234 (((class color) (min-colors 16) (background dark))
2235 :background "darkolivegreen")
2236 (((class color) (min-colors 8))
2237 :background "green" :foreground "black")
2238 (t :inverse-video t))
2239 "Basic face for highlighting."
2240 :group 'basic-faces)
2242 ;; Region face: under NS, default to the system-defined selection
2243 ;; color (optimized for the fixed white background of other apps),
2244 ;; if background is light.
2245 (defface region
2246 '((((class color) (min-colors 88) (background dark))
2247 :background "blue3")
2248 (((class color) (min-colors 88) (background light) (type gtk))
2249 :foreground "gtk_selection_fg_color"
2250 :background "gtk_selection_bg_color")
2251 (((class color) (min-colors 88) (background light) (type ns))
2252 :background "ns_selection_color")
2253 (((class color) (min-colors 88) (background light))
2254 :background "lightgoldenrod2")
2255 (((class color) (min-colors 16) (background dark))
2256 :background "blue3")
2257 (((class color) (min-colors 16) (background light))
2258 :background "lightgoldenrod2")
2259 (((class color) (min-colors 8))
2260 :background "blue" :foreground "white")
2261 (((type tty) (class mono))
2262 :inverse-video t)
2263 (t :background "gray"))
2264 "Basic face for highlighting the region."
2265 :version "21.1"
2266 :group 'basic-faces)
2268 (defface secondary-selection
2269 '((((class color) (min-colors 88) (background light))
2270 :background "yellow1")
2271 (((class color) (min-colors 88) (background dark))
2272 :background "SkyBlue4")
2273 (((class color) (min-colors 16) (background light))
2274 :background "yellow")
2275 (((class color) (min-colors 16) (background dark))
2276 :background "SkyBlue4")
2277 (((class color) (min-colors 8))
2278 :background "cyan" :foreground "black")
2279 (t :inverse-video t))
2280 "Basic face for displaying the secondary selection."
2281 :group 'basic-faces)
2283 (defface trailing-whitespace
2284 '((((class color) (background light))
2285 :background "red1")
2286 (((class color) (background dark))
2287 :background "red1")
2288 (t :inverse-video t))
2289 "Basic face for highlighting trailing whitespace."
2290 :version "21.1"
2291 :group 'basic-faces)
2293 (defface escape-glyph
2294 '((((background dark)) :foreground "cyan")
2295 ;; See the comment in minibuffer-prompt for
2296 ;; the reason not to use blue on MS-DOS.
2297 (((type pc)) :foreground "magenta")
2298 ;; red4 is too dark, but some say blue is too loud.
2299 ;; brown seems to work ok. -- rms.
2300 (t :foreground "brown"))
2301 "Face for characters displayed as sequences using `^' or `\\'."
2302 :group 'basic-faces
2303 :version "22.1")
2305 (defface nobreak-space
2306 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2307 (((class color) (min-colors 8)) :background "magenta")
2308 (t :inverse-video t))
2309 "Face for displaying nobreak space."
2310 :group 'basic-faces
2311 :version "22.1")
2313 (defgroup mode-line-faces nil
2314 "Faces used in the mode line."
2315 :group 'mode-line
2316 :group 'faces
2317 :version "22.1")
2319 (defface mode-line
2320 '((((class color) (min-colors 88))
2321 :box (:line-width -1 :style released-button)
2322 :background "grey75" :foreground "black")
2324 :inverse-video t))
2325 "Basic mode line face for selected window."
2326 :version "21.1"
2327 :group 'mode-line-faces
2328 :group 'basic-faces)
2330 (defface mode-line-inactive
2331 '((default
2332 :inherit mode-line)
2333 (((class color) (min-colors 88) (background light))
2334 :weight light
2335 :box (:line-width -1 :color "grey75" :style nil)
2336 :foreground "grey20" :background "grey90")
2337 (((class color) (min-colors 88) (background dark) )
2338 :weight light
2339 :box (:line-width -1 :color "grey40" :style nil)
2340 :foreground "grey80" :background "grey30"))
2341 "Basic mode line face for non-selected windows."
2342 :version "22.1"
2343 :group 'mode-line-faces
2344 :group 'basic-faces)
2345 (define-obsolete-face-alias 'modeline-inactive 'mode-line-inactive "22.1")
2347 (defface mode-line-highlight
2348 '((((class color) (min-colors 88))
2349 :box (:line-width 2 :color "grey40" :style released-button))
2351 :inherit highlight))
2352 "Basic mode line face for highlighting."
2353 :version "22.1"
2354 :group 'mode-line-faces
2355 :group 'basic-faces)
2356 (define-obsolete-face-alias 'modeline-highlight 'mode-line-highlight "22.1")
2358 (defface mode-line-emphasis
2359 '((t (:weight bold)))
2360 "Face used to emphasize certain mode line features.
2361 Use the face `mode-line-highlight' for features that can be selected."
2362 :version "23.1"
2363 :group 'mode-line-faces
2364 :group 'basic-faces)
2366 (defface mode-line-buffer-id
2367 '((t (:weight bold)))
2368 "Face used for buffer identification parts of the mode line."
2369 :version "22.1"
2370 :group 'mode-line-faces
2371 :group 'basic-faces)
2372 (define-obsolete-face-alias 'modeline-buffer-id 'mode-line-buffer-id "22.1")
2374 (defface header-line
2375 '((default
2376 :inherit mode-line)
2377 (((type tty))
2378 ;; This used to be `:inverse-video t', but that doesn't look very
2379 ;; good when combined with inverse-video mode-lines and multiple
2380 ;; windows. Underlining looks better, and is more consistent with
2381 ;; the window-system face variants, which deemphasize the
2382 ;; header-line in relation to the mode-line face. If a terminal
2383 ;; can't underline, then the header-line will end up without any
2384 ;; highlighting; this may be too confusing in general, although it
2385 ;; happens to look good with the only current use of header-lines,
2386 ;; the info browser. XXX
2387 :inverse-video nil ;Override the value inherited from mode-line.
2388 :underline t)
2389 (((class color grayscale) (background light))
2390 :background "grey90" :foreground "grey20"
2391 :box nil)
2392 (((class color grayscale) (background dark))
2393 :background "grey20" :foreground "grey90"
2394 :box nil)
2395 (((class mono) (background light))
2396 :background "white" :foreground "black"
2397 :inverse-video nil
2398 :box nil
2399 :underline t)
2400 (((class mono) (background dark))
2401 :background "black" :foreground "white"
2402 :inverse-video nil
2403 :box nil
2404 :underline t))
2405 "Basic header-line face."
2406 :version "21.1"
2407 :group 'basic-faces)
2409 (defface vertical-border
2410 '((((type tty)) :inherit mode-line-inactive))
2411 "Face used for vertical window dividers on ttys."
2412 :version "22.1"
2413 :group 'basic-faces)
2415 (defface minibuffer-prompt
2416 '((((background dark)) :foreground "cyan")
2417 ;; Don't use blue because many users of the MS-DOS port customize
2418 ;; their foreground color to be blue.
2419 (((type pc)) :foreground "magenta")
2420 (t :foreground "medium blue"))
2421 "Face for minibuffer prompts.
2422 By default, Emacs automatically adds this face to the value of
2423 `minibuffer-prompt-properties', which is a list of text properties
2424 used to display the prompt text."
2425 :version "22.1"
2426 :group 'basic-faces)
2428 (setq minibuffer-prompt-properties
2429 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2431 (defface fringe
2432 '((((class color) (background light))
2433 :background "grey95")
2434 (((class color) (background dark))
2435 :background "grey10")
2437 :background "gray"))
2438 "Basic face for the fringes to the left and right of windows under X."
2439 :version "21.1"
2440 :group 'frames
2441 :group 'basic-faces)
2443 (defface scroll-bar '((t nil))
2444 "Basic face for the scroll bar colors under X."
2445 :version "21.1"
2446 :group 'frames
2447 :group 'basic-faces)
2449 (defface border '((t nil))
2450 "Basic face for the frame border under X."
2451 :version "21.1"
2452 :group 'frames
2453 :group 'basic-faces)
2455 (defface cursor
2456 '((((background light)) :background "black")
2457 (((background dark)) :background "white"))
2458 "Basic face for the cursor color under X.
2459 Currently, only the `:background' attribute is meaningful; all
2460 other attributes are ignored. The cursor foreground color is
2461 taken from the background color of the underlying text.
2463 Note: Other faces cannot inherit from the cursor face."
2464 :version "21.1"
2465 :group 'cursor
2466 :group 'basic-faces)
2468 (put 'cursor 'face-no-inherit t)
2470 (defface mouse '((t nil))
2471 "Basic face for the mouse color under X."
2472 :version "21.1"
2473 :group 'mouse
2474 :group 'basic-faces)
2476 (defface tool-bar
2477 '((default
2478 :box (:line-width 1 :style released-button)
2479 :foreground "black")
2480 (((type x w32 ns) (class color))
2481 :background "grey75")
2482 (((type x) (class mono))
2483 :background "grey"))
2484 "Basic tool-bar face."
2485 :version "21.1"
2486 :group 'basic-faces)
2488 (defface menu
2489 '((((type tty))
2490 :inverse-video t)
2491 (((type x-toolkit))
2494 :inverse-video t))
2495 "Basic face for the font and colors of the menu bar and popup menus."
2496 :version "21.1"
2497 :group 'menu
2498 :group 'basic-faces)
2500 (defface help-argument-name '((t :inherit italic))
2501 "Face to highlight argument names in *Help* buffers."
2502 :group 'help)
2504 (defface glyphless-char
2505 '((((type tty)) :inherit underline)
2506 (((type pc)) :inherit escape-glyph)
2507 (t :height 0.6))
2508 "Face for displaying non-graphic characters (e.g. U+202A (LRE)).
2509 It is used for characters of no fonts too."
2510 :version "24.1"
2511 :group 'basic-faces)
2513 (defface error
2514 '((default :weight bold)
2515 (((class color) (min-colors 88) (background light)) :foreground "Red1")
2516 (((class color) (min-colors 88) (background dark)) :foreground "Pink")
2517 (((class color) (min-colors 16) (background light)) :foreground "Red1")
2518 (((class color) (min-colors 16) (background dark)) :foreground "Pink")
2519 (((class color) (min-colors 8)) :foreground "red")
2520 (t :inverse-video t))
2521 "Basic face used to highlight errors and to denote failure."
2522 :version "24.1"
2523 :group 'basic-faces)
2525 (defface warning
2526 '((default :weight bold)
2527 (((class color) (min-colors 16)) :foreground "DarkOrange")
2528 (((class color)) :foreground "yellow"))
2529 "Basic face used to highlight warnings."
2530 :version "24.1"
2531 :group 'basic-faces)
2533 (defface success
2534 '((default :weight bold)
2535 (((class color) (min-colors 16) (background light)) :foreground "ForestGreen")
2536 (((class color) (min-colors 88) (background dark)) :foreground "Green1")
2537 (((class color) (min-colors 16) (background dark)) :foreground "Green")
2538 (((class color)) :foreground "green"))
2539 "Basic face used to indicate successful operation."
2540 :version "24.1"
2541 :group 'basic-faces)
2544 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2545 ;;; Manipulating font names.
2546 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2548 ;; This is here for compatibility with Emacs 20.2. For example,
2549 ;; international/fontset.el uses x-resolve-font-name. The following
2550 ;; functions are not used in the face implementation itself.
2552 (defvar x-font-regexp nil)
2553 (defvar x-font-regexp-head nil)
2554 (defvar x-font-regexp-weight nil)
2555 (defvar x-font-regexp-slant nil)
2557 (defconst x-font-regexp-weight-subnum 1)
2558 (defconst x-font-regexp-slant-subnum 2)
2559 (defconst x-font-regexp-swidth-subnum 3)
2560 (defconst x-font-regexp-adstyle-subnum 4)
2562 ;;; Regexps matching font names in "Host Portable Character Representation."
2564 (let ((- "[-?]")
2565 (foundry "[^-]+")
2566 (family "[^-]+")
2567 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2568 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2569 (weight\? "\\([^-]*\\)") ; 1
2570 (slant "\\([ior]\\)") ; 2
2571 ; (slant\? "\\([ior?*]?\\)") ; 2
2572 (slant\? "\\([^-]?\\)") ; 2
2573 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2574 (swidth "\\([^-]*\\)") ; 3
2575 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2576 (adstyle "\\([^-]*\\)") ; 4
2577 (pixelsize "[0-9]+")
2578 (pointsize "[0-9][0-9]+")
2579 (resx "[0-9][0-9]+")
2580 (resy "[0-9][0-9]+")
2581 (spacing "[cmp?*]")
2582 (avgwidth "[0-9]+")
2583 (registry "[^-]+")
2584 (encoding "[^-]+")
2586 (setq x-font-regexp
2587 (purecopy (concat "\\`\\*?[-?*]"
2588 foundry - family - weight\? - slant\? - swidth - adstyle -
2589 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2590 registry - encoding "\\*?\\'"
2592 (setq x-font-regexp-head
2593 (purecopy (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2594 "\\([-*?]\\|\\'\\)")))
2595 (setq x-font-regexp-slant (purecopy (concat - slant -)))
2596 (setq x-font-regexp-weight (purecopy (concat - weight -)))
2597 nil)
2600 (defun x-resolve-font-name (pattern &optional face frame)
2601 "Return a font name matching PATTERN.
2602 All wildcards in PATTERN are instantiated.
2603 If PATTERN is nil, return the name of the frame's base font, which never
2604 contains wildcards.
2605 Given optional arguments FACE and FRAME, return a font which is
2606 also the same size as FACE on FRAME, or fail."
2607 (or (symbolp face)
2608 (setq face (face-name face)))
2609 (and (eq frame t)
2610 (setq frame nil))
2611 (if pattern
2612 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2613 (let ((fonts (x-list-fonts pattern face frame 1)))
2614 (or fonts
2615 (if face
2616 (if (string-match-p "\\*" pattern)
2617 (if (null (face-font face))
2618 (error "No matching fonts are the same height as the frame default font")
2619 (error "No matching fonts are the same height as face `%s'" face))
2620 (if (null (face-font face))
2621 (error "Height of font `%s' doesn't match the frame default font"
2622 pattern)
2623 (error "Height of font `%s' doesn't match face `%s'"
2624 pattern face)))
2625 (error "No fonts match `%s'" pattern)))
2626 (car fonts))
2627 (cdr (assq 'font (frame-parameters (selected-frame))))))
2629 (defcustom font-list-limit 100
2630 "This variable is obsolete and has no effect."
2631 :type 'integer
2632 :group 'display)
2633 (make-obsolete-variable 'font-list-limit nil "24.3")
2635 (provide 'faces)
2637 ;;; faces.el ends here