]> code.delx.au - gnu-emacs/blob - lisp/faces.el
(set-face-attribute):
[gnu-emacs] / lisp / faces.el
1 ;;; faces.el --- Lisp faces
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000
4 ;; Free Software Foundation, Inc.
5
6 ;; This file is part of GNU Emacs.
7
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile
28 (require 'cl))
29
30 (require 'cus-face)
31
32 \f
33 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 ;;; Font selection.
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36
37 (defgroup font-selection nil
38 "Influencing face font selection."
39 :group 'faces)
40
41
42 (defcustom face-font-selection-order
43 '(:width :height :weight :slant)
44 "*A list specifying how face font selection chooses fonts.
45 Each of the four symbols `:width', `:height', `:weight', and `:slant'
46 must appear once in the list, and the list must not contain any other
47 elements. Font selection tries to find a best matching font for
48 those face attributes first that appear first in the list. For
49 example, if `:slant' appears before `:height', font selection first
50 tries to find a font with a suitable slant, even if this results in
51 a font height that isn't optimal."
52 :tag "Font selection order."
53 :type '(list symbol symbol symbol symbol)
54 :group 'font-selection
55 :set #'(lambda (symbol value)
56 (set-default symbol value)
57 (internal-set-font-selection-order value)))
58
59 ;; This is defined originally in {w32,x}faces.c.
60 (defcustom face-font-family-alternatives
61 '(("courier" "fixed")
62 ("helv" "helvetica" "arial" "fixed"))
63 "*Alist of alternative font family names.
64 Each element has the the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
65 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
66 ALTERNATIVE2 etc."
67 :tag "Alternative font families to try."
68 :type '(repeat (repeat string))
69 :group 'font-selection
70 :set #'(lambda (symbol value)
71 (set-default symbol value)
72 (internal-set-alternative-font-family-alist value)))
73
74
75 \f
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ;;; Creation, copying.
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79
80
81 (defun face-list ()
82 "Return a list of all defined face names."
83 (mapcar #'car face-new-frame-defaults))
84
85
86 ;;; ### If not frame-local initialize by what X resources?
87
88 (defun make-face (face &optional no-init-from-resources)
89 "Define a new face with name FACE, a symbol.
90 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
91 variants of FACE from X resources. (X resources recognized are found
92 in the global variable `face-x-resources'.) If FACE is already known
93 as a face, leave it unmodified. Value is FACE."
94 (interactive "SMake face: ")
95 (unless (facep face)
96 ;; Make frame-local faces (this also makes the global one).
97 (dolist (frame (frame-list))
98 (internal-make-lisp-face face frame))
99 ;; Add the face to the face menu.
100 (when (fboundp 'facemenu-add-new-face)
101 (facemenu-add-new-face face))
102 ;; Define frame-local faces for all frames from X resources.
103 (unless no-init-from-resources
104 (make-face-x-resource-internal face)))
105 face)
106
107
108 (defun make-empty-face (face)
109 "Define a new, empty face with name FACE.
110 If the face already exists, it is left unmodified. Value is FACE."
111 (interactive "SMake empty face: ")
112 (make-face face 'no-init-from-resources))
113
114
115 (defun copy-face (old-face new-face &optional frame new-frame)
116 "Define a face just like OLD-FACE, with name NEW-FACE.
117
118 If NEW-FACE already exists as a face, it is modified to be like
119 OLD-FACE. If it doesn't already exist, it is created.
120
121 If the optional argument FRAME is given as a frame, NEW-FACE is
122 changed on FRAME only.
123 If FRAME is t, the frame-independent default specification for OLD-FACE
124 is copied to NEW-FACE.
125 If FRAME is nil, copying is done for the frame-independent defaults
126 and for each existing frame.
127
128 If the optional fourth argument NEW-FRAME is given,
129 copy the information from face OLD-FACE on frame FRAME
130 to NEW-FACE on frame NEW-FRAME."
131 (let ((inhibit-quit t))
132 (if (null frame)
133 (progn
134 (dolist (frame (frame-list))
135 (copy-face old-face new-face frame))
136 (copy-face old-face new-face t))
137 (internal-copy-lisp-face old-face new-face frame new-frame))
138 new-face))
139
140
141 \f
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143 ;;; Obsolete functions
144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145
146 ;; The functions in this section are defined because Lisp packages use
147 ;; them, despite the prefix `internal-' suggesting that they are
148 ;; private to the face implementation.
149
150 (defun internal-find-face (name &optional frame)
151 "Retrieve the face named NAME.
152 Return nil if there is no such face.
153 If the optional argument FRAME is given, this gets the face NAME for
154 that frame; otherwise, it uses the selected frame.
155 If FRAME is the symbol t, then the global, non-frame face is returned.
156 If NAME is already a face, it is simply returned.
157
158 This function is defined for compatibility with Emacs 20.2. It
159 should not be used anymore."
160 (facep name))
161 (make-obsolete 'internal-find-face 'facep "21.1")
162
163
164 (defun internal-get-face (name &optional frame)
165 "Retrieve the face named NAME; error if there is none.
166 If the optional argument FRAME is given, this gets the face NAME for
167 that frame; otherwise, it uses the selected frame.
168 If FRAME is the symbol t, then the global, non-frame face is returned.
169 If NAME is already a face, it is simply returned.
170
171 This function is defined for compatibility with Emacs 20.2. It
172 should not be used anymore."
173 (or (internal-find-face name frame)
174 (check-face name)))
175 (make-obsolete 'internal-get-face "See `facep' and `check-face'." "21.1")
176
177 \f
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179 ;;; Predicates, type checks.
180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
181
182 (defun facep (face)
183 "Return non-nil if FACE is a face name."
184 (internal-lisp-face-p face))
185
186
187 (defun check-face (face)
188 "Signal an error if FACE doesn't name a face.
189 Value is FACE."
190 (unless (facep face)
191 (error "Not a face: %s" face))
192 face)
193
194
195 ;; The ID returned is not to be confused with the internally used IDs
196 ;; of realized faces. The ID assigned to Lisp faces is used to
197 ;; support faces in display table entries.
198
199 (defun face-id (face &optional frame)
200 "Return the interNal ID of face with name FACE.
201 If optional argument FRAME is nil or omitted, use the selected frame."
202 (check-face face)
203 (get face 'face))
204
205
206 (defun face-equal (face1 face2 &optional frame)
207 "Non-nil if faces FACE1 and FACE2 are equal.
208 Faces are considered equal if all their attributes are equal.
209 If the optional argument FRAME is given, report on face FACE in that frame.
210 If FRAME is t, report on the defaults for face FACE (for new frames).
211 If FRAME is omitted or nil, use the selected frame."
212 (internal-lisp-face-equal-p face1 face2 frame))
213
214
215 (defun face-differs-from-default-p (face &optional frame)
216 "Non-nil if FACE displays differently from the default face.
217 If the optional argument FRAME is given, report on face FACE in that frame.
218 If FRAME is t, report on the defaults for face FACE (for new frames).
219 If FRAME is omitted or nil, use the selected frame.
220 A face is considered to be ``the same'' as the default face if it is
221 actually specified in the same way (equal attributes) or if it is
222 fully-unspecified, and thus inherits the attributes of any face it
223 is displayed on top of."
224 (cond ((eq frame t) (setq frame nil))
225 ((null frame) (setq frame (selected-frame))))
226 (let* ((v1 (internal-lisp-face-p face frame))
227 (n (if v1 (length v1) 0))
228 (v2 (internal-lisp-face-p 'default frame))
229 (i 1))
230 (unless v1
231 (error "Not a face: %S" face))
232 (while (and (< i n)
233 (or (eq 'unspecified (aref v1 i))
234 (equal (aref v1 i) (aref v2 i))))
235 (setq i (1+ i)))
236 (< i n)))
237
238
239 (defun face-nontrivial-p (face &optional frame)
240 "True if face FACE has some non-nil attribute.
241 If the optional argument FRAME is given, report on face FACE in that frame.
242 If FRAME is t, report on the defaults for face FACE (for new frames).
243 If FRAME is omitted or nil, use the selected frame."
244 (not (internal-lisp-face-empty-p face frame)))
245
246
247 \f
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249 ;;; Setting face attributes from X resources.
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
251
252 (defcustom face-x-resources
253 '((:family (".attributeFamily" . "Face.AttributeFamily"))
254 (:width (".attributeWidth" . "Face.AttributeWidth"))
255 (:height (".attributeHeight" . "Face.AttributeHeight"))
256 (:weight (".attributeWeight" . "Face.AttributeWeight"))
257 (:slant (".attributeSlant" . "Face.AttributeSlant"))
258 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
259 (:background (".attributeBackground" . "Face.AttributeBackground"))
260 (:overline (".attributeOverline" . "Face.AttributeOverline"))
261 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
262 (:box (".attributeBox" . "Face.AttributeBox"))
263 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
264 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
265 (:stipple
266 (".attributeStipple" . "Face.AttributeStipple")
267 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
268 (:bold (".attributeBold" . "Face.AttributeBold"))
269 (:italic (".attributeItalic" . "Face.AttributeItalic"))
270 (:font (".attributeFont" . "Face.AttributeFont")))
271 "*List of X resources and classes for face attributes.
272 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
273 the name of a face attribute, and each ENTRY is a cons of the form
274 (RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
275 X resource class for the attribute."
276 :type 'sexp
277 :group 'faces)
278
279
280 (defun set-face-attribute-from-resource (face attribute resource class frame)
281 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
282 Value is the attribute value specified by the resource, or nil
283 if not present. This function displays a message if the resource
284 specifies an invalid attribute."
285 (let* ((face-name (face-name face))
286 (value (internal-face-x-get-resource (concat face-name resource)
287 class frame)))
288 (when value
289 (condition-case ()
290 (internal-set-lisp-face-attribute-from-resource
291 face attribute (downcase value) frame)
292 (error
293 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
294 face-name frame attribute value))))
295 value))
296
297
298 (defun set-face-attributes-from-resources (face frame)
299 "Set attributes of FACE from X resources for FRAME."
300 (when (memq (framep frame) '(x w32))
301 (dolist (definition face-x-resources)
302 (let ((attribute (car definition)))
303 (dolist (entry (cdr definition))
304 (set-face-attribute-from-resource face attribute (car entry)
305 (cdr entry) frame))))))
306
307
308 (defun make-face-x-resource-internal (face &optional frame)
309 "Fill frame-local FACE on FRAME from X resources.
310 FRAME nil or not specified means do it for all frames."
311 (if (null frame)
312 (dolist (frame (frame-list))
313 (set-face-attributes-from-resources face frame))
314 (set-face-attributes-from-resources face frame)))
315
316
317 \f
318 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
319 ;;; Retrieving face attributes.
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
321
322 (defun face-name (face)
323 "Return the name of face FACE."
324 (symbol-name (check-face face)))
325
326
327 (defun face-attribute (face attribute &optional frame)
328 "Return the value of FACE's ATTRIBUTE on FRAME.
329 If the optional argument FRAME is given, report on face FACE in that frame.
330 If FRAME is t, report on the defaults for face FACE (for new frames).
331 If FRAME is omitted or nil, use the selected frame."
332 (internal-get-lisp-face-attribute face attribute frame))
333
334
335 (defun face-foreground (face &optional frame)
336 "Return the foreground color name of FACE, or nil if unspecified.
337 If the optional argument FRAME is given, report on face FACE in that frame.
338 If FRAME is t, report on the defaults for face FACE (for new frames).
339 If FRAME is omitted or nil, use the selected frame."
340 (internal-get-lisp-face-attribute face :foreground frame))
341
342
343 (defun face-background (face &optional frame)
344 "Return the background color name of FACE, or nil if unspecified.
345 If the optional argument FRAME is given, report on face FACE in that frame.
346 If FRAME is t, report on the defaults for face FACE (for new frames).
347 If FRAME is omitted or nil, use the selected frame."
348 (internal-get-lisp-face-attribute face :background frame))
349
350
351 (defun face-stipple (face &optional frame)
352 "Return the stipple pixmap name of FACE, or nil if unspecified.
353 If the optional argument FRAME is given, report on face FACE in that frame.
354 If FRAME is t, report on the defaults for face FACE (for new frames).
355 If FRAME is omitted or nil, use the selected frame."
356 (internal-get-lisp-face-attribute face :stipple frame))
357
358
359 (defalias 'face-background-pixmap 'face-stipple)
360
361
362 (defun face-underline-p (face &optional frame)
363 "Return non-nil if FACE is underlined.
364 If the optional argument FRAME is given, report on face FACE in that frame.
365 If FRAME is t, report on the defaults for face FACE (for new frames).
366 If FRAME is omitted or nil, use the selected frame."
367 (eq (face-attribute face :underline frame) t))
368
369
370 (defun face-inverse-video-p (face &optional frame)
371 "Return non-nil if FACE is in inverse video on FRAME.
372 If the optional argument FRAME is given, report on face FACE in that frame.
373 If FRAME is t, report on the defaults for face FACE (for new frames).
374 If FRAME is omitted or nil, use the selected frame."
375 (eq (face-attribute face :inverse-video frame) t))
376
377
378 (defun face-bold-p (face &optional frame)
379 "Return non-nil if the font of FACE is bold on FRAME.
380 If the optional argument FRAME is given, report on face FACE in that frame.
381 If FRAME is t, report on the defaults for face FACE (for new frames).
382 If FRAME is omitted or nil, use the selected frame.
383 Use `face-attribute' for finer control."
384 (let ((bold (face-attribute face :weight frame)))
385 (memq bold '(semi-bold bold extra-bold ultra-bold))))
386
387
388 (defun face-italic-p (face &optional frame)
389 "Return non-nil if the font of FACE is italic on FRAME.
390 If the optional argument FRAME is given, report on face FACE in that frame.
391 If FRAME is t, report on the defaults for face FACE (for new frames).
392 If FRAME is omitted or nil, use the selected frame.
393 Use `face-attribute' for finer control."
394 (let ((italic (face-attribute face :slant frame)))
395 (memq italic '(italic oblique))))
396
397
398
399
400 \f
401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
402 ;;; Face documentation.
403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
404
405 (defun face-documentation (face)
406 "Get the documentation string for FACE."
407 (get face 'face-documentation))
408
409
410 (defun set-face-documentation (face string)
411 "Set the documentation string for FACE to STRING."
412 ;; Perhaps the text should go in DOC.
413 (put face 'face-documentation (purecopy string)))
414
415
416 (defalias 'face-doc-string 'face-documentation)
417 (defalias 'set-face-doc-string 'set-face-documentation)
418
419
420 \f
421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
422 ;; Setting face attributes.
423 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
424
425
426 (defun set-face-attribute (face frame &rest args)
427 "Set attributes of FACE on FRAME from ARGS.
428
429 FRAME nil means change attributes on all frames. FRAME t means change
430 the default for new frames (this is done automatically each time an
431 attribute is changed on all frames).
432
433 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
434 face attribute name. All attributes can be set to `unspecified';
435 this fact is not further mentioned below.
436
437 The following attributes are recognized:
438
439 `:family'
440
441 VALUE must be a string specifying the font family, e.g. ``courier'',
442 or a fontset alias name. If a font family is specified, wild-cards `*'
443 and `?' are allowed.
444
445 `:width'
446
447 VALUE specifies the relative proportionate width of the font to use.
448 It must be one of the symbols `ultra-condensed', `extra-condensed',
449 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
450 `extra-expanded', or `ultra-expanded'.
451
452 `:height'
453
454 VALUE must be either an integer specifying the height of the font to use
455 in 1/10 pt, a floating point number specifying the amount by which to
456 scale any underlying face, or a function, which is called with the old
457 height (from the underlying face), and should return the new height.
458
459 `:weight'
460
461 VALUE specifies the weight of the font to use. It must be one of the
462 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
463 `semi-light', `light', `extra-light', `ultra-light'.
464
465 `:slant'
466
467 VALUE specifies the slant of the font to use. It must be one of the
468 symbols `italic', `oblique', `normal', `reverse-italic', or
469 `reverse-oblique'.
470
471 `:foreground', `:background'
472
473 VALUE must be a color name, a string.
474
475 `:underline'
476
477 VALUE specifies whether characters in FACE should be underlined. If
478 VALUE is t, underline with foreground color of the face. If VALUE is
479 a string, underline with that color. If VALUE is nil, explicitly
480 don't underline.
481
482 `:overline'
483
484 VALUE specifies whether characters in FACE should be overlined. If
485 VALUE is t, overline with foreground color of the face. If VALUE is a
486 string, overline with that color. If VALUE is nil, explicitly don't
487 overline.
488
489 `:strike-through'
490
491 VALUE specifies whether characters in FACE should be drawn with a line
492 striking through them. If VALUE is t, use the foreground color of the
493 face. If VALUE is a string, strike-through with that color. If VALUE
494 is nil, explicitly don't strike through.
495
496 `:box'
497
498 VALUE specifies whether characters in FACE should have a box drawn
499 around them. If VALUE is nil, explicitly don't draw boxes. If
500 VALUE is t, draw a box with lines of width 1 in the foreground color
501 of the face. If VALUE is a string, the string must be a color name,
502 and the box is drawn in that color with a line width of 1. Otherwise,
503 VALUE must be a property list of the form `(:line-width WIDTH
504 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
505 the property list, a default value will be used for the value, as
506 specified below. WIDTH specifies the width of the lines to draw; it
507 defaults to 1. COLOR is the name of the color to draw in, default is
508 the foreground color of the face for simple boxes, and the background
509 color of the face for 3D boxes. STYLE specifies whether a 3D box
510 should be draw. If STYLE is `released-button', draw a box looking
511 like a released 3D button. If STYLE is `pressed-button' draw a box
512 that appears like a pressed button. If STYLE is nil, the default if
513 the property list doesn't contain a style specification, draw a 2D
514 box.
515
516 `:inverse-video'
517
518 VALUE specifies whether characters in FACE should be displayed in
519 inverse video. VALUE must be one of t or nil.
520
521 `:stipple'
522
523 If VALUE is a string, it must be the name of a file of pixmap data.
524 The directories listed in the `x-bitmap-file-path' variable are
525 searched. Alternatively, VALUE may be a list of the form (WIDTH
526 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
527 is a string containing the raw bits of the bitmap. VALUE nil means
528 explicitly don't use a stipple pattern.
529
530 For convenience, attributes `:family', `:width', `:height', `:weight',
531 and `:slant' may also be set in one step from an X font name:
532
533 `:font'
534
535 Set font-related face attributes from VALUE. VALUE must be a valid
536 XLFD font name. If it is a font name pattern, the first matching font
537 will be used.
538
539 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
540 be used to specify that a bold or italic font should be used. VALUE
541 must be t or nil in that case. A value of `unspecified' is not allowed.
542
543 `:inherit'
544
545 VALUE is the name of a face from which to inherit attributes, or a list
546 of face names. Attributes from inherited faces are merged into the face
547 like an underlying face would be, with higher priority than underlying faces."
548 (setq args (purecopy args))
549 (cond ((null frame)
550 ;; Change face on all frames.
551 (dolist (frame (frame-list))
552 (apply #'set-face-attribute face frame args))
553 ;; Record that as a default for new frames.
554 (apply #'set-face-attribute face t args))
555 (t
556 (while args
557 (internal-set-lisp-face-attribute face (car args)
558 (purecopy (cadr args))
559 frame)
560 (setq args (cdr (cdr args)))))))
561
562
563 (defun make-face-bold (face &optional frame noerror)
564 "Make the font of FACE be bold, if possible.
565 FRAME nil or not specified means change face on all frames.
566 Argument NOERROR is ignored and retained for compatibility.
567 Use `set-face-attribute' for finer control of the font weight."
568 (interactive (list (read-face-name "Make which face bold ")))
569 (set-face-attribute face frame :weight 'bold))
570
571
572 (defun make-face-unbold (face &optional frame noerror)
573 "Make the font of FACE be non-bold, if possible.
574 FRAME nil or not specified means change face on all frames.
575 Argument NOERROR is ignored and retained for compatibility."
576 (interactive (list (read-face-name "Make which face non-bold ")))
577 (set-face-attribute face frame :weight 'normal))
578
579
580 (defun make-face-italic (face &optional frame noerror)
581 "Make the font of FACE be italic, if possible.
582 FRAME nil or not specified means change face on all frames.
583 Argument NOERROR is ignored and retained for compatibility.
584 Use `set-face-attribute' for finer control of the font slant."
585 (interactive (list (read-face-name "Make which face italic ")))
586 (set-face-attribute face frame :slant 'italic))
587
588
589 (defun make-face-unitalic (face &optional frame noerror)
590 "Make the font of FACE be non-italic, if possible.
591 FRAME nil or not specified means change face on all frames.
592 Argument NOERROR is ignored and retained for compatibility."
593 (interactive (list (read-face-name "Make which face non-italic ")))
594 (set-face-attribute face frame :slant 'normal))
595
596
597 (defun make-face-bold-italic (face &optional frame noerror)
598 "Make the font of FACE be bold and italic, if possible.
599 FRAME nil or not specified means change face on all frames.
600 Argument NOERROR is ignored and retained for compatibility.
601 Use `set-face-attribute' for finer control of font weight and slant."
602 (interactive (list (read-face-name "Make which face bold-italic: ")))
603 (set-face-attribute face frame :weight 'bold :slant 'italic))
604
605
606 (defun set-face-font (face font &optional frame)
607 "Change font-related attributes of FACE to those of FONT (a string).
608 FRAME nil or not specified means change face on all frames.
609 This sets the attributes `:family', `:width', `:height', `:weight',
610 and `:slant'. When called interactively, prompt for the face and font."
611 (interactive (read-face-and-attribute :font))
612 (set-face-attribute face frame :font font))
613
614
615 ;; Implementation note: Emulating gray background colors with a
616 ;; stipple pattern is now part of the face realization process, and is
617 ;; done in C depending on the frame on which the face is realized.
618
619 (defun set-face-background (face color &optional frame)
620 "Change the background color of face FACE to COLOR (a string).
621 FRAME nil or not specified means change face on all frames.
622 When called interactively, prompt for the face and color."
623 (interactive (read-face-and-attribute :background))
624 (set-face-attribute face frame :background color))
625
626
627 (defun set-face-foreground (face color &optional frame)
628 "Change the foreground color of face FACE to COLOR (a string).
629 FRAME nil or not specified means change face on all frames.
630 When called interactively, prompt for the face and color."
631 (interactive (read-face-and-attribute :foreground))
632 (set-face-attribute face frame :foreground color))
633
634
635 (defun set-face-stipple (face stipple &optional frame)
636 "Change the stipple pixmap of face FACE to STIPPLE.
637 FRAME nil or not specified means change face on all frames.
638 STIPPLE should be a string, the name of a file of pixmap data.
639 The directories listed in the `x-bitmap-file-path' variable are searched.
640
641 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
642 where WIDTH and HEIGHT are the size in pixels,
643 and DATA is a string, containing the raw bits of the bitmap."
644 (interactive (read-face-and-attribute :stipple))
645 (set-face-attribute face frame :stipple stipple))
646
647
648 (defun set-face-underline (face underline &optional frame)
649 "Specify whether face FACE is underlined.
650 UNDERLINE nil means FACE explicitly doesn't underline.
651 UNDERLINE non-nil means FACE explicitly does underlining
652 with the same of the foreground color.
653 If UNDERLINE is a string, underline with the color named UNDERLINE.
654 FRAME nil or not specified means change face on all frames.
655 Use `set-face-attribute' to ``unspecify'' underlining."
656 (interactive
657 (let ((list (read-face-and-attribute :underline)))
658 (list (car list) (eq (car (cdr list)) t))))
659 (set-face-attribute face frame :underline underline))
660
661
662 (defun set-face-underline-p (face underline-p &optional frame)
663 "Specify whether face FACE is underlined.
664 UNDERLINE-P nil means FACE explicitly doesn't underline.
665 UNDERLINE-P non-nil means FACE explicitly does underlining.
666 FRAME nil or not specified means change face on all frames.
667 Use `set-face-attribute' to ``unspecify'' underlining."
668 (interactive
669 (let ((list (read-face-and-attribute :underline)))
670 (list (car list) (eq (car (cdr list)) t))))
671 (set-face-attribute face frame :underline underline-p))
672
673
674 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
675 "Specify whether face FACE is in inverse video.
676 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
677 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
678 FRAME nil or not specified means change face on all frames.
679 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
680 (interactive
681 (let ((list (read-face-and-attribute :inverse-video)))
682 (list (car list) (eq (car (cdr list)) t))))
683 (set-face-attribute face frame :inverse-video inverse-video-p))
684
685
686 (defun set-face-bold-p (face bold-p &optional frame)
687 "Specify whether face FACE is bold.
688 BOLD-P non-nil means FACE should explicitly display bold.
689 BOLD-P nil means FACE should explicitly display non-bold.
690 FRAME nil or not specified means change face on all frames.
691 Use `set-face-attribute' or `modify-face' for finer control."
692 (if (null bold-p)
693 (make-face-unbold face frame)
694 (make-face-bold face frame)))
695
696
697 (defun set-face-italic-p (face italic-p &optional frame)
698 "Specify whether face FACE is italic.
699 ITALIC-P non-nil means FACE should explicitly display italic.
700 ITALIC-P nil means FACE should explicitly display non-italic.
701 FRAME nil or not specified means change face on all frames.
702 Use `set-face-attribute' or `modify-face' for finer control."
703 (if (null italic-p)
704 (make-face-unitalic face frame)
705 (make-face-italic face frame)))
706
707
708 (defalias 'set-face-background-pixmap 'set-face-stipple)
709
710
711 (defun invert-face (face &optional frame)
712 "Swap the foreground and background colors of FACE.
713 FRAME nil or not specified means change face on all frames.
714 If FACE specifies neither foreground nor background color,
715 set its foreground and background to the background and foreground
716 of the default face. Value is FACE."
717 (interactive (list (read-face-name "Invert face ")))
718 (let ((fg (face-attribute face :foreground frame))
719 (bg (face-attribute face :background frame)))
720 (if (or fg bg)
721 (set-face-attribute face frame :foreground bg :background fg)
722 (set-face-attribute face frame
723 :foreground
724 (face-attribute 'default :background frame)
725 :background
726 (face-attribute 'default :foreground frame))))
727 face)
728
729 \f
730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
731 ;;; Interactively modifying faces.
732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
733
734 (defun read-face-name (prompt)
735 "Read and return a face symbol, prompting with PROMPT.
736 Value is a symbol naming a known face."
737 (let ((face-list (mapcar #'(lambda (x) (cons (symbol-name x) x))
738 (face-list)))
739 (def (thing-at-point 'symbol))
740 face)
741 (cond ((assoc def face-list)
742 (setq prompt (concat prompt " (default " def "): ")))
743 (t (setq def nil)
744 (setq prompt (concat prompt ": "))))
745 (while (equal "" (setq face (completing-read
746 prompt face-list nil t nil nil def))))
747 (intern face)))
748
749
750 (defun face-valid-attribute-values (attribute &optional frame)
751 "Return valid values for face attribute ATTRIBUTE.
752 The optional argument FRAME is used to determine available fonts
753 and colors. If it is nil or not specified, the selected frame is
754 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
755 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
756 an integer value."
757 (let (valid)
758 (setq valid
759 (case attribute
760 (:family
761 (if window-system
762 (mapcar #'(lambda (x) (cons (car x) (car x)))
763 (x-font-family-list))
764 ;; Only one font on TTYs.
765 (list (cons "default" "default"))))
766 ((:width :weight :slant :inverse-video)
767 (mapcar #'(lambda (x) (cons (symbol-name x) x))
768 (internal-lisp-face-attribute-values attribute)))
769 ((:underline :overline :strike-through :box)
770 (if window-system
771 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
772 (internal-lisp-face-attribute-values attribute))
773 (mapcar #'(lambda (c) (cons c c))
774 (x-defined-colors frame)))
775 (mapcar #'(lambda (x) (cons (symbol-name x) x))
776 (internal-lisp-face-attribute-values attribute))))
777 ((:foreground :background)
778 (mapcar #'(lambda (c) (cons c c))
779 (defined-colors frame)))
780 ((:height)
781 'integerp)
782 (:stipple
783 (and (memq window-system '(x w32))
784 (mapcar #'list
785 (apply #'nconc (mapcar #'directory-files
786 x-bitmap-file-path)))))
787 (:inherit
788 (cons '("none" . nil)
789 (mapcar #'(lambda (c) (cons (symbol-name c) c))
790 (face-list))))
791 (t
792 (error "Internal error"))))
793 (if (and (listp valid) (not (memq attribute '(:inherit))))
794 (nconc (list (cons "unspecified" 'unspecified)) valid)
795 valid)))
796
797
798
799 (defvar face-attribute-name-alist
800 '((:family . "font family")
801 (:width . "character set width")
802 (:height . "height in 1/10 pt")
803 (:weight . "weight")
804 (:slant . "slant")
805 (:underline . "underline")
806 (:overline . "overline")
807 (:strike-through . "strike-through")
808 (:box . "box")
809 (:inverse-video . "inverse-video display")
810 (:foreground . "foreground color")
811 (:background . "background color")
812 (:stipple . "background stipple")
813 (:inherit . "inheritance"))
814 "An alist of descriptive names for face attributes.
815 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
816 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
817 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
818
819
820 (defun face-descriptive-attribute-name (attribute)
821 "Return a descriptive name for ATTRIBUTE."
822 (cdr (assq attribute face-attribute-name-alist)))
823
824
825 (defun face-read-string (face default name &optional completion-alist)
826 "Interactively read a face attribute string value.
827 FACE is the face whose attribute is read. If non-nil, DEFAULT is the
828 default string to return if no new value is entered. NAME is a
829 descriptive name of the attribute for prompting. COMPLETION-ALIST is an
830 alist of valid values, if non-nil.
831
832 Entering nothing accepts the default string DEFAULT.
833 Value is the new attribute value."
834 ;; Capitalize NAME (we don't use `capitalize' because that capitalizes
835 ;; each word in a string separately).
836 (setq name (concat (upcase (substring name 0 1)) (substring name 1)))
837 (let* ((completion-ignore-case t)
838 (value (completing-read
839 (if default
840 (format "%s for face `%s' (default %s): "
841 name face default)
842 (format "%s for face `%s': " name face))
843 completion-alist)))
844 (if (equal value "") default value)))
845
846
847 (defun face-read-integer (face default name)
848 "Interactively read an integer face attribute value.
849 FACE is the face whose attribute is read. DEFAULT is the default
850 value to return if no new value is entered. NAME is a descriptive
851 name of the attribute for prompting. Value is the new attribute value."
852 (let ((new-value
853 (face-read-string face
854 (format "%s" default)
855 name
856 (list (cons "unspecified" 'unspecified)))))
857 (cond ((equal new-value "unspecified")
858 'unspecified)
859 ((member new-value '("unspecified-fg" "unspecified-bg"))
860 new-value)
861 (t
862 (string-to-int new-value)))))
863
864
865 (defun read-face-attribute (face attribute &optional frame)
866 "Interactively read a new value for FACE's ATTRIBUTE.
867 Optional argument FRAME nil or unspecified means read an attribute value
868 of a global face. Value is the new attribute value."
869 (let* ((old-value (face-attribute face attribute frame))
870 (attribute-name (face-descriptive-attribute-name attribute))
871 (valid (face-valid-attribute-values attribute frame))
872 new-value)
873 ;; Represent complex attribute values as strings by printing them
874 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
875 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
876 ;; SHADOW)'.
877 (when (and (or (eq attribute :stipple)
878 (eq attribute :box))
879 (or (consp old-value)
880 (vectorp old-value)))
881 (setq old-value (prin1-to-string old-value)))
882 (cond ((listp valid)
883 (let ((default
884 (or (car (rassoc old-value valid))
885 (format "%s" old-value))))
886 (setq new-value
887 (face-read-string face default attribute-name valid))
888 (if (equal new-value default)
889 ;; Nothing changed, so don't bother with all the stuff
890 ;; below. In particular, this avoids a non-tty color
891 ;; from being canonicalized for a tty when the user
892 ;; just uses the default.
893 (setq new-value old-value)
894 ;; Terminal frames can support colors that don't appear
895 ;; explicitly in VALID, using color approximation code
896 ;; in tty-colors.el.
897 (if (and (memq attribute '(:foreground :background))
898 (not (memq window-system '(x w32 mac)))
899 (not (member new-value
900 '("unspecified"
901 "unspecified-fg" "unspecified-bg"))))
902 (setq new-value (car (tty-color-desc new-value frame))))
903 (setq new-value (cdr (assoc new-value valid))))))
904 ((eq valid 'integerp)
905 (setq new-value (face-read-integer face old-value attribute-name)))
906 (t (error "Internal error")))
907 ;; Convert stipple and box value text we read back to a list or
908 ;; vector if it looks like one. This makes the assumption that a
909 ;; pixmap file name won't start with an open-paren.
910 (when (and (or (eq attribute :stipple)
911 (eq attribute :box))
912 (stringp new-value)
913 (string-match "^[[(]" new-value))
914 (setq new-value (read new-value)))
915 new-value))
916
917
918 (defun read-face-font (face &optional frame)
919 "Read the name of a font for FACE on FRAME.
920 If optional argument FRAME Is nil or omitted, use the selected frame."
921 (let ((completion-ignore-case t))
922 (completing-read (format "Set font attributes of face %s from font: " face)
923 (mapcar 'list (x-list-fonts "*" nil frame)))))
924
925
926 (defun read-all-face-attributes (face &optional frame)
927 "Interactively read all attributes for FACE.
928 If optional argument FRAME Is nil or omitted, use the selected frame.
929 Value is a property list of attribute names and new values."
930 (let (result)
931 (dolist (attribute face-attribute-name-alist result)
932 (setq result (cons (car attribute)
933 (cons (read-face-attribute face (car attribute) frame)
934 result))))))
935
936
937 (defun modify-face (&optional frame)
938 "Modify attributes of faces interactively.
939 If optional argument FRAME is nil or omitted, modify the face used
940 for newly created frame, i.e. the global face."
941 (interactive)
942 (let ((face (read-face-name "Modify face")))
943 (apply #'set-face-attribute face frame
944 (read-all-face-attributes face frame))))
945
946
947 (defun read-face-and-attribute (attribute &optional frame)
948 "Read face name and face attribute value.
949 ATTRIBUTE is the attribute whose new value is read.
950 FRAME nil or unspecified means read attribute value of global face.
951 Value is a list (FACE NEW-VALUE) where FACE is the face read
952 (a symbol), and NEW-VALUE is value read."
953 (cond ((eq attribute :font)
954 (let* ((prompt (format "Set font-related attributes of face "))
955 (face (read-face-name prompt))
956 (font (read-face-font face frame)))
957 (list face font)))
958 (t
959 (let* ((attribute-name (face-descriptive-attribute-name attribute))
960 (prompt (format "Set %s of face" attribute-name))
961 (face (read-face-name prompt))
962 (new-value (read-face-attribute face attribute frame)))
963 (list face new-value)))))
964
965
966 \f
967 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
968 ;;; Listing faces.
969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
970
971 (defvar list-faces-sample-text
972 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
973 "*Text string to display as the sample text for `list-faces-display'.")
974
975
976 ;; The name list-faces would be more consistent, but let's avoid a
977 ;; conflict with Lucid, which uses that name differently.
978
979 (defun list-faces-display ()
980 "List all faces, using the same sample text in each.
981 The sample text is a string that comes from the variable
982 `list-faces-sample-text'."
983 (interactive)
984 (let ((faces (sort (face-list) #'string-lessp))
985 (face nil)
986 (frame (selected-frame))
987 disp-frame window face-name)
988 (with-output-to-temp-buffer "*Faces*"
989 (save-excursion
990 (set-buffer standard-output)
991 (setq truncate-lines t)
992 (insert
993 (substitute-command-keys
994 (concat
995 "Use "
996 (if (display-mouse-p) "\\[help-follow-mouse] or ")
997 "\\[help-follow] on a face name to customize it\n"
998 "or on its sample text for a decription of the face.\n\n")))
999 (setq help-xref-stack nil)
1000 (while faces
1001 (setq face (car faces))
1002 (setq faces (cdr faces))
1003 (setq face-name (symbol-name face))
1004 (insert (format "%25s " face-name))
1005 ;; Hyperlink to a customization buffer for the face. Using
1006 ;; the help xref mechanism may not be the best way.
1007 (save-excursion
1008 (save-match-data
1009 (search-backward face-name)
1010 (help-xref-button 0 (lambda (f)
1011 (if help-xref-stack
1012 (pop help-xref-stack))
1013 (customize-face f))
1014 face-name
1015 "mouse-2: customize this face")))
1016 (let ((beg (point)))
1017 (insert list-faces-sample-text)
1018 ;; Hyperlink to a help buffer for the face.
1019 (save-excursion
1020 (save-match-data
1021 (search-backward list-faces-sample-text)
1022 (help-xref-button 0 #'describe-face face
1023 "mouse-2: describe this face")))
1024 (insert "\n")
1025 (put-text-property beg (1- (point)) 'face face)
1026 ;; If the sample text has multiple lines, line up all of them.
1027 (goto-char beg)
1028 (forward-line 1)
1029 (while (not (eobp))
1030 (insert " ")
1031 (forward-line 1))))
1032 (goto-char (point-min)))
1033 (print-help-return-message))
1034 ;; If the *Faces* buffer appears in a different frame,
1035 ;; copy all the face definitions from FRAME,
1036 ;; so that the display will reflect the frame that was selected.
1037 (setq window (get-buffer-window (get-buffer "*Faces*") t))
1038 (setq disp-frame (if window (window-frame window)
1039 (car (frame-list))))
1040 (or (eq frame disp-frame)
1041 (let ((faces (face-list)))
1042 (while faces
1043 (copy-face (car faces) (car faces) frame disp-frame)
1044 (setq faces (cdr faces)))))))
1045
1046
1047 (defun describe-face (face &optional frame)
1048 "Display the properties of face FACE on FRAME.
1049 If the optional argument FRAME is given, report on face FACE in that frame.
1050 If FRAME is t, report on the defaults for face FACE (for new frames).
1051 If FRAME is omitted or nil, use the selected frame."
1052 (interactive (list (read-face-name "Describe face")))
1053 (let* ((attrs '((:family . "Family")
1054 (:width . "Width")
1055 (:height . "Height")
1056 (:weight . "Weight")
1057 (:slant . "Slant")
1058 (:foreground . "Foreground")
1059 (:background . "Background")
1060 (:underline . "Underline")
1061 (:overline . "Overline")
1062 (:strike-through . "Strike-through")
1063 (:box . "Box")
1064 (:inverse-video . "Inverse")
1065 (:stipple . "Stipple")
1066 (:font . "Font or fontset")
1067 (:inherit . "Inherit")))
1068 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1069 attrs))))
1070 (with-output-to-temp-buffer "*Help*"
1071 (save-excursion
1072 (set-buffer standard-output)
1073 (dolist (a attrs)
1074 (let ((attr (face-attribute face (car a) frame)))
1075 (insert (make-string (- max-width (length (cdr a))) ?\ )
1076 (cdr a) ": " (format "%s" attr) "\n")))
1077 (insert "\nDocumentation:\n\n"
1078 (or (face-documentation face)
1079 "not documented as a face."))
1080 (let ((customize-label "customize"))
1081 (terpri)
1082 (terpri)
1083 (princ (concat "You can " customize-label " this face."))
1084 (with-current-buffer "*Help*"
1085 (save-excursion
1086 (re-search-backward
1087 (concat "\\(" customize-label "\\)") nil t)
1088 (help-xref-button 1 #'customize-face face
1089 "mouse-2, RET: customize face")))))
1090 (print-help-return-message)
1091 (with-current-buffer "*Help*"
1092 (help-setup-xref (list #'describe-face face) (interactive-p))
1093 (buffer-string)))))
1094 \f
1095 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1096 ;;; Face specifications (defface).
1097 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1098
1099 ;; Parameter FRAME Is kept for call compatibility to with previous
1100 ;; face implementation.
1101
1102 (defun face-attr-construct (face &optional frame)
1103 "Return a defface-style attribute list for FACE on FRAME.
1104 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1105 face attributes of FACE where ATTRIBUTE is the attribute name and
1106 VALUE is the specified value of that attribute."
1107 (let (result)
1108 (dolist (entry face-attribute-name-alist result)
1109 (let* ((attribute (car entry))
1110 (value (face-attribute face attribute)))
1111 (unless (eq value 'unspecified)
1112 (setq result (nconc (list attribute value) result)))))))
1113
1114
1115 (defun face-spec-set-match-display (display frame)
1116 "Non-nil if DISPLAY matches FRAME.
1117 DISPLAY is part of a spec such as can be used in `defface'.
1118 If FRAME is nil, the current FRAME is used."
1119 (let* ((conjuncts display)
1120 conjunct req options
1121 ;; t means we have succeeded against all the conjuncts in
1122 ;; DISPLAY that have been tested so far.
1123 (match t))
1124 (if (eq conjuncts t)
1125 (setq conjuncts nil))
1126 (while (and conjuncts match)
1127 (setq conjunct (car conjuncts)
1128 conjuncts (cdr conjuncts)
1129 req (car conjunct)
1130 options (cdr conjunct)
1131 match (cond ((eq req 'type)
1132 (or (memq window-system options)
1133 (and (null window-system)
1134 (memq 'tty options))
1135 (and (memq 'motif options)
1136 (featurep 'motif))
1137 (and (memq 'lucid options)
1138 (featurep 'x-toolkit)
1139 (not (featurep 'motif)))
1140 (and (memq 'x-toolkit options)
1141 (featurep 'x-toolkit))))
1142 ((eq req 'class)
1143 (memq (frame-parameter frame 'display-type) options))
1144 ((eq req 'background)
1145 (memq (frame-parameter frame 'background-mode)
1146 options))
1147 (t (error "Unknown req `%S' with options `%S'"
1148 req options)))))
1149 match))
1150
1151
1152 (defun face-spec-choose (spec &optional frame)
1153 "Choose the proper attributes for FRAME, out of SPEC."
1154 (unless frame
1155 (setq frame (selected-frame)))
1156 (let ((tail spec)
1157 result)
1158 (while tail
1159 (let* ((entry (car tail))
1160 (display (nth 0 entry))
1161 (attrs (nth 1 entry)))
1162 (setq tail (cdr tail))
1163 (when (face-spec-set-match-display display frame)
1164 (setq result attrs tail nil))))
1165 result))
1166
1167
1168 (defun face-spec-reset-face (face &optional frame)
1169 "Reset all attributes of FACE on FRAME to unspecified."
1170 (let ((attrs face-attribute-name-alist)
1171 params)
1172 (while attrs
1173 (let ((attr-and-name (car attrs)))
1174 (setq params (cons (car attr-and-name) (cons 'unspecified params))))
1175 (setq attrs (cdr attrs)))
1176 (apply #'set-face-attribute face frame params)))
1177
1178
1179 (defun face-spec-set (face spec &optional frame)
1180 "Set FACE's attributes according to the first matching entry in SPEC.
1181 FRAME is the frame whose frame-local face is set. FRAME nil means
1182 do it on all frames. See `defface' for information about SPEC."
1183 (let ((attrs (face-spec-choose spec frame))
1184 params)
1185 (while attrs
1186 (let ((attribute (car attrs))
1187 (value (car (cdr attrs))))
1188 ;; Support some old-style attribute names and values.
1189 (case attribute
1190 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1191 (:italic (setq attribute :slant value (if value 'italic 'normal)))
1192 (t (unless (assq attribute face-x-resources)
1193 (setq attribute nil))))
1194 (when attribute
1195 (setq params (cons attribute (cons value params)))))
1196 (setq attrs (cdr (cdr attrs))))
1197 (face-spec-reset-face face frame)
1198 (apply #'set-face-attribute face frame params)))
1199
1200
1201 (defun face-attr-match-p (face attrs &optional frame)
1202 "Return t if attributes of FACE match values in plist ATTRS.
1203 Optional parameter FRAME is the frame whose definition of FACE
1204 is used. If nil or omitted, use the selected frame."
1205 (unless frame
1206 (setq frame (selected-frame)))
1207 (let ((list face-attribute-name-alist)
1208 (match t))
1209 (while (and match (not (null list)))
1210 (let* ((attr (car (car list)))
1211 (specified-value
1212 (if (plist-member attrs attr)
1213 (plist-get attrs attr)
1214 'unspecified))
1215 (value-now (face-attribute face attr frame)))
1216 (setq match (equal specified-value value-now))
1217 (setq list (cdr list))))
1218 match))
1219
1220 (defun face-spec-match-p (face spec &optional frame)
1221 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1222 (face-attr-match-p face (face-spec-choose spec frame) frame))
1223
1224
1225 \f
1226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1227 ;;; Frame-type independent color support.
1228 ;;; We keep the old x-* names as aliases for back-compatibility.
1229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1230
1231 (defun defined-colors (&optional frame)
1232 "Return a list of colors supported for a particular frame.
1233 The argument FRAME specifies which frame to try.
1234 The value may be different for frames on different display types.
1235 If FRAME doesn't support colors, the value is nil."
1236 (if (memq (framep (or frame (selected-frame))) '(x w32))
1237 (xw-defined-colors frame)
1238 (mapcar 'car (tty-color-alist frame))))
1239 (defalias 'x-defined-colors 'defined-colors)
1240
1241 (defun color-defined-p (color &optional frame)
1242 "Return non-nil if color COLOR is supported on frame FRAME.
1243 If FRAME is omitted or nil, use the selected frame.
1244 If COLOR is the symbol `unspecified' or one of the strings
1245 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1246 (if (memq color '(unspecified "unspecified-bg" "unspecified-fg"))
1247 nil
1248 (if (memq (framep (or frame (selected-frame))) '(x w32))
1249 (xw-color-defined-p color frame)
1250 (numberp (tty-color-translate color frame)))))
1251 (defalias 'x-color-defined-p 'color-defined-p)
1252
1253 (defun color-values (color &optional frame)
1254 "Return a description of the color named COLOR on frame FRAME.
1255 The value is a list of integer RGB values--\(RED GREEN BLUE\).
1256 These values appear to range from 0 to 65280 or 65535, depending
1257 on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
1258 If FRAME is omitted or nil, use the selected frame.
1259 If FRAME cannot display COLOR, the value is nil.
1260 If COLOR is the symbol `unspecified' or one of the strings
1261 \"unspecified-fg\" or \"unspecified-bg\", the value is nil."
1262 (if (memq color '(unspecified "unspecified-fg" "unspecified-bg"))
1263 nil
1264 (if (memq (framep (or frame (selected-frame))) '(x w32))
1265 (xw-color-values color frame)
1266 (tty-color-values color frame))))
1267 (defalias 'x-color-values 'color-values)
1268
1269 (defun display-color-p (&optional display)
1270 "Return t if DISPLAY supports color.
1271 The optional argument DISPLAY specifies which display to ask about.
1272 DISPLAY should be either a frame or a display name (a string).
1273 If omitted or nil, that stands for the selected frame's display."
1274 (if (memq (framep-on-display display) '(x w32))
1275 (xw-display-color-p display)
1276 (tty-display-color-p display)))
1277 (defalias 'x-display-color-p 'display-color-p)
1278
1279 (defun display-grayscale-p (&optional display)
1280 "Return non-nil if frames on DISPLAY can display shades of gray."
1281 (let ((frame-type (framep-on-display display)))
1282 (cond
1283 ((memq frame-type '(x w32 mac))
1284 (x-display-grayscale-p display))
1285 (t
1286 (> (tty-color-gray-shades display) 2)))))
1287
1288 \f
1289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1290 ;;; Background mode.
1291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1292
1293 (defcustom frame-background-mode nil
1294 "*The brightness of the background.
1295 Set this to the symbol `dark' if your background color is dark, `light' if
1296 your background is light, or nil (default) if you want Emacs to
1297 examine the brightness for you. Don't set this variable with `setq';
1298 this won't have the expected effect."
1299 :group 'faces
1300 :set #'(lambda (var value)
1301 (set-default var value)
1302 (mapcar 'frame-set-background-mode (frame-list)))
1303 :initialize 'custom-initialize-changed
1304 :type '(choice (choice-item dark)
1305 (choice-item light)
1306 (choice-item :tag "default" nil)))
1307
1308
1309 (defun frame-set-background-mode (frame)
1310 "Set up the `background-mode' and `display-type' frame parameters for FRAME."
1311 (let* ((bg-resource
1312 (and window-system
1313 (x-get-resource ".backgroundMode" "BackgroundMode")))
1314 (params (frame-parameters frame))
1315 (bg-mode (cond (frame-background-mode)
1316 ((null window-system)
1317 ;; No way to determine this automatically (?).
1318 'dark)
1319 (bg-resource
1320 (intern (downcase bg-resource)))
1321 ((< (apply '+ (x-color-values
1322 (cdr (assq 'background-color
1323 params))
1324 frame))
1325 ;; Just looking at the screen, colors whose
1326 ;; values add up to .6 of the white total
1327 ;; still look dark to me.
1328 (* (apply '+ (x-color-values "white" frame)) .6))
1329 'dark)
1330 (t 'light)))
1331 (display-type (cond ((null window-system)
1332 (if (tty-display-color-p frame) 'color 'mono))
1333 ((x-display-color-p frame)
1334 'color)
1335 ((x-display-grayscale-p frame)
1336 'grayscale)
1337 (t 'mono))))
1338 (modify-frame-parameters frame
1339 (list (cons 'background-mode bg-mode)
1340 (cons 'display-type display-type))))
1341
1342 ;; For all named faces, choose face specs matching the new frame
1343 ;; parameters.
1344 (let ((face-list (face-list)))
1345 (while face-list
1346 (let* ((face (car face-list))
1347 (spec (get face 'face-defface-spec)))
1348 (when spec
1349 (face-spec-set face spec frame))
1350 (setq face-list (cdr face-list))))))
1351
1352
1353
1354 \f
1355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1356 ;;; Frame creation.
1357 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1358
1359 (defun x-handle-named-frame-geometry (parameters)
1360 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1361 Value is the new parameter list."
1362 (let* ((name (or (cdr (assq 'name parameters))
1363 (cdr (assq 'name default-frame-alist))))
1364 (x-resource-name name)
1365 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1366 (when res-geometry
1367 (let ((parsed (x-parse-geometry res-geometry)))
1368 ;; If the resource specifies a position, call the position
1369 ;; and size "user-specified".
1370 (when (or (assq 'top parsed)
1371 (assq 'left parsed))
1372 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1373 ;; Put the geometry parameters at the end. Copy
1374 ;; default-frame-alist so that they go after it.
1375 (setq parameters (append parameters default-frame-alist parsed))))
1376 parameters))
1377
1378
1379 (defun x-handle-reverse-video (frame parameters)
1380 "Handle the reverse-video frame parameter and X resource.
1381 `x-create-frame' does not handle this one."
1382 (when (cdr (or (assq 'reverse parameters)
1383 (assq 'reverse default-frame-alist)
1384 (let ((resource (x-get-resource "reverseVideo"
1385 "ReverseVideo")))
1386 (if resource
1387 (cons nil (member (downcase resource)
1388 '("on" "true")))))))
1389 (let* ((params (frame-parameters frame))
1390 (bg (cdr (assq 'foreground-color params)))
1391 (fg (cdr (assq 'background-color params))))
1392 (modify-frame-parameters frame
1393 (list (cons 'foreground-color fg)
1394 (cons 'background-color bg)))
1395 (if (equal bg (cdr (assq 'border-color params)))
1396 (modify-frame-parameters frame
1397 (list (cons 'border-color fg))))
1398 (if (equal bg (cdr (assq 'mouse-color params)))
1399 (modify-frame-parameters frame
1400 (list (cons 'mouse-color fg))))
1401 (if (equal bg (cdr (assq 'cursor-color params)))
1402 (modify-frame-parameters frame
1403 (list (cons 'cursor-color fg)))))))
1404
1405
1406 (defun x-create-frame-with-faces (&optional parameters)
1407 "Create a frame from optional frame parameters PARAMETERS.
1408 Parameters not specified by PARAMETERS are taken from
1409 `default-frame-alist'. If PARAMETERS specify a frame name,
1410 handle X geometry resources for that name. If either PARAMETERS
1411 or `default-frame-alist' contains a `reverse' parameter, or
1412 the X resource ``reverseVideo'' is present, handle that.
1413 Value is the new frame created."
1414 (setq parameters (x-handle-named-frame-geometry parameters))
1415 (let ((visibility-spec (assq 'visibility parameters))
1416 (frame-list (frame-list))
1417 (frame (x-create-frame (cons '(visibility . nil) parameters)))
1418 success)
1419 (unwind-protect
1420 (progn
1421 (x-handle-reverse-video frame parameters)
1422 (frame-set-background-mode frame)
1423 (face-set-after-frame-default frame)
1424 (if (or (null frame-list) (null visibility-spec))
1425 (make-frame-visible frame)
1426 (modify-frame-parameters frame (list visibility-spec)))
1427 (setq success t))
1428 (unless success
1429 (delete-frame frame)))
1430 frame))
1431
1432
1433 (defun face-set-after-frame-default (frame)
1434 "Set frame-local faces of FRAME from face specs and resources.
1435 Initialize colors of certain faces from frame parameters."
1436 (dolist (face (face-list))
1437 (let ((spec (or (get face 'saved-face)
1438 (get face 'face-defface-spec))))
1439 (when spec
1440 (face-spec-set face spec frame))
1441 (internal-merge-in-global-face face frame)
1442 (when (memq window-system '(x w32))
1443 (make-face-x-resource-internal face frame))))
1444
1445 ;; Initialize attributes from frame parameters.
1446 (let ((params '((foreground-color default :foreground)
1447 (background-color default :background)
1448 (border-color border :background)
1449 (cursor-color cursor :background)
1450 (scroll-bar-foreground scroll-bar :foreground)
1451 (scroll-bar-background scroll-bar :background)
1452 (mouse-color mouse :background))))
1453 (while params
1454 (let ((param-name (nth 0 (car params)))
1455 (face (nth 1 (car params)))
1456 (attr (nth 2 (car params)))
1457 value)
1458 (when (setq value (frame-parameter frame param-name))
1459 (set-face-attribute face frame attr value)))
1460 (setq params (cdr params)))))
1461
1462
1463 (defun tty-create-frame-with-faces (&optional parameters)
1464 "Create a frame from optional frame parameters PARAMETERS.
1465 Parameters not specified by PARAMETERS are taken from
1466 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
1467 contains a `reverse' parameter, handle that. Value is the new frame
1468 created."
1469 (let ((frame (make-terminal-frame parameters))
1470 success)
1471 (unwind-protect
1472 (progn
1473 (frame-set-background-mode frame)
1474 (face-set-after-frame-default frame)
1475 (setq success t))
1476 (unless success
1477 (delete-frame frame)))
1478 frame))
1479
1480
1481 ;; Called from C function init_display to initialize faces of the
1482 ;; dumped terminal frame on startup.
1483
1484 (defun tty-set-up-initial-frame-faces ()
1485 (let ((frame (selected-frame)))
1486 (frame-set-background-mode frame)
1487 (face-set-after-frame-default frame)))
1488
1489
1490
1491 \f
1492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1493 ;;; Compatiblity with 20.2
1494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1495
1496 ;; Update a frame's faces when we change its default font.
1497
1498 (defalias 'frame-update-faces 'ignore)
1499 (make-obsolete 'frame-update-faces "No longer necessary" "21.1")
1500
1501 ;; Update the colors of FACE, after FRAME's own colors have been
1502 ;; changed.
1503
1504 (defalias 'frame-update-face-colors 'frame-set-background-mode)
1505 (make-obsolete 'frame-update-face-colors 'frame-set-background-mode "21.1")
1506
1507 \f
1508 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1509 ;;; Standard faces.
1510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1511
1512 (defgroup basic-faces nil
1513 "The standard faces of Emacs."
1514 :group 'faces)
1515
1516
1517 (defface default
1518 '((t nil))
1519 "Basic default face."
1520 :group 'basic-faces)
1521
1522
1523 (defface mode-line
1524 '((((type x) (class color))
1525 (:box (:line-width 2 :style released-button)
1526 :background "grey75" :foreground "black"))
1527 (((type w32) (class color))
1528 (:box (:line-width 2 :style released-button)
1529 :background "grey75" :foreground "black"))
1530 (t
1531 (:inverse-video t)))
1532 "Basic mode line face."
1533 :version "21.1"
1534 :group 'modeline
1535 :group 'basic-faces)
1536
1537 ;; Make `modeline' an alias for `mode-line', for compatibility.
1538 (put 'modeline 'face-alias 'mode-line)
1539
1540 (defface header-line
1541 '((((type x) (class color))
1542 (:box (:line-width 2 :style released-button)
1543 :background "grey75" :foreground "black"))
1544 (((type w32) (class color))
1545 (:box (:line-width 2 :style released-button)
1546 :background "grey75" :foreground "black"))
1547 (t
1548 (:inverse-video t)))
1549 "Basic header-line face."
1550 :version "21.1"
1551 :group 'basic-faces)
1552
1553
1554 (defface tool-bar
1555 '((((type x) (class color))
1556 (:box (:line-width 1 :style released-button)
1557 :background "grey75" :foreground "black"))
1558 (((type x) (class mono))
1559 (:box (:line-width 1 :style released-button)
1560 :background "grey" :foreground "black"))
1561 (((type w32) (class color))
1562 (:box (:line-width 1 :style released-button)
1563 :background "grey75" :foreground "black"))
1564 (t
1565 ()))
1566 "Basic tool-bar face."
1567 :version "21.1"
1568 :group 'basic-faces)
1569
1570
1571 (defface region
1572 '((((type tty) (class color))
1573 (:background "blue" :foreground "white"))
1574 (((type tty) (class mono))
1575 (:inverse-video t))
1576 (((class color) (background dark))
1577 (:background "blue"))
1578 (((class color) (background light))
1579 (:background "light goldenrod yellow"))
1580 (t (:background "gray")))
1581 "Basic face for highlighting the region."
1582 :group 'basic-faces)
1583
1584
1585 (defface fringe
1586 '((((class color) (background light))
1587 (:background "grey95"))
1588 (((class color) (background dark))
1589 (:background "grey10"))
1590 (t
1591 (:background "gray")))
1592 "Basic face for the fringes to the left and right of windows under X."
1593 :version "21.1"
1594 :group 'frames
1595 :group 'basic-faces)
1596
1597
1598 (defface scroll-bar '()
1599 "Basic face for the scroll bar colors under X."
1600 :version "21.1"
1601 :group 'frames
1602 :group 'basic-faces)
1603
1604
1605 (defface menu
1606 '((((type x-toolkit)) ())
1607 (t (:inverse-video t)))
1608 "Basic menu face."
1609 :version "21.1"
1610 :group 'menu
1611 :group 'basic-faces)
1612
1613
1614 (defface border '()
1615 "Basic face for the frame border under X."
1616 :version "21.1"
1617 :group 'frames
1618 :group 'basic-faces)
1619
1620
1621 (defface cursor '()
1622 "Basic face for the cursor color under X."
1623 :version "21.1"
1624 :group 'cursor
1625 :group 'basic-faces)
1626
1627
1628 (defface mouse '()
1629 "Basic face for the mouse color under X."
1630 :version "21.1"
1631 :group 'mouse
1632 :group 'basic-faces)
1633
1634
1635 (defface bold '((t (:weight bold)))
1636 "Basic bold face."
1637 :group 'basic-faces)
1638
1639
1640 (defface italic '((t (:slant italic)))
1641 "Basic italic font."
1642 :group 'basic-faces)
1643
1644
1645 (defface bold-italic '((t (:weight bold :slant italic)))
1646 "Basic bold-italic face."
1647 :group 'basic-faces)
1648
1649
1650 (defface underline '((t (:underline t)))
1651 "Basic underlined face."
1652 :group 'basic-faces)
1653
1654
1655 (defface highlight
1656 '((((type tty) (class color))
1657 (:background "green"))
1658 (((class color) (background light))
1659 (:background "darkseagreen2"))
1660 (((class color) (background dark))
1661 (:background "darkolivegreen"))
1662 (t (:inverse-video t)))
1663 "Basic face for highlighting."
1664 :group 'basic-faces)
1665
1666
1667 (defface secondary-selection
1668 '((((type tty) (class color))
1669 (:background "cyan"))
1670 (((class color) (background light))
1671 (:background "yellow"))
1672 (((class color) (background dark))
1673 (:background "yellow"))
1674 (t (:inverse-video t)))
1675 "Basic face for displaying the secondary selection."
1676 :group 'basic-faces)
1677
1678
1679 (defface fixed-pitch '((t (:family "courier")))
1680 "The basic fixed-pitch face."
1681 :group 'basic-faces)
1682
1683
1684 (defface variable-pitch '((t (:family "helv")))
1685 "The basic variable-pitch face."
1686 :group 'basic-faces)
1687
1688
1689 (defface trailing-whitespace
1690 '((((class color) (background light))
1691 (:background "red"))
1692 (((class color) (background dark))
1693 (:background "red"))
1694 (t (:inverse-video t)))
1695 "Basic face for highlighting trailing whitespace."
1696 :version "21.1"
1697 :group 'font-lock ; like `show-trailing-whitespace'
1698 :group 'basic-faces)
1699
1700
1701 \f
1702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1703 ;;; Manipulating font names.
1704 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1705
1706 ;; This is here for compatibilty with Emacs 20.2. For example,
1707 ;; international/fontset.el uses x-resolve-font-name. The following
1708 ;; functions are not used in the face implementation itself.
1709
1710 (defvar x-font-regexp nil)
1711 (defvar x-font-regexp-head nil)
1712 (defvar x-font-regexp-weight nil)
1713 (defvar x-font-regexp-slant nil)
1714
1715 (defconst x-font-regexp-weight-subnum 1)
1716 (defconst x-font-regexp-slant-subnum 2)
1717 (defconst x-font-regexp-swidth-subnum 3)
1718 (defconst x-font-regexp-adstyle-subnum 4)
1719
1720 ;;; Regexps matching font names in "Host Portable Character Representation."
1721 ;;;
1722 (let ((- "[-?]")
1723 (foundry "[^-]+")
1724 (family "[^-]+")
1725 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
1726 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
1727 (weight\? "\\([^-]*\\)") ; 1
1728 (slant "\\([ior]\\)") ; 2
1729 ; (slant\? "\\([ior?*]?\\)") ; 2
1730 (slant\? "\\([^-]?\\)") ; 2
1731 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
1732 (swidth "\\([^-]*\\)") ; 3
1733 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
1734 (adstyle "\\([^-]*\\)") ; 4
1735 (pixelsize "[0-9]+")
1736 (pointsize "[0-9][0-9]+")
1737 (resx "[0-9][0-9]+")
1738 (resy "[0-9][0-9]+")
1739 (spacing "[cmp?*]")
1740 (avgwidth "[0-9]+")
1741 (registry "[^-]+")
1742 (encoding "[^-]+")
1743 )
1744 (setq x-font-regexp
1745 (concat "\\`\\*?[-?*]"
1746 foundry - family - weight\? - slant\? - swidth - adstyle -
1747 pixelsize - pointsize - resx - resy - spacing - avgwidth -
1748 registry - encoding "\\*?\\'"
1749 ))
1750 (setq x-font-regexp-head
1751 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
1752 "\\([-*?]\\|\\'\\)"))
1753 (setq x-font-regexp-slant (concat - slant -))
1754 (setq x-font-regexp-weight (concat - weight -))
1755 nil)
1756
1757
1758 (defun x-resolve-font-name (pattern &optional face frame)
1759 "Return a font name matching PATTERN.
1760 All wildcards in PATTERN are instantiated.
1761 If PATTERN is nil, return the name of the frame's base font, which never
1762 contains wildcards.
1763 Given optional arguments FACE and FRAME, return a font which is
1764 also the same size as FACE on FRAME, or fail."
1765 (or (symbolp face)
1766 (setq face (face-name face)))
1767 (and (eq frame t)
1768 (setq frame nil))
1769 (if pattern
1770 ;; Note that x-list-fonts has code to handle a face with nil as its font.
1771 (let ((fonts (x-list-fonts pattern face frame 1)))
1772 (or fonts
1773 (if face
1774 (if (string-match "\\*" pattern)
1775 (if (null (face-font face))
1776 (error "No matching fonts are the same height as the frame default font")
1777 (error "No matching fonts are the same height as face `%s'" face))
1778 (if (null (face-font face))
1779 (error "Height of font `%s' doesn't match the frame default font"
1780 pattern)
1781 (error "Height of font `%s' doesn't match face `%s'"
1782 pattern face)))
1783 (error "No fonts match `%s'" pattern)))
1784 (car fonts))
1785 (cdr (assq 'font (frame-parameters (selected-frame))))))
1786
1787
1788 (defun x-frob-font-weight (font which)
1789 (let ((case-fold-search t))
1790 (cond ((string-match x-font-regexp font)
1791 (concat (substring font 0
1792 (match-beginning x-font-regexp-weight-subnum))
1793 which
1794 (substring font (match-end x-font-regexp-weight-subnum)
1795 (match-beginning x-font-regexp-adstyle-subnum))
1796 ;; Replace the ADD_STYLE_NAME field with *
1797 ;; because the info in it may not be the same
1798 ;; for related fonts.
1799 "*"
1800 (substring font (match-end x-font-regexp-adstyle-subnum))))
1801 ((string-match x-font-regexp-head font)
1802 (concat (substring font 0 (match-beginning 1)) which
1803 (substring font (match-end 1))))
1804 ((string-match x-font-regexp-weight font)
1805 (concat (substring font 0 (match-beginning 1)) which
1806 (substring font (match-end 1)))))))
1807 (make-obsolete 'x-frob-font-weight 'make-face-... "21.1")
1808
1809 (defun x-frob-font-slant (font which)
1810 (let ((case-fold-search t))
1811 (cond ((string-match x-font-regexp font)
1812 (concat (substring font 0
1813 (match-beginning x-font-regexp-slant-subnum))
1814 which
1815 (substring font (match-end x-font-regexp-slant-subnum)
1816 (match-beginning x-font-regexp-adstyle-subnum))
1817 ;; Replace the ADD_STYLE_NAME field with *
1818 ;; because the info in it may not be the same
1819 ;; for related fonts.
1820 "*"
1821 (substring font (match-end x-font-regexp-adstyle-subnum))))
1822 ((string-match x-font-regexp-head font)
1823 (concat (substring font 0 (match-beginning 2)) which
1824 (substring font (match-end 2))))
1825 ((string-match x-font-regexp-slant font)
1826 (concat (substring font 0 (match-beginning 1)) which
1827 (substring font (match-end 1)))))))
1828 (make-obsolete 'x-frob-font-slant 'make-face-... "21.1")
1829
1830 (defun x-make-font-bold (font)
1831 "Given an X font specification, make a bold version of it.
1832 If that can't be done, return nil."
1833 (x-frob-font-weight font "bold"))
1834 (make-obsolete 'x-make-font-bold 'make-face-bold "21.1")
1835
1836 (defun x-make-font-demibold (font)
1837 "Given an X font specification, make a demibold version of it.
1838 If that can't be done, return nil."
1839 (x-frob-font-weight font "demibold"))
1840 (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1")
1841
1842 (defun x-make-font-unbold (font)
1843 "Given an X font specification, make a non-bold version of it.
1844 If that can't be done, return nil."
1845 (x-frob-font-weight font "medium"))
1846 (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1")
1847
1848 (defun x-make-font-italic (font)
1849 "Given an X font specification, make an italic version of it.
1850 If that can't be done, return nil."
1851 (x-frob-font-slant font "i"))
1852 (make-obsolete 'x-make-font-italic 'make-face-italic "21.1")
1853
1854 (defun x-make-font-oblique (font) ; you say tomayto...
1855 "Given an X font specification, make an oblique version of it.
1856 If that can't be done, return nil."
1857 (x-frob-font-slant font "o"))
1858 (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1")
1859
1860 (defun x-make-font-unitalic (font)
1861 "Given an X font specification, make a non-italic version of it.
1862 If that can't be done, return nil."
1863 (x-frob-font-slant font "r"))
1864 (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1")
1865
1866 (defun x-make-font-bold-italic (font)
1867 "Given an X font specification, make a bold and italic version of it.
1868 If that can't be done, return nil."
1869 (and (setq font (x-make-font-bold font))
1870 (x-make-font-italic font)))
1871 (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1")
1872
1873 (provide 'faces)
1874
1875 ;;; faces.el ends here