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