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