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