(makefile-warn-suspicious-lines): clean
[emacs.git] / lisp / cus-face.el
blobb465aada7ae84306db0284b52643a9d094343ba5
1 ;;; cus-face.el -- customization support for faces.
2 ;;
3 ;; Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces
7 ;; Version: Emacs
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ (probably obsolete)
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; See `custom.el'.
31 ;;; Code:
33 (defalias 'custom-facep 'facep)
35 ;;; Declaring a face.
37 ;;;###autoload
38 (defun custom-declare-face (face spec doc &rest args)
39 "Like `defface', but FACE is evaluated as a normal argument."
40 (unless (get face 'face-defface-spec)
41 (put face 'face-defface-spec spec)
42 (when (fboundp 'facep)
43 (unless (facep face)
44 ;; If the user has already created the face, respect that.
45 (let ((value (or (get face 'saved-face) spec))
46 (frames (frame-list))
47 frame)
48 ;; Create global face.
49 (make-empty-face face)
50 ;; Create frame local faces
51 (while frames
52 (setq frame (car frames)
53 frames (cdr frames))
54 (face-spec-set face value frame)))
55 ;; When making a face after frames already exist
56 (if (memq window-system '(x w32))
57 (make-face-x-resource-internal face))))
58 (when (and doc (null (face-documentation face)))
59 (set-face-documentation face (purecopy doc)))
60 (custom-handle-all-keywords face args 'custom-face)
61 (run-hooks 'custom-define-hook))
62 face)
64 ;;; Face attributes.
66 ;; Below, nil is used in widget specifications for `unspecified' face
67 ;; attributes and `off' is used instead of nil attribute values. The
68 ;; reason for this is that nil corresponds to the result you get when
69 ;; looking up an attribute in a defface spec that isn't contained in
70 ;; the spec.
72 (defconst custom-face-attributes
73 '((:family
74 (choice :tag "Font family"
75 :help-echo "Font family or fontset alias name."
76 (const :tag "*" nil)
77 (string :tag "Family"))
78 (lambda (face value &optional frame)
79 (set-face-attribute face frame :family (or value 'unspecified)))
80 (lambda (face &optional frame)
81 (let ((family (face-attribute face :family frame)))
82 (if (eq family 'unspecified) nil family))))
84 (:width
85 (choice :tag "Width"
86 :help-echo "Font width."
87 (const :tag "*" nil)
88 (const :tag "compressed" condensed)
89 (const :tag "condensed" condensed)
90 (const :tag "demiexpanded" semi-expanded)
91 (const :tag "expanded" expanded)
92 (const :tag "extracondensed" extra-condensed)
93 (const :tag "extraexpanded" extra-expanded)
94 (const :tag "medium" normal)
95 (const :tag "narrow" condensed)
96 (const :tag "normal" normal)
97 (const :tag "regular" normal)
98 (const :tag "semicondensed" semi-condensed)
99 (const :tag "semiexpanded" semi-expanded)
100 (const :tag "ultracondensed" ultra-condensed)
101 (const :tag "ultraexpanded" ultra-expanded)
102 (const :tag "wide" extra-expanded))
103 (lambda (face value &optional frame)
104 (set-face-attribute face frame :width (or value 'unspecified)))
105 (lambda (face &optional frame)
106 (let ((width (face-attribute face :width frame)))
107 (if (eq width 'unspecified) nil width))))
109 (:height
110 (choice :tag "Height"
111 :help-echo "Face's font height."
112 (const :tag "*" nil)
113 (integer :tag "Height in 1/10 pt"))
114 (lambda (face value &optional frame)
115 (set-face-attribute face frame :height (or value 'unspecified)))
116 (lambda (face &optional frame)
117 (let ((height (face-attribute face :height frame)))
118 (if (eq height 'unspecified) nil height))))
120 (:weight
121 (choice :tag "Weight"
122 :help-echo "Font weight."
123 (const :tag "*" nil)
124 (const :tag "black" ultra_bold)
125 (const :tag "bold" bold)
126 (const :tag "book" semi-light)
127 (const :tag "demibold" semi-bold)
128 (const :tag "extralight" extra-light)
129 (const :tag "extrabold" extra-bold)
130 (const :tag "heavy" extra-bold)
131 (const :tag "light" light)
132 (const :tag "medium" normal)
133 (const :tag "normal" normal)
134 (const :tag "regular" normal)
135 (const :tag "semibold" semi-bold)
136 (const :tag "semilight" semi-light)
137 (const :tag "ultralight" ultra-light)
138 (const :tag "ultrabold" ultra-bold))
139 (lambda (face value &optional frame)
140 (set-face-attribute face frame :weight (or value 'unspecified)))
141 (lambda (face &optional frame)
142 (let ((weight (face-attribute face :weight frame)))
143 (if (eq weight 'unspecified) nil weight))))
145 (:slant
146 (choice :tag "Slant"
147 :help-echo "Font slant."
148 (const :tag "*" nil)
149 (const :tag "italic" italic)
150 (const :tag "oblique" oblique)
151 (const :tag "normal" normal))
152 (lambda (face value &optional frame)
153 (set-face-attribute face frame :slant (or value 'unspecified)))
154 (lambda (face &optional frame)
155 (let ((slant (face-attribute face :slant frame)))
156 (if (eq slant 'unspecified) nil slant))))
158 (:underline
159 (choice :tag "Underline"
160 :help-echo "Control text underlining."
161 (const :tag "*" nil)
162 (const :tag "On" t)
163 (const :tag "Off" off)
164 (color :tag "Colored"))
165 (lambda (face value &optional frame)
166 (cond ((eq value 'off) (setq value nil))
167 ((null value) (setq value 'unspecified)))
168 (set-face-attribute face frame :underline value))
169 (lambda (face &optional frame)
170 (let ((underline (face-attribute face :underline frame)))
171 (cond ((eq underline 'unspecified) nil)
172 ((null underline) 'off)))))
174 (:overline
175 (choice :tag "Overline"
176 :help-echo "Control text overlining."
177 (const :tag "*" nil)
178 (const :tag "On" t)
179 (const :tag "Off" off)
180 (color :tag "Colored"))
181 (lambda (face value &optional frame)
182 (cond ((eq value 'off) (setq value nil))
183 ((null value) (setq value 'unspecified)))
184 (set-face-attribute face frame :overline value))
185 (lambda (face &optional frame)
186 (let ((overline (face-attribute face :overline frame)))
187 (cond ((eq overline 'unspecified) nil)
188 ((null overline) 'off)))))
190 (:strike-through
191 (choice :tag "Strike-through"
192 :help-echo "Control text strike-through."
193 (const :tag "*" nil)
194 (const :tag "On" t)
195 (const :tag "Off" off)
196 (color :tag "Colored"))
197 (lambda (face value &optional frame)
198 (cond ((eq value 'off) (setq value nil))
199 ((null value) (setq value 'unspecified)))
200 (set-face-attribute face frame :strike-through value))
201 (lambda (face &optional frame)
202 (let ((value (face-attribute face :strike-through frame)))
203 (cond ((eq value 'unspecified) (setq value nil))
204 ((null value) (setq value 'off)))
205 value)))
207 (:box
208 ;; Fixme: this can probably be done better.
209 (choice :tag "Box around text"
210 :help-echo "Control box around text."
211 (const :tag "*" t)
212 (const :tag "Off" nil)
213 (list :tag "Box"
214 :value (:line-width 2 :color "grey75"
215 :style released-button)
216 (const :format "" :value :line-width)
217 (integer :tag "Width")
218 (const :format "" :value :color)
219 (choice :tag "Color" (const :tag "*" nil) color)
220 (const :format "" :value :style)
221 (choice :tag "Style"
222 (const :tag "Raised" released-button)
223 (const :tag "Sunken" pressed-button)
224 (const :tag "None" nil))))
225 (lambda (face value &optional frame)
226 (set-face-attribute face frame :box value))
227 (lambda (face &optional frame)
228 (let ((value (face-attribute face :box frame)))
229 (if (consp value)
230 (list :line-width (or (plist-get value :line-width) 1)
231 :color (plist-get value :color)
232 :style (plist-get value :style))
233 value))))
235 (:inverse-video
236 (choice :tag "Inverse-video"
237 :help-echo "Control whether text should be in inverse-video."
238 (const :tag "*" nil)
239 (const :tag "On" t)
240 (const :tag "Off" off))
241 (lambda (face value &optional frame)
242 (cond ((eq value 'off) (setq value nil))
243 ((null value) (setq value 'unspecified)))
244 (set-face-attribute face frame :inverse-video value))
245 (lambda (face &optional frame)
246 (let ((value (face-attribute face :inverse-video frame)))
247 (cond ((eq value 'unspecified)
248 nil)
249 ((null value)'off)))))
251 (:foreground
252 (choice :tag "Foreground"
253 :help-echo "Set foreground color."
254 (const :tag "*" nil)
255 (color :tag "Color"))
256 (lambda (face value &optional frame)
257 (set-face-attribute face frame :foreground (or value 'unspecified)))
258 (lambda (face &optional frame)
259 (let ((value (face-attribute face :foreground frame)))
260 (if (eq value 'unspecified) nil value))))
262 (:background
263 (choice :tag "Background"
264 :help-echo "Set background color."
265 (const :tag "*" nil)
266 (color :tag "Color"))
267 (lambda (face value &optional frame)
268 (set-face-attribute face frame :background (or value 'unspecified)))
269 (lambda (face &optional frame)
270 (let ((value (face-attribute face :background frame)))
271 (if (eq value 'unspecified) nil value))))
273 (:stipple
274 (choice :tag "Stipple"
275 :help-echo "Name of background bitmap file."
276 (const :tag "*" nil)
277 (file :tag "File" :must-match t))
278 (lambda (face value &optional frame)
279 (set-face-attribute face frame :stipple (or value 'unspecified)))
280 (lambda (face &optional frame)
281 (let ((value (face-attribute face :stipple frame)))
282 (if (eq value 'unspecified) nil value)))))
284 "Alist of face attributes.
286 The elements are of the form (KEY TYPE SET GET), where KEY is the name
287 of the attribute, TYPE is a widget type for editing the attibute, SET
288 is a function for setting the attribute value, and GET is a function
289 for getiing the attribute value.
291 The SET function should take three arguments, the face to modify, the
292 value of the attribute, and optionally the frame where the face should
293 be changed.
295 The GET function should take two arguments, the face to examine, and
296 optionally the frame where the face should be examined.")
299 (defun custom-face-attributes-get (face frame)
300 "For FACE on FRAME, return an alternating list describing its attributes.
301 The list has the form (KEYWORD VALUE KEYWORD VALUE...).
302 Each keyword should be listed in `custom-face-attributes'.
304 If FRAME is nil, use the global defaults for FACE."
305 (let ((attrs custom-face-attributes)
306 plist)
307 (while attrs
308 (let* ((attribute (car (car attrs)))
309 (value (face-attribute face attribute frame)))
310 (setq attrs (cdr attrs))
311 (unless (eq value 'unspecified)
312 (setq plist (cons attribute (cons value plist))))))
313 plist))
315 ;;; Initializing.
317 ;;;###autoload
318 (defun custom-set-faces (&rest args)
319 "Initialize faces according to user preferences.
320 The arguments should be a list where each entry has the form:
322 (FACE SPEC [NOW [COMMENT]])
324 SPEC is stored as the saved value for FACE.
325 If NOW is present and non-nil, FACE is created now, according to SPEC.
326 COMMENT is a string comment about FACE.
328 See `defface' for the format of SPEC."
329 (while args
330 (let ((entry (car args)))
331 (if (listp entry)
332 (let ((face (nth 0 entry))
333 (spec (nth 1 entry))
334 (now (nth 2 entry))
335 (comment (nth 3 entry)))
336 (put face 'saved-face spec)
337 (put face 'saved-face-comment comment)
338 (when now
339 (put face 'force-face t))
340 (when (or now (facep face))
341 (put face 'face-comment comment)
342 (make-empty-face face)
343 (face-spec-set face spec))
344 (setq args (cdr args)))
345 ;; Old format, a plist of FACE SPEC pairs.
346 (let ((face (nth 0 args))
347 (spec (nth 1 args)))
348 (put face 'saved-face spec))
349 (setq args (cdr (cdr args)))))))
351 ;;; The End.
353 (provide 'cus-face)
355 ;;; cus-face.el ends here