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