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