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