Commit | Line | Data |
---|---|---|
5f5c8ee5 | 1 | ;;; faces.el --- Lisp faces |
465fceed | 2 | |
16b34e08 | 3 | ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999 |
5f5c8ee5 | 4 | ;; Free Software Foundation, Inc. |
465fceed ER |
5 | |
6 | ;; This file is part of GNU Emacs. | |
7 | ||
8 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 | ;; it under the terms of the GNU General Public License as published by | |
10 | ;; the Free Software Foundation; either version 2, or (at your option) | |
11 | ;; any later version. | |
12 | ||
13 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | ;; GNU General Public License for more details. | |
17 | ||
18 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
19 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
20 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | ;; Boston, MA 02111-1307, USA. | |
465fceed ER |
22 | |
23 | ;;; Commentary: | |
24 | ||
465fceed ER |
25 | ;;; Code: |
26 | ||
39b3b754 | 27 | (eval-when-compile |
5f5c8ee5 GM |
28 | (require 'custom) |
29 | (require 'cl)) | |
30 | ||
31 | (require 'cus-face) | |
32 | ||
33 | \f | |
34 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
35 | ;;; Font selection. | |
36 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
37 | ||
38 | (defgroup font-selection nil | |
39 | "Influencing face font selection." | |
40 | :group 'faces) | |
41 | ||
42 | ||
43 | (defcustom face-font-selection-order | |
44 | '(:width :height :weight :slant) | |
45 | "*A list specifying how face font selection chooses fonts. | |
46 | Each of the four symbols `:width', `:height', `:weight', and `:slant' | |
47 | must appear once in the list, and the list must not contain any other | |
48 | elements. Font selection tries to find a best matching font for | |
49 | those face attributes first that appear first in the list. For | |
50 | example, if `:slant' appears before `:height', font selection first | |
51 | tries to find a font with a suitable slant, even if this results in | |
52 | a font height that isn't optimal." | |
53 | :tag "Font selection order." | |
54 | :group 'font-selection | |
55 | :set #'(lambda (symbol value) | |
56 | (set-default symbol value) | |
57 | (internal-set-font-selection-order value))) | |
58 | ||
59 | ||
60 | (defcustom face-font-family-alternatives | |
61 | '(("courier" "fixed") | |
62 | ("helv" "helvetica" "fixed")) | |
63 | "*Alist of alternative font family names. | |
64 | Each element has the the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...). | |
65 | If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then | |
66 | ALTERNATIVE2 etc." | |
67 | :tag "Alternative font families to try." | |
68 | :group 'font-selection | |
69 | :set #'(lambda (symbol value) | |
70 | (set-default symbol value) | |
71 | (internal-set-alternative-font-family-alist value))) | |
72 | ||
73 | ||
bdda3754 | 74 | \f |
5f5c8ee5 GM |
75 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
76 | ;;; Creation, copying. | |
77 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
78 | ||
79 | ||
80 | (defun face-list () | |
81 | "Return a list of all defined face names." | |
82 | (mapcar #'car face-new-frame-defaults)) | |
83 | ||
84 | ||
85 | ;;; ### If not frame-local initialize by what X resources? | |
86 | ||
87 | (defun make-face (face &optional no-init-from-resources) | |
88 | "Define a new face with name FACE, a symbol. | |
89 | NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local | |
90 | variants of FACE from X resources. (X resources recognized are found | |
91 | in the global variable `face-x-resources'.) If FACE is already known | |
92 | as a face, leave it unmodified. Value is FACE." | |
93 | (interactive "SMake face: ") | |
94 | (unless (facep face) | |
95 | ;; Make frame-local faces (this also makes the global one). | |
96 | (dolist (frame (frame-list)) | |
97 | (internal-make-lisp-face face frame)) | |
98 | ;; Add the face to the face menu. | |
99 | (when (fboundp 'facemenu-add-new-face) | |
100 | (facemenu-add-new-face face)) | |
101 | ;; Define frame-local faces for all frames from X resources. | |
102 | (unless no-init-from-resources | |
103 | (make-face-x-resource-internal face))) | |
104 | face) | |
105 | ||
106 | ||
107 | (defun make-empty-face (face) | |
108 | "Define a new, empty face with name FACE. | |
109 | If the face already exists, it is left unmodified. Value is FACE." | |
110 | (interactive "SMake empty face: ") | |
111 | (make-face face 'no-init-from-resources)) | |
112 | ||
113 | ||
114 | (defun copy-face (old-face new-face &optional frame new-frame) | |
115 | "Define a face just like OLD-FACE, with name NEW-FACE. | |
116 | ||
117 | If NEW-FACE already exists as a face, it is modified to be like | |
118 | OLD-FACE. If it doesn't already exist, it is created. | |
119 | ||
120 | If the optional argument FRAME is given as a frame, NEW-FACE is | |
121 | changed on FRAME only. | |
122 | If FRAME is t, the frame-independent default specification for OLD-FACE | |
123 | is copied to NEW-FACE. | |
124 | If FRAME is nil, copying is done for the frame-independent defaults | |
125 | and for each existing frame. | |
126 | ||
127 | If the optional fourth argument NEW-FRAME is given, | |
128 | copy the information from face OLD-FACE on frame FRAME | |
129 | to NEW-FACE on frame NEW-FRAME." | |
130 | (let ((inhibit-quit t)) | |
131 | (if (null frame) | |
132 | (progn | |
133 | (dolist (frame (frame-list)) | |
134 | (copy-face old-face new-face frame)) | |
135 | (copy-face old-face new-face t)) | |
136 | (internal-copy-lisp-face old-face new-face frame new-frame)) | |
137 | new-face)) | |
138 | ||
139 | ||
140 | \f | |
141 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
142 | ;;; Obsolete functions | |
143 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
144 | ||
145 | ;; The functions in this section are defined because Lisp packages use | |
146 | ;; them, despite the prefix `internal-' suggesting that they are | |
147 | ;; private to the face implementation. | |
148 | ||
149 | (defun internal-find-face (name &optional frame) | |
150 | "Retrieve the face named NAME. | |
151 | Return nil if there is no such face. | |
152 | If the optional argument FRAME is given, this gets the face NAME for | |
153 | that frame; otherwise, it uses the selected frame. | |
154 | If FRAME is the symbol t, then the global, non-frame face is returned. | |
155 | If NAME is already a face, it is simply returned. | |
156 | ||
157 | This function is defined for compatibility with Emacs 20.2. It | |
158 | should not be used anymore." | |
159 | (facep name)) | |
160 | ||
161 | ||
162 | (defun internal-get-face (name &optional frame) | |
163 | "Retrieve the face named NAME; error if there is none. | |
164 | If the optional argument FRAME is given, this gets the face NAME for | |
165 | that frame; otherwise, it uses the selected frame. | |
166 | If FRAME is the symbol t, then the global, non-frame face is returned. | |
167 | If NAME is already a face, it is simply returned. | |
168 | ||
169 | This function is defined for compatibility with Emacs 20.2. It | |
170 | should not be used anymore." | |
171 | (or (internal-find-face name frame) | |
172 | (check-face name))) | |
173 | ||
174 | ||
175 | \f | |
176 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
177 | ;;; Predicates, type checks. | |
178 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
179 | ||
180 | (defun facep (face) | |
181 | "Return non-nil if FACE is a face name." | |
182 | (internal-lisp-face-p face)) | |
183 | ||
184 | ||
185 | (defun check-face (face) | |
186 | "Signal an error if FACE doesn't name a face. | |
187 | Value is FACE." | |
188 | (unless (facep face) | |
189 | (error "Not a face: %s" face)) | |
190 | face) | |
191 | ||
192 | ||
193 | ;; The ID returned is not to be confused with the internally used IDs | |
194 | ;; of realized faces. The ID assigned to Lisp faces is used to | |
195 | ;; support faces in display table entries. | |
196 | ||
197 | (defun face-id (face &optional frame) | |
198 | "Return the interNal ID of face with name FACE. | |
199 | If optional argument FRAME is nil or omitted, use the selected frame." | |
200 | (check-face face) | |
201 | (get face 'face)) | |
202 | ||
203 | ||
204 | (defun face-equal (face1 face2 &optional frame) | |
205 | "Non-nil if faces FACE1 and FACE2 are equal. | |
206 | Faces are considered equal if all their attributes are equal. | |
207 | If the optional argument FRAME is given, report on face FACE in that frame. | |
208 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
209 | If FRAME is omitted or nil, use the selected frame." | |
210 | (internal-lisp-face-equal-p face1 face2 frame)) | |
211 | ||
212 | ||
213 | (defun face-differs-from-default-p (face &optional frame) | |
214 | "Non-nil if FACE displays differently from the default face. | |
215 | If the optional argument FRAME is given, report on face FACE in that frame. | |
216 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
217 | If FRAME is omitted or nil, use the selected frame. | |
218 | A face is considered to be ``the same'' as the default face if it is | |
219 | actually specified in the same way (equal attributes) or if it is | |
220 | fully-unspecified, and thus inherits the attributes of any face it | |
221 | is displayed on top of." | |
6904df7a GM |
222 | (cond ((eq frame t) (setq frame nil)) |
223 | ((null frame) (setq frame (selected-frame)))) | |
224 | (let* ((v1 (internal-lisp-face-p face frame)) | |
225 | (n (if v1 (length v1) 0)) | |
226 | (v2 (internal-lisp-face-p 'default frame)) | |
227 | (i 1)) | |
228 | (unless v1 | |
229 | (error "Not a face: %S" face)) | |
230 | (while (and (< i n) | |
231 | (or (eq 'unspecified (aref v1 i)) | |
232 | (equal (aref v1 i) (aref v2 i)))) | |
233 | (setq i (1+ i))) | |
234 | (< i n))) | |
5f5c8ee5 GM |
235 | |
236 | ||
237 | (defun face-nontrivial-p (face &optional frame) | |
238 | "True if face FACE has some non-nil attribute. | |
239 | If the optional argument FRAME is given, report on face FACE in that frame. | |
240 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
241 | If FRAME is omitted or nil, use the selected frame." | |
242 | (not (internal-lisp-face-empty-p face frame))) | |
243 | ||
244 | ||
245 | \f | |
246 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
247 | ;;; Setting face attributes from X resources. | |
248 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
249 | ||
250 | (defcustom face-x-resources | |
251 | '((:family (".attributeFamily" . "Face.AttributeFamily")) | |
252 | (:width (".attributeWidth" . "Face.AttributeWidth")) | |
253 | (:height (".attributeHeight" . "Face.AttributeHeight")) | |
254 | (:weight (".attributeWeight" . "Face.AttributeWeight")) | |
255 | (:slant (".attributeSlant" . "Face.AttributeSlant")) | |
256 | (:foreground (".attributeForeground" . "Face.AttributeForeground")) | |
257 | (:background (".attributeBackground" . "Face.AttributeBackground")) | |
258 | (:overline (".attributeOverline" . "Face.AttributeOverline")) | |
259 | (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough")) | |
260 | (:box (".attributeBox" . "Face.AttributeBox")) | |
261 | (:underline (".attributeUnderline" . "Face.AttributeUnderline")) | |
262 | (:inverse-video (".attributeInverse" . "Face.AttributeInverse")) | |
263 | (:stipple | |
264 | (".attributeStipple" . "Face.AttributeStipple") | |
265 | (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap")) | |
266 | (:font (".attributeFont" . "Face.AttributeFont")) | |
267 | (:bold (".attributeBold" . "Face.AttributeBold")) | |
268 | (:italic (".attributeItalic" . "Face.AttributeItalic")) | |
269 | (:font (".attributeFont" . "Face.AttributeFont"))) | |
270 | "*List of X resources and classes for face attributes. | |
271 | Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is | |
272 | the name of a face attribute, and each ENTRY is a cons of the form | |
273 | (RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the | |
274 | X resource class for the attribute." | |
275 | :type 'sexp | |
276 | :group 'faces) | |
277 | ||
278 | ||
279 | (defun set-face-attribute-from-resource (face attribute resource class frame) | |
280 | "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME. | |
281 | Value is the attribute value specified by the resource, or nil | |
282 | if not present. This function displays a message if the resource | |
283 | specifies an invalid attribute." | |
284 | (let* ((face-name (face-name face)) | |
285 | (value (internal-face-x-get-resource (concat face-name resource) | |
286 | class frame))) | |
287 | (when value | |
288 | (condition-case () | |
289 | (internal-set-lisp-face-attribute-from-resource | |
290 | face attribute (downcase value) frame) | |
291 | (error | |
292 | (message "Face %s, frame %s: invalid attribute %s %s from X resource" | |
293 | face-name frame attribute value)))) | |
294 | value)) | |
295 | ||
296 | ||
297 | (defun set-face-attributes-from-resources (face frame) | |
298 | "Set attributes of FACE from X resources for FRAME." | |
299 | (when (memq (framep frame) '(x w32)) | |
300 | (dolist (definition face-x-resources) | |
301 | (let ((attribute (car definition))) | |
302 | (dolist (entry (cdr definition)) | |
303 | (set-face-attribute-from-resource face attribute (car entry) | |
304 | (cdr entry) frame)))))) | |
305 | ||
306 | ||
307 | (defun make-face-x-resource-internal (face &optional frame) | |
308 | "Fill frame-local FACE on FRAME from X resources. | |
309 | FRAME nil or not specified means do it for all frames." | |
310 | (if (null frame) | |
311 | (dolist (frame (frame-list)) | |
312 | (set-face-attributes-from-resources face frame)) | |
313 | (set-face-attributes-from-resources face frame))) | |
314 | ||
315 | ||
316 | \f | |
317 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
318 | ;;; Retrieving face attributes. | |
319 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
320 | ||
feaad827 | 321 | (defun face-name (face) |
465fceed | 322 | "Return the name of face FACE." |
5f5c8ee5 GM |
323 | (symbol-name (check-face face))) |
324 | ||
325 | ||
326 | (defun face-attribute (face attribute &optional frame) | |
327 | "Return the value of FACE's ATTRIBUTE on FRAME. | |
328 | If the optional argument FRAME is given, report on face FACE in that frame. | |
329 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
330 | If FRAME is omitted or nil, use the selected frame." | |
331 | (internal-get-lisp-face-attribute face attribute frame)) | |
332 | ||
333 | ||
334 | (defun face-foreground (face &optional frame) | |
335 | "Return the foreground color name of FACE, or nil if unspecified. | |
336 | If the optional argument FRAME is given, report on face FACE in that frame. | |
337 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
338 | If FRAME is omitted or nil, use the selected frame." | |
339 | (internal-get-lisp-face-attribute face :foreground frame)) | |
340 | ||
341 | ||
342 | (defun face-background (face &optional frame) | |
343 | "Return the background color name of FACE, or nil if unspecified. | |
344 | If the optional argument FRAME is given, report on face FACE in that frame. | |
345 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
346 | If FRAME is omitted or nil, use the selected frame." | |
347 | (internal-get-lisp-face-attribute face :background frame)) | |
348 | ||
349 | ||
350 | (defun face-stipple (face &optional frame) | |
351 | "Return the stipple pixmap name of FACE, or nil if unspecified. | |
352 | If the optional argument FRAME is given, report on face FACE in that frame. | |
353 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
354 | If FRAME is omitted or nil, use the selected frame." | |
355 | (internal-get-lisp-face-attribute face :stipple frame)) | |
356 | ||
357 | ||
358 | (defalias 'face-background-pixmap 'face-stipple) | |
359 | ||
360 | ||
361 | (defun face-underline-p (face &optional frame) | |
362 | "Return non-nil if FACE is underlined. | |
363 | If the optional argument FRAME is given, report on face FACE in that frame. | |
364 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
365 | If FRAME is omitted or nil, use the selected frame." | |
366 | (eq (face-attribute face :underline frame) t)) | |
367 | ||
368 | ||
369 | (defun face-inverse-video-p (face &optional frame) | |
370 | "Return non-nil if FACE is in inverse video on FRAME. | |
371 | If the optional argument FRAME is given, report on face FACE in that frame. | |
372 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
373 | If FRAME is omitted or nil, use the selected frame." | |
374 | (eq (face-attribute face :inverse-video frame) t)) | |
375 | ||
376 | ||
377 | (defun face-bold-p (face &optional frame) | |
378 | "Return non-nil if the font of FACE is bold on FRAME. | |
379 | If the optional argument FRAME is given, report on face FACE in that frame. | |
380 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
381 | If FRAME is omitted or nil, use the selected frame. | |
382 | Use `face-attribute' for finer control." | |
383 | (let ((bold (face-attribute face :weight frame))) | |
da2c7b8c | 384 | (memq bold '(semi-bold bold extra-bold ultra-bold)))) |
5f5c8ee5 GM |
385 | |
386 | ||
387 | (defun face-italic-p (face &optional frame) | |
388 | "Return non-nil if the font of FACE is italic on FRAME. | |
389 | If the optional argument FRAME is given, report on face FACE in that frame. | |
390 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
391 | If FRAME is omitted or nil, use the selected frame. | |
392 | Use `face-attribute' for finer control." | |
393 | (let ((italic (face-attribute face :slant frame))) | |
a48f6020 | 394 | (memq italic '(italic oblique)))) |
5f5c8ee5 GM |
395 | |
396 | ||
397 | ||
398 | ||
399 | \f | |
400 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
401 | ;;; Face documentation. | |
402 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
403 | ||
404 | (defun face-documentation (face) | |
405 | "Get the documentation string for FACE." | |
406 | (get face 'face-documentation)) | |
407 | ||
408 | ||
409 | (defun set-face-documentation (face string) | |
410 | "Set the documentation string for FACE to STRING." | |
49435801 DL |
411 | ;; The text doesn't get into DOC. |
412 | (put face 'face-documentation (purecopy string))) | |
5f5c8ee5 GM |
413 | |
414 | ||
415 | (defalias 'face-doc-string 'face-documentation) | |
416 | (defalias 'set-face-doc-string 'set-face-documentation) | |
417 | ||
418 | ||
419 | \f | |
420 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
421 | ;; Setting face attributes. | |
422 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
423 | ||
424 | ||
425 | (defun set-face-attribute (face frame &rest args) | |
426 | "Set attributes of FACE on FRAME from ARGS. | |
427 | ||
428 | FRAME nil means change attributes on all frames. FRAME t means change | |
429 | the default for new frames (this is done automatically each time an | |
430 | attribute is changed on all frames). | |
431 | ||
432 | ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid | |
433 | face attribute name. All attributes can be set to `unspecified'; | |
434 | this fact is not further mentioned below. | |
435 | ||
436 | The following attributes are recognized: | |
437 | ||
438 | `:family' | |
439 | ||
440 | VALUE must be a string specifying the font family, e.g. ``courier'', | |
441 | or a fontset alias name. If a font family is specified, wild-cards `*' | |
442 | and `?' are allowed. | |
443 | ||
444 | `:width' | |
445 | ||
446 | VALUE specifies the relative proportionate width of the font to use. | |
447 | It must be one of the symbols `ultra-condensed', `extra-condensed', | |
448 | `condensed', `semi-condensed', `normal', `semi-expanded', `expanded', | |
449 | `extra-expanded', or `ultra-expanded'. | |
450 | ||
451 | `:height' | |
452 | ||
453 | VALUE must be an integer specifying the height of the font to use in | |
454 | 1/10 pt. | |
455 | ||
456 | `:weight' | |
457 | ||
458 | VALUE specifies the weight of the font to use. It must be one of the | |
459 | symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal', | |
460 | `semi-light', `light', `extra-light', `ultra-light'. | |
461 | ||
462 | `:slant' | |
463 | ||
464 | VALUE specifies the slant of the font to use. It must be one of the | |
465 | symbols `italic', `oblique', `normal', `reverse-italic', or | |
466 | `reverse-oblique'. | |
467 | ||
468 | `:foreground', `:background' | |
469 | ||
470 | VALUE must be a color name, a string. | |
471 | ||
472 | `:underline' | |
473 | ||
474 | VALUE specifies whether characters in FACE should be underlined. If | |
475 | VALUE is t, underline with foreground color of the face. If VALUE is | |
476 | a string, underline with that color. If VALUE is nil, explicitly | |
477 | don't underline. | |
478 | ||
479 | `:overline' | |
480 | ||
481 | VALUE specifies whether characters in FACE should be overlined. If | |
482 | VALUE is t, overline with foreground color of the face. If VALUE is a | |
483 | string, overline with that color. If VALUE is nil, explicitly don't | |
484 | overline. | |
485 | ||
486 | `:strike-through' | |
487 | ||
488 | VALUE specifies whether characters in FACE should be drawn with a line | |
489 | striking through them. If VALUE is t, use the foreground color of the | |
490 | face. If VALUE is a string, strike-through with that color. If VALUE | |
491 | is nil, explicitly don't strike through. | |
492 | ||
493 | `:box' | |
494 | ||
495 | VALUE specifies whether characters in FACE should have a box drawn | |
496 | around them. If VALUE is nil, explicitly don't draw boxes. If | |
497 | VALUE is t, draw a box with lines of width 1 in the foreground color | |
498 | of the face. If VALUE is a string, the string must be a color name, | |
499 | and the box is drawn in that color with a line width of 1. Otherwise, | |
500 | VALUE must be a property list of the form `(:line-width WIDTH | |
501 | :color COLOR :style STYLE)'. If a keyword/value pair is missing from | |
502 | the property list, a default value will be used for the value, as | |
503 | specified below. WIDTH specifies the width of the lines to draw; it | |
504 | defaults to 1. COLOR is the name of the color to draw in, default is | |
505 | the foreground color of the face for simple boxes, and the background | |
506 | color of the face for 3D boxes. STYLE specifies whether a 3D box | |
507 | should be draw. If STYLE is `released-button', draw a box looking | |
508 | like a released 3D button. If STYLE is `pressed-button' draw a box | |
509 | that appears like a pressed button. If STYLE is nil, the default if | |
510 | the property list doesn't contain a style specification, draw a 2D | |
511 | box. | |
512 | ||
513 | `:inverse-video' | |
514 | ||
515 | VALUE specifies whether characters in FACE should be displayed in | |
516 | inverse video. VALUE must be one of t or nil. | |
517 | ||
518 | `:stipple' | |
519 | ||
520 | If VALUE is a string, it must be the name of a file of pixmap data. | |
521 | The directories listed in the `x-bitmap-file-path' variable are | |
522 | searched. Alternatively, VALUE may be a list of the form (WIDTH | |
523 | HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA | |
524 | is a string containing the raw bits of the bitmap. VALUE nil means | |
525 | explicitly don't use a stipple pattern. | |
526 | ||
527 | For convenience, attributes `:family', `:width', `:height', `:weight', | |
528 | and `:slant' may also be set in one step from an X font name: | |
529 | ||
530 | `:font' | |
531 | ||
532 | Set font-related face attributes from VALUE. VALUE must be a valid | |
533 | XLFD font name. If it is a font name pattern, the first matching font | |
534 | will be used. | |
535 | ||
536 | For compatibility with Emacs 20, keywords `:bold' and `:italic' can | |
537 | be used to specify that a bold or italic font should be used. VALUE | |
538 | must be t or nil in that case. A value of `unspecified' is not allowed." | |
539 | (cond ((null frame) | |
540 | ;; Change face on all frames. | |
541 | (dolist (frame (frame-list)) | |
542 | (apply #'set-face-attribute face frame args)) | |
543 | ;; Record that as a default for new frames. | |
544 | (apply #'set-face-attribute face t args)) | |
545 | (t | |
546 | (while args | |
547 | (internal-set-lisp-face-attribute face (car args) | |
548 | (car (cdr args)) frame) | |
549 | (setq args (cdr (cdr args))))))) | |
550 | ||
551 | ||
39cac3e7 | 552 | (defun make-face-bold (face &optional frame noerror) |
5f5c8ee5 GM |
553 | "Make the font of FACE be bold, if possible. |
554 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 555 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 GM |
556 | Use `set-face-attribute' for finer control of the font weight." |
557 | (interactive (list (read-face-name "Make which face bold: "))) | |
558 | (set-face-attribute face frame :weight 'bold)) | |
559 | ||
560 | ||
39cac3e7 | 561 | (defun make-face-unbold (face &optional frame noerror) |
5f5c8ee5 | 562 | "Make the font of FACE be non-bold, if possible. |
39cac3e7 GM |
563 | FRAME nil or not specified means change face on all frames. |
564 | Argument NOERROR is ignored and retained for compatibility." | |
5f5c8ee5 GM |
565 | (interactive (list (read-face-name "Make which face non-bold: "))) |
566 | (set-face-attribute face frame :weight 'normal)) | |
567 | ||
568 | ||
39cac3e7 | 569 | (defun make-face-italic (face &optional frame noerror) |
5f5c8ee5 GM |
570 | "Make the font of FACE be italic, if possible. |
571 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 572 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 GM |
573 | Use `set-face-attribute' for finer control of the font slant." |
574 | (interactive (list (read-face-name "Make which face italic: "))) | |
575 | (set-face-attribute face frame :slant 'italic)) | |
576 | ||
577 | ||
39cac3e7 | 578 | (defun make-face-unitalic (face &optional frame noerror) |
5f5c8ee5 GM |
579 | "Make the font of FACE be non-italic, if possible. |
580 | FRAME nil or not specified means change face on all frames." | |
581 | (interactive (list (read-face-name "Make which face non-italic: "))) | |
582 | (set-face-attribute face frame :slant 'normal)) | |
583 | ||
584 | ||
39cac3e7 | 585 | (defun make-face-bold-italic (face &optional frame noerror) |
5f5c8ee5 GM |
586 | "Make the font of FACE be bold and italic, if possible. |
587 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 588 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 GM |
589 | Use `set-face-attribute' for finer control of font weight and slant." |
590 | (interactive (list (read-face-name "Make which face bold-italic: "))) | |
591 | (set-face-attribute face frame :weight 'bold :slant 'italic)) | |
592 | ||
593 | ||
594 | (defun set-face-font (face font &optional frame) | |
595 | "Change font-related attributes of FACE to those of FONT (a string). | |
596 | FRAME nil or not specified means change face on all frames. | |
597 | This sets the attributes `:family', `:width', `:height', `:weight', | |
598 | and `:slant'. When called interactively, prompt for the face and font." | |
599 | (interactive (read-face-and-attribute :font)) | |
600 | (set-face-attribute face frame :font font)) | |
601 | ||
602 | ||
603 | ;; Implementation note: Emulating gray background colors with a | |
604 | ;; stipple pattern is now part of the face realization process, and is | |
605 | ;; done in C depending on the frame on which the face is realized. | |
606 | ||
607 | (defun set-face-background (face color &optional frame) | |
608 | "Change the background color of face FACE to COLOR (a string). | |
609 | FRAME nil or not specified means change face on all frames. | |
610 | When called interactively, prompt for the face and color." | |
611 | (interactive (read-face-and-attribute :background)) | |
612 | (set-face-attribute face frame :background color)) | |
613 | ||
614 | ||
615 | (defun set-face-foreground (face color &optional frame) | |
616 | "Change the foreground color of face FACE to COLOR (a string). | |
617 | FRAME nil or not specified means change face on all frames. | |
618 | When called interactively, prompt for the face and color." | |
619 | (interactive (read-face-and-attribute :foreground)) | |
620 | (set-face-attribute face frame :foreground color)) | |
621 | ||
622 | ||
623 | (defun set-face-stipple (face stipple &optional frame) | |
624 | "Change the stipple pixmap of face FACE to STIPPLE. | |
625 | FRAME nil or not specified means change face on all frames. | |
626 | STIPPLE. should be a string, the name of a file of pixmap data. | |
627 | The directories listed in the `x-bitmap-file-path' variable are searched. | |
628 | ||
629 | Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA) | |
630 | where WIDTH and HEIGHT are the size in pixels, | |
631 | and DATA is a string, containing the raw bits of the bitmap." | |
632 | (interactive (read-face-and-attribute :stipple)) | |
633 | (set-face-attribute face frame :stipple stipple)) | |
634 | ||
635 | ||
636 | (defun set-face-underline (face underline &optional frame) | |
637 | "Specify whether face FACE is underlined. | |
638 | UNDERLINE nil means FACE explicitly doesn't underline. | |
639 | UNDERLINE non-nil means FACE explicitly does underlining | |
640 | with the same of the foreground color. | |
641 | If UNDERLINE is a string, underline with the color named UNDERLINE. | |
642 | FRAME nil or not specified means change face on all frames. | |
643 | Use `set-face-attribute' to ``unspecify'' underlining." | |
644 | (interactive | |
645 | (let ((list (read-face-and-attribute :underline))) | |
646 | (list (car list) (eq (car (cdr list)) t)))) | |
647 | (set-face-attribute face frame :underline underline)) | |
648 | ||
649 | ||
650 | (defun set-face-underline-p (face underline-p &optional frame) | |
651 | "Specify whether face FACE is underlined. | |
652 | UNDERLINE-P nil means FACE explicitly doesn't underline. | |
653 | UNDERLINE-P non-nil means FACE explicitly does underlining. | |
654 | FRAME nil or not specified means change face on all frames. | |
655 | Use `set-face-attribute' to ``unspecify'' underlining." | |
656 | (interactive | |
657 | (let ((list (read-face-and-attribute :underline))) | |
658 | (list (car list) (eq (car (cdr list)) t)))) | |
659 | (set-face-attribute face frame :underline underline-p)) | |
660 | ||
661 | ||
662 | (defun set-face-inverse-video-p (face inverse-video-p &optional frame) | |
663 | "Specify whether face FACE is in inverse video. | |
664 | INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video. | |
665 | INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video. | |
666 | FRAME nil or not specified means change face on all frames. | |
667 | Use `set-face-attribute' to ``unspecify'' the inverse video attribute." | |
668 | (interactive | |
669 | (let ((list (read-face-and-attribute :inverse-video))) | |
670 | (list (car list) (eq (car (cdr list)) t)))) | |
671 | (set-face-attribute face frame :inverse-video inverse-video-p)) | |
672 | ||
673 | ||
674 | (defun set-face-bold-p (face bold-p &optional frame) | |
675 | "Specify whether face FACE is bold. | |
676 | BOLD-P non-nil means FACE should explicitly display bold. | |
677 | BOLD-P nil means FACE should explicitly display non-bold. | |
678 | FRAME nil or not specified means change face on all frames. | |
679 | Use `set-face-attribute' or `modify-face' for finer control." | |
680 | (if (null bold-p) | |
681 | (make-face-unbold face frame) | |
682 | (make-face-bold face frame))) | |
683 | ||
684 | ||
685 | (defun set-face-italic-p (face italic-p &optional frame) | |
686 | "Specify whether face FACE is italic. | |
687 | ITALIC-P non-nil means FACE should explicitly display italic. | |
688 | ITALIC-P nil means FACE should explicitly display non-italic. | |
689 | FRAME nil or not specified means change face on all frames. | |
690 | Use `set-face-attribute' or `modify-face' for finer control." | |
691 | (if (null italic-p) | |
692 | (make-face-unitalic face frame) | |
693 | (make-face-italic face frame))) | |
694 | ||
695 | ||
696 | (defalias 'set-face-background-pixmap 'set-face-stipple) | |
697 | ||
698 | ||
699 | (defun invert-face (face &optional frame) | |
700 | "Swap the foreground and background colors of FACE. | |
701 | FRAME nil or not specified means change face on all frames. | |
702 | If FACE specifies neither foreground nor background color, | |
703 | set its foreground and background to the background and foreground | |
704 | of the default face. Value is FACE." | |
705 | (interactive (list (read-face-name "Invert face: "))) | |
706 | (let ((fg (face-attribute face :foreground frame)) | |
707 | (bg (face-attribute face :background frame))) | |
708 | (if (or fg bg) | |
709 | (set-face-attribute face frame :foreground bg :background fg) | |
710 | (set-face-attribute face frame | |
711 | :foreground | |
712 | (face-attribute 'default :background frame) | |
713 | :background | |
714 | (face-attribute 'default :foreground frame)))) | |
715 | face) | |
716 | ||
717 | \f | |
718 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
719 | ;;; Interactively modifying faces. | |
720 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
721 | ||
722 | (defun read-face-name (prompt) | |
723 | "Read and return a face symbol, prompting with PROMPT. | |
724 | Value is a symbol naming a known face." | |
725 | (let ((face-list (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
726 | (face-list))) | |
727 | face) | |
728 | (while (equal "" (setq face (completing-read prompt face-list nil t)))) | |
729 | (intern face))) | |
730 | ||
731 | ||
732 | (defun face-valid-attribute-values (attribute &optional frame) | |
733 | "Return valid values for face attribute ATTRIBUTE. | |
734 | The optional argument FRAME is used to determine available fonts | |
735 | and colors. If it is nil or not specified, the selected frame is | |
736 | used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value | |
737 | out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects | |
738 | an integer value." | |
fbd5f1cc GM |
739 | (let (valid) |
740 | (setq valid | |
741 | (case attribute | |
742 | (:family | |
743 | (if window-system | |
744 | (mapcar #'(lambda (x) (cons (car x) (car x))) | |
745 | (x-font-family-list)) | |
746 | ;; Only one font on TTYs. | |
747 | (list (cons "default" "default")))) | |
748 | ((:width :weight :slant :inverse-video) | |
749 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
750 | (internal-lisp-face-attribute-values attribute))) | |
751 | ((:underline :overline :strike-through :box) | |
752 | (if window-system | |
753 | (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
754 | (internal-lisp-face-attribute-values attribute)) | |
755 | (mapcar #'(lambda (c) (cons c c)) | |
756 | (x-defined-colors frame))) | |
757 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
758 | (internal-lisp-face-attribute-values attribute)))) | |
759 | ((:foreground :background) | |
760 | (mapcar #'(lambda (c) (cons c c)) | |
f795f633 | 761 | (defined-colors frame))) |
fbd5f1cc GM |
762 | ((:height) |
763 | 'integerp) | |
764 | (:stipple | |
f3625fc0 | 765 | (and (memq window-system '(x w32)) |
fbd5f1cc GM |
766 | (mapcar #'list |
767 | (apply #'nconc (mapcar #'directory-files | |
768 | x-bitmap-file-path))))) | |
769 | (t | |
770 | (error "Internal error")))) | |
771 | (if (listp valid) | |
772 | (nconc (list (cons "unspecified" 'unspecified)) valid) | |
773 | valid))) | |
774 | ||
5f5c8ee5 GM |
775 | |
776 | ||
777 | (defvar face-attribute-name-alist | |
778 | '((:family . "font family") | |
779 | (:width . "character set width") | |
780 | (:height . "height in 1/10 pt") | |
781 | (:weight . "weight") | |
782 | (:slant . "slant") | |
783 | (:underline . "underline") | |
784 | (:overline . "overline") | |
785 | (:strike-through . "strike-through") | |
786 | (:box . "box") | |
787 | (:inverse-video . "inverse-video display") | |
788 | (:foreground . "foreground color") | |
789 | (:background . "background color") | |
790 | (:stipple . "background stipple")) | |
791 | "An alist of descriptive names for face attributes. | |
792 | Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where | |
793 | ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and | |
794 | DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.") | |
795 | ||
796 | ||
797 | (defun face-descriptive-attribute-name (attribute) | |
798 | "Return a descriptive name for ATTRIBUTE." | |
799 | (cdr (assq attribute face-attribute-name-alist))) | |
800 | ||
801 | ||
802 | (defun face-read-string (face default name &optional completion-alist) | |
803 | "Interactively read a face attribute string value. | |
804 | FACE is the face whose attribute is read. DEFAULT is the default | |
805 | value to return if no new value is entered. NAME is a descriptive | |
806 | name of the attribute for prompting. COMPLETION-ALIST is an alist | |
807 | of valid values, if non-nil. | |
808 | ||
fbd5f1cc | 809 | Entering nothing accepts the default value DEFAULT. |
5f5c8ee5 GM |
810 | Value is the new attribute value." |
811 | (let* ((completion-ignore-case t) | |
812 | (value (completing-read | |
813 | (if default | |
814 | (format "Set face %s %s (default %s): " | |
815 | face name (downcase (if (symbolp default) | |
816 | (symbol-name default) | |
817 | default))) | |
818 | (format "Set face %s %s: " face name)) | |
819 | completion-alist))) | |
fbd5f1cc | 820 | (if (equal value "") default value))) |
5f5c8ee5 GM |
821 | |
822 | ||
823 | (defun face-read-integer (face default name) | |
824 | "Interactively read an integer face attribute value. | |
825 | FACE is the face whose attribute is read. DEFAULT is the default | |
826 | value to return if no new value is entered. NAME is a descriptive | |
827 | name of the attribute for prompting. Value is the new attribute value." | |
fbd5f1cc GM |
828 | (let ((new-value |
829 | (face-read-string face | |
f9d2fdc4 EZ |
830 | (if (memq |
831 | default | |
832 | '(unspecified unspecified-fg unspecified-bg)) | |
833 | default | |
fbd5f1cc GM |
834 | (int-to-string default)) |
835 | name | |
836 | (list (cons "unspecified" 'unspecified))))) | |
f9d2fdc4 | 837 | (if (memq new-value '(unspecified unspecified-fg unspecified-bg)) |
fbd5f1cc GM |
838 | new-value |
839 | (string-to-int new-value)))) | |
5f5c8ee5 GM |
840 | |
841 | ||
842 | (defun read-face-attribute (face attribute &optional frame) | |
843 | "Interactively read a new value for FACE's ATTRIBUTE. | |
844 | Optional argument FRAME nil or unspecified means read an attribute value | |
845 | of a global face. Value is the new attribute value." | |
846 | (let* ((old-value (face-attribute face attribute frame)) | |
847 | (attribute-name (face-descriptive-attribute-name attribute)) | |
848 | (valid (face-valid-attribute-values attribute frame)) | |
849 | new-value) | |
850 | ;; Represent complex attribute values as strings by printing them | |
851 | ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be | |
852 | ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow | |
853 | ;; SHADOW)'. | |
854 | (when (and (or (eq attribute :stipple) | |
855 | (eq attribute :box)) | |
856 | (or (consp old-value) | |
857 | (vectorp old-value))) | |
858 | (setq old-value (prin1-to-string old-value))) | |
859 | (cond ((listp valid) | |
860 | (setq new-value | |
fbd5f1cc | 861 | (face-read-string face old-value attribute-name valid)) |
f795f633 EZ |
862 | ;; Terminal frames can support colors that don't appear |
863 | ;; explicitly in VALID, using color approximation code | |
864 | ;; in tty-colors.el. | |
865 | (if (and (memq attribute '(:foreground :background)) | |
866 | (not (memq window-system '(x w32 mac))) | |
f9d2fdc4 EZ |
867 | (not (memq new-value |
868 | '(unspecified unspecified-fg unspecified-bg)))) | |
f795f633 | 869 | (setq new-value (car (tty-color-desc new-value)))) |
fbd5f1cc GM |
870 | (unless (eq new-value 'unspecified) |
871 | (setq new-value (cdr (assoc new-value valid))))) | |
5f5c8ee5 GM |
872 | ((eq valid 'integerp) |
873 | (setq new-value (face-read-integer face old-value attribute-name))) | |
874 | (t (error "Internal error"))) | |
875 | ;; Convert stipple and box value text we read back to a list or | |
876 | ;; vector if it looks like one. This makes the assumption that a | |
877 | ;; pixmap file name won't start with an open-paren. | |
878 | (when (and (or (eq attribute :stipple) | |
879 | (eq attribute :box)) | |
880 | (stringp new-value) | |
881 | (string-match "^[[(]" new-value)) | |
882 | (setq new-value (read new-value))) | |
883 | new-value)) | |
884 | ||
885 | ||
886 | (defun read-face-font (face &optional frame) | |
887 | "Read the name of a font for FACE on FRAME. | |
888 | If optional argument FRAME Is nil or omitted, use the selected frame." | |
889 | (let ((completion-ignore-case t)) | |
890 | (completing-read "Set font attributes of face %s from font: " | |
891 | face (x-list-fonts "*" nil frame)))) | |
892 | ||
893 | ||
894 | (defun read-all-face-attributes (face &optional frame) | |
895 | "Interactively read all attributes for FACE. | |
896 | If optional argument FRAME Is nil or omitted, use the selected frame. | |
897 | Value is a property list of attribute names and new values." | |
898 | (let (result) | |
899 | (dolist (attribute face-attribute-name-alist result) | |
900 | (setq result (cons (car attribute) | |
901 | (cons (read-face-attribute face (car attribute) frame) | |
902 | result)))))) | |
903 | ||
904 | ||
905 | (defun modify-face (&optional frame) | |
906 | "Modify attributes of faces interactively. | |
907 | If optional argument FRAME is nil or omitted, modify the face used | |
908 | for newly created frame, i.e. the global face." | |
909 | (interactive) | |
910 | (let ((face (read-face-name "Modify face: "))) | |
911 | (apply #'set-face-attribute face frame | |
912 | (read-all-face-attributes face frame)))) | |
913 | ||
914 | ||
915 | (defun read-face-and-attribute (attribute &optional frame) | |
916 | "Read face name and face attribute value. | |
917 | ATTRIBUTE is the attribute whose new value is read. | |
918 | FRAME nil or unspecified means read attribute value of global face. | |
919 | Value is a list (FACE NEW-VALUE) where FACE is the face read | |
920 | (a symbol), and NEW-VALUE is value read." | |
921 | (cond ((eq attribute :font) | |
922 | (let* ((prompt (format "Set font-related attributes of face: ")) | |
923 | (face (read-face-name prompt)) | |
924 | (font (read-face-font face frame))) | |
925 | (list face font))) | |
926 | (t | |
927 | (let* ((attribute-name (face-descriptive-attribute-name attribute)) | |
928 | (prompt (format "Set %s of face: " attribute-name)) | |
929 | (face (read-face-name prompt)) | |
930 | (new-value (read-face-attribute face attribute frame))) | |
931 | (list face new-value))))) | |
932 | ||
933 | ||
934 | \f | |
935 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
936 | ;;; Listing faces. | |
937 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
938 | ||
939 | (defvar list-faces-sample-text | |
940 | "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
941 | "*Text string to display as the sample text for `list-faces-display'.") | |
942 | ||
943 | ||
944 | ;; The name list-faces would be more consistent, but let's avoid a | |
945 | ;; conflict with Lucid, which uses that name differently. | |
946 | ||
947 | (defun list-faces-display () | |
948 | "List all faces, using the same sample text in each. | |
949 | The sample text is a string that comes from the variable | |
950 | `list-faces-sample-text'." | |
951 | (interactive) | |
952 | (let ((faces (sort (face-list) #'string-lessp)) | |
953 | (face nil) | |
954 | (frame (selected-frame)) | |
955 | disp-frame window) | |
956 | (with-output-to-temp-buffer "*Faces*" | |
957 | (save-excursion | |
958 | (set-buffer standard-output) | |
959 | (setq truncate-lines t) | |
960 | (while faces | |
961 | (setq face (car faces)) | |
962 | (setq faces (cdr faces)) | |
963 | (insert (format "%25s " (face-name face))) | |
964 | (let ((beg (point))) | |
965 | (insert list-faces-sample-text) | |
966 | (insert "\n") | |
967 | (put-text-property beg (1- (point)) 'face face) | |
968 | ;; If the sample text has multiple lines, line up all of them. | |
969 | (goto-char beg) | |
970 | (forward-line 1) | |
971 | (while (not (eobp)) | |
972 | (insert " ") | |
973 | (forward-line 1)))) | |
974 | (goto-char (point-min))) | |
975 | (print-help-return-message)) | |
976 | ;; If the *Faces* buffer appears in a different frame, | |
977 | ;; copy all the face definitions from FRAME, | |
978 | ;; so that the display will reflect the frame that was selected. | |
979 | (setq window (get-buffer-window (get-buffer "*Faces*") t)) | |
980 | (setq disp-frame (if window (window-frame window) | |
981 | (car (frame-list)))) | |
982 | (or (eq frame disp-frame) | |
983 | (let ((faces (face-list))) | |
984 | (while faces | |
985 | (copy-face (car faces) (car faces) frame disp-frame) | |
986 | (setq faces (cdr faces))))))) | |
987 | ||
988 | ||
989 | (defun describe-face (face &optional frame) | |
990 | "Display the properties of face FACE on FRAME. | |
991 | If the optional argument FRAME is given, report on face FACE in that frame. | |
992 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
993 | If FRAME is omitted or nil, use the selected frame." | |
994 | (interactive (list (read-face-name "Describe face: "))) | |
995 | (let* ((attrs '((:family . "Family") | |
996 | (:width . "Width") | |
997 | (:height . "Height") | |
998 | (:weight . "Weight") | |
999 | (:slant . "Slant") | |
1000 | (:foreground . "Foreground") | |
1001 | (:background . "Background") | |
1002 | (:underline . "Underline") | |
1003 | (:overline . "Overline") | |
1004 | (:strike-through . "Strike-through") | |
1005 | (:box . "Box") | |
1006 | (:inverse-video . "Inverse") | |
1007 | (:stipple . "Stipple"))) | |
1008 | (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x))) | |
1009 | attrs)))) | |
1010 | (with-output-to-temp-buffer "*Help*" | |
1011 | (save-excursion | |
1012 | (set-buffer standard-output) | |
1013 | (dolist (a attrs) | |
1014 | (let ((attr (face-attribute face (car a) frame))) | |
1015 | (insert (make-string (- max-width (length (cdr a))) ?\ ) | |
1016 | (cdr a) ": " (format "%s" attr) "\n"))) | |
1017 | (insert "\nDocumentation:\n\n" | |
1018 | (or (face-documentation face) | |
1019 | "not documented as a face."))) | |
1020 | (print-help-return-message)))) | |
1021 | ||
1022 | ||
1023 | ||
1024 | \f | |
1025 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1026 | ;;; Face specifications (defface). | |
1027 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1028 | ||
1029 | ;; Parameter FRAME Is kept for call compatibility to with previous | |
1030 | ;; face implementation. | |
1031 | ||
1032 | (defun face-attr-construct (face &optional frame) | |
1033 | "Return a defface-style attribute list for FACE on FRAME. | |
1034 | Value is a property list of pairs ATTRIBUTE VALUE for all specified | |
1035 | face attributes of FACE where ATTRIBUTE is the attribute name and | |
1036 | VALUE is the specified value of that attribute." | |
1037 | (let (result) | |
1038 | (dolist (entry face-attribute-name-alist result) | |
1039 | (let* ((attribute (car entry)) | |
1040 | (value (face-attribute face attribute))) | |
1041 | (unless (eq value 'unspecified) | |
1042 | (setq result (nconc (list attribute value) result))))))) | |
1043 | ||
1044 | ||
1045 | (defun face-spec-set-match-display (display frame) | |
1046 | "Non-nil if DISPLAY matches FRAME. | |
1047 | DISPLAY is part of a spec such as can be used in `defface'. | |
1048 | If FRAME is nil, the current FRAME is used." | |
1049 | (let* ((conjuncts display) | |
1050 | conjunct req options | |
1051 | ;; t means we have succeeded against all the conjuncts in | |
1052 | ;; DISPLAY that have been tested so far. | |
1053 | (match t)) | |
1054 | (if (eq conjuncts t) | |
1055 | (setq conjuncts nil)) | |
1056 | (while (and conjuncts match) | |
1057 | (setq conjunct (car conjuncts) | |
1058 | conjuncts (cdr conjuncts) | |
1059 | req (car conjunct) | |
1060 | options (cdr conjunct) | |
1061 | match (cond ((eq req 'type) | |
1062 | (or (memq window-system options) | |
1063 | (and (null window-system) | |
ee716db5 GM |
1064 | (memq 'tty options)) |
1065 | (and (memq 'motif options) | |
1066 | (featurep 'motif)) | |
1067 | (and (memq 'lucid options) | |
1068 | (featurep 'x-toolkit) | |
1069 | (not (featurep 'motif))) | |
1070 | (and (memq 'x-toolkit options) | |
1071 | (featurep 'x-toolkit)))) | |
5f5c8ee5 GM |
1072 | ((eq req 'class) |
1073 | (memq (frame-parameter frame 'display-type) options)) | |
1074 | ((eq req 'background) | |
1075 | (memq (frame-parameter frame 'background-mode) | |
1076 | options)) | |
1077 | (t (error "Unknown req `%S' with options `%S'" | |
1078 | req options))))) | |
1079 | match)) | |
1080 | ||
1081 | ||
1082 | (defun face-spec-choose (spec &optional frame) | |
1083 | "Choose the proper attributes for FRAME, out of SPEC." | |
1084 | (unless frame | |
1085 | (setq frame (selected-frame))) | |
1086 | (let ((tail spec) | |
1087 | result) | |
1088 | (while tail | |
1089 | (let* ((entry (car tail)) | |
1090 | (display (nth 0 entry)) | |
1091 | (attrs (nth 1 entry))) | |
1092 | (setq tail (cdr tail)) | |
1093 | (when (face-spec-set-match-display display frame) | |
1094 | (setq result attrs tail nil)))) | |
1095 | result)) | |
1096 | ||
1097 | ||
1098 | (defun face-spec-reset-face (face &optional frame) | |
1099 | "Reset all attributes of FACE on FRAME to unspecified." | |
1100 | (let ((attrs face-attribute-name-alist) | |
1101 | params) | |
1102 | (while attrs | |
1103 | (let ((attr-and-name (car attrs))) | |
1104 | (setq params (cons (car attr-and-name) (cons 'unspecified params)))) | |
1105 | (setq attrs (cdr attrs))) | |
1106 | (apply #'set-face-attribute face frame params))) | |
1107 | ||
1108 | ||
1109 | (defun face-spec-set (face spec &optional frame) | |
1110 | "Set FACE's attributes according to the first matching entry in SPEC. | |
1111 | FRAME is the frame whose frame-local face is set. FRAME nil means | |
1112 | do it on all frames. See `defface' for information about SPEC." | |
1113 | (let ((attrs (face-spec-choose spec frame)) | |
1114 | params) | |
1115 | (while attrs | |
1116 | (let ((attribute (car attrs)) | |
1117 | (value (car (cdr attrs)))) | |
1118 | ;; Support some old-style attribute names and values. | |
1119 | (case attribute | |
1120 | (:bold (setq attribute :weight value (if value 'bold 'normal))) | |
1121 | (:italic (setq attribute :slant value (if value 'italic 'normal)))) | |
1122 | (setq params (cons attribute (cons value params)))) | |
1123 | (setq attrs (cdr (cdr attrs)))) | |
1124 | (face-spec-reset-face face frame) | |
1125 | (apply #'set-face-attribute face frame params))) | |
1126 | ||
1127 | ||
1128 | (defun face-attr-match-p (face attrs &optional frame) | |
1129 | "Value is non-nil if attributes of FACE match values in plist ATTRS. | |
1130 | Optional parameter FRAME is the frame whose definition of FACE | |
1131 | is used. If nil or omitted, use the selected frame." | |
1132 | (unless frame | |
1133 | (setq frame (selected-frame))) | |
1134 | (let ((list face-attribute-name-alist) | |
1135 | (match t)) | |
1136 | (while (and match (not (null list))) | |
1137 | (let* ((attr (car (car list))) | |
1138 | (specified-value (plist-get attrs attr)) | |
1139 | (value-now (face-attribute face attr frame))) | |
1140 | (when specified-value | |
1141 | (setq match (equal specified-value value-now))) | |
1142 | (setq list (cdr list)))) | |
1143 | match)) | |
1144 | ||
1145 | ||
1146 | (defun face-spec-match-p (face spec &optional frame) | |
1147 | "Return t if FACE, on FRAME, matches what SPEC says it should look like." | |
1148 | (face-attr-match-p face (face-spec-choose spec frame) frame)) | |
1149 | ||
1150 | ||
1151 | \f | |
f795f633 EZ |
1152 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1153 | ;;; Frame-type independent color support. | |
1154 | ;;; We keep the old x-* names as aliases for back-compatibility. | |
1155 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1156 | ||
1157 | (defun defined-colors (&optional frame) | |
1158 | "Return a list of colors supported for a particular frame. | |
1159 | The argument FRAME specifies which frame to try. | |
1160 | The value may be different for frames on different display types. | |
1161 | If FRAME doesn't support colors, the value is nil." | |
1162 | (if (memq (framep (or frame (selected-frame))) '(x w32)) | |
1163 | (xw-defined-colors frame) | |
1164 | (mapcar 'car tty-color-alist))) | |
1165 | (defalias 'x-defined-colors 'defined-colors) | |
1166 | ||
1167 | (defun color-defined-p (color &optional frame) | |
1168 | "Return non-nil if color COLOR is supported on frame FRAME. | |
1169 | If FRAME is omitted or nil, use the selected frame. | |
f9d2fdc4 EZ |
1170 | If COLOR is one of the symbols `unspecified', `unspecified-fg', or |
1171 | `unspecified-bg', the value is nil." | |
1172 | (if (memq color '(unspecified unspecified-bg unspecified-fg)) | |
f795f633 EZ |
1173 | nil |
1174 | (if (memq (framep (or frame (selected-frame))) '(x w32)) | |
1175 | (xw-color-defined-p color frame) | |
1176 | (numberp (tty-color-translate color))))) | |
1177 | (defalias 'x-color-defined-p 'color-defined-p) | |
1178 | ||
1179 | (defun color-values (color &optional frame) | |
1180 | "Return a description of the color named COLOR on frame FRAME. | |
1181 | The value is a list of integer RGB values--\(RED GREEN BLUE\). | |
1182 | These values appear to range from 0 to 65280 or 65535, depending | |
1183 | on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\). | |
1184 | If FRAME is omitted or nil, use the selected frame. | |
1185 | If FRAME cannot display COLOR, the value is nil. | |
f9d2fdc4 EZ |
1186 | If COLOR is one of the symbols `unspecified', `unspecified-fg', or |
1187 | `unspecified-bg', the value is nil." | |
1188 | (if (memq color '(unspecified unspecified-fg unspecified-bg)) | |
f795f633 EZ |
1189 | nil |
1190 | (if (memq (framep (or frame (selected-frame))) '(x w32)) | |
1191 | (xw-color-values color frame) | |
1192 | (tty-color-values color frame)))) | |
1193 | (defalias 'x-color-values 'color-values) | |
1194 | ||
1195 | (defun display-color-p (&optional display) | |
1196 | "Return t if DISPLAY supports color. | |
1197 | The optional argument DISPLAY specifies which display to ask about. | |
1198 | DISPLAY should be either a frame or a display name (a string). | |
1199 | If omitted or nil, that stands for the selected frame's display." | |
1200 | (if (and (stringp display) (not (fboundp 'x-display-list))) | |
1201 | nil | |
1202 | (if (memq (framep (or display (selected-frame))) '(x w32)) | |
1203 | (xw-display-color-p display) | |
1204 | (tty-display-color-p)))) | |
1205 | (defalias 'x-display-color-p 'display-color-p) | |
1206 | ||
1207 | \f | |
5f5c8ee5 GM |
1208 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1209 | ;;; Background mode. | |
1210 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1211 | ||
1212 | (defcustom frame-background-mode nil | |
1213 | "*The brightness of the background. | |
1214 | Set this to the symbol `dark' if your background color is dark, `light' if | |
1215 | your background is light, or nil (default) if you want Emacs to | |
1216 | examine the brightness for you." | |
1217 | :group 'faces | |
1218 | :set #'(lambda (var value) | |
1219 | (set var value) | |
1220 | (mapcar 'frame-set-background-mode (frame-list))) | |
1221 | :initialize 'custom-initialize-changed | |
1222 | :type '(choice (choice-item dark) | |
1223 | (choice-item light) | |
1224 | (choice-item :tag "default" nil))) | |
1225 | ||
1226 | ||
1227 | (defun frame-set-background-mode (frame) | |
1228 | "Set up the `background-mode' and `display-type' frame parameters for FRAME." | |
1229 | (let* ((bg-resource | |
1230 | (and window-system | |
1231 | (x-get-resource ".backgroundMode" "BackgroundMode"))) | |
1232 | (params (frame-parameters frame)) | |
1233 | (bg-mode (cond (frame-background-mode) | |
1234 | ((null window-system) | |
1235 | ;; No way to determine this automatically (?). | |
1236 | 'dark) | |
1237 | (bg-resource | |
1238 | (intern (downcase bg-resource))) | |
1239 | ((< (apply '+ (x-color-values | |
1240 | (cdr (assq 'background-color | |
1241 | params)) | |
1242 | frame)) | |
1243 | ;; Just looking at the screen, colors whose | |
1244 | ;; values add up to .6 of the white total | |
1245 | ;; still look dark to me. | |
1246 | (* (apply '+ (x-color-values "white" frame)) .6)) | |
1247 | 'dark) | |
1248 | (t 'light))) | |
1249 | (display-type (cond ((null window-system) | |
1250 | (if (tty-display-color-p) 'color 'mono)) | |
1251 | ((x-display-color-p frame) | |
1252 | 'color) | |
1253 | ((x-display-grayscale-p frame) | |
1254 | 'grayscale) | |
1255 | (t 'mono)))) | |
1256 | (modify-frame-parameters frame | |
1257 | (list (cons 'background-mode bg-mode) | |
1258 | (cons 'display-type display-type)))) | |
1259 | ||
1260 | ;; For all named faces, choose face specs matching the new frame | |
1261 | ;; parameters. | |
1262 | (let ((face-list (face-list))) | |
1263 | (while face-list | |
1264 | (let* ((face (car face-list)) | |
1265 | (spec (get face 'face-defface-spec))) | |
1266 | (when spec | |
1267 | (face-spec-set face spec frame)) | |
1268 | (setq face-list (cdr face-list)))))) | |
1269 | ||
1270 | ||
1271 | ||
1272 | \f | |
1273 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1274 | ;;; Frame creation. | |
1275 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1276 | ||
1277 | (defun x-handle-named-frame-geometry (parameters) | |
1278 | "Add geometry parameters for a named frame to parameter list PARAMETERS. | |
1279 | Value is the new parameter list." | |
1280 | (let* ((name (or (cdr (assq 'name parameters)) | |
1281 | (cdr (assq 'name default-frame-alist)))) | |
1282 | (x-resource-name name) | |
1283 | (res-geometry (if name (x-get-resource "geometry" "Geometry")))) | |
1284 | (when res-geometry | |
1285 | (let ((parsed (x-parse-geometry res-geometry))) | |
1286 | ;; If the resource specifies a position, call the position | |
1287 | ;; and size "user-specified". | |
1288 | (when (or (assq 'top parsed) | |
1289 | (assq 'left parsed)) | |
1290 | (setq parsed (append '((user-position . t) (user-size . t)) parsed))) | |
1291 | ;; Put the geometry parameters at the end. Copy | |
1292 | ;; default-frame-alist so that they go after it. | |
1293 | (setq parameters (append parameters default-frame-alist parsed)))) | |
1294 | parameters)) | |
1295 | ||
1296 | ||
1297 | (defun x-handle-reverse-video (frame parameters) | |
1298 | "Handle the reverse-video frame parameter and X resource. | |
1299 | `x-create-frame' does not handle this one." | |
1300 | (when (cdr (or (assq 'reverse parameters) | |
1301 | (assq 'reverse default-frame-alist) | |
1302 | (let ((resource (x-get-resource "reverseVideo" | |
1303 | "ReverseVideo"))) | |
1304 | (if resource | |
1305 | (cons nil (member (downcase resource) | |
1306 | '("on" "true"))))))) | |
1307 | (let* ((params (frame-parameters frame)) | |
1308 | (bg (cdr (assq 'foreground-color params))) | |
1309 | (fg (cdr (assq 'background-color params)))) | |
1310 | (modify-frame-parameters frame | |
1311 | (list (cons 'foreground-color fg) | |
1312 | (cons 'background-color bg))) | |
1313 | (if (equal bg (cdr (assq 'border-color params))) | |
1314 | (modify-frame-parameters frame | |
1315 | (list (cons 'border-color fg)))) | |
1316 | (if (equal bg (cdr (assq 'mouse-color params))) | |
1317 | (modify-frame-parameters frame | |
1318 | (list (cons 'mouse-color fg)))) | |
1319 | (if (equal bg (cdr (assq 'cursor-color params))) | |
1320 | (modify-frame-parameters frame | |
1321 | (list (cons 'cursor-color fg))))))) | |
1322 | ||
1323 | ||
1324 | (defun x-create-frame-with-faces (&optional parameters) | |
1325 | "Create a frame from optional frame parameters PARAMETERS. | |
1326 | Parameters not specified by PARAMETERS are taken from | |
1327 | `default-frame-alist'. If PARAMETERS specify a frame name, | |
1328 | handle X geometry resources for that name. If either PARAMETERS | |
1329 | or `default-frame-alist' contains a `reverse' parameter, or | |
1330 | the X resource ``reverseVideo'' is present, handle that. | |
1331 | Value is the new frame created." | |
1332 | (setq parameters (x-handle-named-frame-geometry parameters)) | |
1333 | (let ((visibility-spec (assq 'visibility parameters)) | |
1334 | (frame-list (frame-list)) | |
1335 | (frame (x-create-frame (cons '(visibility . nil) parameters))) | |
1336 | success) | |
1337 | (unwind-protect | |
1338 | (progn | |
1339 | (x-handle-reverse-video frame parameters) | |
1340 | (frame-set-background-mode frame) | |
1341 | (face-set-after-frame-default frame) | |
1342 | (if (or (null frame-list) (null visibility-spec)) | |
1343 | (make-frame-visible frame) | |
1344 | (modify-frame-parameters frame (list visibility-spec))) | |
1345 | (setq success t)) | |
1346 | (unless success | |
1347 | (delete-frame frame))) | |
1348 | frame)) | |
1349 | ||
1350 | ||
1351 | (defun face-set-after-frame-default (frame) | |
f1cae29e GM |
1352 | "Set frame-local faces of FRAME from face specs and resources. |
1353 | Initialize colors of certain faces from frame parameters." | |
5f5c8ee5 GM |
1354 | (dolist (face (face-list)) |
1355 | (let ((spec (or (get face 'saved-face) | |
1356 | (get face 'face-defface-spec)))) | |
1357 | (when spec | |
1358 | (face-spec-set face spec frame)) | |
1359 | (internal-merge-in-global-face face frame) | |
75014631 | 1360 | (when (memq window-system '(x w32)) |
f1cae29e GM |
1361 | (make-face-x-resource-internal face frame)))) |
1362 | ||
1363 | ;; Initialize attributes from frame parameters. | |
1364 | (let ((params '((foreground-color default :foreground) | |
1365 | (background-color default :background) | |
1366 | (border-color border :background) | |
1367 | (cursor-color cursor :background) | |
1368 | (scroll-bar-foreground scroll-bar :foreground) | |
1369 | (scroll-bar-background scroll-bar :background) | |
1370 | (mouse-color mouse :background)))) | |
1371 | (while params | |
1372 | (let ((param-name (nth 0 (car params))) | |
1373 | (face (nth 1 (car params))) | |
1374 | (attr (nth 2 (car params))) | |
1375 | value) | |
1376 | (when (setq value (frame-parameter frame param-name)) | |
1377 | (set-face-attribute face frame attr value))) | |
1378 | (setq params (cdr params))))) | |
5f5c8ee5 GM |
1379 | |
1380 | ||
1381 | (defun tty-create-frame-with-faces (&optional parameters) | |
1382 | "Create a frame from optional frame parameters PARAMETERS. | |
1383 | Parameters not specified by PARAMETERS are taken from | |
1384 | `default-frame-alist'. If either PARAMETERS or `default-frame-alist' | |
1385 | contains a `reverse' parameter, handle that. Value is the new frame | |
1386 | created." | |
1387 | (let ((frame (make-terminal-frame parameters)) | |
1388 | success) | |
1389 | (unwind-protect | |
1390 | (progn | |
1391 | (frame-set-background-mode frame) | |
1392 | (face-set-after-frame-default frame) | |
1393 | (setq success t)) | |
1394 | (unless success | |
1395 | (delete-frame frame))) | |
1396 | frame)) | |
465fceed | 1397 | |
465fceed | 1398 | |
5f5c8ee5 GM |
1399 | ;; Called from C function init_display to initialize faces of the |
1400 | ;; dumped terminal frame on startup. | |
465fceed | 1401 | |
5f5c8ee5 GM |
1402 | (defun tty-set-up-initial-frame-faces () |
1403 | (let ((frame (selected-frame))) | |
1404 | (frame-set-background-mode frame) | |
1405 | (face-set-after-frame-default frame))) | |
1406 | ||
465fceed | 1407 | |
465fceed | 1408 | |
5f5c8ee5 GM |
1409 | \f |
1410 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1411 | ;;; Compatiblity with 20.2 | |
1412 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
72418504 | 1413 | |
5f5c8ee5 | 1414 | ;; Update a frame's faces when we change its default font. |
465fceed | 1415 | |
5f5c8ee5 GM |
1416 | (defun frame-update-faces (frame) |
1417 | nil) | |
465fceed | 1418 | |
e8e4cda0 | 1419 | |
5f5c8ee5 GM |
1420 | ;; Update the colors of FACE, after FRAME's own colors have been |
1421 | ;; changed. | |
1bcb155c | 1422 | |
5f5c8ee5 GM |
1423 | (defun frame-update-face-colors (frame) |
1424 | (frame-set-background-mode frame)) | |
d11fba25 | 1425 | |
d11fba25 | 1426 | |
bdda3754 | 1427 | \f |
5f5c8ee5 GM |
1428 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1429 | ;;; Standard faces. | |
1430 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
465fceed | 1431 | |
5f5c8ee5 GM |
1432 | (defgroup basic-faces nil |
1433 | "The standard faces of Emacs." | |
1434 | :group 'faces) | |
ef436392 | 1435 | |
465fceed | 1436 | |
5f5c8ee5 GM |
1437 | (defface default |
1438 | '((t nil)) | |
1439 | "Basic default face." | |
1440 | :group 'basic-faces) | |
465fceed | 1441 | |
72418504 | 1442 | |
3759f14b | 1443 | (defface mode-line |
5f5c8ee5 GM |
1444 | '((((type x) (class color)) |
1445 | (:box (:line-width 2 :style released-button) :background "grey75")) | |
1446 | (t | |
1447 | (:inverse-video t))) | |
1448 | "Basic mode line face." | |
a4391cf1 | 1449 | :version "21.1" |
5f5c8ee5 | 1450 | :group 'basic-faces) |
465fceed | 1451 | |
3759f14b GM |
1452 | ;; Make `modeline' an alias for `mode-line', for compatibility. |
1453 | (put 'modeline 'face-alias 'mode-line) | |
d11fba25 | 1454 | |
e5e7779f | 1455 | (defface header-line |
5f5c8ee5 GM |
1456 | '((((type x) (class color)) |
1457 | (:box (:line-width 2 :style released-button) :background "grey75")) | |
1458 | (t | |
1459 | (:inverse-video t))) | |
e5e7779f | 1460 | "Basic header-line face." |
a4391cf1 | 1461 | :version "21.1" |
5f5c8ee5 | 1462 | :group 'basic-faces) |
e8e4cda0 | 1463 | |
d11fba25 | 1464 | |
533322cd | 1465 | (defface tool-bar |
5f5c8ee5 GM |
1466 | '((((type x) (class color)) |
1467 | (:box (:line-width 1 :style released-button) :background "grey75")) | |
9668a746 GM |
1468 | (((type x) (class mono)) |
1469 | (:box (:line-width 1 :style released-button) :background "grey")) | |
5f5c8ee5 GM |
1470 | (t |
1471 | ())) | |
533322cd | 1472 | "Basic tool-bar face." |
a4391cf1 | 1473 | :version "21.1" |
5f5c8ee5 | 1474 | :group 'basic-faces) |
d11fba25 | 1475 | |
bdda3754 | 1476 | |
5f5c8ee5 GM |
1477 | (defface region |
1478 | '((((type tty) (class color)) | |
1479 | (:background "blue" :foreground "white")) | |
1480 | (((type tty) (class mono)) | |
1481 | (:inverse-video t)) | |
1482 | (((class color) (background dark)) | |
1483 | (:background "blue")) | |
1484 | (((class color) (background light)) | |
1485 | (:background "lightblue")) | |
1486 | (t (:background "gray"))) | |
62f1e1cd | 1487 | "Basic face for highlighting the region." |
5f5c8ee5 | 1488 | :group 'basic-faces) |
66a5c2c6 | 1489 | |
bdda3754 | 1490 | |
f1cae29e | 1491 | (defface fringe |
5f5c8ee5 GM |
1492 | '((((class color)) |
1493 | (:background "grey95")) | |
3d089489 GM |
1494 | (t |
1495 | (:background "gray"))) | |
f1cae29e GM |
1496 | "Basic face for the fringes to the left and right of windows under X." |
1497 | :version "21.1" | |
1498 | :group 'basic-faces) | |
1499 | ||
1500 | ||
1501 | (defface scroll-bar '() | |
1502 | "Basic face for the scroll bar colors under X." | |
1503 | :version "21.1" | |
1504 | :group 'basic-faces) | |
1505 | ||
1506 | ||
ee716db5 GM |
1507 | (defface menu |
1508 | '((((type x-toolkit)) ()) | |
1509 | (t (:inverse-video t))) | |
1510 | "Basic menu face." | |
1511 | :version "21.1" | |
1512 | :group 'basic-faces) | |
1513 | ||
1514 | ||
f1cae29e GM |
1515 | (defface border '() |
1516 | "Basic face for the frame border under X." | |
1517 | :version "21.1" | |
1518 | :group 'basic-faces) | |
1519 | ||
1520 | ||
1521 | (defface cursor '() | |
1522 | "Basic face for the cursor color under X." | |
1523 | :version "21.1" | |
1524 | :group 'basic-faces) | |
1525 | ||
1526 | ||
1527 | (defface mouse '() | |
1528 | "Basic face for the mouse color under X." | |
e59176e2 | 1529 | :version "21.1" |
5f5c8ee5 | 1530 | :group 'basic-faces) |
bdda3754 | 1531 | |
bdda3754 | 1532 | |
5f5c8ee5 GM |
1533 | (defface bold '((t (:weight bold))) |
1534 | "Basic bold face." | |
1535 | :group 'basic-faces) | |
bdda3754 | 1536 | |
bdda3754 | 1537 | |
5f5c8ee5 GM |
1538 | (defface italic '((t (:slant italic))) |
1539 | "Basic italic font." | |
1540 | :group 'basic-faces) | |
bdda3754 | 1541 | |
bdda3754 | 1542 | |
5f5c8ee5 GM |
1543 | (defface bold-italic '((t (:weight bold :slant italic))) |
1544 | "Basic bold-italic face." | |
1545 | :group 'basic-faces) | |
465fceed | 1546 | |
17b3a11b | 1547 | |
5f5c8ee5 GM |
1548 | (defface underline '((t (:underline t))) |
1549 | "Basic underlined face." | |
1550 | :group 'basic-faces) | |
465fceed | 1551 | |
2f2ddd1e | 1552 | |
5f5c8ee5 GM |
1553 | (defface highlight |
1554 | '((((type tty) (class color)) | |
1555 | (:background "green")) | |
1556 | (((class color) (background light)) | |
1557 | (:background "darkseagreen2")) | |
1558 | (((class color) (background dark)) | |
1559 | (:background "darkolivegreen")) | |
1560 | (t (:inverse-video t))) | |
a4391cf1 DL |
1561 | "Basic face for highlighting." |
1562 | :group 'basic-faces) | |
465fceed | 1563 | |
465fceed | 1564 | |
5f5c8ee5 GM |
1565 | (defface secondary-selection |
1566 | '((((type tty) (class color)) | |
1567 | (:background "cyan")) | |
1568 | (((class color) (background light)) | |
230e947b | 1569 | (:background "yellow")) |
5f5c8ee5 | 1570 | (((class color) (background dark)) |
b261ffa4 | 1571 | (:background "yellow")) |
5f5c8ee5 | 1572 | (t (:inverse-video t))) |
a4391cf1 DL |
1573 | "Basic face for displaying the secondary selection." |
1574 | :group 'basic-faces) | |
465fceed | 1575 | |
93d6fcef | 1576 | |
5f5c8ee5 GM |
1577 | (defface fixed-pitch '((t (:family "courier*"))) |
1578 | "The basic fixed-pitch face." | |
1579 | :group 'basic-faces) | |
465fceed | 1580 | |
5f5c8ee5 GM |
1581 | |
1582 | (defface variable-pitch '((t (:family "helv*"))) | |
1583 | "The basic variable-pitch face." | |
1584 | :group 'basic-faces) | |
1585 | ||
1586 | ||
1587 | (defface trailing-whitespace | |
1588 | '((((class color) (background light)) | |
1589 | (:background "red")) | |
1590 | (((class color) (background dark)) | |
1591 | (:background "red")) | |
1592 | (t (:inverse-video t))) | |
a4391cf1 DL |
1593 | "Basic face for highlighting trailing whitespace." |
1594 | :version "21.1" | |
1595 | :group 'basic-faces) | |
465fceed ER |
1596 | |
1597 | ||
465fceed | 1598 | \f |
5f5c8ee5 GM |
1599 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1600 | ;;; Manipulating font names. | |
1601 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1602 | ||
1603 | ;; This is here for compatibilty with Emacs 20.2. For example, | |
1604 | ;; international/fontset.el uses these functions to manipulate font | |
1605 | ;; names. The following functions are not used in the face | |
1606 | ;; implementation itself. | |
465fceed | 1607 | |
d7fa5aa2 RS |
1608 | (defvar x-font-regexp nil) |
1609 | (defvar x-font-regexp-head nil) | |
1610 | (defvar x-font-regexp-weight nil) | |
1611 | (defvar x-font-regexp-slant nil) | |
465fceed | 1612 | |
021ca129 KH |
1613 | (defconst x-font-regexp-weight-subnum 1) |
1614 | (defconst x-font-regexp-slant-subnum 2) | |
1615 | (defconst x-font-regexp-swidth-subnum 3) | |
1616 | (defconst x-font-regexp-adstyle-subnum 4) | |
1617 | ||
465fceed ER |
1618 | ;;; Regexps matching font names in "Host Portable Character Representation." |
1619 | ;;; | |
1620 | (let ((- "[-?]") | |
1621 | (foundry "[^-]+") | |
1622 | (family "[^-]+") | |
1623 | (weight "\\(bold\\|demibold\\|medium\\)") ; 1 | |
1624 | ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1 | |
1625 | (weight\? "\\([^-]*\\)") ; 1 | |
1626 | (slant "\\([ior]\\)") ; 2 | |
1627 | ; (slant\? "\\([ior?*]?\\)") ; 2 | |
1628 | (slant\? "\\([^-]?\\)") ; 2 | |
1629 | ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3 | |
1630 | (swidth "\\([^-]*\\)") ; 3 | |
1631 | ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4 | |
c8787b81 | 1632 | (adstyle "\\([^-]*\\)") ; 4 |
465fceed ER |
1633 | (pixelsize "[0-9]+") |
1634 | (pointsize "[0-9][0-9]+") | |
1635 | (resx "[0-9][0-9]+") | |
1636 | (resy "[0-9][0-9]+") | |
1637 | (spacing "[cmp?*]") | |
1638 | (avgwidth "[0-9]+") | |
1639 | (registry "[^-]+") | |
1640 | (encoding "[^-]+") | |
1641 | ) | |
1642 | (setq x-font-regexp | |
1643 | (concat "\\`\\*?[-?*]" | |
1644 | foundry - family - weight\? - slant\? - swidth - adstyle - | |
e20d641f RS |
1645 | pixelsize - pointsize - resx - resy - spacing - avgwidth - |
1646 | registry - encoding "\\*?\\'" | |
465fceed ER |
1647 | )) |
1648 | (setq x-font-regexp-head | |
1649 | (concat "\\`[-?*]" foundry - family - weight\? - slant\? | |
1650 | "\\([-*?]\\|\\'\\)")) | |
1651 | (setq x-font-regexp-slant (concat - slant -)) | |
1652 | (setq x-font-regexp-weight (concat - weight -)) | |
1653 | nil) | |
1654 | ||
5f5c8ee5 | 1655 | |
281dc1c2 JB |
1656 | (defun x-resolve-font-name (pattern &optional face frame) |
1657 | "Return a font name matching PATTERN. | |
1658 | All wildcards in PATTERN become substantiated. | |
10d89673 JB |
1659 | If PATTERN is nil, return the name of the frame's base font, which never |
1660 | contains wildcards. | |
e17dbede RS |
1661 | Given optional arguments FACE and FRAME, return a font which is |
1662 | also the same size as FACE on FRAME, or fail." | |
14e6867c RS |
1663 | (or (symbolp face) |
1664 | (setq face (face-name face))) | |
1665 | (and (eq frame t) | |
1666 | (setq frame nil)) | |
10d89673 | 1667 | (if pattern |
8db93e45 | 1668 | ;; Note that x-list-fonts has code to handle a face with nil as its font. |
abd89b80 | 1669 | (let ((fonts (x-list-fonts pattern face frame 1))) |
10d89673 JB |
1670 | (or fonts |
1671 | (if face | |
962a60aa RS |
1672 | (if (string-match "\\*" pattern) |
1673 | (if (null (face-font face)) | |
1674 | (error "No matching fonts are the same height as the frame default font") | |
1675 | (error "No matching fonts are the same height as face `%s'" face)) | |
1676 | (if (null (face-font face)) | |
1677 | (error "Height of font `%s' doesn't match the frame default font" | |
1678 | pattern) | |
1679 | (error "Height of font `%s' doesn't match face `%s'" | |
1680 | pattern face))) | |
7cf6fac1 | 1681 | (error "No fonts match `%s'" pattern))) |
10d89673 JB |
1682 | (car fonts)) |
1683 | (cdr (assq 'font (frame-parameters (selected-frame)))))) | |
281dc1c2 | 1684 | |
5f5c8ee5 | 1685 | |
465fceed | 1686 | (defun x-frob-font-weight (font which) |
b7ffee5f SM |
1687 | (let ((case-fold-search t)) |
1688 | (cond ((string-match x-font-regexp font) | |
1689 | (concat (substring font 0 | |
1690 | (match-beginning x-font-regexp-weight-subnum)) | |
1691 | which | |
1692 | (substring font (match-end x-font-regexp-weight-subnum) | |
1693 | (match-beginning x-font-regexp-adstyle-subnum)) | |
1694 | ;; Replace the ADD_STYLE_NAME field with * | |
1695 | ;; because the info in it may not be the same | |
1696 | ;; for related fonts. | |
1697 | "*" | |
1698 | (substring font (match-end x-font-regexp-adstyle-subnum)))) | |
528fbf51 RS |
1699 | ((string-match x-font-regexp-head font) |
1700 | (concat (substring font 0 (match-beginning 1)) which | |
1701 | (substring font (match-end 1)))) | |
1702 | ((string-match x-font-regexp-weight font) | |
b7ffee5f SM |
1703 | (concat (substring font 0 (match-beginning 1)) which |
1704 | (substring font (match-end 1))))))) | |
465fceed | 1705 | |
5f5c8ee5 | 1706 | |
465fceed | 1707 | (defun x-frob-font-slant (font which) |
b7ffee5f SM |
1708 | (let ((case-fold-search t)) |
1709 | (cond ((string-match x-font-regexp font) | |
1710 | (concat (substring font 0 | |
1711 | (match-beginning x-font-regexp-slant-subnum)) | |
1712 | which | |
1713 | (substring font (match-end x-font-regexp-slant-subnum) | |
1714 | (match-beginning x-font-regexp-adstyle-subnum)) | |
1715 | ;; Replace the ADD_STYLE_NAME field with * | |
1716 | ;; because the info in it may not be the same | |
1717 | ;; for related fonts. | |
1718 | "*" | |
1719 | (substring font (match-end x-font-regexp-adstyle-subnum)))) | |
528fbf51 RS |
1720 | ((string-match x-font-regexp-head font) |
1721 | (concat (substring font 0 (match-beginning 2)) which | |
1722 | (substring font (match-end 2)))) | |
1723 | ((string-match x-font-regexp-slant font) | |
b7ffee5f SM |
1724 | (concat (substring font 0 (match-beginning 1)) which |
1725 | (substring font (match-end 1))))))) | |
465fceed | 1726 | |
5f5c8ee5 | 1727 | |
465fceed | 1728 | (defun x-make-font-bold (font) |
f3f31ccf RS |
1729 | "Given an X font specification, make a bold version of it. |
1730 | If that can't be done, return nil." | |
465fceed ER |
1731 | (x-frob-font-weight font "bold")) |
1732 | ||
5f5c8ee5 | 1733 | |
465fceed | 1734 | (defun x-make-font-demibold (font) |
f3f31ccf RS |
1735 | "Given an X font specification, make a demibold version of it. |
1736 | If that can't be done, return nil." | |
465fceed ER |
1737 | (x-frob-font-weight font "demibold")) |
1738 | ||
5f5c8ee5 | 1739 | |
465fceed | 1740 | (defun x-make-font-unbold (font) |
f3f31ccf RS |
1741 | "Given an X font specification, make a non-bold version of it. |
1742 | If that can't be done, return nil." | |
465fceed ER |
1743 | (x-frob-font-weight font "medium")) |
1744 | ||
5f5c8ee5 | 1745 | |
465fceed | 1746 | (defun x-make-font-italic (font) |
f3f31ccf RS |
1747 | "Given an X font specification, make an italic version of it. |
1748 | If that can't be done, return nil." | |
465fceed ER |
1749 | (x-frob-font-slant font "i")) |
1750 | ||
5f5c8ee5 | 1751 | |
465fceed | 1752 | (defun x-make-font-oblique (font) ; you say tomayto... |
f3f31ccf RS |
1753 | "Given an X font specification, make an oblique version of it. |
1754 | If that can't be done, return nil." | |
465fceed ER |
1755 | (x-frob-font-slant font "o")) |
1756 | ||
5f5c8ee5 | 1757 | |
465fceed | 1758 | (defun x-make-font-unitalic (font) |
f3f31ccf RS |
1759 | "Given an X font specification, make a non-italic version of it. |
1760 | If that can't be done, return nil." | |
465fceed | 1761 | (x-frob-font-slant font "r")) |
b7d7285c | 1762 | |
5f5c8ee5 | 1763 | |
b7d7285c KH |
1764 | (defun x-make-font-bold-italic (font) |
1765 | "Given an X font specification, make a bold and italic version of it. | |
1766 | If that can't be done, return nil." | |
1767 | (and (setq font (x-make-font-bold font)) | |
1768 | (x-make-font-italic font))) | |
113ab303 | 1769 | |
465fceed | 1770 | |
f0138172 JB |
1771 | (provide 'faces) |
1772 | ||
5f5c8ee5 | 1773 | ;;; end of faces.el |