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