(gdb-registers-mode): Let gdbmi use
[bpt/emacs.git] / lisp / cus-face.el
CommitLineData
e8af40ee 1;;; cus-face.el --- customization support for faces
d543e20b 2;;
a3997907 3;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
d543e20b
PA
4;;
5;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6;; Keywords: help, faces
d543e20b 7
6c283d44 8;; This file is part of GNU Emacs.
d543e20b 9
6c283d44
RS
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
d543e20b 14
6c283d44
RS
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
d543e20b 19
6c283d44
RS
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
d543e20b 24
6c283d44
RS
25;;; Commentary:
26;;
27;; See `custom.el'.
d543e20b 28
6c283d44 29;;; Code:
d543e20b 30
da0b1f56 31(defalias 'custom-facep 'facep)
ccd0d40c 32
d543e20b
PA
33;;; Declaring a face.
34
35;;;###autoload
36(defun custom-declare-face (face spec doc &rest args)
37 "Like `defface', but FACE is evaluated as a normal argument."
6c283d44 38 (unless (get face 'face-defface-spec)
d543e20b 39 (when (fboundp 'facep)
6c283d44 40 (unless (facep face)
d543e20b 41 ;; If the user has already created the face, respect that.
f4db5253 42 (let ((value (or (get face 'saved-face) spec)))
d543e20b
PA
43 ;; Create global face.
44 (make-empty-face face)
b5188bcd 45 ;; Create frame-local faces
f4db5253 46 (dolist (frame (frame-list))
971e48ca
RS
47 (face-spec-set face value frame)))
48 ;; When making a face after frames already exist
49 (if (memq window-system '(x w32))
50 (make-face-x-resource-internal face))))
b5188bcd
RS
51 ;; Don't record SPEC until we see it causes no errors.
52 (put face 'face-defface-spec spec)
4829145a 53 (push (cons 'defface face) current-load-list)
209ddde3 54 (when (and doc (null (face-documentation face)))
08449ec1 55 (set-face-documentation face (purecopy doc)))
d543e20b
PA
56 (custom-handle-all-keywords face args 'custom-face)
57 (run-hooks 'custom-define-hook))
58 face)
59
da0b1f56
GM
60;;; Face attributes.
61
d543e20b 62(defconst custom-face-attributes
da0b1f56 63 '((:family
c165ad40
MB
64 (string :tag "Font Family"
65 :help-echo "Font family or fontset alias name."))
a3997907 66
da0b1f56
GM
67 (:width
68 (choice :tag "Width"
69 :help-echo "Font width."
c165ad40 70 :value normal ; default
da0b1f56
GM
71 (const :tag "compressed" condensed)
72 (const :tag "condensed" condensed)
73 (const :tag "demiexpanded" semi-expanded)
74 (const :tag "expanded" expanded)
75 (const :tag "extracondensed" extra-condensed)
76 (const :tag "extraexpanded" extra-expanded)
77 (const :tag "medium" normal)
78 (const :tag "narrow" condensed)
79 (const :tag "normal" normal)
80 (const :tag "regular" normal)
81 (const :tag "semicondensed" semi-condensed)
82 (const :tag "semiexpanded" semi-expanded)
83 (const :tag "ultracondensed" ultra-condensed)
84 (const :tag "ultraexpanded" ultra-expanded)
51a1edab 85 (const :tag "wide" extra-expanded)))
71296446 86
da0b1f56
GM
87 (:height
88 (choice :tag "Height"
89 :help-echo "Face's font height."
c165ad40 90 :value 1.0 ; default
6bca3005 91 (integer :tag "Height in 1/10 pt")
51a1edab 92 (number :tag "Scale" 1.0)))
6bca3005 93
da0b1f56
GM
94 (:weight
95 (choice :tag "Weight"
96 :help-echo "Font weight."
c165ad40 97 :value normal ; default
992f7c96 98 (const :tag "black" ultra-bold)
da0b1f56
GM
99 (const :tag "bold" bold)
100 (const :tag "book" semi-light)
101 (const :tag "demibold" semi-bold)
102 (const :tag "extralight" extra-light)
103 (const :tag "extrabold" extra-bold)
104 (const :tag "heavy" extra-bold)
105 (const :tag "light" light)
106 (const :tag "medium" normal)
107 (const :tag "normal" normal)
108 (const :tag "regular" normal)
109 (const :tag "semibold" semi-bold)
110 (const :tag "semilight" semi-light)
111 (const :tag "ultralight" ultra-light)
51a1edab 112 (const :tag "ultrabold" ultra-bold)))
71296446 113
da0b1f56
GM
114 (:slant
115 (choice :tag "Slant"
116 :help-echo "Font slant."
c165ad40 117 :value normal ; default
da0b1f56
GM
118 (const :tag "italic" italic)
119 (const :tag "oblique" oblique)
51a1edab 120 (const :tag "normal" normal)))
71296446 121
da0b1f56
GM
122 (:underline
123 (choice :tag "Underline"
124 :help-echo "Control text underlining."
c165ad40 125 (const :tag "Off" nil)
da0b1f56 126 (const :tag "On" t)
51a1edab 127 (color :tag "Colored")))
71296446 128
da0b1f56
GM
129 (:overline
130 (choice :tag "Overline"
131 :help-echo "Control text overlining."
c165ad40 132 (const :tag "Off" nil)
da0b1f56 133 (const :tag "On" t)
51a1edab 134 (color :tag "Colored")))
71296446 135
da0b1f56
GM
136 (:strike-through
137 (choice :tag "Strike-through"
138 :help-echo "Control text strike-through."
c165ad40 139 (const :tag "Off" nil)
da0b1f56 140 (const :tag "On" t)
51a1edab 141 (color :tag "Colored")))
71296446 142
da0b1f56 143 (:box
1743c17a 144 ;; Fixme: this can probably be done better.
da0b1f56
GM
145 (choice :tag "Box around text"
146 :help-echo "Control box around text."
c165ad40 147 (const :tag "Off" nil)
da0b1f56 148 (list :tag "Box"
36b80a0d 149 :value (:line-width 2 :color "grey75" :style released-button)
1743c17a 150 (const :format "" :value :line-width)
da0b1f56 151 (integer :tag "Width")
1743c17a
DL
152 (const :format "" :value :color)
153 (choice :tag "Color" (const :tag "*" nil) color)
154 (const :format "" :value :style)
155 (choice :tag "Style"
156 (const :tag "Raised" released-button)
157 (const :tag "Sunken" pressed-button)
158 (const :tag "None" nil))))
51a1edab
MB
159 ;; filter to make value suitable for customize
160 (lambda (real-value)
c165ad40
MB
161 (and real-value
162 (let ((lwidth
163 (or (and (consp real-value)
164 (plist-get real-value :line-width))
165 (and (integerp real-value) real-value)
166 1))
167 (color
168 (or (and (consp real-value) (plist-get real-value :color))
169 (and (stringp real-value) real-value)
170 nil))
171 (style
172 (and (consp real-value) (plist-get real-value :style))))
173 (list :line-width lwidth :color color :style style))))
36b80a0d
MB
174 ;; filter to make customized-value suitable for storing
175 (lambda (cus-value)
c165ad40
MB
176 (and cus-value
177 (let ((lwidth (plist-get cus-value :line-width))
178 (color (plist-get cus-value :color))
179 (style (plist-get cus-value :style)))
180 (cond ((and (null color) (null style))
181 lwidth)
182 ((and (null lwidth) (null style))
183 ;; actually can't happen, because LWIDTH is always an int
184 color)
185 (t
186 ;; Keep as a plist, but remove null entries
187 (nconc (and lwidth `(:line-width ,lwidth))
188 (and color `(:color ,color))
189 (and style `(:style ,style)))))))))
71296446 190
da0b1f56
GM
191 (:inverse-video
192 (choice :tag "Inverse-video"
193 :help-echo "Control whether text should be in inverse-video."
c165ad40
MB
194 (const :tag "Off" nil)
195 (const :tag "On" t)))
71296446 196
da0b1f56 197 (:foreground
c165ad40 198 (color :tag "Foreground"
4bbe6176 199 :help-echo "Set foreground color (name or #RRGGBB hex spec)."))
71296446 200
da0b1f56 201 (:background
c165ad40 202 (color :tag "Background"
4bbe6176 203 :help-echo "Set background color (name or #RRGGBB hex spec)."))
71296446 204
da0b1f56
GM
205 (:stipple
206 (choice :tag "Stipple"
675f1fcb 207 :help-echo "Background bit-mask"
c165ad40 208 (const :tag "None" nil)
675f1fcb
MB
209 (file :tag "File"
210 :help-echo "Name of bitmap file."
211 :must-match t)))
6bca3005
MB
212
213 (:inherit
214 (repeat :tag "Inherit"
215 :help-echo "List of faces to inherit attributes from."
216 (face :Tag "Face" default))
51a1edab
MB
217 ;; filter to make value suitable for customize
218 (lambda (real-value)
219 (cond ((or (null real-value) (eq real-value 'unspecified))
220 nil)
221 ((symbolp real-value)
222 (list real-value))
223 (t
224 real-value)))
225 ;; filter to make customized-value suitable for storing
226 (lambda (cus-value)
227 (if (and (consp cus-value) (null (cdr cus-value)))
228 (car cus-value)
229 cus-value))))
71296446 230
da0b1f56
GM
231 "Alist of face attributes.
232
51a1edab
MB
233The elements are of the form (KEY TYPE PRE-FILTER POST-FILTER),
234where KEY is the name of the attribute, TYPE is a widget type for
235editing the attribute, PRE-FILTER is a function to make the attribute's
236value suitable for the customization widget, and POST-FILTER is a
237function to make the customized value suitable for storing. PRE-FILTER
238and POST-FILTER are optional.
d543e20b 239
51a1edab
MB
240The PRE-FILTER should take a single argument, the attribute value as
241stored, and should return a value for customization (using the
242customization type TYPE).
d543e20b 243
51a1edab
MB
244The POST-FILTER should also take a single argument, the value after
245being customized, and should return a value suitable for setting the
246given face attribute.")
d543e20b
PA
247
248(defun custom-face-attributes-get (face frame)
6c283d44
RS
249 "For FACE on FRAME, return an alternating list describing its attributes.
250The list has the form (KEYWORD VALUE KEYWORD VALUE...).
d543e20b
PA
251Each keyword should be listed in `custom-face-attributes'.
252
6c283d44 253If FRAME is nil, use the global defaults for FACE."
da0b1f56
GM
254 (let ((attrs custom-face-attributes)
255 plist)
256 (while attrs
257 (let* ((attribute (car (car attrs)))
258 (value (face-attribute face attribute frame)))
259 (setq attrs (cdr attrs))
6bca3005
MB
260 (unless (or (eq value 'unspecified)
261 (and (null value) (memq attribute '(:inherit))))
da0b1f56
GM
262 (setq plist (cons attribute (cons value plist))))))
263 plist))
d543e20b 264
d543e20b
PA
265;;; Initializing.
266
d543e20b
PA
267;;;###autoload
268(defun custom-set-faces (&rest args)
269 "Initialize faces according to user preferences.
a3997907
RS
270This associates the settings with the `user' theme.
271The arguments should be a list where each entry has the form:
272
273 (FACE SPEC [NOW [COMMENT]])
274
275SPEC is stored as the saved value for FACE, as well as the value for the
276`user' theme. The `user' theme is one of the default themes known to Emacs.
277See `custom-known-themes' for more information on the known themes.
278See `custom-theme-set-faces' for more information on the interplay
279between themes and faces.
280See `defface' for the format of SPEC.
281
282If NOW is present and non-nil, FACE is created now, according to SPEC.
283COMMENT is a string comment about FACE."
284 (apply 'custom-theme-set-faces 'user args))
285
286(defun custom-theme-set-faces (theme &rest args)
287 "Initialize faces for theme THEME.
d543e20b
PA
288The arguments should be a list where each entry has the form:
289
1743c17a 290 (FACE SPEC [NOW [COMMENT]])
d543e20b 291
a3997907
RS
292SPEC is stored as the saved value for FACE, as well as the value for the
293`user' theme. The `user' theme is one of the default themes known to Emacs.
294See `custom-known-themes' for more information on the known themes.
295See `custom-theme-set-faces' for more information on the interplay
296between themes and faces.
297See `defface' for the format of SPEC.
298
6c283d44 299If NOW is present and non-nil, FACE is created now, according to SPEC.
1743c17a 300COMMENT is a string comment about FACE.
d543e20b 301
a3997907
RS
302Several properties of THEME and FACE are used in the process:
303
304If THEME property `theme-immediate' is non-nil, this is equivalent of
305providing the NOW argument to all faces in the argument list: FACE is
306created now. The only difference is FACE property `force-face': if NOW
307is non-nil, FACE property `force-face' is set to the symbol `rogue', else
308if THEME property `theme-immediate' is non-nil, FACE property `force-face'
309is set to the symbol `immediate'.
310
311SPEC itself is saved in FACE property `saved-face' and it is stored in
312FACE's list property `theme-face' \(using `custom-push-theme')."
313 (custom-check-theme theme)
314 (let ((immediate (get theme 'theme-immediate)))
315 (while args
316 (let ((entry (car args)))
317 (if (listp entry)
318 (let ((face (nth 0 entry))
319 (spec (nth 1 entry))
320 (now (nth 2 entry))
321 (comment (nth 3 entry)))
322 (put face 'saved-face spec)
323 (put face 'saved-face-comment comment)
324 (custom-push-theme 'theme-face face theme 'set spec)
325 (when (or now immediate)
326 (put face 'force-face (if now 'rogue 'immediate)))
327 (when (or now immediate (facep face))
328 (unless (facep face)
329 (make-empty-face face))
330 (put face 'face-comment comment)
331 (face-spec-set face spec))
d543e20b
PA
332 (setq args (cdr args)))
333 ;; Old format, a plist of FACE SPEC pairs.
334 (let ((face (nth 0 args))
335 (spec (nth 1 args)))
a3997907
RS
336 (put face 'saved-face spec)
337 (custom-push-theme 'theme-face face theme 'set spec))
338 (setq args (cdr (cdr args))))))))
339
340;;;###autoload
341(defun custom-theme-face-value (face theme)
342 "Return spec of FACE in THEME if THEME modifies FACE.
343Value is nil otherwise. The association between theme and spec for FACE
344is stored in FACE's property `theme-face'. The appropriate face
345is retrieved using `custom-theme-value'."
346 ;; Returns car because the value is stored inside a one element list
347 (car-safe (custom-theme-value theme (get face 'theme-face))))
348
349(defun custom-theme-reset-internal-face (face to-theme)
350 "Reset FACE to the value defined by TO-THEME.
351If FACE is not defined in TO-THEME, reset FACE to the standard
352value. See `custom-theme-face-value'. The standard value is
353stored in SYMBOL's property `face-defface-spec' by `defface'."
354 (let ((spec (custom-theme-face-value face to-theme))
355 was-in-theme)
356 (setq was-in-theme spec)
357 (setq spec (or spec (get face 'face-defface-spec)))
358 (when spec
359 (put face 'save-face was-in-theme)
360 (when (or (get face 'force-face) (facep face))
361 (unless (facep face)
362 (make-empty-face face))
363 (face-spec-set face spec)))
364 spec))
365
366;;;###autoload
367(defun custom-theme-reset-faces (theme &rest args)
368 "Reset the value of the face to values previously defined.
369Associate this setting with THEME.
370
371ARGS is a list of lists of the form
372
373 (FACE TO-THEME)
374
375This means reset FACE to its value in TO-THEME."
376 (custom-check-theme theme)
377 (mapcar '(lambda (arg)
378 (apply 'custom-theme-reset-internal-face arg)
379 (custom-push-theme 'theme-face (car arg) theme 'reset (cadr arg)))
380 args))
381
382;;;###autoload
383(defun custom-reset-faces (&rest args)
384 "Reset the value of the face to values previously saved.
385This is the setting assosiated the `user' theme.
386
387ARGS is defined as for `custom-theme-reset-faces'"
388 (apply 'custom-theme-reset-faces 'user args))
d543e20b
PA
389
390;;; The End.
391
392(provide 'cus-face)
393
ab5796a9 394;;; arch-tag: 9a5c4b63-0d27-4c92-a5af-f2c7ed764c2b
1743c17a 395;;; cus-face.el ends here