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