]> 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 tries to find a best matching font for
52 those face attributes first that appear first 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-output-to-temp-buffer "*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 (print-help-return-message))
1310 ;; If the *Faces* buffer appears in a different frame,
1311 ;; copy all the face definitions from FRAME,
1312 ;; so that the display will reflect the frame that was selected.
1313 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1314 (setq disp-frame (if window (window-frame window)
1315 (car (frame-list))))
1316 (or (eq frame disp-frame)
1317 (let ((faces (face-list)))
1318 (while faces
1319 (copy-face (car faces) (car faces) frame disp-frame)
1320 (setq faces (cdr faces)))))))
1321
1322
1323 (defun describe-face (face &optional frame)
1324 "Display the properties of face FACE on FRAME.
1325 Interactively, FACE defaults to the faces of the character after point
1326 and FRAME defaults to the selected frame.
1327
1328 If the optional argument FRAME is given, report on face FACE in that frame.
1329 If FRAME is t, report on the defaults for face FACE (for new frames).
1330 If FRAME is omitted or nil, use the selected frame."
1331 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1332 (let* ((attrs '((:family . "Family")
1333 (:width . "Width")
1334 (:height . "Height")
1335 (:weight . "Weight")
1336 (:slant . "Slant")
1337 (:foreground . "Foreground")
1338 (:background . "Background")
1339 (:underline . "Underline")
1340 (:overline . "Overline")
1341 (:strike-through . "Strike-through")
1342 (:box . "Box")
1343 (:inverse-video . "Inverse")
1344 (:stipple . "Stipple")
1345 (:font . "Font")
1346 (:fontset . "Fontset")
1347 (:inherit . "Inherit")))
1348 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1349 attrs))))
1350 (help-setup-xref (list #'describe-face face) (interactive-p))
1351 (unless face
1352 (setq face 'default))
1353 (if (not (listp face))
1354 (setq face (list face)))
1355 (with-output-to-temp-buffer (help-buffer)
1356 (save-excursion
1357 (set-buffer standard-output)
1358 (dolist (f face)
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 (print-help-return-message))))
1403
1404 \f
1405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1406 ;;; Face specifications (defface).
1407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1408
1409 ;; Parameter FRAME Is kept for call compatibility to with previous
1410 ;; face implementation.
1411
1412 (defun face-attr-construct (face &optional frame)
1413 "Return a `defface'-style attribute list for FACE on FRAME.
1414 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1415 face attributes of FACE where ATTRIBUTE is the attribute name and
1416 VALUE is the specified value of that attribute."
1417 (let (result)
1418 (dolist (entry face-attribute-name-alist result)
1419 (let* ((attribute (car entry))
1420 (value (face-attribute face attribute)))
1421 (unless (eq value 'unspecified)
1422 (setq result (nconc (list attribute value) result)))))))
1423
1424
1425 (defun face-spec-set-match-display (display frame)
1426 "Non-nil if DISPLAY matches FRAME.
1427 DISPLAY is part of a spec such as can be used in `defface'.
1428 If FRAME is nil, the current FRAME is used."
1429 (let* ((conjuncts display)
1430 conjunct req options
1431 ;; t means we have succeeded against all the conjuncts in
1432 ;; DISPLAY that have been tested so far.
1433 (match t))
1434 (if (eq conjuncts t)
1435 (setq conjuncts nil))
1436 (while (and conjuncts match)
1437 (setq conjunct (car conjuncts)
1438 conjuncts (cdr conjuncts)
1439 req (car conjunct)
1440 options (cdr conjunct)
1441 match (cond ((eq req 'type)
1442 (or (memq (window-system frame) options)
1443 ;; FIXME: This should be revisited to use
1444 ;; display-graphic-p, provided that the
1445 ;; color selection depends on the number
1446 ;; of supported colors, and all defface's
1447 ;; are changed to look at number of colors
1448 ;; instead of (type graphic) etc.
1449 (and (null (window-system frame))
1450 (memq 'tty options))
1451 (and (memq 'motif options)
1452 (featurep 'motif))
1453 (and (memq 'gtk options)
1454 (featurep 'gtk))
1455 (and (memq 'lucid options)
1456 (featurep 'x-toolkit)
1457 (not (featurep 'motif))
1458 (not (featurep 'gtk)))
1459 (and (memq 'x-toolkit options)
1460 (featurep 'x-toolkit))))
1461 ((eq req 'min-colors)
1462 (>= (display-color-cells frame) (car options)))
1463 ((eq req 'class)
1464 (memq (frame-parameter frame 'display-type) options))
1465 ((eq req 'background)
1466 (memq (frame-parameter frame 'background-mode)
1467 options))
1468 ((eq req 'supports)
1469 (display-supports-face-attributes-p options frame))
1470 (t (error "Unknown req `%S' with options `%S'"
1471 req options)))))
1472 match))
1473
1474
1475 (defun face-spec-choose (spec &optional frame)
1476 "Choose the proper attributes for FRAME, out of SPEC.
1477 If SPEC is nil, return nil."
1478 (unless frame
1479 (setq frame (selected-frame)))
1480 (let ((tail spec)
1481 result defaults)
1482 (while tail
1483 (let* ((entry (pop tail))
1484 (display (car entry))
1485 (attrs (cdr entry))
1486 thisval)
1487 ;; Get the attributes as actually specified by this alternative.
1488 (setq thisval
1489 (if (null (cdr attrs)) ;; was (listp (car attrs))
1490 ;; Old-style entry, the attribute list is the
1491 ;; first element.
1492 (car attrs)
1493 attrs))
1494
1495 ;; If the condition is `default', that sets the default
1496 ;; for following conditions.
1497 (if (eq display 'default)
1498 (setq defaults thisval)
1499 ;; Otherwise, if it matches, use it.
1500 (when (face-spec-set-match-display display frame)
1501 (setq result thisval)
1502 (setq tail nil)))))
1503 (if defaults (append result defaults) result)))
1504
1505
1506 (defun face-spec-reset-face (face &optional frame)
1507 "Reset all attributes of FACE on FRAME to unspecified."
1508 (let ((attrs face-attribute-name-alist))
1509 (while attrs
1510 (let ((attr-and-name (car attrs)))
1511 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1512 (setq attrs (cdr attrs)))))
1513
1514
1515 (defun face-spec-set (face spec &optional frame)
1516 "Set FACE's attributes according to the first matching entry in SPEC.
1517 FRAME is the frame whose frame-local face is set. FRAME nil means
1518 do it on all frames. See `defface' for information about SPEC.
1519 If SPEC is nil, do nothing."
1520 (if frame
1521 (let ((attrs (face-spec-choose spec frame)))
1522 (when spec
1523 (face-spec-reset-face face frame))
1524 (while attrs
1525 (let ((attribute (car attrs))
1526 (value (car (cdr attrs))))
1527 ;; Support some old-style attribute names and values.
1528 (case attribute
1529 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1530 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1531 ((:foreground :background)
1532 ;; Compatibility with 20.x. Some bogus face specs seem to
1533 ;; exist containing things like `:foreground nil'.
1534 (if (null value) (setq value 'unspecified)))
1535 (t (unless (assq attribute face-x-resources)
1536 (setq attribute nil))))
1537 (when attribute
1538 (set-face-attribute face frame attribute value)))
1539 (setq attrs (cdr (cdr attrs)))))
1540 ;; When we reset the face based on its spec, then it is unmodified
1541 ;; as far as Custom is concerned.
1542 (put (or (get face 'face-alias) face) 'face-modified nil)
1543 ;; Set each frame according to the rules implied by SPEC.
1544 (dolist (frame (frame-list))
1545 (face-spec-set face spec frame))))
1546
1547
1548 (defun face-attr-match-p (face attrs &optional frame)
1549 "Return t if attributes of FACE match values in plist ATTRS.
1550 Optional parameter FRAME is the frame whose definition of FACE
1551 is used. If nil or omitted, use the selected frame."
1552 (unless frame
1553 (setq frame (selected-frame)))
1554 (let ((list face-attribute-name-alist)
1555 (match t))
1556 (while (and match (not (null list)))
1557 (let* ((attr (car (car list)))
1558 (specified-value
1559 (if (plist-member attrs attr)
1560 (plist-get attrs attr)
1561 'unspecified))
1562 (value-now (face-attribute face attr frame)))
1563 (setq match (equal specified-value value-now))
1564 (setq list (cdr list))))
1565 match))
1566
1567 (defun face-spec-match-p (face spec &optional frame)
1568 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1569 (face-attr-match-p face (face-spec-choose spec frame) frame))
1570
1571 (defsubst face-default-spec (face)
1572 "Return the default face-spec for FACE, ignoring any user customization.
1573 If there is no default for FACE, return nil."
1574 (get face 'face-defface-spec))
1575
1576 (defsubst face-user-default-spec (face)
1577 "Return the user's customized face-spec for FACE, or the default if none.
1578 If there is neither a user setting nor a default for FACE, return nil."
1579 (or (get face 'customized-face)
1580 (get face 'saved-face)
1581 (face-default-spec face)))
1582
1583 (defsubst face-normalize-spec (spec)
1584 "Return a normalized face-spec of SPEC."
1585 (let (normalized-spec)
1586 (while spec
1587 (let ((attribute (car spec))
1588 (value (car (cdr spec))))
1589 ;; Support some old-style attribute names and values.
1590 (case attribute
1591 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1592 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1593 ((:foreground :background)
1594 ;; Compatibility with 20.x. Some bogus face specs seem to
1595 ;; exist containing things like `:foreground nil'.
1596 (if (null value) (setq value 'unspecified)))
1597 (t (unless (assq attribute face-x-resources)
1598 (setq attribute nil))))
1599 (when attribute
1600 (push attribute normalized-spec)
1601 (push value normalized-spec)))
1602 (setq spec (cdr (cdr spec))))
1603 (nreverse normalized-spec)))
1604
1605 \f
1606 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1607 ;;; Frame-type independent color support.
1608 ;;; We keep the old x-* names as aliases for back-compatibility.
1609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1610
1611 (defun defined-colors (&optional frame)
1612 "Return a list of colors supported for a particular frame.
1613 The argument FRAME specifies which frame to try.
1614 The value may be different for frames on different display types.
1615 If FRAME doesn't support colors, the value is nil.
1616 If FRAME is nil, that stands for the selected frame."
1617 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1618 (xw-defined-colors frame)
1619 (mapcar 'car (tty-color-alist frame))))
1620 (defalias 'x-defined-colors 'defined-colors)
1621
1622 (defun color-defined-p (color &optional frame)
1623 "Return non-nil if color COLOR is supported on frame FRAME.
1624 If FRAME is omitted or nil, use the selected frame.
1625 If COLOR is the symbol `unspecified' or one of the strings
1626 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1627 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1628 nil
1629 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1630 (xw-color-defined-p color frame)
1631 (numberp (tty-color-translate color frame)))))
1632 (defalias 'x-color-defined-p 'color-defined-p)
1633
1634 (defun color-values (color &optional frame)
1635 "Return a description of the color named COLOR on frame FRAME.
1636 The value is a list of integer RGB values--(RED GREEN BLUE).
1637 These values appear to range from 0 to 65280 or 65535, depending
1638 on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
1639 If FRAME is omitted or nil, use the selected frame.
1640 If FRAME cannot display COLOR, the value is nil.
1641 If COLOR is the symbol `unspecified' or one of the strings
1642 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1643 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1644 nil
1645 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1646 (xw-color-values color frame)
1647 (tty-color-values color frame))))
1648 (defalias 'x-color-values 'color-values)
1649
1650 (defun display-color-p (&optional display)
1651 "Return t if DISPLAY supports color.
1652 The optional argument DISPLAY specifies which display to ask about.
1653 DISPLAY should be either a frame or a display name (a string).
1654 If omitted or nil, that stands for the selected frame's display."
1655 (if (memq (framep-on-display display) '(x w32 mac))
1656 (xw-display-color-p display)
1657 (tty-display-color-p display)))
1658 (defalias 'x-display-color-p 'display-color-p)
1659
1660 (defun display-grayscale-p (&optional display)
1661 "Return non-nil if frames on DISPLAY can display shades of gray."
1662 (let ((frame-type (framep-on-display display)))
1663 (cond
1664 ((memq frame-type '(x w32 mac))
1665 (x-display-grayscale-p display))
1666 (t
1667 (> (tty-color-gray-shades display) 2)))))
1668
1669 \f
1670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1671 ;;; Background mode.
1672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1673
1674 (defcustom frame-background-mode nil
1675 "*The brightness of the background.
1676 Set this to the symbol `dark' if your background color is dark,
1677 `light' if your background is light, or nil (automatic by default)
1678 if you want Emacs to examine the brightness for you. Don't set this
1679 variable with `setq'; this won't have the expected effect."
1680 :group 'faces
1681 :set #'(lambda (var value)
1682 (set-default var value)
1683 (mapc 'frame-set-background-mode (frame-list)))
1684 :initialize 'custom-initialize-changed
1685 :type '(choice (const dark)
1686 (const light)
1687 (const :tag "automatic" nil)))
1688
1689
1690 (defun frame-set-background-mode (frame)
1691 "Set up display-dependent faces on FRAME.
1692 Display-dependent faces are those which have different definitions
1693 according to the `background-mode' and `display-type' frame parameters."
1694 (let* ((bg-resource
1695 (and (window-system frame)
1696 (x-get-resource "backgroundMode" "BackgroundMode")))
1697 (bg-color (frame-parameter frame 'background-color))
1698 (terminal-bg-mode (terminal-parameter frame 'background-mode))
1699 (tty-type (tty-type frame))
1700 (bg-mode
1701 (cond (frame-background-mode)
1702 (bg-resource
1703 (intern (downcase bg-resource)))
1704 (terminal-bg-mode)
1705 ((and (null (window-system frame))
1706 ;; Unspecified frame background color can only
1707 ;; happen on tty's.
1708 (member bg-color '(nil unspecified "unspecified-bg")))
1709 ;; There is no way to determine the background mode
1710 ;; automatically, so we make a guess based on the
1711 ;; terminal type.
1712 (if (and tty-type
1713 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1714 tty-type))
1715 'light
1716 'dark))
1717 ((equal bg-color "unspecified-fg") ; inverted colors
1718 (if (and tty-type
1719 (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
1720 tty-type))
1721 'dark
1722 'light))
1723 ((>= (apply '+ (color-values bg-color frame))
1724 ;; Just looking at the screen, colors whose
1725 ;; values add up to .6 of the white total
1726 ;; still look dark to me.
1727 (* (apply '+ (color-values "white" frame)) .6))
1728 'light)
1729 (t 'dark)))
1730 (display-type
1731 (cond ((null (window-system frame))
1732 (if (tty-display-color-p frame) 'color 'mono))
1733 ((display-color-p frame)
1734 'color)
1735 ((x-display-grayscale-p frame)
1736 'grayscale)
1737 (t 'mono)))
1738 (old-bg-mode
1739 (frame-parameter frame 'background-mode))
1740 (old-display-type
1741 (frame-parameter frame 'display-type)))
1742
1743 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1744 (let ((locally-modified-faces nil))
1745 ;; Before modifying the frame parameters, we collect a list of
1746 ;; faces that don't match what their face-spec says they should
1747 ;; look like; we then avoid changing these faces below. A
1748 ;; negative list is used on the assumption that most faces will
1749 ;; be unmodified, so we can avoid consing in the common case.
1750 (dolist (face (face-list))
1751 (when (not (face-spec-match-p face
1752 (face-normalize-spec
1753 (face-user-default-spec face))
1754 (selected-frame)))
1755 (push face locally-modified-faces)))
1756 ;; Now change to the new frame parameters
1757 (modify-frame-parameters frame
1758 (list (cons 'background-mode bg-mode)
1759 (cons 'display-type display-type)))
1760 ;; For all named faces, choose face specs matching the new frame
1761 ;; parameters, unless they have been locally modified.
1762 (dolist (face (face-list))
1763 (unless (memq face locally-modified-faces)
1764 (face-spec-set face (face-user-default-spec face) frame)))))))
1765
1766 \f
1767 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1768 ;;; Frame creation.
1769 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1770
1771 (defun x-handle-named-frame-geometry (parameters)
1772 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1773 Value is the new parameter list."
1774 (let* ((name (or (cdr (assq 'name parameters))
1775 (cdr (assq 'name default-frame-alist))))
1776 (x-resource-name name)
1777 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1778 (when res-geometry
1779 (let ((parsed (x-parse-geometry res-geometry)))
1780 ;; If the resource specifies a position, call the position
1781 ;; and size "user-specified".
1782 (when (or (assq 'top parsed)
1783 (assq 'left parsed))
1784 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1785 ;; Put the geometry parameters at the end. Copy
1786 ;; default-frame-alist so that they go after it.
1787 (setq parameters (append parameters default-frame-alist parsed))))
1788 parameters))
1789
1790
1791 (defun x-handle-reverse-video (frame parameters)
1792 "Handle the reverse-video frame parameter and X resource.
1793 `x-create-frame' does not handle this one."
1794 (when (cdr (or (assq 'reverse parameters)
1795 (assq 'reverse default-frame-alist)
1796 (let ((resource (x-get-resource "reverseVideo"
1797 "ReverseVideo")))
1798 (if resource
1799 (cons nil (member (downcase resource)
1800 '("on" "true")))))))
1801 (let* ((params (frame-parameters frame))
1802 (bg (cdr (assq 'foreground-color params)))
1803 (fg (cdr (assq 'background-color params))))
1804 (modify-frame-parameters frame
1805 (list (cons 'foreground-color fg)
1806 (cons 'background-color bg)))
1807 (if (equal bg (cdr (assq 'border-color params)))
1808 (modify-frame-parameters frame
1809 (list (cons 'border-color fg))))
1810 (if (equal bg (cdr (assq 'mouse-color params)))
1811 (modify-frame-parameters frame
1812 (list (cons 'mouse-color fg))))
1813 (if (equal bg (cdr (assq 'cursor-color params)))
1814 (modify-frame-parameters frame
1815 (list (cons 'cursor-color fg)))))))
1816
1817
1818 (defun x-create-frame-with-faces (&optional parameters)
1819 "Create a frame from optional frame parameters PARAMETERS.
1820 Parameters not specified by PARAMETERS are taken from
1821 `default-frame-alist'. If PARAMETERS specify a frame name,
1822 handle X geometry resources for that name. If either PARAMETERS
1823 or `default-frame-alist' contains a `reverse' parameter, or
1824 the X resource ``reverseVideo'' is present, handle that.
1825 Value is the new frame created."
1826 (setq parameters (x-handle-named-frame-geometry parameters))
1827 (let ((visibility-spec (assq 'visibility parameters))
1828 (frame (x-create-frame `((visibility . nil) . ,parameters)))
1829 success)
1830 (unwind-protect
1831 (progn
1832 (x-setup-function-keys frame)
1833 (x-handle-reverse-video frame parameters)
1834 (frame-set-background-mode frame)
1835 (face-set-after-frame-default frame)
1836 ;; Arrange for the kill and yank functions to set and check the clipboard.
1837 (modify-frame-parameters
1838 frame '((interprogram-cut-function . x-select-text)))
1839 (modify-frame-parameters
1840 frame '((interprogram-paste-function . x-cut-buffer-or-selection-value)))
1841 ;; Make sure the tool-bar is ready to be enabled. The
1842 ;; `tool-bar-lines' frame parameter will not take effect
1843 ;; without this call.
1844 (tool-bar-setup frame)
1845 (if (null visibility-spec)
1846 (make-frame-visible frame)
1847 (modify-frame-parameters frame (list visibility-spec)))
1848 (setq success t))
1849 (unless success
1850 (delete-frame frame)))
1851 frame))
1852
1853 (defun face-set-after-frame-default (frame)
1854 "Set frame-local faces of FRAME from face specs and resources.
1855 Initialize colors of certain faces from frame parameters."
1856 (unless inhibit-face-set-after-frame-default
1857 (if (face-attribute 'default :font t)
1858 (set-face-attribute 'default frame :font
1859 (face-attribute 'default :font t))
1860 (set-face-attribute 'default frame :family
1861 (face-attribute 'default :family t))
1862 (set-face-attribute 'default frame :height
1863 (face-attribute 'default :height t))
1864 (set-face-attribute 'default frame :slant
1865 (face-attribute 'default :slant t))
1866 (set-face-attribute 'default frame :weight
1867 (face-attribute 'default :weight t))
1868 (set-face-attribute 'default frame :width
1869 (face-attribute 'default :width t))))
1870 ;; Find attributes that should be initialized from frame parameters.
1871 (let ((face-params '((foreground-color default :foreground)
1872 (background-color default :background)
1873 (border-color border :background)
1874 (cursor-color cursor :background)
1875 (scroll-bar-foreground scroll-bar :foreground)
1876 (scroll-bar-background scroll-bar :background)
1877 (mouse-color mouse :background)))
1878 apply-params)
1879 (dolist (param face-params)
1880 (let* ((value (frame-parameter frame (nth 0 param)))
1881 (face (nth 1 param))
1882 (attr (nth 2 param))
1883 (default-value (face-attribute face attr t)))
1884 ;; Compile a list of face attributes to set, but don't set
1885 ;; them yet. The call to make-face-x-resource-internal,
1886 ;; below, can change frame parameters, and the final set of
1887 ;; frame parameters should be the ones acquired at this step.
1888 (if (eq default-value 'unspecified)
1889 ;; The face spec does not specify a new-frame value for
1890 ;; this attribute. Check if the existing frame parameter
1891 ;; specifies it.
1892 (if value
1893 (push (list face frame attr value) apply-params))
1894 ;; The face spec specifies a value for this attribute, to be
1895 ;; applied to the face on all new frames.
1896 (push (list face frame attr default-value) apply-params))))
1897 ;; Initialize faces from face specs and X resources. The
1898 ;; condition-case prevents invalid specs from causing frame
1899 ;; creation to fail.
1900 (dolist (face (delq 'default (face-list)))
1901 (condition-case ()
1902 (progn
1903 (face-spec-set face (face-user-default-spec face) frame)
1904 (if (memq (window-system frame) '(x w32 mac))
1905 (make-face-x-resource-internal face frame))
1906 (internal-merge-in-global-face face frame))
1907 (error nil)))
1908 ;; Apply the attributes specified by frame parameters. This
1909 ;; rewrites parameters changed by make-face-x-resource-internal
1910 (dolist (param apply-params)
1911 (apply 'set-face-attribute param))))
1912
1913 (defun tty-handle-reverse-video (frame parameters)
1914 "Handle the reverse-video frame parameter for terminal frames."
1915 (when (cdr (or (assq 'reverse parameters)
1916 (assq 'reverse default-frame-alist)))
1917 (let* ((params (frame-parameters frame))
1918 (bg (cdr (assq 'foreground-color params)))
1919 (fg (cdr (assq 'background-color params))))
1920 (modify-frame-parameters frame
1921 (list (cons 'foreground-color fg)
1922 (cons 'background-color bg)))
1923 (if (equal bg (cdr (assq 'mouse-color params)))
1924 (modify-frame-parameters frame
1925 (list (cons 'mouse-color fg))))
1926 (if (equal bg (cdr (assq 'cursor-color params)))
1927 (modify-frame-parameters frame
1928 (list (cons 'cursor-color fg)))))))
1929
1930
1931 (defun tty-create-frame-with-faces (&optional parameters)
1932 "Create a frame from optional frame parameters PARAMETERS.
1933 Parameters not specified by PARAMETERS are taken from
1934 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
1935 contains a `reverse' parameter, handle that. Value is the new frame
1936 created."
1937 (let ((frame (make-terminal-frame parameters))
1938 success)
1939 (unwind-protect
1940 (with-selected-frame frame
1941 (tty-handle-reverse-video frame (frame-parameters frame))
1942
1943 ;; Make sure the kill and yank functions do not touch the X clipboard.
1944 (modify-frame-parameters frame '((interprogram-cut-function . nil)))
1945 (modify-frame-parameters frame '((interprogram-paste-function . nil)))
1946
1947 (set-locale-environment nil frame)
1948 (tty-run-terminal-initialization frame)
1949 (frame-set-background-mode frame)
1950 (face-set-after-frame-default frame)
1951 (setq success t))
1952 (unless success
1953 (delete-frame frame)))
1954 frame))
1955
1956 (defun tty-find-type (pred type)
1957 "Return the longest prefix of TYPE to which PRED returns non-nil.
1958 TYPE should be a tty type name such as \"xterm-16color\".
1959
1960 The function tries only those prefixes that are followed by a
1961 dash or underscore in the original type name, like \"xterm\" in
1962 the above example."
1963 (let (hyphend)
1964 (while (and type
1965 (not (funcall pred type)))
1966 ;; Strip off last hyphen and what follows, then try again
1967 (setq type
1968 (if (setq hyphend (string-match "[-_][^-_]+$" type))
1969 (substring type 0 hyphend)
1970 nil))))
1971 type)
1972
1973 (defun tty-run-terminal-initialization (frame &optional type)
1974 "Run the special initialization code for the terminal type of FRAME.
1975 The optional TYPE parameter may be used to override the autodetected
1976 terminal type to a different value."
1977 (setq type (or type (tty-type frame)))
1978 ;; Load library for our terminal type.
1979 ;; User init file can set term-file-prefix to nil to prevent this.
1980 (with-selected-frame frame
1981 (unless (or (null term-file-prefix)
1982 ;; Don't reinitialize the terminal each time a new
1983 ;; frame is opened on it.
1984 (terminal-parameter frame 'terminal-initted))
1985 (let* (term-init-func)
1986 ;; First, load the terminal initialization file, if it is
1987 ;; available and it hasn't been loaded already.
1988 (tty-find-type #'(lambda (type)
1989 (let ((file (locate-library (concat term-file-prefix type))))
1990 (and file
1991 (or (assoc file load-history)
1992 (load file t t)))))
1993 type)
1994 ;; Next, try to find a matching initialization function, and call it.
1995 (tty-find-type #'(lambda (type)
1996 (fboundp (setq term-init-func
1997 (intern (concat "terminal-init-" type)))))
1998 type)
1999 (when (fboundp term-init-func)
2000 (funcall term-init-func))
2001 (set-terminal-parameter frame 'terminal-initted term-init-func)))))
2002
2003 ;; Called from C function init_display to initialize faces of the
2004 ;; dumped terminal frame on startup.
2005
2006 (defun tty-set-up-initial-frame-faces ()
2007 (let ((frame (selected-frame)))
2008 (frame-set-background-mode frame)
2009 (face-set-after-frame-default frame)))
2010
2011
2012
2013 \f
2014 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015 ;;; Compatiblity with 20.2
2016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2017
2018 ;; Update a frame's faces when we change its default font.
2019
2020 (defalias 'frame-update-faces 'ignore "")
2021 (make-obsolete 'frame-update-faces "no longer necessary." "21.1")
2022
2023 ;; Update the colors of FACE, after FRAME's own colors have been
2024 ;; changed.
2025
2026 (define-obsolete-function-alias 'frame-update-face-colors
2027 'frame-set-background-mode "21.1")
2028
2029 \f
2030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2031 ;;; Standard faces.
2032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2033
2034 (defgroup basic-faces nil
2035 "The standard faces of Emacs."
2036 :group 'faces)
2037
2038 (defface default
2039 '((t nil))
2040 "Basic default face."
2041 :group 'basic-faces)
2042
2043 (defface bold
2044 '((t :weight bold))
2045 "Basic bold face."
2046 :group 'basic-faces)
2047
2048 (defface italic
2049 '((((supports :slant italic))
2050 :slant italic)
2051 (((supports :underline t))
2052 :underline t)
2053 (t
2054 ;; default to italic, even it doesn't appear to be supported,
2055 ;; because in some cases the display engine will do it's own
2056 ;; workaround (to `dim' on ttys)
2057 :slant italic))
2058 "Basic italic face."
2059 :group 'basic-faces)
2060
2061 (defface bold-italic
2062 '((t :weight bold :slant italic))
2063 "Basic bold-italic face."
2064 :group 'basic-faces)
2065
2066 (defface underline
2067 '((((supports :underline t))
2068 :underline t)
2069 (((supports :weight bold))
2070 :weight bold)
2071 (t :underline t))
2072 "Basic underlined face."
2073 :group 'basic-faces)
2074
2075 (defface fixed-pitch
2076 '((t :family "courier"))
2077 "The basic fixed-pitch face."
2078 :group 'basic-faces)
2079
2080 (defface variable-pitch
2081 '((t :family "helv"))
2082 "The basic variable-pitch face."
2083 :group 'basic-faces)
2084
2085 (defface shadow
2086 '((((class color grayscale) (min-colors 88) (background light))
2087 :foreground "grey50")
2088 (((class color grayscale) (min-colors 88) (background dark))
2089 :foreground "grey70")
2090 (((class color) (min-colors 8) (background light))
2091 :foreground "green")
2092 (((class color) (min-colors 8) (background dark))
2093 :foreground "yellow"))
2094 "Basic face for shadowed text."
2095 :group 'basic-faces
2096 :version "22.1")
2097
2098 (defface link
2099 '((((class color) (min-colors 88) (background light))
2100 :foreground "blue1" :underline t)
2101 (((class color) (background light))
2102 :foreground "blue" :underline t)
2103 (((class color) (min-colors 88) (background dark))
2104 :foreground "cyan1" :underline t)
2105 (((class color) (background dark))
2106 :foreground "cyan" :underline t)
2107 (t :inherit underline))
2108 "Basic face for unvisited links."
2109 :group 'basic-faces
2110 :version "22.1")
2111
2112 (defface link-visited
2113 '((default :inherit link)
2114 (((class color) (background light)) :foreground "magenta4")
2115 (((class color) (background dark)) :foreground "violet"))
2116 "Basic face for visited links."
2117 :group 'basic-faces
2118 :version "22.1")
2119
2120 (defface highlight
2121 '((((class color) (min-colors 88) (background light))
2122 :background "darkseagreen2")
2123 (((class color) (min-colors 88) (background dark))
2124 :background "darkolivegreen")
2125 (((class color) (min-colors 16) (background light))
2126 :background "darkseagreen2")
2127 (((class color) (min-colors 16) (background dark))
2128 :background "darkolivegreen")
2129 (((class color) (min-colors 8))
2130 :background "green" :foreground "black")
2131 (t :inverse-video t))
2132 "Basic face for highlighting."
2133 :group 'basic-faces)
2134
2135 (defface region
2136 '((((class color) (min-colors 88) (background dark))
2137 :background "blue3")
2138 (((class color) (min-colors 88) (background light))
2139 :background "lightgoldenrod2")
2140 (((class color) (min-colors 16) (background dark))
2141 :background "blue3")
2142 (((class color) (min-colors 16) (background light))
2143 :background "lightgoldenrod2")
2144 (((class color) (min-colors 8))
2145 :background "blue" :foreground "white")
2146 (((type tty) (class mono))
2147 :inverse-video t)
2148 (t :background "gray"))
2149 "Basic face for highlighting the region."
2150 :version "21.1"
2151 :group 'basic-faces)
2152
2153 (defface secondary-selection
2154 '((((class color) (min-colors 88) (background light))
2155 :background "yellow1")
2156 (((class color) (min-colors 88) (background dark))
2157 :background "SkyBlue4")
2158 (((class color) (min-colors 16) (background light))
2159 :background "yellow")
2160 (((class color) (min-colors 16) (background dark))
2161 :background "SkyBlue4")
2162 (((class color) (min-colors 8))
2163 :background "cyan" :foreground "black")
2164 (t :inverse-video t))
2165 "Basic face for displaying the secondary selection."
2166 :group 'basic-faces)
2167
2168 (defface trailing-whitespace
2169 '((((class color) (background light))
2170 :background "red1")
2171 (((class color) (background dark))
2172 :background "red1")
2173 (t :inverse-video t))
2174 "Basic face for highlighting trailing whitespace."
2175 :version "21.1"
2176 :group 'whitespace-faces ; like `show-trailing-whitespace'
2177 :group 'basic-faces)
2178
2179 (defface escape-glyph
2180 '((((background dark)) :foreground "cyan")
2181 ;; See the comment in minibuffer-prompt for
2182 ;; the reason not to use blue on MS-DOS.
2183 (((type pc)) :foreground "magenta")
2184 ;; red4 is too dark, but some say blue is too loud.
2185 ;; brown seems to work ok. -- rms.
2186 (t :foreground "brown"))
2187 "Face for characters displayed as sequences using `^' or `\\'."
2188 :group 'basic-faces
2189 :version "22.1")
2190
2191 (defface nobreak-space
2192 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2193 (((class color) (min-colors 8)) :background "magenta")
2194 (t :inverse-video t))
2195 "Face for displaying nobreak space."
2196 :group 'basic-faces
2197 :version "22.1")
2198
2199 (defgroup mode-line-faces nil
2200 "Faces used in the mode line."
2201 :group 'mode-line
2202 :group 'faces
2203 :version "22.1")
2204
2205 (defface mode-line
2206 '((((class color) (min-colors 88))
2207 :box (:line-width -1 :style released-button)
2208 :background "grey75" :foreground "black")
2209 (t
2210 :inverse-video t))
2211 "Basic mode line face for selected window."
2212 :version "21.1"
2213 :group 'mode-line-faces
2214 :group 'basic-faces)
2215
2216 (defface mode-line-inactive
2217 '((default
2218 :inherit mode-line)
2219 (((class color) (min-colors 88) (background light))
2220 :weight light
2221 :box (:line-width -1 :color "grey75" :style nil)
2222 :foreground "grey20" :background "grey90")
2223 (((class color) (min-colors 88) (background dark) )
2224 :weight light
2225 :box (:line-width -1 :color "grey40" :style nil)
2226 :foreground "grey80" :background "grey30"))
2227 "Basic mode line face for non-selected windows."
2228 :version "22.1"
2229 :group 'mode-line-faces
2230 :group 'basic-faces)
2231
2232 (defface mode-line-highlight
2233 '((((class color) (min-colors 88))
2234 :box (:line-width 2 :color "grey40" :style released-button))
2235 (t
2236 :inherit highlight))
2237 "Basic mode line face for highlighting."
2238 :version "22.1"
2239 :group 'mode-line-faces
2240 :group 'basic-faces)
2241
2242 (defface mode-line-buffer-id
2243 '((t (:weight bold)))
2244 "Face used for buffer identification parts of the mode line."
2245 :version "22.1"
2246 :group 'mode-line-faces
2247 :group 'basic-faces)
2248
2249 ;; Make `modeline' an alias for `mode-line', for compatibility.
2250 (put 'modeline 'face-alias 'mode-line)
2251 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
2252 (put 'modeline-highlight 'face-alias 'mode-line-highlight)
2253 (put 'modeline-buffer-id 'face-alias 'mode-line-buffer-id)
2254
2255 (defface header-line
2256 '((default
2257 :inherit mode-line)
2258 (((type tty))
2259 ;; This used to be `:inverse-video t', but that doesn't look very
2260 ;; good when combined with inverse-video mode-lines and multiple
2261 ;; windows. Underlining looks better, and is more consistent with
2262 ;; the window-system face variants, which deemphasize the
2263 ;; header-line in relation to the mode-line face. If a terminal
2264 ;; can't underline, then the header-line will end up without any
2265 ;; highlighting; this may be too confusing in general, although it
2266 ;; happens to look good with the only current use of header-lines,
2267 ;; the info browser. XXX
2268 :inverse-video nil ;Override the value inherited from mode-line.
2269 :underline t)
2270 (((class color grayscale) (background light))
2271 :background "grey90" :foreground "grey20"
2272 :box nil)
2273 (((class color grayscale) (background dark))
2274 :background "grey20" :foreground "grey90"
2275 :box nil)
2276 (((class mono) (background light))
2277 :background "white" :foreground "black"
2278 :inverse-video nil
2279 :box nil
2280 :underline t)
2281 (((class mono) (background dark))
2282 :background "black" :foreground "white"
2283 :inverse-video nil
2284 :box nil
2285 :underline t))
2286 "Basic header-line face."
2287 :version "21.1"
2288 :group 'basic-faces)
2289
2290 (defface vertical-border
2291 '((((type tty)) :inherit mode-line-inactive))
2292 "Face used for vertical window dividers on ttys."
2293 :version "22.1"
2294 :group 'basic-faces)
2295
2296 (defface minibuffer-prompt
2297 '((((background dark)) :foreground "cyan")
2298 ;; Don't use blue because many users of the MS-DOS port customize
2299 ;; their foreground color to be blue.
2300 (((type pc)) :foreground "magenta")
2301 (t :foreground "medium blue"))
2302 "Face for minibuffer prompts.
2303 By default, Emacs automatically adds this face to the value of
2304 `minibuffer-prompt-properties', which is a list of text properties
2305 used to display the prompt text."
2306 :version "22.1"
2307 :group 'basic-faces)
2308
2309 (setq minibuffer-prompt-properties
2310 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
2311
2312 (defface fringe
2313 '((((class color) (background light))
2314 :background "grey95")
2315 (((class color) (background dark))
2316 :background "grey10")
2317 (t
2318 :background "gray"))
2319 "Basic face for the fringes to the left and right of windows under X."
2320 :version "21.1"
2321 :group 'frames
2322 :group 'basic-faces)
2323
2324 (defface scroll-bar '((t nil))
2325 "Basic face for the scroll bar colors under X."
2326 :version "21.1"
2327 :group 'frames
2328 :group 'basic-faces)
2329
2330 (defface border '((t nil))
2331 "Basic face for the frame border under X."
2332 :version "21.1"
2333 :group 'frames
2334 :group 'basic-faces)
2335
2336 (defface cursor '((t nil))
2337 "Basic face for the cursor color under X.
2338 Note: Other faces cannot inherit from the cursor face."
2339 :version "21.1"
2340 :group 'cursor
2341 :group 'basic-faces)
2342
2343 (put 'cursor 'face-no-inherit t)
2344
2345 (defface mouse '((t nil))
2346 "Basic face for the mouse color under X."
2347 :version "21.1"
2348 :group 'mouse
2349 :group 'basic-faces)
2350
2351 (defface tool-bar
2352 '((default
2353 :box (:line-width 1 :style released-button)
2354 :foreground "black")
2355 (((type x w32 mac) (class color))
2356 :background "grey75")
2357 (((type x) (class mono))
2358 :background "grey"))
2359 "Basic tool-bar face."
2360 :version "21.1"
2361 :group 'basic-faces)
2362
2363 (defface menu
2364 '((((type tty))
2365 :inverse-video t)
2366 (((type x-toolkit))
2367 )
2368 (t
2369 :inverse-video t))
2370 "Basic face for the font and colors of the menu bar and popup menus."
2371 :version "21.1"
2372 :group 'menu
2373 :group 'basic-faces)
2374
2375 \f
2376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2377 ;;; Manipulating font names.
2378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2379
2380 ;; This is here for compatibilty with Emacs 20.2. For example,
2381 ;; international/fontset.el uses x-resolve-font-name. The following
2382 ;; functions are not used in the face implementation itself.
2383
2384 (defvar x-font-regexp nil)
2385 (defvar x-font-regexp-head nil)
2386 (defvar x-font-regexp-weight nil)
2387 (defvar x-font-regexp-slant nil)
2388
2389 (defconst x-font-regexp-weight-subnum 1)
2390 (defconst x-font-regexp-slant-subnum 2)
2391 (defconst x-font-regexp-swidth-subnum 3)
2392 (defconst x-font-regexp-adstyle-subnum 4)
2393
2394 ;;; Regexps matching font names in "Host Portable Character Representation."
2395 ;;;
2396 (let ((- "[-?]")
2397 (foundry "[^-]+")
2398 (family "[^-]+")
2399 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2400 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2401 (weight\? "\\([^-]*\\)") ; 1
2402 (slant "\\([ior]\\)") ; 2
2403 ; (slant\? "\\([ior?*]?\\)") ; 2
2404 (slant\? "\\([^-]?\\)") ; 2
2405 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2406 (swidth "\\([^-]*\\)") ; 3
2407 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2408 (adstyle "\\([^-]*\\)") ; 4
2409 (pixelsize "[0-9]+")
2410 (pointsize "[0-9][0-9]+")
2411 (resx "[0-9][0-9]+")
2412 (resy "[0-9][0-9]+")
2413 (spacing "[cmp?*]")
2414 (avgwidth "[0-9]+")
2415 (registry "[^-]+")
2416 (encoding "[^-]+")
2417 )
2418 (setq x-font-regexp
2419 (concat "\\`\\*?[-?*]"
2420 foundry - family - weight\? - slant\? - swidth - adstyle -
2421 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2422 registry - encoding "\\*?\\'"
2423 ))
2424 (setq x-font-regexp-head
2425 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2426 "\\([-*?]\\|\\'\\)"))
2427 (setq x-font-regexp-slant (concat - slant -))
2428 (setq x-font-regexp-weight (concat - weight -))
2429 nil)
2430
2431
2432 (defun x-resolve-font-name (pattern &optional face frame)
2433 "Return a font name matching PATTERN.
2434 All wildcards in PATTERN are instantiated.
2435 If PATTERN is nil, return the name of the frame's base font, which never
2436 contains wildcards.
2437 Given optional arguments FACE and FRAME, return a font which is
2438 also the same size as FACE on FRAME, or fail."
2439 (or (symbolp face)
2440 (setq face (face-name face)))
2441 (and (eq frame t)
2442 (setq frame nil))
2443 (if pattern
2444 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2445 (let ((fonts (x-list-fonts pattern face frame 1)))
2446 (or fonts
2447 (if face
2448 (if (string-match "\\*" pattern)
2449 (if (null (face-font face))
2450 (error "No matching fonts are the same height as the frame default font")
2451 (error "No matching fonts are the same height as face `%s'" face))
2452 (if (null (face-font face))
2453 (error "Height of font `%s' doesn't match the frame default font"
2454 pattern)
2455 (error "Height of font `%s' doesn't match face `%s'"
2456 pattern face)))
2457 (error "No fonts match `%s'" pattern)))
2458 (car fonts))
2459 (cdr (assq 'font (frame-parameters (selected-frame))))))
2460
2461
2462 (defun x-frob-font-weight (font which)
2463 (let ((case-fold-search t))
2464 (cond ((string-match x-font-regexp font)
2465 (concat (substring font 0
2466 (match-beginning x-font-regexp-weight-subnum))
2467 which
2468 (substring font (match-end x-font-regexp-weight-subnum)
2469 (match-beginning x-font-regexp-adstyle-subnum))
2470 ;; Replace the ADD_STYLE_NAME field with *
2471 ;; because the info in it may not be the same
2472 ;; for related fonts.
2473 "*"
2474 (substring font (match-end x-font-regexp-adstyle-subnum))))
2475 ((string-match x-font-regexp-head font)
2476 (concat (substring font 0 (match-beginning 1)) which
2477 (substring font (match-end 1))))
2478 ((string-match x-font-regexp-weight font)
2479 (concat (substring font 0 (match-beginning 1)) which
2480 (substring font (match-end 1)))))))
2481 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
2482
2483 (defun x-frob-font-slant (font which)
2484 (let ((case-fold-search t))
2485 (cond ((string-match x-font-regexp font)
2486 (concat (substring font 0
2487 (match-beginning x-font-regexp-slant-subnum))
2488 which
2489 (substring font (match-end x-font-regexp-slant-subnum)
2490 (match-beginning x-font-regexp-adstyle-subnum))
2491 ;; Replace the ADD_STYLE_NAME field with *
2492 ;; because the info in it may not be the same
2493 ;; for related fonts.
2494 "*"
2495 (substring font (match-end x-font-regexp-adstyle-subnum))))
2496 ((string-match x-font-regexp-head font)
2497 (concat (substring font 0 (match-beginning 2)) which
2498 (substring font (match-end 2))))
2499 ((string-match x-font-regexp-slant font)
2500 (concat (substring font 0 (match-beginning 1)) which
2501 (substring font (match-end 1)))))))
2502 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
2503
2504 ;; These aliases are here so that we don't get warnings about obsolete
2505 ;; functions from the byte compiler.
2506 (defalias 'internal-frob-font-weight 'x-frob-font-weight)
2507 (defalias 'internal-frob-font-slant 'x-frob-font-slant)
2508
2509 (defun x-make-font-bold (font)
2510 "Given an X font specification, make a bold version of it.
2511 If that can't be done, return nil."
2512 (internal-frob-font-weight font "bold"))
2513 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
2514
2515 (defun x-make-font-demibold (font)
2516 "Given an X font specification, make a demibold version of it.
2517 If that can't be done, return nil."
2518 (internal-frob-font-weight font "demibold"))
2519 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
2520
2521 (defun x-make-font-unbold (font)
2522 "Given an X font specification, make a non-bold version of it.
2523 If that can't be done, return nil."
2524 (internal-frob-font-weight font "medium"))
2525 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
2526
2527 (defun x-make-font-italic (font)
2528 "Given an X font specification, make an italic version of it.
2529 If that can't be done, return nil."
2530 (internal-frob-font-slant font "i"))
2531 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
2532
2533 (defun x-make-font-oblique (font) ; you say tomayto...
2534 "Given an X font specification, make an oblique version of it.
2535 If that can't be done, return nil."
2536 (internal-frob-font-slant font "o"))
2537 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
2538
2539 (defun x-make-font-unitalic (font)
2540 "Given an X font specification, make a non-italic version of it.
2541 If that can't be done, return nil."
2542 (internal-frob-font-slant font "r"))
2543 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
2544
2545 (defun x-make-font-bold-italic (font)
2546 "Given an X font specification, make a bold and italic version of it.
2547 If that can't be done, return nil."
2548 (and (setq font (internal-frob-font-weight font "bold"))
2549 (internal-frob-font-slant font "i")))
2550 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2551
2552 (provide 'faces)
2553
2554 ;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
2555 ;;; faces.el ends here