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