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