195
|
1 ;;; cus-face.el -- Support for Custom faces.
|
28
|
2 ;;
|
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
4 ;;
|
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
195
|
6 ;; Maintainer: Hrvoje Niksic <hniksic@srce.hr>
|
28
|
7 ;; Keywords: help, faces
|
195
|
8 ;; Version: 1.9960-x
|
28
|
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
|
|
10
|
|
11 ;;; Commentary:
|
|
12 ;;
|
|
13 ;; See `custom.el'.
|
|
14
|
195
|
15 ;; This file should probably be dissolved, and code moved to faces.el,
|
|
16 ;; like Stallman did.
|
|
17
|
28
|
18 ;;; Code:
|
|
19
|
|
20 (require 'custom)
|
|
21
|
195
|
22 ;; To elude the warnings for font functions.
|
|
23 (eval-when-compile
|
|
24 (require 'font))
|
120
|
25
|
30
|
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."
|
197
|
31 ;; (when (fboundp 'load-gc)
|
|
32 ;; (error "Attempt to declare a face during dump"))
|
149
|
33 (unless (get face 'face-defface-spec)
|
|
34 (put face 'face-defface-spec spec)
|
195
|
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))
|
197
|
38 (frames (relevant-custom-frames))
|
195
|
39 frame)
|
|
40 ;; Create global face.
|
201
|
41 (make-empty-face face)
|
197
|
42 (face-display-set face value)
|
195
|
43 ;; Create frame local faces
|
|
44 (while frames
|
|
45 (setq frame (car frames)
|
|
46 frames (cdr frames))
|
201
|
47 (face-display-set face value frame))
|
|
48 (init-face-from-resources face)))
|
30
|
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
|
163
|
58 '((:bold (boolean :tag "Bold"
|
|
59 :help-echo "Control whether a bold font should be used.")
|
197
|
60 custom-set-face-bold custom-face-bold)
|
163
|
61 (:italic (boolean :tag "Italic"
|
|
62 :help-echo "\
|
30
|
63 Control whether an italic font should be used.")
|
197
|
64 custom-set-face-italic custom-face-italic)
|
163
|
65 (:underline (boolean :tag "Underline"
|
|
66 :help-echo "\
|
30
|
67 Control whether the text should be underlined.")
|
197
|
68 set-face-underline-p face-underline-p)
|
30
|
69 (:foreground (color :tag "Foreground"
|
185
|
70 :value ""
|
30
|
71 :help-echo "Set foreground color.")
|
199
|
72 set-face-foreground face-foreground-name)
|
30
|
73 (:background (color :tag "Background"
|
185
|
74 :value ""
|
30
|
75 :help-echo "Set background color.")
|
199
|
76 set-face-background face-background-name)
|
|
77 ;; (:inverse-video (boolean :tag "Inverse"
|
197
|
78 ;; :help-echo "\
|
|
79 ;;Control whether the text should be inverted.")
|
199
|
80 ;; custom-inverse-face custom-face-inverse)
|
30
|
81 (:stipple (editable-field :format "Stipple: %v"
|
|
82 :help-echo "Name of background bitmap file.")
|
197
|
83 set-face-background-pixmap custom-face-stipple)
|
|
84 (:family (editable-field :format "Font Family: %v"
|
|
85 :help-echo "\
|
|
86 Name of font family to use (e.g. times).")
|
|
87 custom-set-face-font-family custom-face-font-family)
|
|
88 (:size (editable-field :format "Size: %v"
|
|
89 :help-echo "\
|
|
90 Text size (e.g. 9pt or 2mm).")
|
|
91 custom-set-face-font-size custom-face-font-size)
|
|
92 (:strikethru (toggle :format "%[Strikethru%]: %v\n"
|
|
93 :help-echo "\
|
|
94 Control whether the text should be strikethru.")
|
|
95 set-face-strikethru-p face-strikethru-p))
|
30
|
96 "Alist of face attributes.
|
|
97
|
118
|
98 The elements are of the form (KEY TYPE SET GET) where KEY is a symbol
|
30
|
99 identifying the attribute, TYPE is a widget type for editing the
|
118
|
100 attibute, SET is a function for setting the attribute value, and GET is a function for getiing the attribute value.
|
30
|
101
|
|
102 The SET function should take three arguments, the face to modify, the
|
|
103 value of the attribute, and optionally the frame where the face should
|
118
|
104 be changed.
|
|
105
|
|
106 The GET function should take two arguments, the face to examine, and
|
|
107 optonally the frame where the face should be examined.")
|
30
|
108
|
197
|
109 (defun face-custom-attributes-set (face frame &rest atts)
|
30
|
110 "For FACE on FRAME set the attributes [KEYWORD VALUE]....
|
|
111 Each keyword should be listed in `custom-face-attributes'.
|
|
112
|
|
113 If FRAME is nil, set the default face."
|
197
|
114 (while atts
|
30
|
115 (let* ((name (nth 0 atts))
|
|
116 (value (nth 1 atts))
|
|
117 (fun (nth 2 (assq name custom-face-attributes))))
|
|
118 (setq atts (cdr (cdr atts)))
|
|
119 (condition-case nil
|
|
120 (funcall fun face value frame)
|
|
121 (error nil)))))
|
|
122
|
197
|
123 (defun face-custom-attributes-get (face frame)
|
118
|
124 "For FACE on FRAME get the attributes [KEYWORD VALUE]....
|
|
125 Each keyword should be listed in `custom-face-attributes'.
|
|
126
|
|
127 If FRAME is nil, use the default face."
|
120
|
128 (condition-case nil
|
|
129 ;; Attempt to get `font.el' from w3.
|
|
130 (require 'font)
|
|
131 (error nil))
|
118
|
132 (let ((atts custom-face-attributes)
|
|
133 att result get)
|
|
134 (while atts
|
|
135 (setq att (car atts)
|
|
136 atts (cdr atts)
|
|
137 get (nth 3 att))
|
161
|
138 (condition-case nil
|
|
139 ;; This may fail if w3 doesn't exists.
|
195
|
140 (when get
|
161
|
141 (let ((answer (funcall get face frame)))
|
|
142 (unless (equal answer (funcall get 'default frame))
|
|
143 (when (widget-apply (nth 1 att) :match answer)
|
|
144 (setq result (cons (nth 0 att) (cons answer result)))))))
|
|
145 (error nil)))
|
118
|
146 result))
|
|
147
|
30
|
148 (defun custom-set-face-bold (face value &optional frame)
|
|
149 "Set the bold property of FACE to VALUE."
|
|
150 (if value
|
|
151 (make-face-bold face frame)
|
|
152 (make-face-unbold face frame)))
|
|
153
|
197
|
154 ;; Really, we should get rid of these font.el dependencies... They
|
|
155 ;; are still presenting a problem with dumping the faces (font.el is
|
|
156 ;; too bloated for us to dump). I am thinking about hacking up
|
|
157 ;; font-like functionality myself for the sake of this file. It will
|
|
158 ;; probably be to-the-point and more efficient.
|
|
159
|
120
|
160 (defun custom-face-bold (face &rest args)
|
|
161 "Return non-nil if the font of FACE is bold."
|
195
|
162 (let* ((font (apply 'face-font-name face args))
|
197
|
163 ;; Gag
|
120
|
164 (fontobj (font-create-object font)))
|
|
165 (font-bold-p fontobj)))
|
|
166
|
30
|
167 (defun custom-set-face-italic (face value &optional frame)
|
|
168 "Set the italic property of FACE to VALUE."
|
|
169 (if value
|
|
170 (make-face-italic face frame)
|
|
171 (make-face-unitalic face frame)))
|
|
172
|
120
|
173 (defun custom-face-italic (face &rest args)
|
|
174 "Return non-nil if the font of FACE is italic."
|
195
|
175 (let* ((font (apply 'face-font-name face args))
|
197
|
176 ;; Gag
|
120
|
177 (fontobj (font-create-object font)))
|
|
178 (font-italic-p fontobj)))
|
|
179
|
|
180 (defun custom-face-stipple (face &rest args)
|
|
181 "Return the name of the stipple file used for FACE."
|
195
|
182 (let ((image (apply 'specifier-instance
|
|
183 (face-background-pixmap face) args)))
|
|
184 (and image
|
|
185 (image-instance-file-name image))))
|
30
|
186
|
195
|
187 (defun custom-set-face-font-size (face size &rest args)
|
|
188 "Set the font of FACE to SIZE"
|
|
189 (let* ((font (apply 'face-font-name face args))
|
197
|
190 ;; Gag
|
195
|
191 (fontobj (font-create-object font)))
|
|
192 (set-font-size fontobj size)
|
|
193 (apply 'font-set-face-font face fontobj args)))
|
30
|
194
|
195
|
195 (defun custom-face-font-size (face &rest args)
|
|
196 "Return the size of the font of FACE as a string."
|
|
197 (let* ((font (apply 'face-font-name face args))
|
197
|
198 ;; Gag
|
195
|
199 (fontobj (font-create-object font)))
|
|
200 (format "%s" (font-size fontobj))))
|
120
|
201
|
195
|
202 (defun custom-set-face-font-family (face family &rest args)
|
|
203 "Set the font of FACE to FAMILY."
|
|
204 (let* ((font (apply 'face-font-name face args))
|
197
|
205 ;; Gag
|
195
|
206 (fontobj (font-create-object font)))
|
|
207 (set-font-family fontobj family)
|
|
208 (apply 'font-set-face-font face fontobj args)))
|
30
|
209
|
195
|
210 (defun custom-face-font-family (face &rest args)
|
|
211 "Return the name of the font family of FACE."
|
|
212 (let* ((font (apply 'face-font-name face args))
|
197
|
213 ;; Gag
|
195
|
214 (fontobj (font-create-object font)))
|
|
215 (font-family fontobj)))
|
120
|
216
|
197
|
217 ;;(defun custom-reverse-face (face value &optional frame)
|
|
218 ;; "Swap the foreground and background colors of face FACE.
|
|
219 ;;If the colors are not specified in the face, use the default colors."
|
|
220 ;; (interactive (list (read-face-name "Reverse face: ")))
|
|
221 ;; (when value
|
|
222 ;; (if (eq (frame-type) 'tty)
|
|
223 ;; (set-face-reverse-p face value frame)
|
|
224 ;; (let ((fg (face-foreground-instance face frame))
|
|
225 ;; (bg (face-background-instance face frame)))
|
|
226 ;; (set-face-foreground face bg frame)
|
|
227 ;; (set-face-background face fg frame)))))
|
28
|
228
|
197
|
229 ;;(defun custom-face-reverse (face &optional frame)
|
|
230 ;; "Returns non-nil if the face is reverse."
|
|
231 ;; (if (eq (frame-type) 'tty)
|
|
232 ;; (face-reverse-p face frame)
|
|
233 ;; ;;; ### Implement me
|
|
234 ;; ))
|
28
|
235
|
|
236 ;;; Initializing.
|
|
237
|
|
238 ;;;###autoload
|
|
239 (defun custom-set-faces (&rest args)
|
|
240 "Initialize faces according to user preferences.
|
|
241 The arguments should be a list where each entry has the form:
|
|
242
|
|
243 (FACE SPEC [NOW])
|
|
244
|
|
245 SPEC will be stored as the saved value for FACE. If NOW is present
|
|
246 and non-nil, FACE will also be created according to SPEC.
|
|
247
|
|
248 See `defface' for the format of SPEC."
|
|
249 (while args
|
|
250 (let ((entry (car args)))
|
|
251 (if (listp entry)
|
|
252 (let ((face (nth 0 entry))
|
|
253 (spec (nth 1 entry))
|
|
254 (now (nth 2 entry)))
|
|
255 (put face 'saved-face spec)
|
|
256 (when now
|
32
|
257 (put face 'force-face t))
|
195
|
258 (when (or now (find-face face))
|
199
|
259 (unless (find-face face)
|
201
|
260 (make-empty-face face))
|
149
|
261 (face-spec-set face spec))
|
28
|
262 (setq args (cdr args)))
|
|
263 ;; Old format, a plist of FACE SPEC pairs.
|
|
264 (let ((face (nth 0 args))
|
|
265 (spec (nth 1 args)))
|
|
266 (put face 'saved-face spec))
|
|
267 (setq args (cdr (cdr args)))))))
|
|
268
|
|
269 ;;; The End.
|
|
270
|
|
271 (provide 'cus-face)
|
|
272
|
|
273 ;; cus-face.el ends here
|