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