209
|
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@srce.hr>
|
|
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
|
|
20 (require 'custom)
|
|
21
|
|
22 ;; To elude the warnings for font functions.
|
|
23 (eval-when-compile
|
|
24 (require 'font))
|
|
25
|
|
26 ;;; Declaring a face.
|
|
27
|
|
28 ;;;###autoload
|
|
29 (defun custom-declare-face (face spec doc &rest args)
|
|
30 "Like `defface', but FACE is evaluated as a normal argument."
|
267
|
31 ;; (when (fboundp 'pureload)
|
209
|
32 ;; (error "Attempt to declare a face during dump"))
|
|
33 (unless (get face 'face-defface-spec)
|
|
34 (put face 'face-defface-spec spec)
|
|
35 (unless (find-face face)
|
|
36 ;; If the user has already created the face, respect that.
|
|
37 (let ((value (or (get face 'saved-face) spec))
|
|
38 (frames (relevant-custom-frames))
|
|
39 frame)
|
|
40 ;; Create global face.
|
|
41 (make-empty-face face)
|
|
42 (face-display-set face value)
|
|
43 ;; Create frame local faces
|
|
44 (while frames
|
|
45 (setq frame (car frames)
|
|
46 frames (cdr frames))
|
|
47 (face-display-set face value frame))
|
|
48 (init-face-from-resources face)))
|
|
49 (when (and doc (null (face-doc-string face)))
|
|
50 (set-face-doc-string face doc))
|
|
51 (custom-handle-all-keywords face args 'custom-face)
|
|
52 (run-hooks 'custom-define-hook))
|
|
53 face)
|
|
54
|
|
55 ;;; Font Attributes.
|
|
56
|
367
|
57 ;; Consider adding the stuff in the XML font model here.
|
209
|
58 (defconst custom-face-attributes
|
290
|
59 '((:foreground (color :tag "Foreground"
|
209
|
60 :value ""
|
|
61 :help-echo "Set foreground color.")
|
|
62 set-face-foreground face-foreground-name)
|
|
63 (:background (color :tag "Background"
|
|
64 :value ""
|
|
65 :help-echo "Set background color.")
|
|
66 set-face-background face-background-name)
|
290
|
67 (:size (editable-field :format "Size: %v"
|
|
68 :help-echo "\
|
|
69 Text size (e.g. 9pt or 2mm).")
|
|
70 custom-set-face-font-size custom-face-font-size)
|
209
|
71 (:stipple (editable-field :format "Stipple: %v"
|
|
72 :help-echo "Name of background bitmap file.")
|
213
|
73 set-face-stipple custom-face-stipple)
|
209
|
74 (:family (editable-field :format "Font Family: %v"
|
|
75 :help-echo "\
|
|
76 Name of font family to use (e.g. times).")
|
|
77 custom-set-face-font-family custom-face-font-family)
|
290
|
78 (:bold (toggle :format "%[Bold%]: %v\n"
|
|
79 :help-echo "Control whether a bold font should be used.")
|
|
80 custom-set-face-bold custom-face-bold)
|
|
81 (:italic (toggle :format "%[Italic%]: %v\n"
|
|
82 :help-echo "\
|
|
83 Control whether an italic font should be used.")
|
|
84 custom-set-face-italic custom-face-italic)
|
|
85 (:underline (toggle :format "%[Underline%]: %v\n"
|
|
86 :help-echo "\
|
|
87 Control whether the text should be underlined.")
|
|
88 set-face-underline-p face-underline-p)
|
|
89 ;; #### Should make it work on X
|
209
|
90 (:strikethru (toggle :format "%[Strikethru%]: %v\n"
|
|
91 :help-echo "\
|
|
92 Control whether the text should be strikethru.")
|
290
|
93 set-face-strikethru-p face-strikethru-p)
|
|
94 (:inverse-video (toggle :format "%[Inverse Video%]: %v\n"
|
|
95 :help-echo "\
|
|
96 Control whether the text should be inverted. Works only on TTY-s")
|
|
97 set-face-reverse-p face-reverse-p))
|
209
|
98 "Alist of face attributes.
|
|
99
|
|
100 The elements are of the form (KEY TYPE SET GET) where KEY is a symbol
|
|
101 identifying the attribute, TYPE is a widget type for editing the
|
367
|
102 attribute, SET is a function for setting the attribute value, and GET is
|
|
103 a function for getting the attribute value.
|
209
|
104
|
|
105 The SET function should take three arguments, the face to modify, the
|
|
106 value of the attribute, and optionally the frame where the face should
|
|
107 be changed.
|
|
108
|
|
109 The GET function should take two arguments, the face to examine, and
|
367
|
110 optionally the frame where the face should be examined.")
|
209
|
111
|
|
112 (defun face-custom-attributes-set (face frame &rest atts)
|
|
113 "For FACE on FRAME set the attributes [KEYWORD VALUE]....
|
|
114 Each keyword should be listed in `custom-face-attributes'.
|
|
115
|
|
116 If FRAME is nil, set the default face."
|
|
117 (while atts
|
|
118 (let* ((name (nth 0 atts))
|
|
119 (value (nth 1 atts))
|
|
120 (fun (nth 2 (assq name custom-face-attributes))))
|
|
121 (setq atts (cdr (cdr atts)))
|
|
122 (condition-case nil
|
|
123 (funcall fun face value frame)
|
|
124 (error nil)))))
|
|
125
|
|
126 (defun face-custom-attributes-get (face frame)
|
|
127 "For FACE on FRAME get the attributes [KEYWORD VALUE]....
|
|
128 Each keyword should be listed in `custom-face-attributes'.
|
|
129
|
|
130 If FRAME is nil, use the default face."
|
|
131 (condition-case nil
|
|
132 ;; Attempt to get `font.el' from w3.
|
|
133 (require 'font)
|
|
134 (error nil))
|
|
135 (let ((atts custom-face-attributes)
|
|
136 att result get)
|
|
137 (while atts
|
|
138 (setq att (car atts)
|
|
139 atts (cdr atts)
|
|
140 get (nth 3 att))
|
|
141 (condition-case nil
|
235
|
142 ;; This may fail if w3 doesn't exist.
|
209
|
143 (when get
|
|
144 (let ((answer (funcall get face frame)))
|
|
145 (unless (equal answer (funcall get 'default frame))
|
|
146 (when (widget-apply (nth 1 att) :match answer)
|
|
147 (setq result (cons (nth 0 att) (cons answer result)))))))
|
|
148 (error nil)))
|
|
149 result))
|
|
150
|
314
|
151 (defsubst custom-face-get-spec (symbol)
|
|
152 (or (get symbol 'customized-face)
|
|
153 (get symbol 'saved-face)
|
|
154 (get symbol 'face-defface-spec)
|
|
155 ;; Attempt to construct it.
|
|
156 (list (list t (face-custom-attributes-get
|
|
157 symbol (selected-frame))))))
|
|
158
|
209
|
159 (defun custom-set-face-bold (face value &optional frame)
|
|
160 "Set the bold property of FACE to VALUE."
|
|
161 (if value
|
|
162 (make-face-bold face frame)
|
|
163 (make-face-unbold face frame)))
|
|
164
|
|
165 ;; Really, we should get rid of these font.el dependencies... They
|
|
166 ;; are still presenting a problem with dumping the faces (font.el is
|
|
167 ;; too bloated for us to dump). I am thinking about hacking up
|
|
168 ;; font-like functionality myself for the sake of this file. It will
|
|
169 ;; probably be to-the-point and more efficient.
|
|
170
|
|
171 (defun custom-face-bold (face &rest args)
|
|
172 "Return non-nil if the font of FACE is bold."
|
|
173 (let* ((font (apply 'face-font-name face args))
|
|
174 ;; Gag
|
|
175 (fontobj (font-create-object font)))
|
|
176 (font-bold-p fontobj)))
|
|
177
|
|
178 (defun custom-set-face-italic (face value &optional frame)
|
|
179 "Set the italic property of FACE to VALUE."
|
|
180 (if value
|
|
181 (make-face-italic face frame)
|
|
182 (make-face-unitalic face frame)))
|
|
183
|
|
184 (defun custom-face-italic (face &rest args)
|
|
185 "Return non-nil if the font of FACE is italic."
|
|
186 (let* ((font (apply 'face-font-name face args))
|
|
187 ;; Gag
|
|
188 (fontobj (font-create-object font)))
|
|
189 (font-italic-p fontobj)))
|
|
190
|
|
191 (defun custom-face-stipple (face &rest args)
|
|
192 "Return the name of the stipple file used for FACE."
|
|
193 (let ((image (apply 'specifier-instance
|
|
194 (face-background-pixmap face) args)))
|
|
195 (and image
|
|
196 (image-instance-file-name image))))
|
|
197
|
|
198 (defun custom-set-face-font-size (face size &rest args)
|
|
199 "Set the font of FACE to SIZE"
|
|
200 (let* ((font (apply 'face-font-name face args))
|
|
201 ;; Gag
|
|
202 (fontobj (font-create-object font)))
|
|
203 (set-font-size fontobj size)
|
|
204 (apply 'font-set-face-font face fontobj args)))
|
|
205
|
|
206 (defun custom-face-font-size (face &rest args)
|
|
207 "Return the size of the font of FACE as a string."
|
|
208 (let* ((font (apply 'face-font-name face args))
|
|
209 ;; Gag
|
|
210 (fontobj (font-create-object font)))
|
|
211 (format "%s" (font-size fontobj))))
|
|
212
|
|
213 (defun custom-set-face-font-family (face family &rest args)
|
|
214 "Set the font of FACE to FAMILY."
|
|
215 (let* ((font (apply 'face-font-name face args))
|
|
216 ;; Gag
|
|
217 (fontobj (font-create-object font)))
|
|
218 (set-font-family fontobj family)
|
|
219 (apply 'font-set-face-font face fontobj args)))
|
|
220
|
|
221 (defun custom-face-font-family (face &rest args)
|
|
222 "Return the name of the font family of FACE."
|
|
223 (let* ((font (apply 'face-font-name face args))
|
|
224 ;; Gag
|
|
225 (fontobj (font-create-object font)))
|
|
226 (font-family fontobj)))
|
|
227
|
321
|
228 ;;;###autoload
|
314
|
229 (defun custom-set-face-update-spec (face display plist)
|
|
230 "Customize the FACE for display types matching DISPLAY, merging
|
|
231 in the new items from PLIST"
|
|
232 (let ((spec (face-spec-update-all-matching (custom-face-get-spec face)
|
|
233 display plist)))
|
|
234 (put face 'customized-face spec)
|
|
235 (face-spec-set face spec)))
|
|
236
|
209
|
237 ;;; Initializing.
|
|
238
|
|
239 ;;;###autoload
|
|
240 (defun custom-set-faces (&rest args)
|
|
241 "Initialize faces according to user preferences.
|
|
242 The arguments should be a list where each entry has the form:
|
|
243
|
|
244 (FACE SPEC [NOW])
|
|
245
|
|
246 SPEC will be stored as the saved value for FACE. If NOW is present
|
|
247 and non-nil, FACE will also be created according to SPEC.
|
|
248
|
|
249 See `defface' for the format of SPEC."
|
|
250 (while args
|
|
251 (let ((entry (car args)))
|
|
252 (if (listp entry)
|
|
253 (let ((face (nth 0 entry))
|
|
254 (spec (nth 1 entry))
|
|
255 (now (nth 2 entry)))
|
|
256 (put face 'saved-face spec)
|
|
257 (when now
|
|
258 (put face 'force-face t))
|
|
259 (when (or now (find-face face))
|
|
260 (unless (find-face face)
|
|
261 (make-empty-face face))
|
|
262 (face-spec-set face spec))
|
|
263 (setq args (cdr args)))
|
|
264 ;; Old format, a plist of FACE SPEC pairs.
|
|
265 (let ((face (nth 0 args))
|
|
266 (spec (nth 1 args)))
|
|
267 (put face 'saved-face spec))
|
|
268 (setq args (cdr (cdr args)))))))
|
|
269
|
|
270 ;;; The End.
|
|
271
|
|
272 (provide 'cus-face)
|
|
273
|
|
274 ;; cus-face.el ends here
|