428
|
1 ;;; custom.el -- Tools for declaring and initializing options.
|
|
2
|
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
|
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
|
|
7 ;; Keywords: help, faces, dumped
|
|
8 ;; Version: 1.9960-x
|
|
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
|
|
10
|
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify
|
|
14 ;; it under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful,
|
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This file is dumped with XEmacs.
|
|
31
|
|
32 ;; This file only contain the code needed to declare and initialize
|
|
33 ;; user options. The code to customize options is autoloaded from
|
|
34 ;; `cus-edit.el'.
|
|
35 ;;
|
|
36 ;; The code implementing face declarations is in `cus-face.el'
|
|
37
|
|
38 ;;; Code:
|
|
39
|
771
|
40 ;; it is now safe to put the `provide' anywhere. if an error occurs while
|
|
41 ;; loading, all provides (and fsets) will be undone. put it first to
|
|
42 ;; prevent require/provide loop with custom and cus-face.
|
|
43 (provide 'custom)
|
|
44
|
428
|
45 (eval-when-compile
|
771
|
46 (load "cl-macs" nil t)
|
|
47 ;; To elude warnings.
|
|
48 (require 'cus-face))
|
428
|
49
|
442
|
50 (autoload 'custom-declare-face "cus-face")
|
|
51 (autoload 'defun* "cl-macs")
|
428
|
52
|
|
53 (require 'widget)
|
|
54
|
|
55 (defvar custom-define-hook nil
|
|
56 ;; Customize information for this option is in `cus-edit.el'.
|
|
57 "Hook called after defining each customize option.")
|
|
58
|
|
59 ;;; The `defcustom' Macro.
|
|
60
|
|
61 (defun custom-initialize-default (symbol value)
|
|
62 "Initialize SYMBOL with VALUE.
|
|
63 This will do nothing if symbol already has a default binding.
|
|
64 Otherwise, if symbol has a `saved-value' property, it will evaluate
|
|
65 the car of that and used as the default binding for symbol.
|
|
66 Otherwise, VALUE will be evaluated and used as the default binding for
|
|
67 symbol."
|
|
68 (unless (default-boundp symbol)
|
|
69 ;; Use the saved value if it exists, otherwise the standard setting.
|
|
70 (set-default symbol (if (get symbol 'saved-value)
|
|
71 (eval (car (get symbol 'saved-value)))
|
|
72 (eval value)))))
|
|
73
|
|
74 (defun custom-initialize-set (symbol value)
|
|
75 "Initialize SYMBOL with VALUE.
|
|
76 Like `custom-initialize-default', but use the function specified by
|
|
77 `:set' to initialize SYMBOL."
|
|
78 (unless (default-boundp symbol)
|
|
79 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
80 symbol
|
|
81 (if (get symbol 'saved-value)
|
|
82 (eval (car (get symbol 'saved-value)))
|
|
83 (eval value)))))
|
|
84
|
|
85 (defun custom-initialize-reset (symbol value)
|
|
86 "Initialize SYMBOL with VALUE.
|
|
87 Like `custom-initialize-set', but use the function specified by
|
|
88 `:get' to reinitialize SYMBOL if it is already bound."
|
|
89 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
90 symbol
|
|
91 (cond ((default-boundp symbol)
|
|
92 (funcall (or (get symbol 'custom-get) 'default-value)
|
|
93 symbol))
|
|
94 ((get symbol 'saved-value)
|
|
95 (eval (car (get symbol 'saved-value))))
|
|
96 (t
|
|
97 (eval value)))))
|
|
98
|
|
99 (defun custom-initialize-changed (symbol value)
|
|
100 "Initialize SYMBOL with VALUE.
|
|
101 Like `custom-initialize-reset', but only use the `:set' function if the
|
|
102 not using the standard setting. Otherwise, use the `set-default'."
|
|
103 (cond ((default-boundp symbol)
|
|
104 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
105 symbol
|
|
106 (funcall (or (get symbol 'custom-get) 'default-value)
|
|
107 symbol)))
|
|
108 ((get symbol 'saved-value)
|
|
109 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
110 symbol
|
|
111 (eval (car (get symbol 'saved-value)))))
|
|
112 (t
|
|
113 (set-default symbol (eval value)))))
|
|
114
|
|
115 (defun custom-declare-variable (symbol value doc &rest args)
|
|
116 "Like `defcustom', but SYMBOL and VALUE are evaluated as normal arguments."
|
|
117 ;; Remember the standard setting.
|
|
118 (put symbol 'standard-value (list value))
|
|
119 ;; Maybe this option was rogue in an earlier version. It no longer is.
|
|
120 (when (eq (get symbol 'force-value) 'rogue)
|
|
121 ;; It no longer is.
|
|
122 (put symbol 'force-value nil))
|
|
123 (when doc
|
|
124 (put symbol 'variable-documentation doc))
|
|
125 (let ((initialize 'custom-initialize-reset)
|
|
126 (requests nil))
|
|
127 (while args
|
|
128 (let ((arg (car args)))
|
|
129 (setq args (cdr args))
|
|
130 (check-argument-type 'keywordp arg)
|
|
131 (let ((keyword arg)
|
|
132 (value (car args)))
|
|
133 (unless args
|
|
134 (signal 'error (list "Keyword is missing an argument" keyword)))
|
|
135 (setq args (cdr args))
|
|
136 (cond ((eq keyword :initialize)
|
|
137 (setq initialize value))
|
|
138 ((eq keyword :set)
|
|
139 (put symbol 'custom-set value))
|
|
140 ((eq keyword :get)
|
|
141 (put symbol 'custom-get value))
|
|
142 ((eq keyword :require)
|
|
143 (setq requests (cons value requests)))
|
|
144 ((eq keyword :type)
|
|
145 (put symbol 'custom-type value))
|
|
146 ((eq keyword :options)
|
|
147 (if (get symbol 'custom-options)
|
|
148 ;; Slow safe code to avoid duplicates.
|
|
149 (mapc (lambda (option)
|
|
150 (custom-add-option symbol option))
|
|
151 value)
|
|
152 ;; Fast code for the common case.
|
|
153 (put symbol 'custom-options (copy-sequence value))))
|
|
154 (t
|
|
155 (custom-handle-keyword symbol keyword value
|
|
156 'custom-variable))))))
|
|
157 (put symbol 'custom-requests requests)
|
|
158 ;; Do the actual initialization.
|
|
159 (funcall initialize symbol value))
|
|
160 ;; #### This is a rough equivalent of LOADHIST_ATTACH. However,
|
|
161 ;; LOADHIST_ATTACH also checks for `initialized'.
|
|
162 (push symbol current-load-list)
|
|
163 (run-hooks 'custom-define-hook)
|
|
164 symbol)
|
|
165
|
|
166 (defmacro defcustom (symbol value doc &rest args)
|
|
167 "Declare SYMBOL as a customizable variable that defaults to VALUE.
|
|
168 DOC is the variable documentation.
|
|
169
|
|
170 Neither SYMBOL nor VALUE needs to be quoted.
|
|
171 If SYMBOL is not already bound, initialize it to VALUE.
|
|
172 The remaining arguments should have the form
|
|
173
|
|
174 [KEYWORD VALUE]...
|
|
175
|
|
176 The following KEYWORD's are defined:
|
|
177
|
|
178 :type VALUE should be a widget type for editing the symbols value.
|
|
179 The default is `sexp'.
|
|
180 :options VALUE should be a list of valid members of the widget type.
|
|
181 :group VALUE should be a customization group.
|
|
182 Add SYMBOL to that group.
|
|
183 :initialize VALUE should be a function used to initialize the
|
|
184 variable. It takes two arguments, the symbol and value
|
|
185 given in the `defcustom' call. The default is
|
|
186 `custom-initialize-set'
|
|
187 :set VALUE should be a function to set the value of the symbol.
|
|
188 It takes two arguments, the symbol to set and the value to
|
|
189 give it. The default is `set-default'.
|
|
190 :get VALUE should be a function to extract the value of symbol.
|
|
191 The function takes one argument, a symbol, and should return
|
|
192 the current value for that symbol. The default is
|
|
193 `default-value'.
|
|
194 :require VALUE should be a feature symbol. Each feature will be
|
442
|
195 required after initialization, of the user have saved this
|
428
|
196 option.
|
903
|
197 :version VALUE should be a string specifying that the variable was
|
|
198 first introduced, or its default value was changed, in Emacs
|
|
199 version VERSION.
|
|
200 :set-after VARIABLE specifies that SYMBOL should be set after VARIABLE when
|
|
201 both have been customized.
|
428
|
202
|
|
203 Read the section about customization in the Emacs Lisp manual for more
|
|
204 information."
|
|
205 `(custom-declare-variable (quote ,symbol) (quote ,value) ,doc ,@args))
|
|
206
|
|
207 ;;; The `defface' Macro.
|
|
208
|
|
209 (defmacro defface (face spec doc &rest args)
|
|
210 "Declare FACE as a customizable face that defaults to SPEC.
|
|
211 FACE does not need to be quoted.
|
|
212
|
|
213 Third argument DOC is the face documentation.
|
|
214
|
|
215 If FACE has been set with `custom-set-face', set the face attributes
|
|
216 as specified by that function, otherwise set the face attributes
|
|
217 according to SPEC.
|
|
218
|
|
219 The remaining arguments should have the form
|
|
220
|
|
221 [KEYWORD VALUE]...
|
|
222
|
|
223 The following KEYWORDs are defined:
|
|
224
|
|
225 :group VALUE should be a customization group.
|
|
226 Add FACE to that group.
|
|
227
|
|
228 SPEC should be an alist of the form ((DISPLAY ATTS)...).
|
|
229
|
|
230 ATTS is a list of face attributes and their values. The possible
|
|
231 attributes are defined in the variable `custom-face-attributes'.
|
|
232
|
|
233 The ATTS of the first entry in SPEC where the DISPLAY matches the
|
|
234 frame should take effect in that frame. DISPLAY can either be the
|
|
235 symbol t, which will match all frames, or an alist of the form
|
|
236 \((REQ ITEM...)...)
|
|
237
|
|
238 For the DISPLAY to match a FRAME, the REQ property of the frame must
|
|
239 match one of the ITEM. The following REQ are defined:
|
|
240
|
|
241 `type' (the value of `window-system')
|
442
|
242 Should be one of `x', `mswindows', or `tty'.
|
428
|
243
|
|
244 `class' (the frame's color support)
|
|
245 Should be one of `color', `grayscale', or `mono'.
|
|
246
|
|
247 `background' (what color is used for the background text)
|
|
248 Should be one of `light' or `dark'.
|
|
249
|
|
250 Read the section about customization in the Emacs Lisp manual for more
|
|
251 information."
|
|
252 `(custom-declare-face (quote ,face) ,spec ,doc ,@args))
|
|
253
|
|
254 ;;; The `defgroup' Macro.
|
|
255
|
|
256 (defun custom-declare-group (symbol members doc &rest args)
|
|
257 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
|
|
258 (while members
|
|
259 (apply 'custom-add-to-group symbol (car members))
|
|
260 (pop members))
|
|
261 (put symbol 'custom-group (nconc members (get symbol 'custom-group)))
|
|
262 (when doc
|
|
263 (put symbol 'group-documentation doc))
|
|
264 (while args
|
|
265 (let ((arg (car args)))
|
|
266 (setq args (cdr args))
|
|
267 (check-argument-type 'keywordp arg)
|
|
268 (let ((keyword arg)
|
|
269 (value (car args)))
|
|
270 (unless args
|
|
271 (signal 'error (list "Keyword is missing an argument" keyword)))
|
|
272 (setq args (cdr args))
|
|
273 (cond ((eq keyword :prefix)
|
|
274 (put symbol 'custom-prefix value))
|
|
275 (t
|
|
276 (custom-handle-keyword symbol keyword value
|
|
277 'custom-group))))))
|
|
278 (run-hooks 'custom-define-hook)
|
|
279 symbol)
|
|
280
|
|
281 (defmacro defgroup (symbol members doc &rest args)
|
|
282 "Declare SYMBOL as a customization group containing MEMBERS.
|
|
283 SYMBOL does not need to be quoted.
|
|
284
|
|
285 Third arg DOC is the group documentation.
|
|
286
|
|
287 MEMBERS should be an alist of the form ((NAME WIDGET)...) where NAME
|
|
288 is a symbol and WIDGET is a widget for editing that symbol. Useful
|
|
289 widgets are `custom-variable' for editing variables, `custom-face' for
|
|
290 edit faces, and `custom-group' for editing groups.
|
|
291
|
|
292 The remaining arguments should have the form
|
|
293
|
|
294 [KEYWORD VALUE]...
|
|
295
|
|
296 The following KEYWORD's are defined:
|
|
297
|
|
298 :group VALUE should be a customization group.
|
|
299 Add SYMBOL to that group.
|
|
300
|
|
301 Read the section about customization in the Emacs Lisp manual for more
|
|
302 information."
|
|
303 `(custom-declare-group (quote ,symbol) ,members ,doc ,@args))
|
|
304
|
|
305 (defvar custom-group-hash-table (make-hash-table :size 300 :test 'eq)
|
|
306 "Hash-table of non-empty groups.")
|
|
307
|
|
308 (defun custom-add-to-group (group option widget)
|
|
309 "To existing GROUP add a new OPTION of type WIDGET.
|
|
310 If there already is an entry for that option, overwrite it."
|
|
311 (let* ((members (get group 'custom-group))
|
|
312 (old (assq option members)))
|
|
313 (if old
|
|
314 (setcar (cdr old) widget)
|
|
315 (put group 'custom-group (nconc members (list (list option widget))))))
|
|
316 (puthash group t custom-group-hash-table))
|
|
317
|
|
318 ;;; Properties.
|
|
319
|
|
320 (defun custom-handle-all-keywords (symbol args type)
|
|
321 "For customization option SYMBOL, handle keyword arguments ARGS.
|
|
322 Third argument TYPE is the custom option type."
|
|
323 (while args
|
|
324 (let ((arg (car args)))
|
|
325 (setq args (cdr args))
|
|
326 (check-argument-type 'keywordp arg)
|
|
327 (let ((keyword arg)
|
|
328 (value (car args)))
|
|
329 (unless args
|
|
330 (signal 'error (list "Keyword is missing an argument" keyword)))
|
|
331 (setq args (cdr args))
|
|
332 (custom-handle-keyword symbol keyword value type)))))
|
|
333
|
|
334 (defun custom-handle-keyword (symbol keyword value type)
|
|
335 "For customization option SYMBOL, handle KEYWORD with VALUE.
|
|
336 Fourth argument TYPE is the custom option type."
|
|
337 (cond ((eq keyword :group)
|
903
|
338 (custom-add-to-group value symbol type))
|
|
339 ((eq keyword :version)
|
|
340 (custom-add-version symbol value))
|
|
341 ((eq keyword :link)
|
|
342 (custom-add-link symbol value))
|
|
343 ((eq keyword :load)
|
|
344 (custom-add-load symbol value))
|
|
345 ((eq keyword :tag)
|
|
346 (put symbol 'custom-tag value))
|
|
347 ((eq keyword :set-after)
|
|
348 (custom-add-dependencies symbol value))
|
|
349 (t
|
|
350 (signal 'error (list "Unknown keyword" keyword)))))
|
|
351
|
|
352 (defun custom-add-dependencies (symbol value)
|
|
353 "To the custom option SYMBOL, add dependencies specified by VALUE.
|
|
354 VALUE should be a list of symbols. For each symbol in that list,
|
|
355 this specifies that SYMBOL should be set after the specified symbol, if
|
|
356 both appear in constructs like `custom-set-variables'."
|
|
357 (unless (listp value)
|
|
358 (error "Invalid custom dependency `%s'" value))
|
|
359 (let* ((deps (get symbol 'custom-dependencies))
|
|
360 (new-deps deps))
|
|
361 (while value
|
|
362 (let ((dep (car value)))
|
|
363 (unless (symbolp dep)
|
|
364 (error "Invalid custom dependency `%s'" dep))
|
|
365 (unless (memq dep new-deps)
|
|
366 (setq new-deps (cons dep new-deps)))
|
|
367 (setq value (cdr value))))
|
|
368 (unless (eq deps new-deps)
|
|
369 (put symbol 'custom-dependencies new-deps))))
|
428
|
370
|
|
371 (defun custom-add-option (symbol option)
|
|
372 "To the variable SYMBOL add OPTION.
|
|
373
|
|
374 If SYMBOL is a hook variable, OPTION should be a hook member.
|
|
375 For other types variables, the effect is undefined."
|
|
376 (let ((options (get symbol 'custom-options)))
|
|
377 (unless (member option options)
|
|
378 (put symbol 'custom-options (cons option options)))))
|
|
379
|
|
380 (defun custom-add-link (symbol widget)
|
|
381 "To the custom option SYMBOL add the link WIDGET."
|
|
382 (let ((links (get symbol 'custom-links)))
|
|
383 (unless (member widget links)
|
|
384 (put symbol 'custom-links (cons widget links)))))
|
|
385
|
|
386 (defun custom-add-version (symbol version)
|
|
387 "To the custom option SYMBOL add the version VERSION."
|
|
388 (put symbol 'custom-version version))
|
|
389
|
|
390 (defun custom-add-load (symbol load)
|
|
391 "To the custom option SYMBOL add the dependency LOAD.
|
|
392 LOAD should be either a library file name, or a feature name."
|
|
393 (puthash symbol t custom-group-hash-table)
|
|
394 (let ((loads (get symbol 'custom-loads)))
|
|
395 (unless (member load loads)
|
|
396 (put symbol 'custom-loads (cons load loads)))))
|
|
397
|
|
398 ;;; deftheme macro
|
|
399
|
|
400 (defvar custom-known-themes '(user standard)
|
|
401 "Themes that have been defthemed.")
|
|
402
|
|
403 ;; #### add strings for group
|
|
404 ;; #### during bootstrap we cannot use cl-macs stuff
|
|
405 (defun* custom-define-theme (theme feature &optional doc
|
|
406 &key short-description immediate variable-reset-string
|
|
407 variable-set-string face-set-string face-reset-string
|
|
408 &allow-other-keys)
|
|
409 (push theme custom-known-themes)
|
|
410 (put theme 'theme-feature feature)
|
|
411 (put theme 'theme-documentation doc)
|
|
412 (if immediate (put theme 'theme-immediate immediate))
|
|
413 (if variable-reset-string
|
|
414 (put theme 'theme-variable-reset-string variable-reset-string ))
|
|
415 (if variable-set-string
|
|
416 (put theme 'theme-variable-set-string variable-set-string ))
|
|
417 (if face-reset-string
|
|
418 (put theme 'theme-face-reset-string face-reset-string ))
|
|
419 (if face-set-string
|
|
420 (put theme 'theme-face-set-string face-set-string ))
|
|
421 (if short-description
|
|
422 (put theme 'theme-short-description short-description )))
|
|
423
|
|
424 (defun custom-make-theme-feature (theme)
|
|
425 (intern (concat (symbol-name theme) "-theme")))
|
|
426
|
|
427 (defmacro deftheme (theme &rest body)
|
|
428 "(deftheme THEME &optional DOC &key KEYWORDS)
|
|
429
|
|
430 Define a theme labeled by SYMBOL THEME. The optional argument DOC is a
|
442
|
431 doc string describing the theme. It is optionally followed by the
|
444
|
432 following keyword arguments
|
428
|
433
|
|
434 :short-description DESC
|
|
435 DESC is a short (one line) description of the theme. If not given DOC
|
|
436 is used.
|
|
437 :immediate FLAG
|
|
438 If FLAG is non-nil variables set in this theme are bound
|
|
439 immediately when loading the theme.
|
|
440 :variable-set-string VARIABLE_-SET-STRING
|
|
441 A string used by the UI to indicate that the value takes it
|
|
442 setting from this theme. It is passed to FORMAT with the
|
|
443 name of the theme a additional argument.
|
|
444 If not given, a generic description is used.
|
|
445 :variable-reset-string VARIABLE-RESET-STRING
|
|
446 As above but used in the case the variable has been forced to
|
|
447 the value in this theme.
|
|
448 :face-set-string FACE-SET-STRING
|
|
449 :face-reset-string FACE-RESET-STRING
|
|
450 As above but for faces."
|
|
451 (let ((feature (custom-make-theme-feature theme)))
|
|
452 `(custom-define-theme (quote ,theme) (quote ,feature) ,@body)))
|
|
453
|
|
454 (defsubst custom-theme-p (theme)
|
|
455 "Non-nil when THEME has been defined."
|
|
456 (memq theme custom-known-themes))
|
|
457
|
|
458 (defsubst custom-check-theme (theme)
|
444
|
459 "Check whether THEME is valid and signal an error if NOT."
|
428
|
460 (unless (custom-theme-p theme)
|
|
461 (error "Unknown theme `%s'" theme)))
|
|
462
|
|
463
|
|
464 ; #### do we need to deftheme 'user and/or 'standard here to make the
|
|
465 ; code in cus-edit cleaner?.
|
|
466
|
|
467 ;;; Initializing.
|
|
468
|
|
469 (defun custom-push-theme (prop symbol theme mode value)
|
|
470 (let ((old (get symbol prop)))
|
|
471 (if (eq (car-safe (car-safe old)) theme)
|
|
472 (setq old (cdr old)))
|
|
473 (put symbol prop (cons (list theme mode value) old))))
|
|
474
|
|
475 (defun custom-set-variables (&rest args)
|
|
476 "Initialize variables according to user preferences.
|
|
477 The settings are registered as theme `user'.
|
|
478 The arguments should be a list where each entry has the form:
|
|
479
|
|
480 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]])
|
|
481
|
|
482 The unevaluated VALUE is stored as the saved value for SYMBOL.
|
|
483 If NOW is present and non-nil, VALUE is also evaluated and bound as
|
|
484 the default value for the SYMBOL.
|
|
485 REQUEST is a list of features we must 'require for SYMBOL.
|
|
486 COMMENT is a comment string about SYMBOL."
|
|
487 (apply 'custom-theme-set-variables 'user args))
|
|
488
|
|
489 (defun custom-theme-set-variables (theme &rest args)
|
|
490 "Initialize variables according to settings specified by args.
|
|
491 Records the settings as belonging to THEME.
|
|
492
|
|
493 See `custom-set-variables' for a description of the arguments ARGS."
|
|
494 (custom-check-theme theme)
|
903
|
495 (setq args
|
|
496 (sort args
|
|
497 (lambda (a1 a2)
|
|
498 (let* ((sym1 (car a1))
|
|
499 (sym2 (car a2))
|
|
500 (1-then-2 (memq sym1 (get sym2 'custom-dependencies)))
|
|
501 (2-then-1 (memq sym2 (get sym1 'custom-dependencies))))
|
|
502 (cond ((and 1-then-2 2-then-1)
|
|
503 (error "Circular custom dependency between `%s' and `%s'"
|
|
504 sym1 sym2))
|
|
505 (1-then-2 t)
|
|
506 (2-then-1 nil)
|
|
507 ;; Put symbols with :require last. The macro
|
|
508 ;; define-minor-mode generates a defcustom
|
|
509 ;; with a :require and a :set, where the
|
|
510 ;; setter function calls the mode function.
|
|
511 ;; Putting symbols with :require last ensures
|
|
512 ;; that the mode function will see other
|
|
513 ;; customized values rather than default
|
|
514 ;; values.
|
|
515 (t (nth 3 a2)))))))
|
428
|
516 (let ((immediate (get theme 'theme-immediate)))
|
|
517 (while args * etc/custom/example-themes/example-theme.el:
|
|
518 (let ((entry (car args)))
|
|
519 (if (listp entry)
|
|
520 (let* ((symbol (nth 0 entry))
|
|
521 (value (nth 1 entry))
|
|
522 (now (nth 2 entry))
|
|
523 (requests (nth 3 entry))
|
|
524 (comment (nth 4 entry))
|
|
525 (set (or (get symbol 'custom-set) 'set-default)))
|
|
526 (put symbol 'saved-value (list value))
|
|
527 (custom-push-theme 'theme-value symbol theme 'set value)
|
|
528 (put symbol 'saved-variable-comment comment)
|
|
529 (cond ((or now immediate)
|
|
530 ;; Rogue variable, set it now.
|
|
531 (put symbol 'force-value (if now 'rogue 'immediate))
|
|
532 (funcall set symbol (eval value)))
|
|
533 ((default-boundp symbol)
|
|
534 ;; Something already set this, overwrite it.
|
|
535 (funcall set symbol (eval value))))
|
|
536 (and (or now (default-boundp symbol))
|
|
537 (put symbol 'variable-comment comment))
|
|
538 (when requests
|
|
539 (put symbol 'custom-requests requests)
|
|
540 (mapc 'require requests))
|
|
541 (setq args (cdr args)))
|
|
542 ;; Old format, a plist of SYMBOL VALUE pairs.
|
|
543 (message "Warning: old format `custom-set-variables'")
|
|
544 (ding)
|
|
545 (sit-for 2)
|
|
546 (let ((symbol (nth 0 args))
|
|
547 (value (nth 1 args)))
|
|
548 (put symbol 'saved-value (list value))
|
|
549 (custom-push-theme 'theme-value symbol theme 'set value))
|
|
550 (setq args (cdr (cdr args))))))))
|
|
551
|
|
552 (defvar custom-loaded-themes nil
|
|
553 "Themes in the order they are loaded.")
|
|
554
|
|
555 (defun custom-theme-loaded-p (theme)
|
|
556 "Return non-nil when THEME has been loaded."
|
|
557 (memq theme custom-loaded-themes))
|
|
558
|
|
559 (defun provide-theme (theme)
|
|
560 "Indicate that this file provides THEME."
|
|
561 (custom-check-theme theme)
|
|
562 (provide (get theme 'theme-feature))
|
|
563 (push theme custom-loaded-themes))
|
|
564
|
|
565 (defun require-theme (theme &optional soft)
|
|
566 "Try to load a theme by requiring its feature."
|
|
567 ;; Note we do no check for validity of the theme here.
|
|
568 ;; This allows to pull in themes by a file-name convention
|
|
569 (require (get theme 'theme-feature (custom-make-theme-feature theme))))
|
|
570
|
|
571 (defun custom-do-theme-reset (theme)
|
|
572 ; #### untested! slow!
|
|
573 (let (spec-list)
|
|
574 (mapatoms (lambda (symbol)
|
|
575 (setq spec-list (get symbol 'theme-value))
|
|
576 (when spec-list
|
|
577 (setq spec-list (delete-if (lambda (elt)
|
|
578 (eq (car elt) theme))
|
|
579 spec-list))
|
|
580 (put symbol 'theme-value spec-list)
|
|
581 (custom-theme-reset-internal symbol 'user))
|
|
582 (setq spec-list (get symbol 'theme-face))
|
|
583 (when spec-list
|
|
584 (setq spec-list (delete-if (lambda (elt)
|
|
585 (eq (car elt) theme))
|
|
586 spec-list))
|
|
587 (put symbol 'theme-face spec-list)
|
|
588 (custom-theme-reset-internal-face symbol 'user))))))
|
|
589
|
|
590 (defun custom-theme-load-themes (by-theme &rest body)
|
|
591 "Load the themes specified by BODY and record them as required by
|
442
|
592 theme BY-THEME. BODY is a sequence of
|
428
|
593 - a SYMBOL
|
|
594 require the theme SYMBOL
|
|
595 - a list (reset THEME)
|
|
596 Undo all the settings made by THEME.
|
|
597 - a list (hidden THEME)
|
|
598 require the THEME but hide it from the user."
|
|
599 (custom-check-theme by-theme)
|
|
600 (dolist (theme body)
|
|
601 (cond ((and (consp theme) (eq (car theme) 'reset))
|
|
602 (custom-do-theme-reset (cadr theme)))
|
|
603 ((and (consp theme) (eq (car theme) 'hidden))
|
|
604 (require-theme (cadr theme))
|
|
605 (unless (custom-theme-loaded-p (cadr theme))
|
|
606 (put (cadr theme) 'theme-hidden t)))
|
|
607 (t
|
|
608 (require-theme theme)
|
|
609 (remprop theme 'theme-hidden)))
|
|
610 (push theme (get by-theme 'theme-loads-themes))))
|
|
611
|
|
612 (defun custom-load-themes (&rest body)
|
|
613 "Load themes for the USER theme as specified by BODY.
|
|
614
|
|
615 BODY is as with custom-theme-load-themes."
|
|
616 (apply #'custom-theme-load-themes 'user body))
|
|
617
|
|
618
|
|
619
|
|
620
|
|
621 (defsubst copy-upto-last (elt list)
|
444
|
622 "Copy all the elements of the list upto the last occurrence of elt."
|
428
|
623 ;; Is it faster to do more work in C than to do less in elisp?
|
|
624 (nreverse (cdr (member elt (reverse list)))))
|
|
625
|
|
626 (defun custom-theme-value (theme theme-spec-list)
|
|
627 "Determine the value for THEME defined by THEME-SPEC-LIST.
|
|
628 Returns (list value) if found. Nil otherwise."
|
440
|
629 ;; Note we do _NOT_ signal an error if the theme is unknown
|
428
|
630 ;; it might have gone away without the user knowing.
|
|
631 (let ((theme-or-lower (memq theme (cons 'user custom-loaded-themes)))
|
|
632 value)
|
|
633 (mapc #'(lambda (theme-spec)
|
|
634 (when (member (car theme-spec) theme-or-lower)
|
|
635 (setq value (cdr theme-spec))
|
|
636 ;; We need to continue because if theme =A and we found
|
|
637 ;; B then if the load order is B A C B
|
|
638 ;; we actually want the value in C.
|
|
639 (setq theme-or-lower (copy-upto-last (car theme-spec)
|
|
640 theme-or-lower))
|
|
641 ;; We could should circuit if this is now nil.
|
|
642 ))
|
|
643 theme-spec-list)
|
|
644 (if value
|
|
645 (if (eq (car value) 'set)
|
|
646 (list (cadr value))
|
|
647 ;; Yet another reset spec. car value = reset
|
|
648 (custom-theme-value (cadr value) theme-spec-list)))))
|
|
649
|
|
650
|
|
651 (defun custom-theme-variable-value (variable theme)
|
|
652 "Return (list value) value of VARIABLE in THEME if the THEME modifies the
|
|
653 VARIABLE. Nil otherwise."
|
|
654 (custom-theme-value theme (get variable 'theme-value)))
|
|
655
|
|
656 (defun custom-theme-reset-internal (symbol to-theme)
|
|
657 (let ((value (custom-theme-variable-value symbol to-theme))
|
|
658 was-in-theme)
|
|
659 (setq was-in-theme value)
|
|
660 (setq value (or value (get symbol 'standard-value)))
|
|
661 (when value
|
|
662 (put symbol 'saved-value was-in-theme)
|
|
663 (if (or (get 'force-value symbol) (default-boundp symbol))
|
|
664 (funcall (get symbol 'custom-set 'set-default) symbol
|
|
665 (eval (car value)))))
|
|
666 value))
|
|
667
|
|
668
|
|
669 (defun custom-theme-reset-variables (theme &rest args)
|
|
670 "Reset the value of the variables to values previously defined.
|
442
|
671 Associate this setting with THEME.
|
428
|
672
|
|
673 ARGS is a list of lists of the form
|
|
674
|
|
675 (variable to-theme)
|
|
676
|
|
677 This means reset variable to its value in to-theme."
|
|
678 (custom-check-theme theme)
|
|
679 (mapc #'(lambda (arg)
|
|
680 (apply #'custom-theme-reset-internal arg)
|
|
681 (custom-push-theme 'theme-value (car arg) theme 'reset (cadr arg)))
|
|
682 args))
|
|
683
|
|
684 (defun custom-reset-variables (&rest args)
|
|
685 "Reset the value of the variables to values previously defined.
|
442
|
686 Associate this setting with the `user' theme.
|
428
|
687
|
|
688 The ARGS are as in `custom-theme-reset-variables'."
|
|
689 (apply #'custom-theme-reset-variables 'user args))
|
|
690
|
|
691
|
|
692 ;;; The End.
|
|
693
|
|
694 ;; custom.el ends here
|