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