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