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