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