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