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