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