]> code.delx.au - gnu-emacs/blob - lisp/faces.el
(ps-face-foreground-name, ps-face-background-name):
[gnu-emacs] / lisp / faces.el
1 ;;; faces.el --- Lisp faces
2
3 ;; Copyright (C) 1992,1993,1994,1995,1996,1998,1999,2000,2001,2002,2004,2005
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 (aliasfaces nil)
858 (nonaliasfaces nil)
859 faces)
860 ;; Make a list of the named faces that the `face' property uses.
861 (if (and (listp faceprop)
862 ;; Don't treat an attribute spec as a list of faces.
863 (not (keywordp (car faceprop)))
864 (not (memq (car faceprop) '(foreground-color background-color))))
865 (dolist (f faceprop)
866 (if (symbolp f)
867 (push f faces)))
868 (if (symbolp faceprop)
869 (push faceprop faces)))
870 ;; If there are none, try to get a face name from the buffer.
871 (if (and (null faces)
872 (memq (intern-soft (thing-at-point 'symbol)) (face-list)))
873 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
874
875 ;; Build up the completion tables.
876 (mapatoms (lambda (s)
877 (if (custom-facep s)
878 (if (get s 'face-alias)
879 (push (symbol-name s) aliasfaces)
880 (push (symbol-name s) nonaliasfaces)))))
881
882 ;; If we only want one, and the default is more than one,
883 ;; discard the unwanted ones now.
884 (unless multiple
885 (if faces
886 (setq faces (list (car faces)))))
887 (let* ((input
888 ;; Read the input.
889 (completing-read
890 (if (or faces string-describing-default)
891 (format "%s (default %s): " prompt
892 (if faces (mapconcat 'symbol-name faces ", ")
893 string-describing-default))
894 (format "%s: " prompt))
895 (complete-in-turn nonaliasfaces aliasfaces) nil t))
896 ;; Canonicalize the output.
897 (output
898 (if (equal input "")
899 faces
900 (if (stringp input)
901 (list (intern input))
902 input))))
903 ;; Return either a list of faces or just one face.
904 (if multiple
905 output
906 (car output)))))
907
908
909 (defun face-valid-attribute-values (attribute &optional frame)
910 "Return valid values for face attribute ATTRIBUTE.
911 The optional argument FRAME is used to determine available fonts
912 and colors. If it is nil or not specified, the selected frame is
913 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
914 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
915 an integer value."
916 (let ((valid
917 (case attribute
918 (:family
919 (if window-system
920 (mapcar #'(lambda (x) (cons (car x) (car x)))
921 (x-font-family-list))
922 ;; Only one font on TTYs.
923 (list (cons "default" "default"))))
924 ((:width :weight :slant :inverse-video)
925 (mapcar #'(lambda (x) (cons (symbol-name x) x))
926 (internal-lisp-face-attribute-values attribute)))
927 ((:underline :overline :strike-through :box)
928 (if window-system
929 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
930 (internal-lisp-face-attribute-values attribute))
931 (mapcar #'(lambda (c) (cons c c))
932 (x-defined-colors frame)))
933 (mapcar #'(lambda (x) (cons (symbol-name x) x))
934 (internal-lisp-face-attribute-values attribute))))
935 ((:foreground :background)
936 (mapcar #'(lambda (c) (cons c c))
937 (defined-colors frame)))
938 ((:height)
939 'integerp)
940 (:stipple
941 (and (memq window-system '(x w32 mac))
942 (mapcar #'list
943 (apply #'nconc
944 (mapcar (lambda (dir)
945 (and (file-readable-p dir)
946 (file-directory-p dir)
947 (directory-files dir)))
948 x-bitmap-file-path)))))
949 (:inherit
950 (cons '("none" . nil)
951 (mapcar #'(lambda (c) (cons (symbol-name c) c))
952 (face-list))))
953 (t
954 (error "Internal error")))))
955 (if (and (listp valid) (not (memq attribute '(:inherit))))
956 (nconc (list (cons "unspecified" 'unspecified)) valid)
957 valid)))
958
959
960 (defvar face-attribute-name-alist
961 '((:family . "font family")
962 (:width . "character set width")
963 (:height . "height in 1/10 pt")
964 (:weight . "weight")
965 (:slant . "slant")
966 (:underline . "underline")
967 (:overline . "overline")
968 (:strike-through . "strike-through")
969 (:box . "box")
970 (:inverse-video . "inverse-video display")
971 (:foreground . "foreground color")
972 (:background . "background color")
973 (:stipple . "background stipple")
974 (:inherit . "inheritance"))
975 "An alist of descriptive names for face attributes.
976 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
977 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
978 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
979
980
981 (defun face-descriptive-attribute-name (attribute)
982 "Return a descriptive name for ATTRIBUTE."
983 (cdr (assq attribute face-attribute-name-alist)))
984
985
986 (defun face-read-string (face default name &optional completion-alist)
987 "Interactively read a face attribute string value.
988 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
989 default string to return if no new value is entered. NAME is a
990 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
991 alist of valid values, if non-nil.
992
993 Entering nothing accepts the default string DEFAULT.
994 Value is the new attribute value."
995 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
996 ;; each word in a string separately).
997 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
998 (let* ((completion-ignore-case t)
999 (value (completing-read
1000 (if default
1001 (format "%s for face `%s' (default %s): "
1002 name face default)
1003 (format "%s for face `%s': " name face))
1004 completion-alist)))
1005 (if (equal value "") default value)))
1006
1007
1008 (defun face-read-integer (face default name)
1009 "Interactively read an integer face attribute value.
1010 FACE is the face whose attribute is read. DEFAULT is the default
1011 value to return if no new value is entered. NAME is a descriptive
1012 name of the attribute for prompting. Value is the new attribute value."
1013 (let ((new-value
1014 (face-read-string face
1015 (format "%s" default)
1016 name
1017 (list (cons "unspecified" 'unspecified)))))
1018 (cond ((equal new-value "unspecified")
1019 'unspecified)
1020 ((member new-value '("unspecified-fg" "unspecified-bg"))
1021 new-value)
1022 (t
1023 (string-to-number new-value)))))
1024
1025
1026 (defun read-face-attribute (face attribute &optional frame)
1027 "Interactively read a new value for FACE's ATTRIBUTE.
1028 Optional argument FRAME nil or unspecified means read an attribute value
1029 of a global face. Value is the new attribute value."
1030 (let* ((old-value (face-attribute face attribute frame))
1031 (attribute-name (face-descriptive-attribute-name attribute))
1032 (valid (face-valid-attribute-values attribute frame))
1033 new-value)
1034 ;; Represent complex attribute values as strings by printing them
1035 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
1036 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
1037 ;; SHADOW)'.
1038 (when (and (or (eq attribute :stipple)
1039 (eq attribute :box))
1040 (or (consp old-value)
1041 (vectorp old-value)))
1042 (setq old-value (prin1-to-string old-value)))
1043 (cond ((listp valid)
1044 (let ((default
1045 (or (car (rassoc old-value valid))
1046 (format "%s" old-value))))
1047 (setq new-value
1048 (face-read-string face default attribute-name valid))
1049 (if (equal new-value default)
1050 ;; Nothing changed, so don't bother with all the stuff
1051 ;; below. In particular, this avoids a non-tty color
1052 ;; from being canonicalized for a tty when the user
1053 ;; just uses the default.
1054 (setq new-value old-value)
1055 ;; Terminal frames can support colors that don't appear
1056 ;; explicitly in VALID, using color approximation code
1057 ;; in tty-colors.el.
1058 (when (and (memq attribute '(:foreground :background))
1059 (not (memq window-system '(x w32 mac)))
1060 (not (member new-value
1061 '("unspecified"
1062 "unspecified-fg" "unspecified-bg"))))
1063 (setq new-value (car (tty-color-desc new-value frame))))
1064 (when (assoc new-value valid)
1065 (setq new-value (cdr (assoc new-value valid)))))))
1066 ((eq valid 'integerp)
1067 (setq new-value (face-read-integer face old-value attribute-name)))
1068 (t (error "Internal error")))
1069 ;; Convert stipple and box value text we read back to a list or
1070 ;; vector if it looks like one. This makes the assumption that a
1071 ;; pixmap file name won't start with an open-paren.
1072 (when (and (or (eq attribute :stipple)
1073 (eq attribute :box))
1074 (stringp new-value)
1075 (string-match "^[[(]" new-value))
1076 (setq new-value (read new-value)))
1077 new-value))
1078
1079
1080 (defun read-face-font (face &optional frame)
1081 "Read the name of a font for FACE on FRAME.
1082 If optional argument FRAME Is nil or omitted, use the selected frame."
1083 (let ((completion-ignore-case t))
1084 (completing-read (format "Set font attributes of face `%s' from font: " face)
1085 (x-list-fonts "*" nil frame))))
1086
1087
1088 (defun read-all-face-attributes (face &optional frame)
1089 "Interactively read all attributes for FACE.
1090 If optional argument FRAME Is nil or omitted, use the selected frame.
1091 Value is a property list of attribute names and new values."
1092 (let (result)
1093 (dolist (attribute face-attribute-name-alist result)
1094 (setq result (cons (car attribute)
1095 (cons (read-face-attribute face (car attribute) frame)
1096 result))))))
1097
1098 (defun modify-face (&optional face foreground background stipple
1099 bold-p italic-p underline-p inverse-p frame)
1100 "Modify attributes of faces interactively.
1101 If optional argument FRAME is nil or omitted, modify the face used
1102 for newly created frame, i.e. the global face.
1103 For non-interactive use, `set-face-attribute' is preferred.
1104 When called from elisp, if FACE is nil, all arguments but FRAME are ignored
1105 and the face and its settings are obtained by querying the user."
1106 (interactive)
1107 (if face
1108 (set-face-attribute face frame
1109 :foreground (or foreground 'unspecified)
1110 :background (or background 'unspecified)
1111 :stipple stipple
1112 :bold bold-p
1113 :italic italic-p
1114 :underline underline-p
1115 :inverse-video inverse-p)
1116 (setq face (read-face-name "Modify face"))
1117 (apply #'set-face-attribute face frame
1118 (read-all-face-attributes face frame))))
1119
1120 (defun read-face-and-attribute (attribute &optional frame)
1121 "Read face name and face attribute value.
1122 ATTRIBUTE is the attribute whose new value is read.
1123 FRAME nil or unspecified means read attribute value of global face.
1124 Value is a list (FACE NEW-VALUE) where FACE is the face read
1125 \(a symbol), and NEW-VALUE is value read."
1126 (cond ((eq attribute :font)
1127 (let* ((prompt "Set font-related attributes of face")
1128 (face (read-face-name prompt))
1129 (font (read-face-font face frame)))
1130 (list face font)))
1131 (t
1132 (let* ((attribute-name (face-descriptive-attribute-name attribute))
1133 (prompt (format "Set %s of face" attribute-name))
1134 (face (read-face-name prompt))
1135 (new-value (read-face-attribute face attribute frame)))
1136 (list face new-value)))))
1137
1138
1139 \f
1140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1141 ;;; Listing faces.
1142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1143
1144 (defvar list-faces-sample-text
1145 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1146 "*Text string to display as the sample text for `list-faces-display'.")
1147
1148
1149 ;; The name list-faces would be more consistent, but let's avoid a
1150 ;; conflict with Lucid, which uses that name differently.
1151
1152 (defvar help-xref-stack)
1153 (defun list-faces-display (&optional regexp)
1154 "List all faces, using the same sample text in each.
1155 The sample text is a string that comes from the variable
1156 `list-faces-sample-text'.
1157
1158 If REGEXP is non-nil, list only those faces with names matching
1159 this regular expression. When called interactively with a prefix
1160 arg, prompt for a regular expression."
1161 (interactive (list (and current-prefix-arg
1162 (read-string "List faces matching regexp: "))))
1163 (let ((all-faces (zerop (length regexp)))
1164 (frame (selected-frame))
1165 (max-length 0)
1166 faces line-format
1167 disp-frame window face-name)
1168 ;; We filter and take the max length in one pass
1169 (setq faces
1170 (delq nil
1171 (mapcar (lambda (f)
1172 (let ((s (symbol-name f)))
1173 (when (or all-faces (string-match regexp s))
1174 (setq max-length (max (length s) max-length))
1175 f)))
1176 (sort (face-list) #'string-lessp))))
1177 (unless faces
1178 (error "No faces matching \"%s\"" regexp))
1179 (setq max-length (1+ max-length)
1180 line-format (format "%%-%ds" max-length))
1181 (with-output-to-temp-buffer "*Faces*"
1182 (save-excursion
1183 (set-buffer standard-output)
1184 (setq truncate-lines t)
1185 (insert
1186 (substitute-command-keys
1187 (concat
1188 "Use "
1189 (if (display-mouse-p) "\\[help-follow-mouse] or ")
1190 "\\[help-follow] on a face name to customize it\n"
1191 "or on its sample text for a description of the face.\n\n")))
1192 (setq help-xref-stack nil)
1193 (dolist (face faces)
1194 (setq face-name (symbol-name face))
1195 (insert (format line-format face-name))
1196 ;; Hyperlink to a customization buffer for the face. Using
1197 ;; the help xref mechanism may not be the best way.
1198 (save-excursion
1199 (save-match-data
1200 (search-backward face-name)
1201 (setq help-xref-stack-item `(list-faces-display ,regexp))
1202 (help-xref-button 0 'help-customize-face face)))
1203 (let ((beg (point))
1204 (line-beg (line-beginning-position)))
1205 (insert list-faces-sample-text)
1206 ;; Hyperlink to a help buffer for the face.
1207 (save-excursion
1208 (save-match-data
1209 (search-backward list-faces-sample-text)
1210 (help-xref-button 0 'help-face face)))
1211 (insert "\n")
1212 (put-text-property beg (1- (point)) 'face face)
1213 ;; Make all face commands default to the proper face
1214 ;; anywhere in the line.
1215 (put-text-property line-beg (1- (point)) 'read-face-name face)
1216 ;; If the sample text has multiple lines, line up all of them.
1217 (goto-char beg)
1218 (forward-line 1)
1219 (while (not (eobp))
1220 (insert-char ?\s max-length)
1221 (forward-line 1))))
1222 (goto-char (point-min)))
1223 (print-help-return-message))
1224 ;; If the *Faces* buffer appears in a different frame,
1225 ;; copy all the face definitions from FRAME,
1226 ;; so that the display will reflect the frame that was selected.
1227 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1228 (setq disp-frame (if window (window-frame window)
1229 (car (frame-list))))
1230 (or (eq frame disp-frame)
1231 (let ((faces (face-list)))
1232 (while faces
1233 (copy-face (car faces) (car faces) frame disp-frame)
1234 (setq faces (cdr faces)))))))
1235
1236
1237 (defun describe-face (face &optional frame)
1238 "Display the properties of face FACE on FRAME.
1239 Interactively, FACE defaults to the faces of the character after point
1240 and FRAME defaults to the selected frame.
1241
1242 If the optional argument FRAME is given, report on face FACE in that frame.
1243 If FRAME is t, report on the defaults for face FACE (for new frames).
1244 If FRAME is omitted or nil, use the selected frame."
1245 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1246 (let* ((attrs '((:family . "Family")
1247 (:width . "Width")
1248 (:height . "Height")
1249 (:weight . "Weight")
1250 (:slant . "Slant")
1251 (:foreground . "Foreground")
1252 (:background . "Background")
1253 (:underline . "Underline")
1254 (:overline . "Overline")
1255 (:strike-through . "Strike-through")
1256 (:box . "Box")
1257 (:inverse-video . "Inverse")
1258 (:stipple . "Stipple")
1259 (:font . "Font or fontset")
1260 (:inherit . "Inherit")))
1261 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1262 attrs))))
1263 (help-setup-xref (list #'describe-face face) (interactive-p))
1264 (unless face
1265 (setq face 'default))
1266 (if (not (listp face))
1267 (setq face (list face)))
1268 (with-output-to-temp-buffer (help-buffer)
1269 (save-excursion
1270 (set-buffer standard-output)
1271 (dolist (f face)
1272 (insert "Face: " (symbol-name f))
1273 (if (not (facep f))
1274 (insert " undefined face.\n")
1275 (let ((customize-label "customize this face")
1276 file-name)
1277 (princ (concat " (" customize-label ")\n"))
1278 (insert "Documentation: "
1279 (or (face-documentation f)
1280 "Not documented as a face.")
1281 "\n")
1282 (with-current-buffer standard-output
1283 (save-excursion
1284 (re-search-backward
1285 (concat "\\(" customize-label "\\)") nil t)
1286 (help-xref-button 1 'help-customize-face f)))
1287 ;; The next 4 sexps are copied from describe-function-1
1288 ;; and simplified.
1289 (setq file-name (symbol-file f 'defface))
1290 (when file-name
1291 (princ "Defined in `")
1292 (princ file-name)
1293 (princ "'")
1294 ;; Make a hyperlink to the library.
1295 (save-excursion
1296 (re-search-backward "`\\([^`']+\\)'" nil t)
1297 (help-xref-button 1 'help-face-def f file-name))
1298 (princ ".")
1299 (terpri)
1300 (terpri))
1301 (dolist (a attrs)
1302 (let ((attr (face-attribute f (car a) frame)))
1303 (insert (make-string (- max-width (length (cdr a))) ?\ )
1304 (cdr a) ": " (format "%s" attr) "\n")))))
1305 (terpri)))
1306 (print-help-return-message))))
1307
1308 \f
1309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1310 ;;; Face specifications (defface).
1311 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1312
1313 ;; Parameter FRAME Is kept for call compatibility to with previous
1314 ;; face implementation.
1315
1316 (defun face-attr-construct (face &optional frame)
1317 "Return a defface-style attribute list for FACE on FRAME.
1318 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1319 face attributes of FACE where ATTRIBUTE is the attribute name and
1320 VALUE is the specified value of that attribute."
1321 (let (result)
1322 (dolist (entry face-attribute-name-alist result)
1323 (let* ((attribute (car entry))
1324 (value (face-attribute face attribute)))
1325 (unless (eq value 'unspecified)
1326 (setq result (nconc (list attribute value) result)))))))
1327
1328
1329 (defun face-spec-set-match-display (display frame)
1330 "Non-nil if DISPLAY matches FRAME.
1331 DISPLAY is part of a spec such as can be used in `defface'.
1332 If FRAME is nil, the current FRAME is used."
1333 (let* ((conjuncts display)
1334 conjunct req options
1335 ;; t means we have succeeded against all the conjuncts in
1336 ;; DISPLAY that have been tested so far.
1337 (match t))
1338 (if (eq conjuncts t)
1339 (setq conjuncts nil))
1340 (while (and conjuncts match)
1341 (setq conjunct (car conjuncts)
1342 conjuncts (cdr conjuncts)
1343 req (car conjunct)
1344 options (cdr conjunct)
1345 match (cond ((eq req 'type)
1346 (or (memq window-system options)
1347 ;; FIXME: This should be revisited to use
1348 ;; display-graphic-p, provided that the
1349 ;; color selection depends on the number
1350 ;; of supported colors, and all defface's
1351 ;; are changed to look at number of colors
1352 ;; instead of (type graphic) etc.
1353 (and (null window-system)
1354 (memq 'tty options))
1355 (and (memq 'motif options)
1356 (featurep 'motif))
1357 (and (memq 'gtk options)
1358 (featurep 'gtk))
1359 (and (memq 'lucid options)
1360 (featurep 'x-toolkit)
1361 (not (featurep 'motif))
1362 (not (featurep 'gtk)))
1363 (and (memq 'x-toolkit options)
1364 (featurep 'x-toolkit))))
1365 ((eq req 'min-colors)
1366 (>= (display-color-cells frame) (car options)))
1367 ((eq req 'class)
1368 (memq (frame-parameter frame 'display-type) options))
1369 ((eq req 'background)
1370 (memq (frame-parameter frame 'background-mode)
1371 options))
1372 ((eq req 'supports)
1373 (display-supports-face-attributes-p options frame))
1374 (t (error "Unknown req `%S' with options `%S'"
1375 req options)))))
1376 match))
1377
1378
1379 (defun face-spec-choose (spec &optional frame)
1380 "Choose the proper attributes for FRAME, out of SPEC.
1381 If SPEC is nil, return nil."
1382 (unless frame
1383 (setq frame (selected-frame)))
1384 (let ((tail spec)
1385 result defaults)
1386 (while tail
1387 (let* ((entry (pop tail))
1388 (display (car entry))
1389 (attrs (cdr entry))
1390 thisval)
1391 ;; Get the attributes as actually specified by this alternative.
1392 (setq thisval
1393 (if (null (cdr attrs)) ;; was (listp (car attrs))
1394 ;; Old-style entry, the attribute list is the
1395 ;; first element.
1396 (car attrs)
1397 attrs))
1398
1399 ;; If the condition is `default', that sets the default
1400 ;; for following conditions.
1401 (if (eq display 'default)
1402 (setq defaults thisval)
1403 ;; Otherwise, if it matches, use it.
1404 (when (face-spec-set-match-display display frame)
1405 (setq result thisval)
1406 (setq tail nil)))))
1407 (if defaults (append result defaults) result)))
1408
1409
1410 (defun face-spec-reset-face (face &optional frame)
1411 "Reset all attributes of FACE on FRAME to unspecified."
1412 (let ((attrs face-attribute-name-alist))
1413 (while attrs
1414 (let ((attr-and-name (car attrs)))
1415 (set-face-attribute face frame (car attr-and-name) 'unspecified))
1416 (setq attrs (cdr attrs)))))
1417
1418
1419 (defun face-spec-set (face spec &optional frame)
1420 "Set FACE's attributes according to the first matching entry in SPEC.
1421 FRAME is the frame whose frame-local face is set. FRAME nil means
1422 do it on all frames. See `defface' for information about SPEC.
1423 If SPEC is nil, do nothing."
1424 (let ((attrs (face-spec-choose spec frame)))
1425 (when attrs
1426 (face-spec-reset-face face frame))
1427 (while attrs
1428 (let ((attribute (car attrs))
1429 (value (car (cdr attrs))))
1430 ;; Support some old-style attribute names and values.
1431 (case attribute
1432 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1433 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1434 ((:foreground :background)
1435 ;; Compatibility with 20.x. Some bogus face specs seem to
1436 ;; exist containing things like `:foreground nil'.
1437 (if (null value) (setq value 'unspecified)))
1438 (t (unless (assq attribute face-x-resources)
1439 (setq attribute nil))))
1440 (when attribute
1441 (set-face-attribute face frame attribute value)))
1442 (setq attrs (cdr (cdr attrs)))))
1443 ;; When we reset the face based on its spec, then it is unmodified
1444 ;; as far as Custom is concerned.
1445 (if (null frame)
1446 (put face 'face-modified nil)))
1447
1448
1449 (defun face-attr-match-p (face attrs &optional frame)
1450 "Return t if attributes of FACE match values in plist ATTRS.
1451 Optional parameter FRAME is the frame whose definition of FACE
1452 is used. If nil or omitted, use the selected frame."
1453 (unless frame
1454 (setq frame (selected-frame)))
1455 (let ((list face-attribute-name-alist)
1456 (match t))
1457 (while (and match (not (null list)))
1458 (let* ((attr (car (car list)))
1459 (specified-value
1460 (if (plist-member attrs attr)
1461 (plist-get attrs attr)
1462 'unspecified))
1463 (value-now (face-attribute face attr frame)))
1464 (setq match (equal specified-value value-now))
1465 (setq list (cdr list))))
1466 match))
1467
1468 (defun face-spec-match-p (face spec &optional frame)
1469 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1470 (face-attr-match-p face (face-spec-choose spec frame) frame))
1471
1472 (defsubst face-default-spec (face)
1473 "Return the default face-spec for FACE, ignoring any user customization.
1474 If there is no default for FACE, return nil."
1475 (get face 'face-defface-spec))
1476
1477 (defsubst face-user-default-spec (face)
1478 "Return the user's customized face-spec for FACE, or the default if none.
1479 If there is neither a user setting nor a default for FACE, return nil."
1480 (or (get face 'customized-face)
1481 (get face 'saved-face)
1482 (face-default-spec face)))
1483
1484 \f
1485 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1486 ;;; Frame-type independent color support.
1487 ;;; We keep the old x-* names as aliases for back-compatibility.
1488 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1489
1490 (defun defined-colors (&optional frame)
1491 "Return a list of colors supported for a particular frame.
1492 The argument FRAME specifies which frame to try.
1493 The value may be different for frames on different display types.
1494 If FRAME doesn't support colors, the value is nil."
1495 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1496 (xw-defined-colors frame)
1497 (mapcar 'car (tty-color-alist frame))))
1498 (defalias 'x-defined-colors 'defined-colors)
1499
1500 (defun color-defined-p (color &optional frame)
1501 "Return non-nil if color COLOR is supported on frame FRAME.
1502 If FRAME is omitted or nil, use the selected frame.
1503 If COLOR is the symbol `unspecified' or one of the strings
1504 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1505 (if (member color '(unspecified "unspecified-bg" "unspecified-fg"))
1506 nil
1507 (if (member (framep (or frame (selected-frame))) '(x w32 mac))
1508 (xw-color-defined-p color frame)
1509 (numberp (tty-color-translate color frame)))))
1510 (defalias 'x-color-defined-p 'color-defined-p)
1511
1512 (defun color-values (color &optional frame)
1513 "Return a description of the color named COLOR on frame FRAME.
1514 The value is a list of integer RGB values--\(RED GREEN BLUE\).
1515 These values appear to range from 0 65535; white is \(65535 65535 65535\).
1516 If FRAME is omitted or nil, use the selected frame.
1517 If FRAME cannot display COLOR, the value is nil.
1518 If COLOR is the symbol `unspecified' or one of the strings
1519 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1520 (if (member color '(unspecified "unspecified-fg" "unspecified-bg"))
1521 nil
1522 (if (memq (framep (or frame (selected-frame))) '(x w32 mac))
1523 (xw-color-values color frame)
1524 (tty-color-values color frame))))
1525 (defalias 'x-color-values 'color-values)
1526
1527 (defun display-color-p (&optional display)
1528 "Return t if DISPLAY supports color.
1529 The optional argument DISPLAY specifies which display to ask about.
1530 DISPLAY should be either a frame or a display name (a string).
1531 If omitted or nil, that stands for the selected frame's display."
1532 (if (memq (framep-on-display display) '(x w32 mac))
1533 (xw-display-color-p display)
1534 (tty-display-color-p display)))
1535 (defalias 'x-display-color-p 'display-color-p)
1536
1537 (defun display-grayscale-p (&optional display)
1538 "Return non-nil if frames on DISPLAY can display shades of gray."
1539 (let ((frame-type (framep-on-display display)))
1540 (cond
1541 ((memq frame-type '(x w32 mac))
1542 (x-display-grayscale-p display))
1543 (t
1544 (> (tty-color-gray-shades display) 2)))))
1545
1546 \f
1547 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1548 ;;; Background mode.
1549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1550
1551 (defcustom frame-background-mode nil
1552 "*The brightness of the background.
1553 Set this to the symbol `dark' if your background color is dark,
1554 `light' if your background is light, or nil (default) if you want Emacs
1555 to examine the brightness for you. Don't set this variable with `setq';
1556 this won't have the expected effect."
1557 :group 'faces
1558 :set #'(lambda (var value)
1559 (set-default var value)
1560 (mapc 'frame-set-background-mode (frame-list)))
1561 :initialize 'custom-initialize-changed
1562 :type '(choice (choice-item dark)
1563 (choice-item light)
1564 (choice-item :tag "default" nil)))
1565
1566
1567 (defun frame-set-background-mode (frame)
1568 "Set up display-dependent faces on FRAME.
1569 Display-dependent faces are those which have different definitions
1570 according to the `background-mode' and `display-type' frame parameters."
1571 (let* ((bg-resource
1572 (and window-system
1573 (x-get-resource "backgroundMode" "BackgroundMode")))
1574 (bg-color (frame-parameter frame 'background-color))
1575 (bg-mode
1576 (cond (frame-background-mode)
1577 (bg-resource
1578 (intern (downcase bg-resource)))
1579 ((and (null window-system) (null bg-color))
1580 ;; No way to determine this automatically (?).
1581 'dark)
1582 ;; Unspecified frame background color can only happen
1583 ;; on tty's.
1584 ((member bg-color '(unspecified "unspecified-bg"))
1585 'dark)
1586 ((equal bg-color "unspecified-fg") ; inverted colors
1587 'light)
1588 ((>= (apply '+ (x-color-values bg-color frame))
1589 ;; Just looking at the screen, colors whose
1590 ;; values add up to .6 of the white total
1591 ;; still look dark to me.
1592 (* (apply '+ (x-color-values "white" frame)) .6))
1593 'light)
1594 (t 'dark)))
1595 (display-type
1596 (cond ((null window-system)
1597 (if (tty-display-color-p frame) 'color 'mono))
1598 ((x-display-color-p frame)
1599 'color)
1600 ((x-display-grayscale-p frame)
1601 'grayscale)
1602 (t 'mono)))
1603 (old-bg-mode
1604 (frame-parameter frame 'background-mode))
1605 (old-display-type
1606 (frame-parameter frame 'display-type)))
1607
1608 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type))
1609 (let ((locally-modified-faces nil))
1610 ;; Before modifying the frame parameters, we collect a list of
1611 ;; faces that don't match what their face-spec says they should
1612 ;; look like; we then avoid changing these faces below. A
1613 ;; negative list is used on the assumption that most faces will
1614 ;; be unmodified, so we can avoid consing in the common case.
1615 (dolist (face (face-list))
1616 (when (not (face-spec-match-p face
1617 (face-user-default-spec face)
1618 (selected-frame)))
1619 (push face locally-modified-faces)))
1620 ;; Now change to the new frame parameters
1621 (modify-frame-parameters frame
1622 (list (cons 'background-mode bg-mode)
1623 (cons 'display-type display-type)))
1624 ;; For all named faces, choose face specs matching the new frame
1625 ;; parameters, unless they have been locally modified.
1626 (dolist (face (face-list))
1627 (unless (memq face locally-modified-faces)
1628 (face-spec-set face (face-user-default-spec face) frame)))))))
1629
1630 \f
1631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1632 ;;; Frame creation.
1633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1634
1635 (defun x-handle-named-frame-geometry (parameters)
1636 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1637 Value is the new parameter list."
1638 (let* ((name (or (cdr (assq 'name parameters))
1639 (cdr (assq 'name default-frame-alist))))
1640 (x-resource-name name)
1641 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1642 (when res-geometry
1643 (let ((parsed (x-parse-geometry res-geometry)))
1644 ;; If the resource specifies a position, call the position
1645 ;; and size "user-specified".
1646 (when (or (assq 'top parsed)
1647 (assq 'left parsed))
1648 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1649 ;; Put the geometry parameters at the end. Copy
1650 ;; default-frame-alist so that they go after it.
1651 (setq parameters (append parameters default-frame-alist parsed))))
1652 parameters))
1653
1654
1655 (defun x-handle-reverse-video (frame parameters)
1656 "Handle the reverse-video frame parameter and X resource.
1657 `x-create-frame' does not handle this one."
1658 (when (cdr (or (assq 'reverse parameters)
1659 (assq 'reverse default-frame-alist)
1660 (let ((resource (x-get-resource "reverseVideo"
1661 "ReverseVideo")))
1662 (if resource
1663 (cons nil (member (downcase resource)
1664 '("on" "true")))))))
1665 (let* ((params (frame-parameters frame))
1666 (bg (cdr (assq 'foreground-color params)))
1667 (fg (cdr (assq 'background-color params))))
1668 (modify-frame-parameters frame
1669 (list (cons 'foreground-color fg)
1670 (cons 'background-color bg)))
1671 (if (equal bg (cdr (assq 'border-color params)))
1672 (modify-frame-parameters frame
1673 (list (cons 'border-color fg))))
1674 (if (equal bg (cdr (assq 'mouse-color params)))
1675 (modify-frame-parameters frame
1676 (list (cons 'mouse-color fg))))
1677 (if (equal bg (cdr (assq 'cursor-color params)))
1678 (modify-frame-parameters frame
1679 (list (cons 'cursor-color fg)))))))
1680
1681
1682 (defun x-create-frame-with-faces (&optional parameters)
1683 "Create a frame from optional frame parameters PARAMETERS.
1684 Parameters not specified by PARAMETERS are taken from
1685 `default-frame-alist'. If PARAMETERS specify a frame name,
1686 handle X geometry resources for that name. If either PARAMETERS
1687 or `default-frame-alist' contains a `reverse' parameter, or
1688 the X resource ``reverseVideo'' is present, handle that.
1689 Value is the new frame created."
1690 (setq parameters (x-handle-named-frame-geometry parameters))
1691 (let ((visibility-spec (assq 'visibility parameters))
1692 (frame-list (frame-list))
1693 (frame (x-create-frame (cons '(visibility . nil) parameters)))
1694 success)
1695 (unwind-protect
1696 (progn
1697 (x-handle-reverse-video frame parameters)
1698 (frame-set-background-mode frame)
1699 (face-set-after-frame-default frame)
1700 (if (or (null frame-list) (null visibility-spec))
1701 (make-frame-visible frame)
1702 (modify-frame-parameters frame (list visibility-spec)))
1703 (setq success t))
1704 (unless success
1705 (delete-frame frame)))
1706 frame))
1707
1708
1709 (defun face-set-after-frame-default (frame)
1710 "Set frame-local faces of FRAME from face specs and resources.
1711 Initialize colors of certain faces from frame parameters."
1712 (if (face-attribute 'default :font t)
1713 (set-face-attribute 'default frame :font
1714 (face-attribute 'default :font t))
1715 (set-face-attribute 'default frame :family
1716 (face-attribute 'default :family t))
1717 (set-face-attribute 'default frame :height
1718 (face-attribute 'default :height t))
1719 (set-face-attribute 'default frame :slant
1720 (face-attribute 'default :slant t))
1721 (set-face-attribute 'default frame :weight
1722 (face-attribute 'default :weight t))
1723 (set-face-attribute 'default frame :width
1724 (face-attribute 'default :width t)))
1725 (dolist (face (face-list))
1726 ;; Don't let frame creation fail because of an invalid face spec.
1727 (condition-case ()
1728 (when (not (equal face 'default))
1729 (face-spec-set face (face-user-default-spec face) frame)
1730 (internal-merge-in-global-face face frame)
1731 (when (and (memq window-system '(x w32 mac))
1732 (or (not (boundp 'inhibit-default-face-x-resources))
1733 (not (eq face 'default))))
1734 (make-face-x-resource-internal face frame)))
1735 (error nil)))
1736 ;; Initialize attributes from frame parameters.
1737 (let ((params '((foreground-color default :foreground)
1738 (background-color default :background)
1739 (border-color border :background)
1740 (cursor-color cursor :background)
1741 (scroll-bar-foreground scroll-bar :foreground)
1742 (scroll-bar-background scroll-bar :background)
1743 (mouse-color mouse :background))))
1744 (dolist (param params)
1745 (let ((frame-param (frame-parameter frame (nth 0 param)))
1746 (face (nth 1 param))
1747 (attr (nth 2 param)))
1748 (when (and frame-param
1749 ;; Don't override face attributes explicitly
1750 ;; specified for new frames.
1751 (eq (face-attribute face attr t) 'unspecified))
1752 (set-face-attribute face frame attr frame-param))))))
1753
1754
1755 (defun tty-handle-reverse-video (frame parameters)
1756 "Handle the reverse-video frame parameter for terminal frames."
1757 (when (cdr (or (assq 'reverse parameters)
1758 (assq 'reverse default-frame-alist)))
1759 (let* ((params (frame-parameters frame))
1760 (bg (cdr (assq 'foreground-color params)))
1761 (fg (cdr (assq 'background-color params))))
1762 (modify-frame-parameters frame
1763 (list (cons 'foreground-color fg)
1764 (cons 'background-color bg)))
1765 (if (equal bg (cdr (assq 'mouse-color params)))
1766 (modify-frame-parameters frame
1767 (list (cons 'mouse-color fg))))
1768 (if (equal bg (cdr (assq 'cursor-color params)))
1769 (modify-frame-parameters frame
1770 (list (cons 'cursor-color fg)))))))
1771
1772
1773 (defun tty-create-frame-with-faces (&optional parameters)
1774 "Create a frame from optional frame parameters PARAMETERS.
1775 Parameters not specified by PARAMETERS are taken from
1776 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
1777 contains a `reverse' parameter, handle that. Value is the new frame
1778 created."
1779 (let ((frame (make-terminal-frame parameters))
1780 success)
1781 (unwind-protect
1782 (progn
1783 (tty-handle-reverse-video frame (frame-parameters frame))
1784 (frame-set-background-mode frame)
1785 (face-set-after-frame-default frame)
1786 (setq success t))
1787 (unless success
1788 (delete-frame frame)))
1789 frame))
1790
1791
1792 ;; Called from C function init_display to initialize faces of the
1793 ;; dumped terminal frame on startup.
1794
1795 (defun tty-set-up-initial-frame-faces ()
1796 (let ((frame (selected-frame)))
1797 (frame-set-background-mode frame)
1798 (face-set-after-frame-default frame)))
1799
1800
1801
1802 \f
1803 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1804 ;;; Compatiblity with 20.2
1805 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1806
1807 ;; Update a frame's faces when we change its default font.
1808
1809 (defalias 'frame-update-faces 'ignore "")
1810 (make-obsolete 'frame-update-faces "no longer necessary." "21.1")
1811
1812 ;; Update the colors of FACE, after FRAME's own colors have been
1813 ;; changed.
1814
1815 (defalias 'frame-update-face-colors 'frame-set-background-mode)
1816 (make-obsolete 'frame-update-face-colors 'frame-set-background-mode "21.1")
1817
1818 \f
1819 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1820 ;;; Standard faces.
1821 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1822
1823 (defgroup basic-faces nil
1824 "The standard faces of Emacs."
1825 :group 'faces)
1826
1827
1828 (defface default
1829 '((t nil))
1830 "Basic default face."
1831 :group 'basic-faces)
1832
1833
1834 (defface mode-line
1835 '((((class color) (min-colors 88))
1836 :box (:line-width -1 :style released-button)
1837 :background "grey75" :foreground "black")
1838 (t
1839 :inverse-video t))
1840 "Basic mode line face for selected window."
1841 :version "21.1"
1842 :group 'modeline
1843 :group 'basic-faces)
1844
1845 (defface mode-line-inactive
1846 '((default
1847 :inherit mode-line)
1848 (((class color) (min-colors 88) (background light))
1849 :weight light
1850 :box (:line-width -1 :color "grey75" :style nil)
1851 :foreground "grey20" :background "grey90")
1852 (((class color) (min-colors 88) (background dark) )
1853 :weight light
1854 :box (:line-width -1 :color "grey40" :style nil)
1855 :foreground "grey80" :background "grey30"))
1856 "Basic mode line face for non-selected windows."
1857 :version "22.1"
1858 :group 'modeline
1859 :group 'basic-faces)
1860
1861 (defface mode-line-highlight
1862 '((((class color) (min-colors 88) (background light))
1863 :background "RoyalBlue4" :foreground "white")
1864 (((class color) (min-colors 88) (background dark))
1865 :background "light sky blue" :foreground "black")
1866 (t
1867 :inverse-video t))
1868 "Basic mode line face for highlighting."
1869 :version "22.1"
1870 :group 'modeline
1871 :group 'basic-faces)
1872
1873 (defface vertical-border
1874 '((default :inherit mode-line-inactive))
1875 "Face used for vertical window dividers on ttys."
1876 :version "22.1"
1877 :group 'modeline
1878 :group 'basic-faces)
1879
1880 ;; Make `modeline' an alias for `mode-line', for compatibility.
1881 (put 'modeline 'face-alias 'mode-line)
1882 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
1883 (put 'modeline-highlight 'face-alias 'mode-line-highlight)
1884
1885 (defface header-line
1886 '((default
1887 :inherit mode-line)
1888 (((type tty))
1889 ;; This used to be `:inverse-video t', but that doesn't look very
1890 ;; good when combined with inverse-video mode-lines and multiple
1891 ;; windows. Underlining looks better, and is more consistent with
1892 ;; the window-system face variants, which deemphasize the
1893 ;; header-line in relation to the mode-line face. If a terminal
1894 ;; can't underline, then the header-line will end up without any
1895 ;; highlighting; this may be too confusing in general, although it
1896 ;; happens to look good with the only current use of header-lines,
1897 ;; the info browser. XXX
1898 :inverse-video nil ;Override the value inherited from mode-line.
1899 :underline t)
1900 (((class color grayscale) (background light))
1901 :background "grey90" :foreground "grey20"
1902 :box nil)
1903 (((class color grayscale) (background dark))
1904 :background "grey20" :foreground "grey90"
1905 :box nil)
1906 (((class mono) (background light))
1907 :background "white" :foreground "black"
1908 :inverse-video nil
1909 :box nil
1910 :underline t)
1911 (((class mono) (background dark))
1912 :background "black" :foreground "white"
1913 :inverse-video nil
1914 :box nil
1915 :underline t))
1916 "Basic header-line face."
1917 :version "21.1"
1918 :group 'basic-faces)
1919
1920
1921 (defface tool-bar
1922 '((default
1923 :box (:line-width 1 :style released-button)
1924 :foreground "black")
1925 (((type x w32 mac) (class color))
1926 :background "grey75")
1927 (((type x) (class mono))
1928 :background "grey"))
1929 "Basic tool-bar face."
1930 :version "21.1"
1931 :group 'basic-faces)
1932
1933
1934 (defface minibuffer-prompt '((((background dark)) :foreground "cyan")
1935 ;; Don't use blue because many users of
1936 ;; the MS-DOS port customize their
1937 ;; foreground color to be blue.
1938 (((type pc)) :foreground "magenta")
1939 (t :foreground "dark blue"))
1940 "Face for minibuffer prompts."
1941 :version "22.1"
1942 :group 'basic-faces)
1943
1944 (setq minibuffer-prompt-properties
1945 (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt)))
1946
1947 (defface region
1948 '((((class color) (min-colors 88) (background dark))
1949 :background "blue3")
1950 (((class color) (min-colors 88) (background light))
1951 :background "lightgoldenrod2")
1952 (((class color) (min-colors 16) (background dark))
1953 :background "blue3")
1954 (((class color) (min-colors 16) (background light))
1955 :background "lightgoldenrod2")
1956 (((class color) (min-colors 8))
1957 :background "blue" :foreground "white")
1958 (((type tty) (class mono))
1959 :inverse-video t)
1960 (t :background "gray"))
1961 "Basic face for highlighting the region."
1962 :version "21.1"
1963 :group 'basic-faces)
1964
1965
1966 (defface fringe
1967 '((((class color) (background light))
1968 :background "grey95")
1969 (((class color) (background dark))
1970 :background "grey10")
1971 (t
1972 :background "gray"))
1973 "Basic face for the fringes to the left and right of windows under X."
1974 :version "21.1"
1975 :group 'frames
1976 :group 'basic-faces)
1977
1978
1979 (defface scroll-bar '()
1980 "Basic face for the scroll bar colors under X."
1981 :version "21.1"
1982 :group 'frames
1983 :group 'basic-faces)
1984
1985
1986 (defface menu
1987 '((((type tty))
1988 :inverse-video t)
1989 (((type x-toolkit))
1990 )
1991 (t
1992 :inverse-video t))
1993 "Basic face for the font and colors of the menu bar and popup menus."
1994 :version "21.1"
1995 :group 'menu
1996 :group 'basic-faces)
1997
1998
1999 (defface border '()
2000 "Basic face for the frame border under X."
2001 :version "21.1"
2002 :group 'frames
2003 :group 'basic-faces)
2004
2005
2006 (defface cursor '()
2007 "Basic face for the cursor color under X.
2008 Note: Other faces cannot inherit from the cursor face."
2009 :version "21.1"
2010 :group 'cursor
2011 :group 'basic-faces)
2012
2013 (put 'cursor 'face-no-inherit t)
2014
2015 (defface mouse '()
2016 "Basic face for the mouse color under X."
2017 :version "21.1"
2018 :group 'mouse
2019 :group 'basic-faces)
2020
2021
2022 (defface bold '((t :weight bold))
2023 "Basic bold face."
2024 :group 'basic-faces)
2025
2026
2027 (defface italic
2028 '((((supports :slant italic))
2029 :slant italic)
2030 (((supports :underline t))
2031 :underline t)
2032 (t
2033 ;; default to italic, even it doesn't appear to be supported,
2034 ;; because in some cases the display engine will do it's own
2035 ;; workaround (to `dim' on ttys)
2036 :slant italic))
2037 "Basic italic font."
2038 :group 'basic-faces)
2039
2040
2041 (defface bold-italic '((t :weight bold :slant italic))
2042 "Basic bold-italic face."
2043 :group 'basic-faces)
2044
2045
2046 (defface underline '((((supports :underline t))
2047 :underline t)
2048 (((supports :weight bold))
2049 :weight bold)
2050 (t :underline t))
2051 "Basic underlined face."
2052 :group 'basic-faces)
2053
2054
2055 (defface highlight
2056 '((((class color) (min-colors 88) (background light))
2057 :background "darkseagreen2")
2058 (((class color) (min-colors 88) (background dark))
2059 :background "darkolivegreen")
2060 (((class color) (min-colors 16) (background light))
2061 :background "darkseagreen2")
2062 (((class color) (min-colors 16) (background dark))
2063 :background "darkolivegreen")
2064 (((class color) (min-colors 8))
2065 :background "green" :foreground "black")
2066 (t :inverse-video t))
2067 "Basic face for highlighting."
2068 :group 'basic-faces)
2069
2070
2071 (defface secondary-selection
2072 '((((class color) (min-colors 88) (background light))
2073 :background "yellow1")
2074 (((class color) (min-colors 88) (background dark))
2075 :background "SkyBlue4")
2076 (((class color) (min-colors 16) (background light))
2077 :background "yellow")
2078 (((class color) (min-colors 16) (background dark))
2079 :background "SkyBlue4")
2080 (((class color) (min-colors 8))
2081 :background "cyan" :foreground "black")
2082 (t :inverse-video t))
2083 "Basic face for displaying the secondary selection."
2084 :group 'basic-faces)
2085
2086
2087 (defface fixed-pitch '((t :family "courier"))
2088 "The basic fixed-pitch face."
2089 :group 'basic-faces)
2090
2091
2092 (defface variable-pitch '((t :family "helv"))
2093 "The basic variable-pitch face."
2094 :group 'basic-faces)
2095
2096
2097 (defface trailing-whitespace
2098 '((((class color) (background light))
2099 :background "red1")
2100 (((class color) (background dark))
2101 :background "red1")
2102 (t :inverse-video t))
2103 "Basic face for highlighting trailing whitespace."
2104 :version "21.1"
2105 :group 'whitespace ; like `show-trailing-whitespace'
2106 :group 'basic-faces)
2107
2108 (defface escape-glyph
2109 '((((background dark)) :foreground "cyan")
2110 ;; See the comment in minibuffer-prompt for
2111 ;; the reason not to use blue on MS-DOS.
2112 (((type pc)) :foreground "magenta")
2113 ;; red4 is too light -- rms.
2114 (t :foreground "blue"))
2115 "Face for characters displayed as ^-sequences or \-sequences."
2116 :group 'basic-faces
2117 :version "22.1")
2118
2119 (defface no-break-space
2120 '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
2121 (((class color) (min-colors 8)) :background "magenta" :foreground )
2122 (t :inverse-video t))
2123 "Face for non-breaking space."
2124 :group 'basic-faces
2125 :version "22.1")
2126
2127 (defface shadow
2128 '((((background dark)) :foreground "grey70")
2129 (((background light)) :foreground "grey50"))
2130 "Basic face for shadowed text."
2131 :group 'basic-faces
2132 :version "22.1")
2133
2134 \f
2135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2136 ;;; Manipulating font names.
2137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2138
2139 ;; This is here for compatibilty with Emacs 20.2. For example,
2140 ;; international/fontset.el uses x-resolve-font-name. The following
2141 ;; functions are not used in the face implementation itself.
2142
2143 (defvar x-font-regexp nil)
2144 (defvar x-font-regexp-head nil)
2145 (defvar x-font-regexp-weight nil)
2146 (defvar x-font-regexp-slant nil)
2147
2148 (defconst x-font-regexp-weight-subnum 1)
2149 (defconst x-font-regexp-slant-subnum 2)
2150 (defconst x-font-regexp-swidth-subnum 3)
2151 (defconst x-font-regexp-adstyle-subnum 4)
2152
2153 ;;; Regexps matching font names in "Host Portable Character Representation."
2154 ;;;
2155 (let ((- "[-?]")
2156 (foundry "[^-]+")
2157 (family "[^-]+")
2158 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
2159 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
2160 (weight\? "\\([^-]*\\)") ; 1
2161 (slant "\\([ior]\\)") ; 2
2162 ; (slant\? "\\([ior?*]?\\)") ; 2
2163 (slant\? "\\([^-]?\\)") ; 2
2164 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
2165 (swidth "\\([^-]*\\)") ; 3
2166 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
2167 (adstyle "\\([^-]*\\)") ; 4
2168 (pixelsize "[0-9]+")
2169 (pointsize "[0-9][0-9]+")
2170 (resx "[0-9][0-9]+")
2171 (resy "[0-9][0-9]+")
2172 (spacing "[cmp?*]")
2173 (avgwidth "[0-9]+")
2174 (registry "[^-]+")
2175 (encoding "[^-]+")
2176 )
2177 (setq x-font-regexp
2178 (concat "\\`\\*?[-?*]"
2179 foundry - family - weight\? - slant\? - swidth - adstyle -
2180 pixelsize - pointsize - resx - resy - spacing - avgwidth -
2181 registry - encoding "\\*?\\'"
2182 ))
2183 (setq x-font-regexp-head
2184 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
2185 "\\([-*?]\\|\\'\\)"))
2186 (setq x-font-regexp-slant (concat - slant -))
2187 (setq x-font-regexp-weight (concat - weight -))
2188 nil)
2189
2190
2191 (defun x-resolve-font-name (pattern &optional face frame)
2192 "Return a font name matching PATTERN.
2193 All wildcards in PATTERN are instantiated.
2194 If PATTERN is nil, return the name of the frame's base font, which never
2195 contains wildcards.
2196 Given optional arguments FACE and FRAME, return a font which is
2197 also the same size as FACE on FRAME, or fail."
2198 (or (symbolp face)
2199 (setq face (face-name face)))
2200 (and (eq frame t)
2201 (setq frame nil))
2202 (if pattern
2203 ;; Note that x-list-fonts has code to handle a face with nil as its font.
2204 (let ((fonts (x-list-fonts pattern face frame 1)))
2205 (or fonts
2206 (if face
2207 (if (string-match "\\*" pattern)
2208 (if (null (face-font face))
2209 (error "No matching fonts are the same height as the frame default font")
2210 (error "No matching fonts are the same height as face `%s'" face))
2211 (if (null (face-font face))
2212 (error "Height of font `%s' doesn't match the frame default font"
2213 pattern)
2214 (error "Height of font `%s' doesn't match face `%s'"
2215 pattern face)))
2216 (error "No fonts match `%s'" pattern)))
2217 (car fonts))
2218 (cdr (assq 'font (frame-parameters (selected-frame))))))
2219
2220
2221 (defun x-frob-font-weight (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-weight-subnum))
2226 which
2227 (substring font (match-end x-font-regexp-weight-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 1)) which
2236 (substring font (match-end 1))))
2237 ((string-match x-font-regexp-weight font)
2238 (concat (substring font 0 (match-beginning 1)) which
2239 (substring font (match-end 1)))))))
2240 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
2241
2242 (defun x-frob-font-slant (font which)
2243 (let ((case-fold-search t))
2244 (cond ((string-match x-font-regexp font)
2245 (concat (substring font 0
2246 (match-beginning x-font-regexp-slant-subnum))
2247 which
2248 (substring font (match-end x-font-regexp-slant-subnum)
2249 (match-beginning x-font-regexp-adstyle-subnum))
2250 ;; Replace the ADD_STYLE_NAME field with *
2251 ;; because the info in it may not be the same
2252 ;; for related fonts.
2253 "*"
2254 (substring font (match-end x-font-regexp-adstyle-subnum))))
2255 ((string-match x-font-regexp-head font)
2256 (concat (substring font 0 (match-beginning 2)) which
2257 (substring font (match-end 2))))
2258 ((string-match x-font-regexp-slant font)
2259 (concat (substring font 0 (match-beginning 1)) which
2260 (substring font (match-end 1)))))))
2261 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
2262
2263 ;; These aliases are here so that we don't get warnings about obsolete
2264 ;; functions from the byte compiler.
2265 (defalias 'internal-frob-font-weight 'x-frob-font-weight)
2266 (defalias 'internal-frob-font-slant 'x-frob-font-slant)
2267
2268 (defun x-make-font-bold (font)
2269 "Given an X font specification, make a bold version of it.
2270 If that can't be done, return nil."
2271 (internal-frob-font-weight font "bold"))
2272 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
2273
2274 (defun x-make-font-demibold (font)
2275 "Given an X font specification, make a demibold version of it.
2276 If that can't be done, return nil."
2277 (internal-frob-font-weight font "demibold"))
2278 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
2279
2280 (defun x-make-font-unbold (font)
2281 "Given an X font specification, make a non-bold version of it.
2282 If that can't be done, return nil."
2283 (internal-frob-font-weight font "medium"))
2284 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
2285
2286 (defun x-make-font-italic (font)
2287 "Given an X font specification, make an italic version of it.
2288 If that can't be done, return nil."
2289 (internal-frob-font-slant font "i"))
2290 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
2291
2292 (defun x-make-font-oblique (font) ; you say tomayto...
2293 "Given an X font specification, make an oblique version of it.
2294 If that can't be done, return nil."
2295 (internal-frob-font-slant font "o"))
2296 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
2297
2298 (defun x-make-font-unitalic (font)
2299 "Given an X font specification, make a non-italic version of it.
2300 If that can't be done, return nil."
2301 (internal-frob-font-slant font "r"))
2302 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
2303
2304 (defun x-make-font-bold-italic (font)
2305 "Given an X font specification, make a bold and italic version of it.
2306 If that can't be done, return nil."
2307 (and (setq font (internal-frob-font-weight font "bold"))
2308 (internal-frob-font-slant font "i")))
2309 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
2310
2311 (provide 'faces)
2312
2313 ;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
2314 ;;; faces.el ends here