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