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