Mercurial > emacs
annotate lisp/faces.el @ 25063:7c69e1001e35
(get_next_display_element): Display DEL as `^?'.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 26 Jul 1999 11:50:17 +0000 |
parents | 583c6bc7fe82 |
children | b4b6828139fd |
rev | line source |
---|---|
25012 | 1 ;;; faces.el --- Lisp faces |
2456 | 2 |
25012 | 3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998 |
4 ;; Free Software Foundation, Inc. | |
2456 | 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 | |
14169 | 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. | |
2456 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;;; Code: | |
26 | |
10107
2af74ff52cd0
At compile time, discard any defsubr definitions
Richard M. Stallman <rms@gnu.org>
parents:
10105
diff
changeset
|
27 (eval-when-compile |
25012 | 28 (require 'custom) |
29 (require 'cl)) | |
2456 | 30 |
25012 | 31 (require 'cus-face) |
2456 | 32 |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
33 |
25012 | 34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
35 ;;; Font selection. | |
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2456 | 37 |
25012 | 38 (defgroup font-selection nil |
39 "Influencing face font selection." | |
40 :group 'faces) | |
2456 | 41 |
12562
a9b08e50d6ec
(x-create-frame-with-faces): Set background-mode
Karl Heuer <kwzh@gnu.org>
parents:
12475
diff
changeset
|
42 |
25012 | 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))) | |
17522
209c61e51bd0
(frame-set-background-mode): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17386
diff
changeset
|
58 |
13725 | 59 |
25012 | 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))) | |
13725 | 72 |
25012 | 73 |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
74 |
25012 | 75 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
76 ;;; Creation, copying. | |
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
78 |
3925
f286657c098e
* faces.el (global-face-data): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
3911
diff
changeset
|
79 |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
80 (defun face-list () |
25012 | 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 | |
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. | |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
148 |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
149 (defun internal-find-face (name &optional frame) |
25012 | 150 "Retrieve the face named NAME. |
151 Return nil if there is no such face. | |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
152 If the optional argument FRAME is given, this gets the face NAME for |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
153 that frame; otherwise, it uses the selected frame. |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
154 If FRAME is the symbol t, then the global, non-frame face is returned. |
25012 | 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 | |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
161 |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
162 (defun internal-get-face (name &optional frame) |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
163 "Retrieve the face named NAME; error if there is none. |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
164 If the optional argument FRAME is given, this gets the face NAME for |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
165 that frame; otherwise, it uses the selected frame. |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
166 If FRAME is the symbol t, then the global, non-frame face is returned. |
25012 | 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." | |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
171 (or (internal-find-face name frame) |
25012 | 172 (check-face name))) |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
173 |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
174 |
25012 | 175 |
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) | |
2744
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
191 |
f4fc0c4c76f9
Re-arranged stuff to put defsubst accessors at the top
Jim Blandy <jimb@redhat.com>
parents:
2715
diff
changeset
|
192 |
25012 | 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. | |
17386
b251c8820860
(make-face): New arg no-resources.
Richard M. Stallman <rms@gnu.org>
parents:
17173
diff
changeset
|
196 |
25012 | 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)) | |
2456 | 202 |
203 | |
204 (defun face-equal (face1 face2 &optional frame) | |
25012 | 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 | |
2456 | 212 |
213 (defun face-differs-from-default-p (face &optional frame) | |
25012 | 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)))) | |
10379
f9d713e8c77c
(face-nontrivial-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10375
diff
changeset
|
224 |
2456 | 225 |
10379
f9d713e8c77c
(face-nontrivial-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10375
diff
changeset
|
226 (defun face-nontrivial-p (face &optional frame) |
f9d713e8c77c
(face-nontrivial-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10375
diff
changeset
|
227 "True if face FACE has some non-nil attribute. |
25012 | 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 | |
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 | |
306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
307 ;;; Retrieving face attributes. | |
308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
309 | |
310 (defun face-name (face) | |
311 "Return the name of face FACE." | |
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))) | |
373 (not (memq bold '(normal unspecified))))) | |
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))) | |
383 (not (memq italic '(normal unspecified))))) | |
384 | |
385 | |
386 | |
387 | |
388 | |
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 | |
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) | |
10379
f9d713e8c77c
(face-nontrivial-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10375
diff
changeset
|
681 |
2456 | 682 |
683 (defun invert-face (face &optional frame) | |
25012 | 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." | |
2456 | 689 (interactive (list (read-face-name "Invert face: "))) |
25012 | 690 (let ((fg (face-attribute face :foreground frame)) |
691 (bg (face-attribute face :background frame))) | |
2456 | 692 (if (or fg bg) |
25012 | 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)))) | |
2456 | 699 face) |
700 | |
25012 | 701 |
702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
703 ;;; Interactively modifying faces. | |
704 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2456 | 705 |
25012 | 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." | |
723 (case attribute | |
724 (:family | |
725 (if window-system | |
726 (mapcar #'(lambda (x) (cons (car x) (car x))) | |
727 (x-font-family-list)) | |
728 ;; Only one font on TTYs. | |
729 (cons "default" "default"))) | |
730 ((:width :weight :slant :inverse-video) | |
731 (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
732 (internal-lisp-face-attribute-values attribute))) | |
733 ((:underline :overline :strike-through :box) | |
734 (if window-system | |
735 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
736 (internal-lisp-face-attribute-values attribute)) | |
737 (mapcar #'(lambda (c) (cons c c)) | |
738 (x-defined-colors frame))) | |
739 (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
740 (internal-lisp-face-attribute-values attribute)))) | |
741 ((:foreground :background) | |
742 (mapcar #'(lambda (c) (cons c c)) | |
743 (or (and window-system (x-defined-colors frame)) | |
744 (tty-defined-colors)))) | |
745 ((:height) | |
746 'integerp) | |
747 (:stipple | |
748 (and window-system | |
749 (mapcar #'list | |
750 (apply #'nconc (mapcar #'directory-files | |
751 x-bitmap-file-path))))) | |
752 (t | |
753 (error "Internal error")))) | |
754 | |
755 | |
756 (defvar face-attribute-name-alist | |
757 '((:family . "font family") | |
758 (:width . "character set width") | |
759 (:height . "height in 1/10 pt") | |
760 (:weight . "weight") | |
761 (:slant . "slant") | |
762 (:underline . "underline") | |
763 (:overline . "overline") | |
764 (:strike-through . "strike-through") | |
765 (:box . "box") | |
766 (:inverse-video . "inverse-video display") | |
767 (:foreground . "foreground color") | |
768 (:background . "background color") | |
769 (:stipple . "background stipple")) | |
770 "An alist of descriptive names for face attributes. | |
771 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where | |
772 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and | |
773 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.") | |
774 | |
775 | |
776 (defun face-descriptive-attribute-name (attribute) | |
777 "Return a descriptive name for ATTRIBUTE." | |
778 (cdr (assq attribute face-attribute-name-alist))) | |
779 | |
780 | |
781 (defun face-read-string (face default name &optional completion-alist) | |
782 "Interactively read a face attribute string value. | |
783 FACE is the face whose attribute is read. DEFAULT is the default | |
784 value to return if no new value is entered. NAME is a descriptive | |
785 name of the attribute for prompting. COMPLETION-ALIST is an alist | |
786 of valid values, if non-nil. | |
787 | |
788 Entering ``none'' as attribute value means an unspecified attribute | |
789 value. Entering nothing accepts the default value DEFAULT. | |
790 | |
791 Value is the new attribute value." | |
792 (let* ((completion-ignore-case t) | |
793 (value (completing-read | |
794 (if default | |
795 (format "Set face %s %s (default %s): " | |
796 face name (downcase (if (symbolp default) | |
797 (symbol-name default) | |
798 default))) | |
799 (format "Set face %s %s: " face name)) | |
800 completion-alist))) | |
801 (if (equal value "none") | |
802 nil | |
803 (if (equal value "") default value)))) | |
804 | |
805 | |
806 (defun face-read-integer (face default name) | |
807 "Interactively read an integer face attribute value. | |
808 FACE is the face whose attribute is read. DEFAULT is the default | |
809 value to return if no new value is entered. NAME is a descriptive | |
810 name of the attribute for prompting. Value is the new attribute value." | |
811 (let ((new-value (face-read-string face | |
812 (and default (int-to-string default)) | |
813 name))) | |
814 (and new-value | |
815 (string-to-int new-value)))) | |
816 | |
817 | |
818 (defun read-face-attribute (face attribute &optional frame) | |
819 "Interactively read a new value for FACE's ATTRIBUTE. | |
820 Optional argument FRAME nil or unspecified means read an attribute value | |
821 of a global face. Value is the new attribute value." | |
822 (let* ((old-value (face-attribute face attribute frame)) | |
823 (attribute-name (face-descriptive-attribute-name attribute)) | |
824 (valid (face-valid-attribute-values attribute frame)) | |
825 new-value) | |
826 ;; Represent complex attribute values as strings by printing them | |
827 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be | |
828 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow | |
829 ;; SHADOW)'. | |
830 (when (and (or (eq attribute :stipple) | |
831 (eq attribute :box)) | |
832 (or (consp old-value) | |
833 (vectorp old-value))) | |
834 (setq old-value (prin1-to-string old-value))) | |
835 (cond ((listp valid) | |
836 (setq new-value | |
837 (cdr (assoc (face-read-string face old-value | |
838 attribute-name valid) | |
839 valid)))) | |
840 ((eq valid 'integerp) | |
841 (setq new-value (face-read-integer face old-value attribute-name))) | |
842 (t (error "Internal error"))) | |
843 ;; Convert stipple and box value text we read back to a list or | |
844 ;; vector if it looks like one. This makes the assumption that a | |
845 ;; pixmap file name won't start with an open-paren. | |
846 (when (and (or (eq attribute :stipple) | |
847 (eq attribute :box)) | |
848 (stringp new-value) | |
849 (string-match "^[[(]" new-value)) | |
850 (setq new-value (read new-value))) | |
851 new-value)) | |
852 | |
853 | |
854 (defun read-face-font (face &optional frame) | |
855 "Read the name of a font for FACE on FRAME. | |
856 If optional argument FRAME Is nil or omitted, use the selected frame." | |
857 (let ((completion-ignore-case t)) | |
858 (completing-read "Set font attributes of face %s from font: " | |
859 face (x-list-fonts "*" nil frame)))) | |
860 | |
861 | |
862 (defun read-all-face-attributes (face &optional frame) | |
863 "Interactively read all attributes for FACE. | |
864 If optional argument FRAME Is nil or omitted, use the selected frame. | |
865 Value is a property list of attribute names and new values." | |
866 (let (result) | |
867 (dolist (attribute face-attribute-name-alist result) | |
868 (setq result (cons (car attribute) | |
869 (cons (read-face-attribute face (car attribute) frame) | |
870 result)))))) | |
871 | |
872 | |
873 (defun modify-face (&optional frame) | |
874 "Modify attributes of faces interactively. | |
875 If optional argument FRAME is nil or omitted, modify the face used | |
876 for newly created frame, i.e. the global face." | |
877 (interactive) | |
878 (let ((face (read-face-name "Modify face: "))) | |
879 (apply #'set-face-attribute face frame | |
880 (read-all-face-attributes face frame)))) | |
881 | |
882 | |
883 (defun read-face-and-attribute (attribute &optional frame) | |
884 "Read face name and face attribute value. | |
885 ATTRIBUTE is the attribute whose new value is read. | |
886 FRAME nil or unspecified means read attribute value of global face. | |
887 Value is a list (FACE NEW-VALUE) where FACE is the face read | |
888 (a symbol), and NEW-VALUE is value read." | |
889 (cond ((eq attribute :font) | |
890 (let* ((prompt (format "Set font-related attributes of face: ")) | |
891 (face (read-face-name prompt)) | |
892 (font (read-face-font face frame))) | |
893 (list face font))) | |
894 (t | |
895 (let* ((attribute-name (face-descriptive-attribute-name attribute)) | |
896 (prompt (format "Set %s of face: " attribute-name)) | |
897 (face (read-face-name prompt)) | |
898 (new-value (read-face-attribute face attribute frame))) | |
899 (list face new-value))))) | |
900 | |
901 | |
902 | |
903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
904 ;;; Listing faces. | |
905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
906 | |
907 (defvar list-faces-sample-text | |
908 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
909 "*Text string to display as the sample text for `list-faces-display'.") | |
910 | |
911 | |
912 ;; The name list-faces would be more consistent, but let's avoid a | |
913 ;; conflict with Lucid, which uses that name differently. | |
914 | |
915 (defun list-faces-display () | |
916 "List all faces, using the same sample text in each. | |
917 The sample text is a string that comes from the variable | |
918 `list-faces-sample-text'." | |
919 (interactive) | |
920 (let ((faces (sort (face-list) #'string-lessp)) | |
921 (face nil) | |
922 (frame (selected-frame)) | |
923 disp-frame window) | |
924 (with-output-to-temp-buffer "*Faces*" | |
925 (save-excursion | |
926 (set-buffer standard-output) | |
927 (setq truncate-lines t) | |
928 (while faces | |
929 (setq face (car faces)) | |
930 (setq faces (cdr faces)) | |
931 (insert (format "%25s " (face-name face))) | |
932 (let ((beg (point))) | |
933 (insert list-faces-sample-text) | |
934 (insert "\n") | |
935 (put-text-property beg (1- (point)) 'face face) | |
936 ;; If the sample text has multiple lines, line up all of them. | |
937 (goto-char beg) | |
938 (forward-line 1) | |
939 (while (not (eobp)) | |
940 (insert " ") | |
941 (forward-line 1)))) | |
942 (goto-char (point-min))) | |
943 (print-help-return-message)) | |
944 ;; If the *Faces* buffer appears in a different frame, | |
945 ;; copy all the face definitions from FRAME, | |
946 ;; so that the display will reflect the frame that was selected. | |
947 (setq window (get-buffer-window (get-buffer "*Faces*") t)) | |
948 (setq disp-frame (if window (window-frame window) | |
949 (car (frame-list)))) | |
950 (or (eq frame disp-frame) | |
951 (let ((faces (face-list))) | |
952 (while faces | |
953 (copy-face (car faces) (car faces) frame disp-frame) | |
954 (setq faces (cdr faces))))))) | |
955 | |
956 | |
957 (defun describe-face (face &optional frame) | |
958 "Display the properties of face FACE on FRAME. | |
959 If the optional argument FRAME is given, report on face FACE in that frame. | |
960 If FRAME is t, report on the defaults for face FACE (for new frames). | |
961 If FRAME is omitted or nil, use the selected frame." | |
962 (interactive (list (read-face-name "Describe face: "))) | |
963 (let* ((attrs '((:family . "Family") | |
964 (:width . "Width") | |
965 (:height . "Height") | |
966 (:weight . "Weight") | |
967 (:slant . "Slant") | |
968 (:foreground . "Foreground") | |
969 (:background . "Background") | |
970 (:underline . "Underline") | |
971 (:overline . "Overline") | |
972 (:strike-through . "Strike-through") | |
973 (:box . "Box") | |
974 (:inverse-video . "Inverse") | |
975 (:stipple . "Stipple"))) | |
976 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x))) | |
977 attrs)))) | |
978 (with-output-to-temp-buffer "*Help*" | |
979 (save-excursion | |
980 (set-buffer standard-output) | |
981 (dolist (a attrs) | |
982 (let ((attr (face-attribute face (car a) frame))) | |
983 (insert (make-string (- max-width (length (cdr a))) ?\ ) | |
984 (cdr a) ": " (format "%s" attr) "\n"))) | |
985 (insert "\nDocumentation:\n\n" | |
986 (or (face-documentation face) | |
987 "not documented as a face."))) | |
988 (print-help-return-message)))) | |
989 | |
990 | |
991 | |
2456 | 992 |
25012 | 993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
994 ;;; Face specifications (defface). | |
995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
996 | |
997 ;; Parameter FRAME Is kept for call compatibility to with previous | |
998 ;; face implementation. | |
999 | |
1000 (defun face-attr-construct (face &optional frame) | |
1001 "Return a defface-style attribute list for FACE on FRAME. | |
1002 Value is a property list of pairs ATTRIBUTE VALUE for all specified | |
1003 face attributes of FACE where ATTRIBUTE is the attribute name and | |
1004 VALUE is the specified value of that attribute." | |
1005 (let (result) | |
1006 (dolist (entry face-attribute-name-alist result) | |
1007 (let* ((attribute (car entry)) | |
1008 (value (face-attribute face attribute))) | |
1009 (unless (eq value 'unspecified) | |
1010 (setq result (nconc (list attribute value) result))))))) | |
1011 | |
1012 | |
1013 (defun face-spec-set-match-display (display frame) | |
1014 "Non-nil if DISPLAY matches FRAME. | |
1015 DISPLAY is part of a spec such as can be used in `defface'. | |
1016 If FRAME is nil, the current FRAME is used." | |
1017 (let* ((conjuncts display) | |
1018 conjunct req options | |
1019 ;; t means we have succeeded against all the conjuncts in | |
1020 ;; DISPLAY that have been tested so far. | |
1021 (match t)) | |
1022 (if (eq conjuncts t) | |
1023 (setq conjuncts nil)) | |
1024 (while (and conjuncts match) | |
1025 (setq conjunct (car conjuncts) | |
1026 conjuncts (cdr conjuncts) | |
1027 req (car conjunct) | |
1028 options (cdr conjunct) | |
1029 match (cond ((eq req 'type) | |
1030 (or (memq window-system options) | |
1031 (and (null window-system) | |
1032 (memq 'tty options)))) | |
1033 ((eq req 'class) | |
1034 (memq (frame-parameter frame 'display-type) options)) | |
1035 ((eq req 'background) | |
1036 (memq (frame-parameter frame 'background-mode) | |
1037 options)) | |
1038 (t (error "Unknown req `%S' with options `%S'" | |
1039 req options))))) | |
1040 match)) | |
1041 | |
1042 | |
1043 (defun face-spec-choose (spec &optional frame) | |
1044 "Choose the proper attributes for FRAME, out of SPEC." | |
1045 (unless frame | |
1046 (setq frame (selected-frame))) | |
1047 (let ((tail spec) | |
1048 result) | |
1049 (while tail | |
1050 (let* ((entry (car tail)) | |
1051 (display (nth 0 entry)) | |
1052 (attrs (nth 1 entry))) | |
1053 (setq tail (cdr tail)) | |
1054 (when (face-spec-set-match-display display frame) | |
1055 (setq result attrs tail nil)))) | |
1056 result)) | |
1057 | |
1058 | |
1059 (defun face-spec-reset-face (face &optional frame) | |
1060 "Reset all attributes of FACE on FRAME to unspecified." | |
1061 (let ((attrs face-attribute-name-alist) | |
1062 params) | |
1063 (while attrs | |
1064 (let ((attr-and-name (car attrs))) | |
1065 (setq params (cons (car attr-and-name) (cons 'unspecified params)))) | |
1066 (setq attrs (cdr attrs))) | |
1067 (apply #'set-face-attribute face frame params))) | |
1068 | |
1069 | |
1070 (defun face-spec-set (face spec &optional frame) | |
1071 "Set FACE's attributes according to the first matching entry in SPEC. | |
1072 FRAME is the frame whose frame-local face is set. FRAME nil means | |
1073 do it on all frames. See `defface' for information about SPEC." | |
1074 (let ((attrs (face-spec-choose spec frame)) | |
1075 params) | |
1076 (while attrs | |
1077 (let ((attribute (car attrs)) | |
1078 (value (car (cdr attrs)))) | |
1079 ;; Support some old-style attribute names and values. | |
1080 (case attribute | |
1081 (:bold (setq attribute :weight value (if value 'bold 'normal))) | |
1082 (:italic (setq attribute :slant value (if value 'italic 'normal)))) | |
1083 (setq params (cons attribute (cons value params)))) | |
1084 (setq attrs (cdr (cdr attrs)))) | |
1085 (face-spec-reset-face face frame) | |
1086 (apply #'set-face-attribute face frame params))) | |
1087 | |
1088 | |
1089 (defun face-attr-match-p (face attrs &optional frame) | |
1090 "Value is non-nil if attributes of FACE match values in plist ATTRS. | |
1091 Optional parameter FRAME is the frame whose definition of FACE | |
1092 is used. If nil or omitted, use the selected frame." | |
1093 (unless frame | |
1094 (setq frame (selected-frame))) | |
1095 (let ((list face-attribute-name-alist) | |
1096 (match t)) | |
1097 (while (and match (not (null list))) | |
1098 (let* ((attr (car (car list))) | |
1099 (specified-value (plist-get attrs attr)) | |
1100 (value-now (face-attribute face attr frame))) | |
1101 (when specified-value | |
1102 (setq match (equal specified-value value-now))) | |
1103 (setq list (cdr list)))) | |
1104 match)) | |
1105 | |
1106 | |
1107 (defun face-spec-match-p (face spec &optional frame) | |
1108 "Return t if FACE, on FRAME, matches what SPEC says it should look like." | |
1109 (face-attr-match-p face (face-spec-choose spec frame) frame)) | |
1110 | |
1111 | |
1112 | |
1113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1114 ;;; Background mode. | |
1115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1116 | |
1117 (defcustom frame-background-mode nil | |
1118 "*The brightness of the background. | |
1119 Set this to the symbol `dark' if your background color is dark, `light' if | |
1120 your background is light, or nil (default) if you want Emacs to | |
1121 examine the brightness for you." | |
1122 :group 'faces | |
1123 :set #'(lambda (var value) | |
1124 (set var value) | |
1125 (mapcar 'frame-set-background-mode (frame-list))) | |
1126 :initialize 'custom-initialize-changed | |
1127 :type '(choice (choice-item dark) | |
1128 (choice-item light) | |
1129 (choice-item :tag "default" nil))) | |
1130 | |
1131 | |
1132 (defun frame-set-background-mode (frame) | |
1133 "Set up the `background-mode' and `display-type' frame parameters for FRAME." | |
1134 (let* ((bg-resource | |
1135 (and window-system | |
1136 (x-get-resource ".backgroundMode" "BackgroundMode"))) | |
1137 (params (frame-parameters frame)) | |
1138 (bg-mode (cond (frame-background-mode) | |
1139 ((null window-system) | |
1140 ;; No way to determine this automatically (?). | |
1141 'dark) | |
1142 (bg-resource | |
1143 (intern (downcase bg-resource))) | |
1144 ((< (apply '+ (x-color-values | |
1145 (cdr (assq 'background-color | |
1146 params)) | |
1147 frame)) | |
1148 ;; Just looking at the screen, colors whose | |
1149 ;; values add up to .6 of the white total | |
1150 ;; still look dark to me. | |
1151 (* (apply '+ (x-color-values "white" frame)) .6)) | |
1152 'dark) | |
1153 (t 'light))) | |
1154 (display-type (cond ((null window-system) | |
1155 (if (tty-display-color-p) 'color 'mono)) | |
1156 ((x-display-color-p frame) | |
1157 'color) | |
1158 ((x-display-grayscale-p frame) | |
1159 'grayscale) | |
1160 (t 'mono)))) | |
1161 (modify-frame-parameters frame | |
1162 (list (cons 'background-mode bg-mode) | |
1163 (cons 'display-type display-type)))) | |
1164 | |
1165 ;; For all named faces, choose face specs matching the new frame | |
1166 ;; parameters. | |
1167 (let ((face-list (face-list))) | |
1168 (while face-list | |
1169 (let* ((face (car face-list)) | |
1170 (spec (get face 'face-defface-spec))) | |
1171 (when spec | |
1172 (face-spec-set face spec frame)) | |
1173 (setq face-list (cdr face-list)))))) | |
1174 | |
1175 | |
1176 | |
1177 | |
1178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1179 ;;; Frame creation. | |
1180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1181 | |
1182 (defun x-handle-named-frame-geometry (parameters) | |
1183 "Add geometry parameters for a named frame to parameter list PARAMETERS. | |
1184 Value is the new parameter list." | |
1185 (let* ((name (or (cdr (assq 'name parameters)) | |
1186 (cdr (assq 'name default-frame-alist)))) | |
1187 (x-resource-name name) | |
1188 (res-geometry (if name (x-get-resource "geometry" "Geometry")))) | |
1189 (when res-geometry | |
1190 (let ((parsed (x-parse-geometry res-geometry))) | |
1191 ;; If the resource specifies a position, call the position | |
1192 ;; and size "user-specified". | |
1193 (when (or (assq 'top parsed) | |
1194 (assq 'left parsed)) | |
1195 (setq parsed (append '((user-position . t) (user-size . t)) parsed))) | |
1196 ;; Put the geometry parameters at the end. Copy | |
1197 ;; default-frame-alist so that they go after it. | |
1198 (setq parameters (append parameters default-frame-alist parsed)))) | |
1199 parameters)) | |
1200 | |
1201 | |
1202 (defun x-handle-reverse-video (frame parameters) | |
1203 "Handle the reverse-video frame parameter and X resource. | |
1204 `x-create-frame' does not handle this one." | |
1205 (when (cdr (or (assq 'reverse parameters) | |
1206 (assq 'reverse default-frame-alist) | |
1207 (let ((resource (x-get-resource "reverseVideo" | |
1208 "ReverseVideo"))) | |
1209 (if resource | |
1210 (cons nil (member (downcase resource) | |
1211 '("on" "true"))))))) | |
1212 (let* ((params (frame-parameters frame)) | |
1213 (bg (cdr (assq 'foreground-color params))) | |
1214 (fg (cdr (assq 'background-color params)))) | |
1215 (modify-frame-parameters frame | |
1216 (list (cons 'foreground-color fg) | |
1217 (cons 'background-color bg))) | |
1218 (if (equal bg (cdr (assq 'border-color params))) | |
1219 (modify-frame-parameters frame | |
1220 (list (cons 'border-color fg)))) | |
1221 (if (equal bg (cdr (assq 'mouse-color params))) | |
1222 (modify-frame-parameters frame | |
1223 (list (cons 'mouse-color fg)))) | |
1224 (if (equal bg (cdr (assq 'cursor-color params))) | |
1225 (modify-frame-parameters frame | |
1226 (list (cons 'cursor-color fg))))))) | |
1227 | |
1228 | |
1229 (defun x-create-frame-with-faces (&optional parameters) | |
1230 "Create a frame from optional frame parameters PARAMETERS. | |
1231 Parameters not specified by PARAMETERS are taken from | |
1232 `default-frame-alist'. If PARAMETERS specify a frame name, | |
1233 handle X geometry resources for that name. If either PARAMETERS | |
1234 or `default-frame-alist' contains a `reverse' parameter, or | |
1235 the X resource ``reverseVideo'' is present, handle that. | |
1236 Value is the new frame created." | |
1237 (setq parameters (x-handle-named-frame-geometry parameters)) | |
1238 (let ((visibility-spec (assq 'visibility parameters)) | |
1239 (frame-list (frame-list)) | |
1240 (frame (x-create-frame (cons '(visibility . nil) parameters))) | |
1241 success) | |
1242 (unwind-protect | |
1243 (progn | |
1244 (x-handle-reverse-video frame parameters) | |
1245 (frame-set-background-mode frame) | |
1246 (face-set-after-frame-default frame) | |
1247 (if (or (null frame-list) (null visibility-spec)) | |
1248 (make-frame-visible frame) | |
1249 (modify-frame-parameters frame (list visibility-spec))) | |
1250 (setq success t)) | |
1251 (unless success | |
1252 (delete-frame frame))) | |
1253 frame)) | |
1254 | |
1255 | |
1256 (defun face-set-after-frame-default (frame) | |
1257 "Set frame-local faces of FRAME from face specs and resources." | |
1258 (dolist (face (face-list)) | |
1259 (let ((spec (or (get face 'saved-face) | |
1260 (get face 'face-defface-spec)))) | |
1261 (when spec | |
1262 (face-spec-set face spec frame)) | |
1263 (internal-merge-in-global-face face frame) | |
1264 (when window-system | |
1265 (make-face-x-resource-internal face frame))))) | |
1266 | |
1267 | |
1268 (defun tty-create-frame-with-faces (&optional parameters) | |
1269 "Create a frame from optional frame parameters PARAMETERS. | |
1270 Parameters not specified by PARAMETERS are taken from | |
1271 `default-frame-alist'. If either PARAMETERS or `default-frame-alist' | |
1272 contains a `reverse' parameter, handle that. Value is the new frame | |
1273 created." | |
1274 (let ((frame (make-terminal-frame parameters)) | |
1275 success) | |
1276 (unwind-protect | |
1277 (progn | |
1278 (frame-set-background-mode frame) | |
1279 (face-set-after-frame-default frame) | |
1280 (setq success t)) | |
1281 (unless success | |
1282 (delete-frame frame))) | |
1283 frame)) | |
1284 | |
1285 | |
1286 ;; Called from C function init_display to initialize faces of the | |
1287 ;; dumped terminal frame on startup. | |
1288 | |
1289 (defun tty-set-up-initial-frame-faces () | |
1290 (let ((frame (selected-frame))) | |
1291 (frame-set-background-mode frame) | |
1292 (face-set-after-frame-default frame))) | |
1293 | |
1294 | |
1295 | |
1296 | |
1297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1298 ;;; Compatiblity with 20.2 | |
1299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1300 | |
1301 ;; Update a frame's faces when we change its default font. | |
1302 | |
1303 (defun frame-update-faces (frame) | |
1304 nil) | |
1305 | |
1306 | |
1307 ;; Update the colors of FACE, after FRAME's own colors have been | |
1308 ;; changed. | |
1309 | |
1310 (defun frame-update-face-colors (frame) | |
1311 (frame-set-background-mode frame)) | |
1312 | |
1313 | |
1314 | |
1315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1316 ;;; Standard faces. | |
1317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1318 | |
1319 ;; Make the standard faces. The C code knows faces `default', | |
1320 ;; `modeline', `toolbar' and `region', so they must be the first faces | |
1321 ;; made. Unspecified attributes of these three faces are filled-in | |
1322 ;; from frame parameters in the C code. | |
1323 | |
1324 (defgroup basic-faces nil | |
1325 "The standard faces of Emacs." | |
1326 :group 'faces) | |
1327 | |
1328 | |
1329 (defface default | |
1330 '((t nil)) | |
1331 "Basic default face." | |
1332 :group 'basic-faces) | |
1333 | |
1334 | |
1335 (defface modeline | |
1336 '((((type x) (class color)) | |
1337 (:box (:line-width 2 :style released-button) :background "grey75")) | |
1338 (t | |
1339 (:inverse-video t))) | |
1340 "Basic mode line face." | |
1341 :group 'basic-faces) | |
1342 | |
1343 | |
1344 (defface top-line | |
1345 '((((type x) (class color)) | |
1346 (:box (:line-width 2 :style released-button) :background "grey75")) | |
1347 (t | |
1348 (:inverse-video t))) | |
1349 "Basic top line face." | |
1350 :group 'basic-faces) | |
1351 | |
1352 | |
1353 (defface toolbar | |
1354 '((((type x) (class color)) | |
1355 (:box (:line-width 1 :style released-button) :background "grey75")) | |
1356 (t | |
1357 ())) | |
1358 "Basic toolbar face." | |
1359 :group 'basic-faces) | |
1360 | |
1361 | |
1362 (defface region | |
1363 '((((type tty) (class color)) | |
1364 (:background "blue" :foreground "white")) | |
1365 (((type tty) (class mono)) | |
1366 (:inverse-video t)) | |
1367 (((class color) (background dark)) | |
1368 (:background "blue")) | |
1369 (((class color) (background light)) | |
1370 (:background "lightblue")) | |
1371 (t (:background "gray"))) | |
1372 "Basic face for highlight the region." | |
1373 :group 'basic-faces) | |
1374 | |
1375 | |
1376 (defface bitmap-area | |
1377 '((((class color)) | |
1378 (:background "grey95")) | |
1379 (t (:background "gray"))) | |
1380 "Basic face for bitmap areas under X." | |
1381 :group 'basic-faces) | |
1382 | |
1383 | |
1384 (defface bold '((t (:weight bold))) | |
1385 "Basic bold face." | |
1386 :group 'basic-faces) | |
1387 | |
1388 | |
1389 (defface italic '((t (:slant italic))) | |
1390 "Basic italic font." | |
1391 :group 'basic-faces) | |
1392 | |
1393 | |
1394 (defface bold-italic '((t (:weight bold :slant italic))) | |
1395 "Basic bold-italic face." | |
1396 :group 'basic-faces) | |
1397 | |
1398 | |
1399 (defface underline '((t (:underline t))) | |
1400 "Basic underlined face." | |
1401 :group 'basic-faces) | |
1402 | |
1403 | |
1404 (defface highlight | |
1405 '((((type tty) (class color)) | |
1406 (:background "green")) | |
1407 (((class color) (background light)) | |
1408 (:background "darkseagreen2")) | |
1409 (((class color) (background dark)) | |
1410 (:background "darkolivegreen")) | |
1411 (t (:inverse-video t))) | |
1412 "Basic face for highlighting.") | |
1413 | |
1414 | |
1415 (defface secondary-selection | |
1416 '((((type tty) (class color)) | |
1417 (:background "cyan")) | |
1418 (((class color) (background light)) | |
1419 (:background "paleturquoise")) | |
1420 (((class color) (background dark)) | |
1421 (:background "darkslateblue")) | |
1422 (t (:inverse-video t))) | |
1423 "Basic face for displaying the secondary selection.") | |
1424 | |
1425 | |
1426 (defface fixed-pitch '((t (:family "courier*"))) | |
1427 "The basic fixed-pitch face." | |
1428 :group 'basic-faces) | |
1429 | |
1430 | |
1431 (defface variable-pitch '((t (:family "helv*"))) | |
1432 "The basic variable-pitch face." | |
1433 :group 'basic-faces) | |
1434 | |
1435 | |
1436 (defface trailing-whitespace | |
1437 '((((class color) (background light)) | |
1438 (:background "red")) | |
1439 (((class color) (background dark)) | |
1440 (:background "red")) | |
1441 (t (:inverse-video t))) | |
1442 "Basic face for highlighting trailing whitespace.") | |
1443 | |
1444 | |
1445 | |
1446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1447 ;;; Manipulating font names. | |
1448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1449 | |
1450 ;; This is here for compatibilty with Emacs 20.2. For example, | |
1451 ;; international/fontset.el uses these functions to manipulate font | |
1452 ;; names. The following functions are not used in the face | |
1453 ;; implementation itself. | |
2456 | 1454 |
16687
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16590
diff
changeset
|
1455 (defvar x-font-regexp nil) |
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16590
diff
changeset
|
1456 (defvar x-font-regexp-head nil) |
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16590
diff
changeset
|
1457 (defvar x-font-regexp-weight nil) |
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16590
diff
changeset
|
1458 (defvar x-font-regexp-slant nil) |
2456 | 1459 |
12668
7660e82d0346
(x-font-regexp-weight-subnum, x-font-regexp-slant-subnum)
Karl Heuer <kwzh@gnu.org>
parents:
12651
diff
changeset
|
1460 (defconst x-font-regexp-weight-subnum 1) |
7660e82d0346
(x-font-regexp-weight-subnum, x-font-regexp-slant-subnum)
Karl Heuer <kwzh@gnu.org>
parents:
12651
diff
changeset
|
1461 (defconst x-font-regexp-slant-subnum 2) |
7660e82d0346
(x-font-regexp-weight-subnum, x-font-regexp-slant-subnum)
Karl Heuer <kwzh@gnu.org>
parents:
12651
diff
changeset
|
1462 (defconst x-font-regexp-swidth-subnum 3) |
7660e82d0346
(x-font-regexp-weight-subnum, x-font-regexp-slant-subnum)
Karl Heuer <kwzh@gnu.org>
parents:
12651
diff
changeset
|
1463 (defconst x-font-regexp-adstyle-subnum 4) |
7660e82d0346
(x-font-regexp-weight-subnum, x-font-regexp-slant-subnum)
Karl Heuer <kwzh@gnu.org>
parents:
12651
diff
changeset
|
1464 |
2456 | 1465 ;;; Regexps matching font names in "Host Portable Character Representation." |
1466 ;;; | |
1467 (let ((- "[-?]") | |
1468 (foundry "[^-]+") | |
1469 (family "[^-]+") | |
1470 (weight "\\(bold\\|demibold\\|medium\\)") ; 1 | |
1471 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1 | |
1472 (weight\? "\\([^-]*\\)") ; 1 | |
1473 (slant "\\([ior]\\)") ; 2 | |
1474 ; (slant\? "\\([ior?*]?\\)") ; 2 | |
1475 (slant\? "\\([^-]?\\)") ; 2 | |
1476 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3 | |
1477 (swidth "\\([^-]*\\)") ; 3 | |
1478 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4 | |
12690
e2d3fa52d100
(x-font-regexp): Add \\(\\) for substring extraction.
Karl Heuer <kwzh@gnu.org>
parents:
12668
diff
changeset
|
1479 (adstyle "\\([^-]*\\)") ; 4 |
2456 | 1480 (pixelsize "[0-9]+") |
1481 (pointsize "[0-9][0-9]+") | |
1482 (resx "[0-9][0-9]+") | |
1483 (resy "[0-9][0-9]+") | |
1484 (spacing "[cmp?*]") | |
1485 (avgwidth "[0-9]+") | |
1486 (registry "[^-]+") | |
1487 (encoding "[^-]+") | |
1488 ) | |
1489 (setq x-font-regexp | |
1490 (concat "\\`\\*?[-?*]" | |
1491 foundry - family - weight\? - slant\? - swidth - adstyle - | |
12475
eb436b0c4ab3
(x-font-regexp): Include the avgwidth.
Richard M. Stallman <rms@gnu.org>
parents:
12460
diff
changeset
|
1492 pixelsize - pointsize - resx - resy - spacing - avgwidth - |
eb436b0c4ab3
(x-font-regexp): Include the avgwidth.
Richard M. Stallman <rms@gnu.org>
parents:
12460
diff
changeset
|
1493 registry - encoding "\\*?\\'" |
2456 | 1494 )) |
1495 (setq x-font-regexp-head | |
1496 (concat "\\`[-?*]" foundry - family - weight\? - slant\? | |
1497 "\\([-*?]\\|\\'\\)")) | |
1498 (setq x-font-regexp-slant (concat - slant -)) | |
1499 (setq x-font-regexp-weight (concat - weight -)) | |
1500 nil) | |
1501 | |
25012 | 1502 |
3071
68de05fb5751
* faces.el (set-face-font): Call x-resolve-font-name on the font
Jim Blandy <jimb@redhat.com>
parents:
3049
diff
changeset
|
1503 (defun x-resolve-font-name (pattern &optional face frame) |
68de05fb5751
* faces.el (set-face-font): Call x-resolve-font-name on the font
Jim Blandy <jimb@redhat.com>
parents:
3049
diff
changeset
|
1504 "Return a font name matching PATTERN. |
68de05fb5751
* faces.el (set-face-font): Call x-resolve-font-name on the font
Jim Blandy <jimb@redhat.com>
parents:
3049
diff
changeset
|
1505 All wildcards in PATTERN become substantiated. |
3130
82c29bacb6b3
* faces.el (x-resolve-font-name): If PATTERN is nil, return the
Jim Blandy <jimb@redhat.com>
parents:
3071
diff
changeset
|
1506 If PATTERN is nil, return the name of the frame's base font, which never |
82c29bacb6b3
* faces.el (x-resolve-font-name): If PATTERN is nil, return the
Jim Blandy <jimb@redhat.com>
parents:
3071
diff
changeset
|
1507 contains wildcards. |
10170
5fc240a3e4a0
(face-initialize): Test for framep not t or nil.
Richard M. Stallman <rms@gnu.org>
parents:
10107
diff
changeset
|
1508 Given optional arguments FACE and FRAME, return a font which is |
5fc240a3e4a0
(face-initialize): Test for framep not t or nil.
Richard M. Stallman <rms@gnu.org>
parents:
10107
diff
changeset
|
1509 also the same size as FACE on FRAME, or fail." |
3233
28b2df35c33e
(x-resolve-font-name): Allow symbol as FACE arg.
Richard M. Stallman <rms@gnu.org>
parents:
3182
diff
changeset
|
1510 (or (symbolp face) |
28b2df35c33e
(x-resolve-font-name): Allow symbol as FACE arg.
Richard M. Stallman <rms@gnu.org>
parents:
3182
diff
changeset
|
1511 (setq face (face-name face))) |
28b2df35c33e
(x-resolve-font-name): Allow symbol as FACE arg.
Richard M. Stallman <rms@gnu.org>
parents:
3182
diff
changeset
|
1512 (and (eq frame t) |
28b2df35c33e
(x-resolve-font-name): Allow symbol as FACE arg.
Richard M. Stallman <rms@gnu.org>
parents:
3182
diff
changeset
|
1513 (setq frame nil)) |
3130
82c29bacb6b3
* faces.el (x-resolve-font-name): If PATTERN is nil, return the
Jim Blandy <jimb@redhat.com>
parents:
3071
diff
changeset
|
1514 (if pattern |
5092
36508a7c0a3f
(x-resolve-font-name): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5081
diff
changeset
|
1515 ;; Note that x-list-fonts has code to handle a face with nil as its font. |
16002
c8cbde1d3f11
(internal-set-face-1): When calling x-list-fonts, ask for just one match.
Richard M. Stallman <rms@gnu.org>
parents:
15884
diff
changeset
|
1516 (let ((fonts (x-list-fonts pattern face frame 1))) |
3130
82c29bacb6b3
* faces.el (x-resolve-font-name): If PATTERN is nil, return the
Jim Blandy <jimb@redhat.com>
parents:
3071
diff
changeset
|
1517 (or fonts |
82c29bacb6b3
* faces.el (x-resolve-font-name): If PATTERN is nil, return the
Jim Blandy <jimb@redhat.com>
parents:
3071
diff
changeset
|
1518 (if face |
10584 | 1519 (if (string-match "\\*" pattern) |
1520 (if (null (face-font face)) | |
1521 (error "No matching fonts are the same height as the frame default font") | |
1522 (error "No matching fonts are the same height as face `%s'" face)) | |
1523 (if (null (face-font face)) | |
1524 (error "Height of font `%s' doesn't match the frame default font" | |
1525 pattern) | |
1526 (error "Height of font `%s' doesn't match face `%s'" | |
1527 pattern face))) | |
3353
8cbd38886eef
(x-resolve-font-name): Clean up error messages.
Richard M. Stallman <rms@gnu.org>
parents:
3298
diff
changeset
|
1528 (error "No fonts match `%s'" pattern))) |
3130
82c29bacb6b3
* faces.el (x-resolve-font-name): If PATTERN is nil, return the
Jim Blandy <jimb@redhat.com>
parents:
3071
diff
changeset
|
1529 (car fonts)) |
82c29bacb6b3
* faces.el (x-resolve-font-name): If PATTERN is nil, return the
Jim Blandy <jimb@redhat.com>
parents:
3071
diff
changeset
|
1530 (cdr (assq 'font (frame-parameters (selected-frame)))))) |
3071
68de05fb5751
* faces.el (set-face-font): Call x-resolve-font-name on the font
Jim Blandy <jimb@redhat.com>
parents:
3049
diff
changeset
|
1531 |
25012 | 1532 |
2456 | 1533 (defun x-frob-font-weight (font which) |
13704
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1534 (let ((case-fold-search t)) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1535 (cond ((string-match x-font-regexp font) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1536 (concat (substring font 0 |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1537 (match-beginning x-font-regexp-weight-subnum)) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1538 which |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1539 (substring font (match-end x-font-regexp-weight-subnum) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1540 (match-beginning x-font-regexp-adstyle-subnum)) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1541 ;; Replace the ADD_STYLE_NAME field with * |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1542 ;; because the info in it may not be the same |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1543 ;; for related fonts. |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1544 "*" |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1545 (substring font (match-end x-font-regexp-adstyle-subnum)))) |
14880
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1546 ((string-match x-font-regexp-head font) |
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1547 (concat (substring font 0 (match-beginning 1)) which |
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1548 (substring font (match-end 1)))) |
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1549 ((string-match x-font-regexp-weight font) |
13704
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1550 (concat (substring font 0 (match-beginning 1)) which |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1551 (substring font (match-end 1))))))) |
2456 | 1552 |
25012 | 1553 |
2456 | 1554 (defun x-frob-font-slant (font which) |
13704
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1555 (let ((case-fold-search t)) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1556 (cond ((string-match x-font-regexp font) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1557 (concat (substring font 0 |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1558 (match-beginning x-font-regexp-slant-subnum)) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1559 which |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1560 (substring font (match-end x-font-regexp-slant-subnum) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1561 (match-beginning x-font-regexp-adstyle-subnum)) |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1562 ;; Replace the ADD_STYLE_NAME field with * |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1563 ;; because the info in it may not be the same |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1564 ;; for related fonts. |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1565 "*" |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1566 (substring font (match-end x-font-regexp-adstyle-subnum)))) |
14880
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1567 ((string-match x-font-regexp-head font) |
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1568 (concat (substring font 0 (match-beginning 2)) which |
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1569 (substring font (match-end 2)))) |
b405f39b5493
(x-frob-font-slant): Properly handle a match against
Richard M. Stallman <rms@gnu.org>
parents:
14409
diff
changeset
|
1570 ((string-match x-font-regexp-slant font) |
13704
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1571 (concat (substring font 0 (match-beginning 1)) which |
3dcaddea344a
Wrap case-fold-search for x-frob-font-weight and x-frob-font-slant.
Simon Marshall <simon@gnu.org>
parents:
13609
diff
changeset
|
1572 (substring font (match-end 1))))))) |
2456 | 1573 |
25012 | 1574 |
2456 | 1575 (defun x-make-font-bold (font) |
4439
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1576 "Given an X font specification, make a bold version of it. |
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1577 If that can't be done, return nil." |
2456 | 1578 (x-frob-font-weight font "bold")) |
1579 | |
25012 | 1580 |
2456 | 1581 (defun x-make-font-demibold (font) |
4439
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1582 "Given an X font specification, make a demibold version of it. |
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1583 If that can't be done, return nil." |
2456 | 1584 (x-frob-font-weight font "demibold")) |
1585 | |
25012 | 1586 |
2456 | 1587 (defun x-make-font-unbold (font) |
4439
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1588 "Given an X font specification, make a non-bold version of it. |
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1589 If that can't be done, return nil." |
2456 | 1590 (x-frob-font-weight font "medium")) |
1591 | |
25012 | 1592 |
2456 | 1593 (defun x-make-font-italic (font) |
4439
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1594 "Given an X font specification, make an italic version of it. |
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1595 If that can't be done, return nil." |
2456 | 1596 (x-frob-font-slant font "i")) |
1597 | |
25012 | 1598 |
2456 | 1599 (defun x-make-font-oblique (font) ; you say tomayto... |
4439
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1600 "Given an X font specification, make an oblique version of it. |
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1601 If that can't be done, return nil." |
2456 | 1602 (x-frob-font-slant font "o")) |
1603 | |
25012 | 1604 |
2456 | 1605 (defun x-make-font-unitalic (font) |
4439
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1606 "Given an X font specification, make a non-italic version of it. |
e7ab04f23df5
Make boldness and italicness affect subsequently created frames.
Richard M. Stallman <rms@gnu.org>
parents:
4122
diff
changeset
|
1607 If that can't be done, return nil." |
2456 | 1608 (x-frob-font-slant font "r")) |
17752
2687f3d7c191
(x-make-font-bold-italic): New function.
Kenichi Handa <handa@m17n.org>
parents:
17560
diff
changeset
|
1609 |
25012 | 1610 |
17752
2687f3d7c191
(x-make-font-bold-italic): New function.
Kenichi Handa <handa@m17n.org>
parents:
17560
diff
changeset
|
1611 (defun x-make-font-bold-italic (font) |
2687f3d7c191
(x-make-font-bold-italic): New function.
Kenichi Handa <handa@m17n.org>
parents:
17560
diff
changeset
|
1612 "Given an X font specification, make a bold and italic version of it. |
2687f3d7c191
(x-make-font-bold-italic): New function.
Kenichi Handa <handa@m17n.org>
parents:
17560
diff
changeset
|
1613 If that can't be done, return nil." |
2687f3d7c191
(x-make-font-bold-italic): New function.
Kenichi Handa <handa@m17n.org>
parents:
17560
diff
changeset
|
1614 (and (setq font (x-make-font-bold font)) |
2687f3d7c191
(x-make-font-bold-italic): New function.
Kenichi Handa <handa@m17n.org>
parents:
17560
diff
changeset
|
1615 (x-make-font-italic font))) |
2456 | 1616 |
1617 | |
2715
9caee9338229
* faces.el: Call internal-set-face-1, not internat-set-face-1.
Jim Blandy <jimb@redhat.com>
parents:
2714
diff
changeset
|
1618 (provide 'faces) |
9caee9338229
* faces.el: Call internal-set-face-1, not internat-set-face-1.
Jim Blandy <jimb@redhat.com>
parents:
2714
diff
changeset
|
1619 |
25012 | 1620 ;;; end of faces.el |