1 ;;; cus-face.el --- customization support for faces
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Keywords: help, faces
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 3 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
31 (defalias 'custom-facep
'facep
)
35 (defun custom-declare-face (face spec doc
&rest args
)
36 "Like `defface', but FACE is evaluated as a normal argument."
37 (unless (get face
'face-defface-spec
)
38 (when (fboundp 'facep
)
40 ;; If the user has already created the face, respect that.
41 (let ((value (or (get face
'saved-face
) spec
))
42 (have-window-system (memq initial-window-system
'(x w32
))))
43 ;; Create global face.
44 (make-empty-face face
)
45 ;; Create frame-local faces
46 (dolist (frame (frame-list))
47 (face-spec-set-2 face frame value
)
48 (when (memq (window-system frame
) '(x w32 ns
))
49 (setq have-window-system t
)))
50 ;; When making a face after frames already exist
51 (if have-window-system
52 (make-face-x-resource-internal face
)))))
53 ;; Don't record SPEC until we see it causes no errors.
54 (put face
'face-defface-spec
(purecopy spec
))
55 (push (cons 'defface face
) current-load-list
)
56 (when (and doc
(null (face-documentation face
)))
57 (set-face-documentation face
(purecopy doc
)))
58 (custom-handle-all-keywords face args
'custom-face
)
59 (run-hooks 'custom-define-hook
))
64 (defconst custom-face-attributes
66 (string :tag
"Font Family"
67 :help-echo
"Font family or fontset alias name."))
70 (string :tag
"Font Foundry"
71 :help-echo
"Font foundry name."))
75 :help-echo
"Font width."
76 :value normal
; default
77 (const :tag
"compressed" condensed
)
78 (const :tag
"condensed" condensed
)
79 (const :tag
"demiexpanded" semi-expanded
)
80 (const :tag
"expanded" expanded
)
81 (const :tag
"extracondensed" extra-condensed
)
82 (const :tag
"extraexpanded" extra-expanded
)
83 (const :tag
"medium" normal
)
84 (const :tag
"narrow" condensed
)
85 (const :tag
"normal" normal
)
86 (const :tag
"regular" normal
)
87 (const :tag
"semicondensed" semi-condensed
)
88 (const :tag
"semiexpanded" semi-expanded
)
89 (const :tag
"ultracondensed" ultra-condensed
)
90 (const :tag
"ultraexpanded" ultra-expanded
)
91 (const :tag
"wide" extra-expanded
)))
95 :help-echo
"Face's font height."
97 (integer :tag
"Height in 1/10 pt")
98 (number :tag
"Scale" 1.0)))
101 (choice :tag
"Weight"
102 :help-echo
"Font weight."
103 :value normal
; default
104 (const :tag
"black" ultra-bold
)
105 (const :tag
"bold" bold
)
106 (const :tag
"book" semi-light
)
107 (const :tag
"demibold" semi-bold
)
108 (const :tag
"extralight" extra-light
)
109 (const :tag
"extrabold" extra-bold
)
110 (const :tag
"heavy" extra-bold
)
111 (const :tag
"light" light
)
112 (const :tag
"medium" normal
)
113 (const :tag
"normal" normal
)
114 (const :tag
"regular" normal
)
115 (const :tag
"semibold" semi-bold
)
116 (const :tag
"semilight" semi-light
)
117 (const :tag
"ultralight" ultra-light
)
118 (const :tag
"ultrabold" ultra-bold
)
119 (const :tag
"thin" thin
)))
123 :help-echo
"Font slant."
124 :value normal
; default
125 (const :tag
"italic" italic
)
126 (const :tag
"oblique" oblique
)
127 (const :tag
"normal" normal
)
128 (const :tag
"roman" roman
)))
131 (choice :tag
"Underline"
132 :help-echo
"Control text underlining."
133 (const :tag
"Off" nil
)
135 (color :tag
"Colored")))
138 (choice :tag
"Overline"
139 :help-echo
"Control text overlining."
140 (const :tag
"Off" nil
)
142 (color :tag
"Colored")))
145 (choice :tag
"Strike-through"
146 :help-echo
"Control text strike-through."
147 (const :tag
"Off" nil
)
149 (color :tag
"Colored")))
152 ;; Fixme: this can probably be done better.
153 (choice :tag
"Box around text"
154 :help-echo
"Control box around text."
155 (const :tag
"Off" nil
)
157 :value
(:line-width
2 :color
"grey75" :style released-button
)
158 (const :format
"" :value
:line-width
)
159 (integer :tag
"Width")
160 (const :format
"" :value
:color
)
161 (choice :tag
"Color" (const :tag
"*" nil
) color
)
162 (const :format
"" :value
:style
)
164 (const :tag
"Raised" released-button
)
165 (const :tag
"Sunken" pressed-button
)
166 (const :tag
"None" nil
))))
167 ;; filter to make value suitable for customize
171 (or (and (consp real-value
)
172 (plist-get real-value
:line-width
))
173 (and (integerp real-value
) real-value
)
176 (or (and (consp real-value
) (plist-get real-value
:color
))
177 (and (stringp real-value
) real-value
)
180 (and (consp real-value
) (plist-get real-value
:style
))))
181 (list :line-width lwidth
:color color
:style style
))))
182 ;; filter to make customized-value suitable for storing
185 (let ((lwidth (plist-get cus-value
:line-width
))
186 (color (plist-get cus-value
:color
))
187 (style (plist-get cus-value
:style
)))
188 (cond ((and (null color
) (null style
))
190 ((and (null lwidth
) (null style
))
191 ;; actually can't happen, because LWIDTH is always an int
194 ;; Keep as a plist, but remove null entries
195 (nconc (and lwidth
`(:line-width
,lwidth
))
196 (and color
`(:color
,color
))
197 (and style
`(:style
,style
)))))))))
200 (choice :tag
"Inverse-video"
201 :help-echo
"Control whether text should be in inverse-video."
202 (const :tag
"Off" nil
)
203 (const :tag
"On" t
)))
206 (color :tag
"Foreground"
207 :help-echo
"Set foreground color (name or #RRGGBB hex spec)."))
210 (color :tag
"Background"
211 :help-echo
"Set background color (name or #RRGGBB hex spec)."))
214 (choice :tag
"Stipple"
215 :help-echo
"Background bit-mask"
216 (const :tag
"None" nil
)
218 :help-echo
"Name of bitmap file."
222 (repeat :tag
"Inherit"
223 :help-echo
"List of faces to inherit attributes from."
224 (face :Tag
"Face" default
))
225 ;; filter to make value suitable for customize
227 (cond ((or (null real-value
) (eq real-value
'unspecified
))
229 ((symbolp real-value
)
233 ;; filter to make customized-value suitable for storing
235 (if (and (consp cus-value
) (null (cdr cus-value
)))
239 "Alist of face attributes.
241 The elements are of the form (KEY TYPE PRE-FILTER POST-FILTER),
242 where KEY is the name of the attribute, TYPE is a widget type for
243 editing the attribute, PRE-FILTER is a function to make the attribute's
244 value suitable for the customization widget, and POST-FILTER is a
245 function to make the customized value suitable for storing. PRE-FILTER
246 and POST-FILTER are optional.
248 The PRE-FILTER should take a single argument, the attribute value as
249 stored, and should return a value for customization (using the
250 customization type TYPE).
252 The POST-FILTER should also take a single argument, the value after
253 being customized, and should return a value suitable for setting the
254 given face attribute.")
256 (defun custom-face-attributes-get (face frame
)
257 "For FACE on FRAME, return an alternating list describing its attributes.
258 The list has the form (KEYWORD VALUE KEYWORD VALUE...).
259 Each keyword should be listed in `custom-face-attributes'.
261 If FRAME is nil, use the global defaults for FACE."
262 (let ((attrs custom-face-attributes
)
265 (let* ((attribute (car (car attrs
)))
266 (value (face-attribute face attribute frame
)))
267 (setq attrs
(cdr attrs
))
268 (unless (or (eq value
'unspecified
)
269 (and (null value
) (memq attribute
'(:inherit
))))
270 (setq plist
(cons attribute
(cons value plist
))))))
275 (defun custom-set-faces (&rest args
)
276 "Initialize faces according to user preferences.
277 This associates the settings with the `user' theme.
278 The arguments should be a list where each entry has the form:
280 (FACE SPEC [NOW [COMMENT]])
282 SPEC is stored as the saved value for FACE, as well as the value for the
283 `user' theme. The `user' theme is one of the default themes known to Emacs.
284 See `custom-known-themes' for more information on the known themes.
285 See `custom-theme-set-faces' for more information on the interplay
286 between themes and faces.
287 See `defface' for the format of SPEC.
289 If NOW is present and non-nil, FACE is created now, according to SPEC.
290 COMMENT is a string comment about FACE."
291 (apply 'custom-theme-set-faces
'user args
))
293 (defun custom-theme-set-faces (theme &rest args
)
294 "Initialize faces for theme THEME.
295 The arguments should be a list where each entry has the form:
297 (FACE SPEC [NOW [COMMENT]])
299 SPEC is stored as the saved value for FACE, as well as the value for the
300 `user' theme. The `user' theme is one of the default themes known to Emacs.
301 See `custom-known-themes' for more information on the known themes.
302 See `custom-theme-set-faces' for more information on the interplay
303 between themes and faces.
304 See `defface' for the format of SPEC.
306 If NOW is present and non-nil, FACE is created now, according to SPEC.
307 COMMENT is a string comment about FACE.
309 Several properties of THEME and FACE are used in the process:
311 If THEME property `theme-immediate' is non-nil, this is equivalent of
312 providing the NOW argument to all faces in the argument list: FACE is
313 created now. The only difference is FACE property `force-face': if NOW
314 is non-nil, FACE property `force-face' is set to the symbol `rogue', else
315 if THEME property `theme-immediate' is non-nil, FACE property `force-face'
316 is set to the symbol `immediate'.
318 SPEC itself is saved in FACE property `saved-face' and it is stored in
319 FACE's list property `theme-face' \(using `custom-push-theme')."
320 (custom-check-theme theme
)
321 (let ((immediate (get theme
'theme-immediate
)))
323 (unless (listp entry
)
324 (error "Incompatible Custom theme spec"))
325 (let ((face (car entry
))
326 (spec (nth 1 entry
)))
327 ;; If FACE is actually an alias, customize the face it
329 (if (get face
'face-alias
)
330 (setq face
(get face
'face-alias
)))
331 (if custom--inhibit-theme-enable
332 ;; Just update theme settings.
333 (custom-push-theme 'theme-face face theme
'set spec
)
334 ;; Update theme settings and set the face spec.
335 (let ((now (nth 2 entry
))
336 (comment (nth 3 entry
))
337 (oldspec (get face
'theme-face
)))
338 (when (not (and oldspec
(eq 'user
(caar oldspec
))))
339 (put face
'saved-face spec
)
340 (put face
'saved-face-comment comment
))
341 ;; Do this AFTER checking the `theme-face' property.
342 (custom-push-theme 'theme-face face theme
'set spec
)
343 (when (or now immediate
)
344 (put face
'force-face
(if now
'rogue
'immediate
)))
345 (when (or now immediate
(facep face
))
347 (make-empty-face face
))
348 (put face
'face-comment comment
)
349 (put face
'face-override-spec nil
)
350 (face-spec-set face spec t
))))))))
352 ;; XEmacs compability function. In XEmacs, when you reset a Custom
353 ;; Theme, you have to specify the theme to reset it to. We just apply
355 (defun custom-theme-reset-faces (theme &rest args
)
356 "Reset the specs in THEME of some faces to their specs in other themes.
357 Each of the arguments ARGS has this form:
361 This means reset FACE. The argument IGNORED is ignored."
362 (custom-check-theme theme
)
364 (custom-push-theme 'theme-face
(car arg
) theme
'reset
)))
366 (defun custom-reset-faces (&rest args
)
367 "Reset the specs of some faces to their specs in specified themes.
368 This creates settings in the `user' theme.
370 Each of the arguments ARGS has this form:
374 This means reset FACE to its value in FROM-THEME."
375 (apply 'custom-theme-reset-faces
'user args
))
381 ;; arch-tag: 9a5c4b63-0d27-4c92-a5af-f2c7ed764c2b
382 ;;; cus-face.el ends here