Mercurial > emacs
annotate lisp/cus-face.el @ 25125:8282b2b596a2
(lock_if_free): Indentation fix.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Fri, 30 Jul 1999 14:30:03 +0000 |
parents | 1553432b90d5 |
children | e3ed0e86532c |
rev | line source |
---|---|
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
1 ;;; cus-face.el -- customization support for faces. |
17334 | 2 ;; |
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. | |
4 ;; | |
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
6 ;; Keywords: help, faces | |
17568
65f85125b4f2
Changed version number.
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
17567
diff
changeset
|
7 ;; Version: Emacs |
17334 | 8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ |
9 | |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
10 ;; This file is part of GNU Emacs. |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
11 |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
15 ;; any later version. |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
16 |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
17 ;; GNU Emacs is distributed in the hope that it will be useful, |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
20 ;; GNU General Public License for more details. |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
21 |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
25 ;; Boston, MA 02111-1307, USA. |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
26 |
17334 | 27 ;;; Commentary: |
28 ;; | |
29 ;; See `custom.el'. | |
30 | |
31 ;;; Code: | |
32 | |
24984 | 33 (defalias 'custom-facep 'facep) |
17856
1e5f1a1f0db3
(custom-facep): Defined (once again).
Richard M. Stallman <rms@gnu.org>
parents:
17568
diff
changeset
|
34 |
17334 | 35 ;;; Declaring a face. |
36 | |
37 ;;;###autoload | |
38 (defun custom-declare-face (face spec doc &rest args) | |
39 "Like `defface', but FACE is evaluated as a normal argument." | |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
40 (unless (get face 'face-defface-spec) |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
41 (put face 'face-defface-spec spec) |
17334 | 42 (when (fboundp 'facep) |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
43 (unless (facep face) |
17334 | 44 ;; If the user has already created the face, respect that. |
45 (let ((value (or (get face 'saved-face) spec)) | |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
46 (frames (frame-list)) |
17334 | 47 frame) |
48 ;; Create global face. | |
49 (make-empty-face face) | |
50 ;; Create frame local faces | |
51 (while frames | |
52 (setq frame (car frames) | |
53 frames (cdr frames)) | |
19257
e487ed925a50
(custom-declare-face): Call make-face-x-resource-internal.
Richard M. Stallman <rms@gnu.org>
parents:
18935
diff
changeset
|
54 (face-spec-set face value frame))) |
e487ed925a50
(custom-declare-face): Call make-face-x-resource-internal.
Richard M. Stallman <rms@gnu.org>
parents:
18935
diff
changeset
|
55 ;; When making a face after frames already exist |
e487ed925a50
(custom-declare-face): Call make-face-x-resource-internal.
Richard M. Stallman <rms@gnu.org>
parents:
18935
diff
changeset
|
56 (if (memq window-system '(x w32)) |
e487ed925a50
(custom-declare-face): Call make-face-x-resource-internal.
Richard M. Stallman <rms@gnu.org>
parents:
18935
diff
changeset
|
57 (make-face-x-resource-internal face)))) |
18935
ab4cd3135797
(custom-declare-face): Use [set-]face-documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18599
diff
changeset
|
58 (when (and doc (null (face-documentation face))) |
ab4cd3135797
(custom-declare-face): Use [set-]face-documentation.
Richard M. Stallman <rms@gnu.org>
parents:
18599
diff
changeset
|
59 (set-face-documentation face doc)) |
17334 | 60 (custom-handle-all-keywords face args 'custom-face) |
61 (run-hooks 'custom-define-hook)) | |
62 face) | |
63 | |
24984 | 64 ;;; Face attributes. |
65 | |
66 ;; Below, nil is used in widget specifications for `unspecified' face | |
67 ;; attributes and `off' is used instead of nil attribute values. The | |
68 ;; reason for this is that nil corresponds to the result you get when | |
69 ;; looking up an attribute in a defface spec that isn't contained in | |
70 ;; the spec. | |
17334 | 71 |
72 (defconst custom-face-attributes | |
24984 | 73 '((:family |
74 (choice :tag "Font family" | |
75 :help-echo "Font family or fontset alias name." | |
76 (const :tag "*" nil) | |
77 (string :tag "Family")) | |
78 (lambda (face value &optional frame) | |
79 (set-face-attribute face frame :family (or value 'unspecified))) | |
80 (lambda (face &optional frame) | |
81 (let ((family (face-attribute face :family frame))) | |
82 (if (eq family 'unspecified) nil family)))) | |
83 | |
84 (:width | |
85 (choice :tag "Width" | |
86 :help-echo "Font width." | |
87 (const :tag "*" nil) | |
88 (const :tag "compressed" condensed) | |
89 (const :tag "condensed" condensed) | |
90 (const :tag "demiexpanded" semi-expanded) | |
91 (const :tag "expanded" expanded) | |
92 (const :tag "extracondensed" extra-condensed) | |
93 (const :tag "extraexpanded" extra-expanded) | |
94 (const :tag "medium" normal) | |
95 (const :tag "narrow" condensed) | |
96 (const :tag "normal" normal) | |
97 (const :tag "regular" normal) | |
98 (const :tag "semicondensed" semi-condensed) | |
99 (const :tag "semiexpanded" semi-expanded) | |
100 (const :tag "ultracondensed" ultra-condensed) | |
101 (const :tag "ultraexpanded" ultra-expanded) | |
102 (const :tag "wide" extra-expanded)) | |
103 (lambda (face value &optional frame) | |
104 (set-face-attribute face frame :width (or value 'unspecified))) | |
105 (lambda (face &optional frame) | |
106 (let ((width (face-attribute face :width frame))) | |
107 (if (eq width 'unspecified) nil width)))) | |
108 | |
109 (:height | |
110 (choice :tag "Height" | |
111 :help-echo "Face's font height." | |
112 (const :tag "*" nil) | |
113 (integer :tag "Height in 1/10 pt")) | |
114 (lambda (face value &optional frame) | |
115 (set-face-attribute face frame :height (or value 'unspecified))) | |
116 (lambda (face &optional frame) | |
117 (let ((height (face-attribute face :height frame))) | |
118 (if (eq height 'unspecified) nil height)))) | |
119 | |
120 (:weight | |
121 (choice :tag "Weight" | |
122 :help-echo "Font weight." | |
123 (const :tag "*" nil) | |
124 (const :tag "black" ultra_bold) | |
125 (const :tag "bold" bold) | |
126 (const :tag "book" semi-light) | |
127 (const :tag "demibold" semi-bold) | |
128 (const :tag "extralight" extra-light) | |
129 (const :tag "extrabold" extra-bold) | |
130 (const :tag "heavy" extra-bold) | |
131 (const :tag "light" light) | |
132 (const :tag "medium" normal) | |
133 (const :tag "normal" normal) | |
134 (const :tag "regular" normal) | |
135 (const :tag "semibold" semi-bold) | |
136 (const :tag "semilight" semi-light) | |
137 (const :tag "ultralight" ultra-light) | |
138 (const :tag "ultrabold" ultra-bold)) | |
139 (lambda (face value &optional frame) | |
140 (set-face-attribute face frame :weight (or value 'unspecified))) | |
141 (lambda (face &optional frame) | |
142 (let ((weight (face-attribute face :weight frame))) | |
143 (if (eq weight 'unspecified) nil weight)))) | |
144 | |
145 (:slant | |
146 (choice :tag "Slant" | |
147 :help-echo "Font slant." | |
148 (const :tag "*" nil) | |
149 (const :tag "italic" italic) | |
150 (const :tag "oblique" oblique) | |
151 (const :tag "normal" normal)) | |
152 (lambda (face value &optional frame) | |
153 (set-face-attribute face frame :slant (or value 'unspecified))) | |
154 (lambda (face &optional frame) | |
155 (let ((slant (face-attribute face :slant frame))) | |
156 (if (eq slant 'unspecified) nil slant)))) | |
157 | |
158 (:underline | |
159 (choice :tag "Underline" | |
160 :help-echo "Control text underlining." | |
161 (const :tag "*" nil) | |
162 (const :tag "On" t) | |
163 (const :tag "Off" off) | |
164 (color :tag "Colored")) | |
165 (lambda (face value &optional frame) | |
166 (cond ((eq value 'off) (setq value nil)) | |
167 ((null value) (setq value 'unspecified))) | |
168 (set-face-attribute face frame :underline value)) | |
169 (lambda (face &optional frame) | |
170 (let ((underline (face-attribute face :underline frame))) | |
171 (cond ((eq underline 'unspecified) (setq underline nil)) | |
172 ((null underline) (setq underline 'off))) | |
173 underline))) | |
174 | |
175 (:overline | |
176 (choice :tag "Overline" | |
177 :help-echo "Control text overlining." | |
178 (const :tag "*" nil) | |
179 (const :tag "On" t) | |
180 (const :tag "Off" off) | |
181 (color :tag "Colored")) | |
182 (lambda (face value &optional frame) | |
183 (cond ((eq value 'off) (setq value nil)) | |
184 ((null value) (setq value 'unspecified))) | |
185 (set-face-attribute face frame :overline value)) | |
186 (lambda (face &optional frame) | |
187 (let ((overline (face-attribute face :overline frame))) | |
188 (cond ((eq overline 'unspecified) (setq overline nil)) | |
189 ((null overline) (setq overline 'off))) | |
190 overline))) | |
191 | |
192 (:strike-through | |
193 (choice :tag "Strike-through" | |
194 :help-echo "Control text strike-through." | |
195 (const :tag "*" nil) | |
196 (const :tag "On" t) | |
197 (const :tag "Off" off) | |
198 (color :tag "Colored")) | |
199 (lambda (face value &optional frame) | |
200 (cond ((eq value 'off) (setq value nil)) | |
201 ((null value) (setq value 'unspecified))) | |
202 (set-face-attribute face frame :strike-through value)) | |
203 (lambda (face &optional frame) | |
204 (let ((value (face-attribute face :strike-through frame))) | |
205 (cond ((eq value 'unspecified) (setq value nil)) | |
206 ((null value) (setq value 'off))) | |
207 value))) | |
208 | |
209 (:box | |
210 (choice :tag "Box around text" | |
211 :help-echo "Control box around text." | |
212 (const :tag "*" nil) | |
213 (const :tag "Off" off) | |
214 (list :tag "Box" | |
215 :value (1 "black" nil) | |
216 (integer :tag "Width") | |
217 (color :tag "Color") | |
218 (choice :tag "Shadows" | |
219 (const :tag "None" nil) | |
220 (const :tag "Raised" raised) | |
221 (const :tag "Sunken" sunken)))) | |
222 (lambda (face value &optional frame) | |
223 (cond ((consp value) | |
224 (let ((width (nth 0 value)) | |
225 (color (nth 1 value)) | |
226 (shadow (nth 2 value))) | |
227 (setq value (list :width width :color color :shadow shadow)))) | |
228 ((eq value 'off) | |
229 (setq value nil)) | |
230 ((null value) | |
231 (setq value 'unspecified))) | |
232 (set-face-attribute face frame :box value)) | |
233 (lambda (face &optional frame) | |
234 (let ((value (face-attribute face :box frame))) | |
235 (cond ((consp value) | |
236 (let ((width (plist-get value :width)) | |
237 (color (plist-get value :color)) | |
238 (shadow (plist-get value :shadow))) | |
239 (setq value (list width color shadow)))) | |
240 ((eq value 'unspecified) | |
241 (setq value nil)) | |
242 ((null value) | |
243 (setq value 'off))) | |
244 value))) | |
245 | |
246 (:inverse-video | |
247 (choice :tag "Inverse-video" | |
248 :help-echo "Control whether text should be in inverse-video." | |
249 (const :tag "*" nil) | |
250 (const :tag "On" t) | |
251 (const :tag "Off" off)) | |
252 (lambda (face value &optional frame) | |
253 (cond ((eq value 'off) (setq value nil)) | |
254 ((null value) (setq value 'unspecified))) | |
255 (set-face-attribute face frame :inverse-video value)) | |
256 (lambda (face &optional frame) | |
257 (let ((value (face-attribute face :inverse-video frame))) | |
258 (cond ((eq value 'unspecified) (setq value nil)) | |
259 ((null value) (setq value 'off))) | |
260 value))) | |
261 | |
262 (:foreground | |
263 (choice :tag "Foreground" | |
264 :help-echo "Set foreground color." | |
265 (const :tag "*" nil) | |
266 (color :tag "Color")) | |
267 (lambda (face value &optional frame) | |
268 (set-face-attribute face frame :foreground (or value 'unspecified))) | |
269 (lambda (face &optional frame) | |
270 (let ((value (face-attribute face :foreground frame))) | |
271 (if (eq value 'unspecified) nil value)))) | |
272 | |
273 (:background | |
274 (choice :tag "Background" | |
275 :help-echo "Set background color." | |
276 (const :tag "*" nil) | |
277 (color :tag "Color")) | |
278 (lambda (face value &optional frame) | |
279 (set-face-attribute face frame :background (or value 'unspecified))) | |
280 (lambda (face &optional frame) | |
281 (let ((value (face-attribute face :background frame))) | |
282 (if (eq value 'unspecified) nil value)))) | |
283 | |
284 (:stipple | |
285 (choice :tag "Stipple" | |
286 :help-echo "Name of background bitmap file." | |
287 (const :tag "*" nil) | |
288 (file :tag "File" :must-match t)) | |
289 (lambda (face value &optional frame) | |
290 (set-face-attribute face frame :stipple (or value 'unspecified))) | |
291 (lambda (face &optional frame) | |
292 (let ((value (face-attribute face :stipple frame))) | |
293 (if (eq value 'unspecified) nil value))))) | |
294 | |
295 "Alist of face attributes. | |
296 | |
297 The elements are of the form (KEY TYPE SET GET), where KEY is the name | |
298 of the attribute, TYPE is a widget type for editing the attibute, SET | |
299 is a function for setting the attribute value, and GET is a function | |
300 for getiing the attribute value. | |
17334 | 301 |
302 The SET function should take three arguments, the face to modify, the | |
303 value of the attribute, and optionally the frame where the face should | |
304 be changed. | |
305 | |
306 The GET function should take two arguments, the face to examine, and | |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
307 optionally the frame where the face should be examined.") |
17334 | 308 |
24984 | 309 |
17334 | 310 (defun custom-face-attributes-get (face frame) |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
311 "For FACE on FRAME, return an alternating list describing its attributes. |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
312 The list has the form (KEYWORD VALUE KEYWORD VALUE...). |
17334 | 313 Each keyword should be listed in `custom-face-attributes'. |
314 | |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
315 If FRAME is nil, use the global defaults for FACE." |
24984 | 316 (let ((attrs custom-face-attributes) |
317 plist) | |
318 (while attrs | |
319 (let* ((attribute (car (car attrs))) | |
320 (value (face-attribute face attribute frame))) | |
321 (setq attrs (cdr attrs)) | |
322 (unless (eq value 'unspecified) | |
323 (setq plist (cons attribute (cons value plist)))))) | |
324 plist)) | |
17334 | 325 |
326 ;;; Initializing. | |
327 | |
328 ;;;###autoload | |
329 (defun custom-set-faces (&rest args) | |
330 "Initialize faces according to user preferences. | |
331 The arguments should be a list where each entry has the form: | |
332 | |
333 (FACE SPEC [NOW]) | |
334 | |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
335 SPEC is stored as the saved value for FACE. |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
336 If NOW is present and non-nil, FACE is created now, according to SPEC. |
17334 | 337 |
338 See `defface' for the format of SPEC." | |
339 (while args | |
340 (let ((entry (car args))) | |
341 (if (listp entry) | |
342 (let ((face (nth 0 entry)) | |
343 (spec (nth 1 entry)) | |
344 (now (nth 2 entry))) | |
345 (put face 'saved-face spec) | |
346 (when now | |
347 (put face 'force-face t)) | |
17524
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
348 (when (or now (facep face)) |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
349 (make-empty-face face) |
8ba505704d9d
Major simplification; most of file contents deleted.
Richard M. Stallman <rms@gnu.org>
parents:
17415
diff
changeset
|
350 (face-spec-set face spec)) |
17334 | 351 (setq args (cdr args))) |
352 ;; Old format, a plist of FACE SPEC pairs. | |
353 (let ((face (nth 0 args)) | |
354 (spec (nth 1 args))) | |
355 (put face 'saved-face spec)) | |
356 (setq args (cdr (cdr args))))))) | |
357 | |
358 ;;; The End. | |
359 | |
360 (provide 'cus-face) | |
361 | |
362 ;; cus-face.el ends here |