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