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