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