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