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