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