428
|
1 ;;; cus-face.el -- Support for Custom faces.
|
|
2 ;;
|
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
4 ;;
|
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
|
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
|
|
7 ;; Keywords: help, faces
|
|
8 ;; Version: 1.9960-x
|
|
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
|
|
10
|
3027
|
11 ;;; Synched with: Not synched.
|
|
12
|
428
|
13 ;;; Commentary:
|
|
14 ;;
|
|
15 ;; See `custom.el'.
|
|
16
|
|
17 ;;; Code:
|
|
18
|
771
|
19 ;; it is now safe to put the `provide' anywhere. if an error occurs while
|
|
20 ;; loading, all provides (and fsets) will be undone. put it first to
|
|
21 ;; prevent require/provide loop with custom and cus-face.
|
|
22 (provide 'cus-face)
|
428
|
23 (require 'custom)
|
|
24
|
|
25 ;; To elude the warnings for font functions.
|
|
26 (eval-when-compile
|
|
27 (require 'font))
|
|
28
|
|
29 ;;; Declaring a face.
|
|
30
|
|
31 ;;;###autoload
|
|
32 (defun custom-declare-face (face spec doc &rest args)
|
|
33 "Like `defface', but FACE is evaluated as a normal argument."
|
|
34 ;; (when (fboundp 'pureload)
|
|
35 ;; (error "Attempt to declare a face during dump"))
|
|
36 ;; #### should we possibly reset force-face here?
|
|
37 (unless (get face 'face-defface-spec)
|
|
38 (put face 'face-defface-spec spec)
|
|
39 (unless (find-face face)
|
|
40 ;; If the user has already created the face, respect that.
|
|
41 (let ((value (or (get face 'saved-face) spec))
|
|
42 (frames (relevant-custom-frames))
|
|
43 frame)
|
|
44 ;; Create global face.
|
|
45 (make-empty-face face)
|
|
46 (face-display-set face value nil '(custom))
|
|
47 ;; Create frame local faces
|
|
48 (while frames
|
|
49 (setq frame (car frames)
|
|
50 frames (cdr frames))
|
|
51 (face-display-set face value frame '(custom)))
|
|
52 (init-face-from-resources face)))
|
|
53 (when (and doc (null (face-doc-string face)))
|
|
54 (set-face-doc-string face doc))
|
|
55 (custom-handle-all-keywords face args 'custom-face)
|
|
56 (run-hooks 'custom-define-hook))
|
|
57 face)
|
|
58
|
|
59 ;;; Font Attributes.
|
|
60
|
444
|
61 ;; Consider adding the stuff in the XML font model here.
|
428
|
62 (defconst custom-face-attributes
|
|
63 '((:foreground (color :tag "Foreground"
|
|
64 :value ""
|
|
65 :help-echo "Set foreground color.")
|
|
66 set-face-foreground face-foreground-name)
|
|
67 (:background (color :tag "Background"
|
|
68 :value ""
|
|
69 :help-echo "Set background color.")
|
|
70 set-face-background face-background-name)
|
|
71 (:size (editable-field :format "Size: %v"
|
|
72 :help-echo "\
|
|
73 Text size (e.g. 9pt or 2mm).")
|
|
74 custom-set-face-font-size custom-face-font-size)
|
|
75 (:family (editable-field :format "Font Family: %v"
|
|
76 :help-echo "\
|
|
77 Name of font family to use (e.g. times).")
|
|
78 custom-set-face-font-family custom-face-font-family)
|
|
79 (:background-pixmap (editable-field :format "Background pixmap: %v"
|
|
80 :help-echo "\
|
|
81 Name of background pixmap file.")
|
|
82 set-face-background-pixmap custom-face-background-pixmap)
|
|
83 (:dim (toggle :format "%[Dim%]: %v\n"
|
|
84 :help-echo "Control whether the text should be dimmed.")
|
|
85 set-face-dim-p face-dim-p)
|
|
86 (:bold (toggle :format "%[Bold%]: %v\n"
|
|
87 :help-echo "Control whether a bold font should be used.")
|
|
88 custom-set-face-bold custom-face-bold)
|
|
89 (:italic (toggle :format "%[Italic%]: %v\n"
|
|
90 :help-echo "\
|
|
91 Control whether an italic font should be used.")
|
|
92 custom-set-face-italic custom-face-italic)
|
|
93 (:underline (toggle :format "%[Underline%]: %v\n"
|
|
94 :help-echo "\
|
|
95 Control whether the text should be underlined.")
|
|
96 set-face-underline-p face-underline-p)
|
|
97 (:strikethru (toggle :format "%[Strikethru%]: %v\n"
|
|
98 :help-echo "\
|
|
99 Control whether the text should be strikethru.")
|
|
100 set-face-strikethru-p face-strikethru-p)
|
|
101 (:inverse-video (toggle :format "%[Inverse Video%]: %v\n"
|
|
102 :help-echo "\
|
|
103 Control whether the text should be inverted. Works only on TTY-s")
|
3027
|
104 set-face-reverse-p face-reverse-p)
|
|
105 (:inherit
|
|
106 (repeat :tag "Inherit"
|
|
107 :help-echo "List of faces to inherit attributes from."
|
|
108 (face :Tag "Face" default))
|
|
109 ;; FSF 21.3
|
|
110 ; ;; filter to make value suitable for customize
|
|
111 ; (lambda (real-value)
|
|
112 ; (cond ((or (null real-value) (eq real-value 'unspecified))
|
|
113 ; nil)
|
|
114 ; ((symbolp real-value)
|
|
115 ; (list real-value))
|
|
116 ; (t
|
|
117 ; real-value)))
|
|
118 ; ;; filter to make customized-value suitable for storing
|
|
119 ; (lambda (cus-value)
|
|
120 ; (if (and (consp cus-value) (null (cdr cus-value)))
|
|
121 ; (car cus-value)
|
|
122 ; cus-value))
|
|
123 custom-set-face-inherit custom-face-inherit))
|
444
|
124 "Alist of face attributes.
|
428
|
125
|
444
|
126 The elements are lists of the form (KEY TYPE SET GET) where:
|
|
127 KEY is a symbol identifying the attribute.
|
|
128 TYPE is a widget type for editing the attribute.
|
|
129 SET is a function for setting the attribute value.
|
|
130 GET is a function for getting the attribute value.
|
428
|
131
|
444
|
132 The SET function should take three arguments: the face to modify, the
|
428
|
133 value of the attribute, and optionally the frame where the face should
|
|
134 be changed.
|
|
135
|
|
136 The GET function should take two arguments, the face to examine, and
|
444
|
137 optionally the frame where the face should be examined.")
|
428
|
138
|
|
139 (defun face-custom-attributes-set (face frame tags &rest atts)
|
|
140 "For FACE on FRAME set the attributes [KEYWORD VALUE]....
|
|
141 Each keyword should be listed in `custom-face-attributes'.
|
|
142
|
|
143 If FRAME is nil, set the default face."
|
|
144 (while atts
|
|
145 (let* ((name (nth 0 atts))
|
|
146 (value (nth 1 atts))
|
|
147 (fun (nth 2 (assq name custom-face-attributes))))
|
|
148 (setq atts (cdr (cdr atts)))
|
|
149 (condition-case nil
|
|
150 (funcall fun face value frame tags)
|
|
151 (error nil)))))
|
|
152
|
|
153 (defun face-custom-attributes-get (face frame)
|
|
154 "For FACE on FRAME get the attributes [KEYWORD VALUE]....
|
|
155 Each keyword should be listed in `custom-face-attributes'.
|
|
156
|
|
157 If FRAME is nil, use the default face."
|
|
158 (condition-case nil
|
|
159 ;; Attempt to get `font.el' from w3.
|
|
160 (require 'font)
|
|
161 (error nil))
|
|
162 (let ((atts custom-face-attributes)
|
|
163 att result get)
|
|
164 (while atts
|
|
165 (setq att (car atts)
|
|
166 atts (cdr atts)
|
|
167 get (nth 3 att))
|
|
168 (condition-case nil
|
|
169 ;; This may fail if w3 doesn't exist.
|
|
170 (when get
|
|
171 (let ((answer (funcall get face frame)))
|
|
172 (unless (equal answer (funcall get 'default frame))
|
|
173 (when (widget-apply (nth 1 att) :match answer)
|
|
174 (setq result (cons (nth 0 att) (cons answer result)))))))
|
|
175 (error nil)))
|
|
176 result))
|
|
177
|
|
178 (defsubst custom-face-get-spec (symbol)
|
|
179 (or (get symbol 'customized-face)
|
|
180 (get symbol 'saved-face)
|
|
181 (get symbol 'face-defface-spec)
|
|
182 ;; Attempt to construct it.
|
|
183 (list (list t (face-custom-attributes-get
|
|
184 symbol (selected-frame))))))
|
|
185
|
|
186 (defun custom-set-face-bold (face value &optional frame tags)
|
|
187 "Set the bold property of FACE to VALUE."
|
|
188 (if value
|
|
189 (make-face-bold face frame tags)
|
|
190 (make-face-unbold face frame tags)))
|
|
191
|
|
192 ;; Really, we should get rid of these font.el dependencies... They
|
|
193 ;; are still presenting a problem with dumping the faces (font.el is
|
|
194 ;; too bloated for us to dump). I am thinking about hacking up
|
|
195 ;; font-like functionality myself for the sake of this file. It will
|
|
196 ;; probably be to-the-point and more efficient.
|
|
197
|
|
198 (defun custom-face-bold (face &rest args)
|
|
199 "Return non-nil if the font of FACE is bold."
|
|
200 (let* ((font (apply 'face-font-name face args))
|
|
201 ;; Gag
|
|
202 (fontobj (font-create-object font)))
|
|
203 (font-bold-p fontobj)))
|
|
204
|
|
205 (defun custom-set-face-italic (face value &optional frame tags)
|
|
206 "Set the italic property of FACE to VALUE."
|
|
207 (if value
|
|
208 (make-face-italic face frame tags)
|
|
209 (make-face-unitalic face frame tags)))
|
|
210
|
|
211 (defun custom-face-italic (face &rest args)
|
|
212 "Return non-nil if the font of FACE is italic."
|
|
213 (let* ((font (apply 'face-font-name face args))
|
|
214 ;; Gag
|
|
215 (fontobj (font-create-object font)))
|
|
216 (font-italic-p fontobj)))
|
|
217
|
|
218 (defun custom-face-background-pixmap (face &rest args)
|
|
219 "Return the name of the background pixmap file used for FACE."
|
3027
|
220 (let ((image (apply 'specifier-instance
|
|
221 (face-background-pixmap face) args)))
|
444
|
222 (and image
|
428
|
223 (image-instance-file-name image))))
|
|
224
|
3027
|
225 (defun custom-set-face-inherit (face value &optional frame tags)
|
|
226 "Set FACE to inherit its properties from another face."
|
|
227 (if (listp value) (setq value (car value))) ;; #### Temporary hack!
|
|
228 (if (find-face value)
|
|
229 (set-face-parent face value frame tags)))
|
|
230
|
|
231 (defun custom-face-inherit (face &rest args)
|
|
232 "Return the value (instance) of the `inherit' property for FACE."
|
|
233 ;; #### Major, temporary hack!
|
|
234 (let ((spec (apply 'specifier-instantiator
|
|
235 (face-font face) args)))
|
|
236 (and spec (vector spec) (aref spec 0))))
|
|
237
|
707
|
238 ;; This consistently fails to dtrt
|
|
239 ;;(defun custom-set-face-font-size (face size &optional locale tags)
|
|
240 ;; "Set the font of FACE to SIZE."
|
|
241 ;; ;; #### should this call have tags in it?
|
|
242 ;; (let* ((font (apply 'face-font-name face (list locale)))
|
|
243 ;; ;; Gag
|
|
244 ;; (fontobj (font-create-object font)))
|
|
245 ;; (set-font-size fontobj size)
|
|
246 ;; (apply 'font-set-face-font face fontobj locale tags)))
|
|
247
|
|
248 ;; From Jan Vroonhof -- see faces.el
|
428
|
249 (defun custom-set-face-font-size (face size &optional locale tags)
|
444
|
250 "Set the font of FACE to SIZE."
|
707
|
251 (make-face-size face size locale tags))
|
428
|
252
|
|
253 (defun custom-face-font-size (face &rest args)
|
|
254 "Return the size of the font of FACE as a string."
|
|
255 (let* ((font (apply 'face-font-name face args))
|
|
256 ;; Gag
|
|
257 (fontobj (font-create-object font)))
|
|
258 (format "%s" (font-size fontobj))))
|
|
259
|
707
|
260 ;; Jan suggests this may not dtrt
|
|
261 ;;(defun custom-set-face-font-family (face family &optional locale tags)
|
|
262 ;; "Set the font of FACE to FAMILY."
|
|
263 ;; ;; #### should this call have tags in it?
|
|
264 ;; (let* ((font (apply 'face-font-name face (list locale)))
|
|
265 ;; ;; Gag
|
|
266 ;; (fontobj (font-create-object font)))
|
|
267 ;; (set-font-family fontobj family)
|
|
268 ;; (apply 'font-set-face-font face fontobj locale tags)))
|
|
269
|
|
270 ;; From Jan Vroonhof -- see faces.el
|
428
|
271 (defun custom-set-face-font-family (face family &optional locale tags)
|
|
272 "Set the font of FACE to FAMILY."
|
707
|
273 (make-face-family face family locale tags))
|
428
|
274
|
|
275 (defun custom-face-font-family (face &rest args)
|
|
276 "Return the name of the font family of FACE."
|
|
277 (let* ((font (apply 'face-font-name face args))
|
|
278 ;; Gag
|
|
279 (fontobj (font-create-object font)))
|
|
280 (font-family fontobj)))
|
|
281
|
|
282 ;;;###autoload
|
|
283 (defun custom-set-face-update-spec (face display plist)
|
|
284 "Customize the FACE for display types matching DISPLAY, merging
|
3918
|
285 in the new items from PLIST."
|
428
|
286 (let ((spec (face-spec-update-all-matching (custom-face-get-spec face)
|
|
287 display plist)))
|
|
288 (put face 'customized-face spec)
|
|
289 (face-spec-set face spec nil '(custom))))
|
|
290
|
|
291 ;;; Initializing.
|
|
292
|
|
293 ;;;###autoload
|
|
294 (defun custom-set-faces (&rest args)
|
|
295 "Initialize faces according to user preferences.
|
|
296 This asociates the setting with the USER theme.
|
|
297 The arguments should be a list where each entry has the form:
|
|
298
|
|
299 (FACE SPEC [NOW [COMMENT]])
|
|
300
|
|
301 SPEC will be stored as the saved value for FACE. If NOW is present
|
|
302 and non-nil, FACE will also be created according to SPEC.
|
|
303 COMMENT is a string comment about FACE.
|
|
304
|
|
305 See `defface' for the format of SPEC."
|
|
306 (apply #'custom-theme-set-faces 'user args))
|
|
307
|
|
308 ;;;###autoload
|
|
309 (defun custom-theme-set-faces (theme &rest args)
|
|
310 "Initialize faces according to settings specified by args.
|
|
311 Records the settings as belonging to THEME.
|
|
312
|
|
313 See `custom-set-faces' for a description of the arguments ARGS."
|
|
314 (custom-check-theme theme)
|
|
315 (let ((immediate (get theme 'theme-immediate)))
|
|
316 (while args
|
|
317 (let ((entry (car args)))
|
|
318 (if (listp entry)
|
|
319 (let ((face (nth 0 entry))
|
|
320 (spec (nth 1 entry))
|
|
321 (now (nth 2 entry))
|
|
322 (comment (nth 3 entry)))
|
|
323 (put face 'saved-face spec)
|
|
324 (custom-push-theme 'theme-face face theme 'set spec)
|
|
325 (put face 'saved-face-comment comment)
|
|
326 (when (or now immediate)
|
|
327 (put face 'force-face (if now 'rogue 'immediate)))
|
|
328 (when (or now immediate (find-face face))
|
|
329 (put face 'face-comment comment)
|
|
330 (unless (find-face face)
|
|
331 (make-empty-face face))
|
|
332 (face-spec-set face spec nil '(custom)))
|
|
333 (setq args (cdr args)))
|
|
334 ;; Old format, a plist of FACE SPEC pairs.
|
|
335 (let ((face (nth 0 args))
|
|
336 (spec (nth 1 args)))
|
|
337 (put face 'saved-face spec)
|
|
338 (custom-push-theme 'theme-face face theme 'set spec))
|
|
339 (setq args (cdr (cdr args))))))))
|
|
340
|
|
341 ;;;###autoload
|
|
342 (defun custom-theme-face-value (face theme)
|
|
343 "Return spec of FACE in THEME if the THEME modifies the
|
|
344 FACE. Nil otherwise."
|
|
345 (car-safe (custom-theme-value theme (get face 'theme-face))))
|
|
346
|
|
347 (defun custom-theme-reset-internal-face (face to-theme)
|
|
348 (let ((spec (custom-theme-face-value face to-theme))
|
|
349 was-in-theme)
|
|
350 (setq was-in-theme spec)
|
|
351 (setq spec (or spec (get face 'standard-value)))
|
|
352 (when spec
|
|
353 (put face 'save-face was-in-theme)
|
|
354 (when (or (get face 'force-face) (find-face face))
|
|
355 (unless (find-face face)
|
|
356 (make-empty-face face))
|
|
357 (face-spec-set face spec)))
|
|
358 spec))
|
|
359
|
|
360 ;;;###autoload
|
|
361 (defun custom-theme-reset-faces (theme &rest args)
|
|
362 "Reset the value of the face to values previously defined.
|
442
|
363 Associate this setting with THEME.
|
428
|
364
|
|
365 ARGS is a list of lists of the form
|
|
366
|
|
367 (face to-theme)
|
|
368
|
|
369 This means reset face to its value in to-theme."
|
3842
|
370 (custom-check-theme theme)
|
428
|
371 (mapc #'(lambda (arg)
|
|
372 (apply #'custom-theme-reset-internal-face arg)
|
|
373 (custom-push-theme (car arg) 'theme-face theme 'reset (cadr arg)))
|
|
374 args))
|
|
375
|
|
376 ;;;###autoload
|
|
377 (defun custom-reset-faces (&rest args)
|
|
378 "Reset the value of the face to values previously defined.
|
442
|
379 Associate this setting with the 'user' theme.
|
428
|
380
|
444
|
381 ARGS is defined as for `custom-theme-reset-faces'."
|
428
|
382 (apply #'custom-theme-reset-faces 'user args))
|
|
383
|
|
384
|
|
385 ;;; The End.
|
|
386
|
|
387 ;; cus-face.el ends here
|