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