2544
|
1 ;;; custom.el --- tools for declaring and initializing options
|
|
2 ;;
|
|
3 ;; Copyright (C) 1996, 1997, 1999, 2001, 2002 Free Software Foundation, Inc.
|
|
4 ;;
|
428
|
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
|
2544
|
6 ;; Maintainer: XEmacs Development Group
|
428
|
7 ;; Keywords: help, faces, dumped
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify
|
|
12 ;; it under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs 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.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
24 ;; Boston, MA 02111-1307, USA.
|
|
25
|
2544
|
26 ;;; Synched with: FSF 21.3.
|
1333
|
27
|
428
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This file is dumped with XEmacs.
|
|
31
|
2544
|
32 ;;
|
|
33 ;; This file only contains the code needed to declare and initialize
|
428
|
34 ;; user options. The code to customize options is autoloaded from
|
2544
|
35 ;; `cus-edit.el' and is documented in the XEmacs Lisp Reference manual.
|
|
36
|
|
37 ;; The code implementing face declarations is in `cus-face.el'.
|
428
|
38
|
|
39 ;;; Code:
|
|
40
|
771
|
41 ;; it is now safe to put the `provide' anywhere. if an error occurs while
|
|
42 ;; loading, all provides (and fsets) will be undone. put it first to
|
|
43 ;; prevent require/provide loop with custom and cus-face.
|
|
44 (provide 'custom)
|
|
45
|
428
|
46 (eval-when-compile
|
771
|
47 (load "cl-macs" nil t)
|
|
48 ;; To elude warnings.
|
|
49 (require 'cus-face))
|
428
|
50
|
442
|
51 (autoload 'custom-declare-face "cus-face")
|
|
52 (autoload 'defun* "cl-macs")
|
428
|
53
|
|
54 (require 'widget)
|
|
55
|
|
56 (defvar custom-define-hook nil
|
|
57 ;; Customize information for this option is in `cus-edit.el'.
|
|
58 "Hook called after defining each customize option.")
|
|
59
|
2544
|
60 (defvar custom-dont-initialize nil
|
|
61 "Non-nil means `defcustom' should not initialize the variable.
|
|
62 That is used for the sake of `custom-make-dependencies'.
|
|
63 Users should not set it.")
|
|
64
|
|
65 (defvar custom-current-group-alist nil
|
|
66 "Alist of (FILE . GROUP) indicating the current group to use for FILE.")
|
|
67
|
428
|
68 ;;; The `defcustom' Macro.
|
|
69
|
|
70 (defun custom-initialize-default (symbol value)
|
|
71 "Initialize SYMBOL with VALUE.
|
|
72 This will do nothing if symbol already has a default binding.
|
|
73 Otherwise, if symbol has a `saved-value' property, it will evaluate
|
|
74 the car of that and used as the default binding for symbol.
|
|
75 Otherwise, VALUE will be evaluated and used as the default binding for
|
|
76 symbol."
|
|
77 (unless (default-boundp symbol)
|
|
78 ;; Use the saved value if it exists, otherwise the standard setting.
|
|
79 (set-default symbol (if (get symbol 'saved-value)
|
|
80 (eval (car (get symbol 'saved-value)))
|
|
81 (eval value)))))
|
|
82
|
|
83 (defun custom-initialize-set (symbol value)
|
|
84 "Initialize SYMBOL with VALUE.
|
1333
|
85 If the symbol doesn't have a default binding already,
|
|
86 then set it using its `:set' function (or `set-default' if it has none).
|
|
87 The value is either the value in the symbol's `saved-value' property,
|
|
88 if any, or VALUE.
|
|
89
|
|
90 This is like `custom-initialize-default', but uses the function specified by
|
428
|
91 `:set' to initialize SYMBOL."
|
|
92 (unless (default-boundp symbol)
|
|
93 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
94 symbol
|
|
95 (if (get symbol 'saved-value)
|
|
96 (eval (car (get symbol 'saved-value)))
|
|
97 (eval value)))))
|
|
98
|
|
99 (defun custom-initialize-reset (symbol value)
|
|
100 "Initialize SYMBOL with VALUE.
|
1333
|
101 Set the symbol, using its `:set' function (or `set-default' if it has none).
|
|
102 The value is either the symbol's current value
|
|
103 \(as obtained using the `:get' function), if any,
|
|
104 or the value in the symbol's `saved-value' property if any,
|
|
105 or (last of all) VALUE.
|
|
106
|
428
|
107 Like `custom-initialize-set', but use the function specified by
|
|
108 `:get' to reinitialize SYMBOL if it is already bound."
|
|
109 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
110 symbol
|
|
111 (cond ((default-boundp symbol)
|
|
112 (funcall (or (get symbol 'custom-get) 'default-value)
|
|
113 symbol))
|
|
114 ((get symbol 'saved-value)
|
|
115 (eval (car (get symbol 'saved-value))))
|
|
116 (t
|
|
117 (eval value)))))
|
|
118
|
4289
|
119 ;; XEmacs change; move to defsubst, since this is only called in one place
|
|
120 ;; and usage of it clusters.
|
|
121 (defsubst custom-initialize-changed (symbol value)
|
428
|
122 "Initialize SYMBOL with VALUE.
|
4289
|
123 Like `custom-initialize-reset', but only use the `:set' function if
|
1333
|
124 not using the standard setting.
|
|
125 For the standard setting, use `set-default'."
|
428
|
126 (cond ((default-boundp symbol)
|
|
127 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
128 symbol
|
|
129 (funcall (or (get symbol 'custom-get) 'default-value)
|
|
130 symbol)))
|
|
131 ((get symbol 'saved-value)
|
|
132 (funcall (or (get symbol 'custom-set) 'set-default)
|
|
133 symbol
|
|
134 (eval (car (get symbol 'saved-value)))))
|
|
135 (t
|
|
136 (set-default symbol (eval value)))))
|
|
137
|
1333
|
138 (defun custom-declare-variable (symbol default doc &rest args)
|
|
139 "Like `defcustom', but SYMBOL and DEFAULT are evaluated as normal arguments.
|
|
140 DEFAULT should be an expression to evaluate to compute the default value,
|
2544
|
141 not the default value itself.
|
|
142
|
|
143 DEFAULT is stored as SYMBOL's value in the standard theme. See
|
|
144 `custom-known-themes' for a list of known themes. For backwards
|
|
145 compatibility, DEFAULT is also stored in SYMBOL's property
|
|
146 `standard-value'. At the same time, SYMBOL's property `force-value' is
|
4289
|
147 set to nil, as the value is no longer rogue.
|
|
148
|
|
149 The byte compiler adds an XEmacs-specific :default keyword and value to
|
|
150 `custom-declare-variable' calls when it byte-compiles the DEFAULT argument.
|
|
151 These describe what the custom UI shows when editing a customizable
|
|
152 variable's associated Lisp expression. We don't encourage use of this
|
|
153 keyword in your own programs. "
|
2544
|
154 ;; Remember the standard setting. The value should be in the standard
|
4289
|
155 ;; theme, not in this property. However, this would require changing
|
2544
|
156 ;; the C source of defvar and others as well...
|
1333
|
157 (put symbol 'standard-value (list default))
|
428
|
158 ;; Maybe this option was rogue in an earlier version. It no longer is.
|
|
159 (when (eq (get symbol 'force-value) 'rogue)
|
|
160 ;; It no longer is.
|
|
161 (put symbol 'force-value nil))
|
|
162 (when doc
|
|
163 (put symbol 'variable-documentation doc))
|
|
164 (let ((initialize 'custom-initialize-reset)
|
2544
|
165 (requests nil))
|
|
166 (unless (memq :group args)
|
|
167 (custom-add-to-group (custom-current-group) symbol 'custom-variable))
|
428
|
168 (while args
|
|
169 (let ((arg (car args)))
|
2544
|
170 (setq args (cdr args))
|
428
|
171 (check-argument-type 'keywordp arg)
|
2544
|
172 (let ((keyword arg)
|
|
173 (value (car args)))
|
|
174 (unless args
|
428
|
175 (signal 'error (list "Keyword is missing an argument" keyword)))
|
2544
|
176 (setq args (cdr args))
|
|
177 (cond ((eq keyword :initialize)
|
|
178 (setq initialize value))
|
|
179 ((eq keyword :set)
|
|
180 (put symbol 'custom-set value))
|
|
181 ((eq keyword :get)
|
|
182 (put symbol 'custom-get value))
|
|
183 ((eq keyword :require)
|
|
184 (push value requests))
|
|
185 ((eq keyword :type)
|
|
186 (put symbol 'custom-type (purecopy value)))
|
|
187 ((eq keyword :options)
|
|
188 (if (get symbol 'custom-options)
|
|
189 ;; Slow safe code to avoid duplicates.
|
|
190 (mapc (lambda (option)
|
|
191 (custom-add-option symbol option))
|
|
192 value)
|
|
193 ;; Fast code for the common case.
|
|
194 (put symbol 'custom-options (copy-sequence value))))
|
4289
|
195 ;; In the event that the byte compile has compiled the init
|
|
196 ;; value, we want the value the UI sees to be uncompiled.
|
|
197 ((eq keyword :default)
|
|
198 (put symbol 'standard-value (list value)))
|
2544
|
199 (t
|
|
200 (custom-handle-keyword symbol keyword value
|
|
201 'custom-variable))))))
|
428
|
202 (put symbol 'custom-requests requests)
|
|
203 ;; Do the actual initialization.
|
2544
|
204 (unless custom-dont-initialize
|
|
205 (funcall initialize symbol default)))
|
428
|
206 ;; #### This is a rough equivalent of LOADHIST_ATTACH. However,
|
|
207 ;; LOADHIST_ATTACH also checks for `initialized'.
|
2544
|
208 (push (cons 'defvar symbol) current-load-list)
|
428
|
209 (run-hooks 'custom-define-hook)
|
|
210 symbol)
|
|
211
|
|
212 (defmacro defcustom (symbol value doc &rest args)
|
|
213 "Declare SYMBOL as a customizable variable that defaults to VALUE.
|
|
214 DOC is the variable documentation.
|
|
215
|
|
216 Neither SYMBOL nor VALUE needs to be quoted.
|
|
217 If SYMBOL is not already bound, initialize it to VALUE.
|
|
218 The remaining arguments should have the form
|
|
219
|
|
220 [KEYWORD VALUE]...
|
|
221
|
1333
|
222 The following keywords are meaningful:
|
428
|
223
|
2544
|
224 :type VALUE should be a widget type for editing the symbol's value.
|
428
|
225 The default is `sexp'.
|
|
226 :options VALUE should be a list of valid members of the widget type.
|
|
227 :group VALUE should be a customization group.
|
|
228 Add SYMBOL to that group.
|
2544
|
229 :link LINK-DATA
|
|
230 Include an external link after the documentation string for this
|
|
231 item. This is a sentence containing an active field which
|
|
232 references some other documentation.
|
|
233
|
|
234 There are three alternatives you can use for LINK-DATA:
|
|
235
|
|
236 (custom-manual INFO-NODE)
|
|
237 Link to an Info node; INFO-NODE is a string which specifies
|
|
238 the node name, as in \"(emacs)Top\". The link appears as
|
|
239 `[manual]' in the customization buffer.
|
|
240
|
|
241 (info-link INFO-NODE)
|
|
242 Like `custom-manual' except that the link appears in the
|
|
243 customization buffer with the Info node name.
|
|
244
|
|
245 (url-link URL)
|
|
246 Link to a web page; URL is a string which specifies the URL.
|
|
247 The link appears in the customization buffer as URL.
|
|
248
|
|
249 You can specify the text to use in the customization buffer by
|
|
250 adding `:tag NAME' after the first element of the LINK-DATA; for
|
|
251 example, (info-link :tag \"foo\" \"(emacs)Top\") makes a link to the
|
|
252 Emacs manual which appears in the buffer as `foo'.
|
|
253
|
|
254 An item can have more than one external link; however, most items
|
|
255 have none at all.
|
1333
|
256 :initialize
|
2544
|
257 VALUE should be a function used to initialize the
|
|
258 variable. It takes two arguments, the symbol and value
|
|
259 given in the `defcustom' call. The default is
|
|
260 `custom-initialize-reset'.
|
1333
|
261 :set VALUE should be a function to set the value of the symbol.
|
|
262 It takes two arguments, the symbol to set and the value to
|
|
263 give it. The default choice of function is `custom-set-default'.
|
428
|
264 :get VALUE should be a function to extract the value of symbol.
|
1333
|
265 The function takes one argument, a symbol, and should return
|
|
266 the current value for that symbol. The default choice of function
|
|
267 is `custom-default-value'. #### XEmacs used to say `default-value';
|
|
268 is that right?
|
|
269 :require
|
|
270 VALUE should be a feature symbol. If you save a value
|
|
271 for this option, then when your custom init file loads the value,
|
|
272 it does (require VALUE) first.
|
|
273 :version
|
|
274 VALUE should be a string specifying that the variable was
|
903
|
275 first introduced, or its default value was changed, in Emacs
|
|
276 version VERSION.
|
2544
|
277 :tag LABEL
|
|
278 Use LABEL, a string, instead of the item's name, to label the item
|
|
279 in customization menus and buffers.
|
|
280 :load FILE
|
|
281 Load file FILE (a string) before displaying this customization
|
|
282 item. Loading is done with `load', and only if the file is
|
|
283 not already loaded.
|
|
284 :set-after VARIABLES
|
|
285 Specifies that SYMBOL should be set after the list of variables
|
|
286 VARIABLES when both have been customized.
|
428
|
287
|
|
288 Read the section about customization in the Emacs Lisp manual for more
|
|
289 information."
|
|
290 `(custom-declare-variable (quote ,symbol) (quote ,value) ,doc ,@args))
|
|
291
|
|
292 ;;; The `defface' Macro.
|
|
293
|
|
294 (defmacro defface (face spec doc &rest args)
|
|
295 "Declare FACE as a customizable face that defaults to SPEC.
|
|
296 FACE does not need to be quoted.
|
|
297
|
|
298 Third argument DOC is the face documentation.
|
|
299
|
|
300 If FACE has been set with `custom-set-face', set the face attributes
|
|
301 as specified by that function, otherwise set the face attributes
|
|
302 according to SPEC.
|
|
303
|
|
304 The remaining arguments should have the form
|
|
305
|
|
306 [KEYWORD VALUE]...
|
|
307
|
|
308 The following KEYWORDs are defined:
|
|
309
|
|
310 :group VALUE should be a customization group.
|
|
311 Add FACE to that group.
|
|
312
|
|
313 SPEC should be an alist of the form ((DISPLAY ATTS)...).
|
|
314
|
|
315 ATTS is a list of face attributes and their values. The possible
|
|
316 attributes are defined in the variable `custom-face-attributes'.
|
|
317
|
|
318 The ATTS of the first entry in SPEC where the DISPLAY matches the
|
|
319 frame should take effect in that frame. DISPLAY can either be the
|
|
320 symbol t, which will match all frames, or an alist of the form
|
|
321 \((REQ ITEM...)...)
|
|
322
|
|
323 For the DISPLAY to match a FRAME, the REQ property of the frame must
|
|
324 match one of the ITEM. The following REQ are defined:
|
|
325
|
|
326 `type' (the value of `window-system')
|
442
|
327 Should be one of `x', `mswindows', or `tty'.
|
428
|
328
|
|
329 `class' (the frame's color support)
|
|
330 Should be one of `color', `grayscale', or `mono'.
|
|
331
|
|
332 `background' (what color is used for the background text)
|
|
333 Should be one of `light' or `dark'.
|
|
334
|
|
335 Read the section about customization in the Emacs Lisp manual for more
|
|
336 information."
|
|
337 `(custom-declare-face (quote ,face) ,spec ,doc ,@args))
|
|
338
|
|
339 ;;; The `defgroup' Macro.
|
|
340
|
2544
|
341 (defun custom-current-group ()
|
|
342 (cdr (assoc load-file-name custom-current-group-alist)))
|
|
343
|
428
|
344 (defun custom-declare-group (symbol members doc &rest args)
|
|
345 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
|
|
346 (while members
|
|
347 (apply 'custom-add-to-group symbol (car members))
|
|
348 (pop members))
|
|
349 (when doc
|
|
350 (put symbol 'group-documentation doc))
|
|
351 (while args
|
|
352 (let ((arg (car args)))
|
|
353 (setq args (cdr args))
|
|
354 (check-argument-type 'keywordp arg)
|
|
355 (let ((keyword arg)
|
2544
|
356 (value (car args)))
|
428
|
357 (unless args
|
|
358 (signal 'error (list "Keyword is missing an argument" keyword)))
|
2544
|
359 (setq args (cdr args))
|
|
360 (cond ((eq keyword :prefix)
|
|
361 (put symbol 'custom-prefix value))
|
|
362 (t
|
|
363 (custom-handle-keyword symbol keyword value
|
|
364 'custom-group))))))
|
|
365 ;; Record the group on the `current' list.
|
|
366 (let ((elt (assoc load-file-name custom-current-group-alist)))
|
|
367 (if elt (setcdr elt symbol)
|
|
368 (push (cons load-file-name symbol) custom-current-group-alist)))
|
428
|
369 (run-hooks 'custom-define-hook)
|
|
370 symbol)
|
|
371
|
|
372 (defmacro defgroup (symbol members doc &rest args)
|
|
373 "Declare SYMBOL as a customization group containing MEMBERS.
|
|
374 SYMBOL does not need to be quoted.
|
|
375
|
|
376 Third arg DOC is the group documentation.
|
|
377
|
|
378 MEMBERS should be an alist of the form ((NAME WIDGET)...) where NAME
|
|
379 is a symbol and WIDGET is a widget for editing that symbol. Useful
|
|
380 widgets are `custom-variable' for editing variables, `custom-face' for
|
|
381 edit faces, and `custom-group' for editing groups.
|
|
382
|
|
383 The remaining arguments should have the form
|
|
384
|
|
385 [KEYWORD VALUE]...
|
|
386
|
2544
|
387 The following KEYWORDs are defined:
|
428
|
388
|
|
389 :group VALUE should be a customization group.
|
|
390 Add SYMBOL to that group.
|
|
391
|
|
392 Read the section about customization in the Emacs Lisp manual for more
|
|
393 information."
|
2544
|
394
|
|
395 ;; XEmacs: Evidently a purposeful omission from the docs:
|
|
396 ;:version VALUE should be a string specifying that the group was introduced
|
|
397 ; in Emacs version VERSION.
|
|
398 ;
|
|
399
|
|
400 ;; FSF: (not a problem for XEmacs)
|
|
401 ;; It is better not to use backquote in this file,
|
|
402 ;; because that makes a bootstrapping problem
|
|
403 ;; if you need to recompile all the Lisp files using interpreted code.
|
|
404 ; (nconc (list 'custom-declare-group (list 'quote symbol) members doc) args))
|
428
|
405 `(custom-declare-group (quote ,symbol) ,members ,doc ,@args))
|
|
406
|
|
407 (defvar custom-group-hash-table (make-hash-table :size 300 :test 'eq)
|
|
408 "Hash-table of non-empty groups.")
|
|
409
|
|
410 (defun custom-add-to-group (group option widget)
|
|
411 "To existing GROUP add a new OPTION of type WIDGET.
|
2544
|
412 If there already is an entry for OPTION and WIDGET, nothing is done."
|
|
413 (let ((members (get group 'custom-group))
|
|
414 (entry (list option widget)))
|
|
415 (unless (member entry members)
|
|
416 (put group 'custom-group (nconc members (list entry)))))
|
428
|
417 (puthash group t custom-group-hash-table))
|
|
418
|
2544
|
419 (defun custom-group-of-mode (mode)
|
|
420 "Return the custom group corresponding to the major or minor MODE.
|
|
421 If no such group is found, return nil."
|
|
422 (or (get mode 'custom-mode-group)
|
|
423 (if (or (get mode 'custom-group)
|
|
424 (and (string-match "-mode\\'" (symbol-name mode))
|
|
425 (get (setq mode (intern (substring (symbol-name mode)
|
|
426 0 (match-beginning 0))))
|
|
427 'custom-group)))
|
|
428 mode)))
|
|
429
|
428
|
430 ;;; Properties.
|
|
431
|
|
432 (defun custom-handle-all-keywords (symbol args type)
|
|
433 "For customization option SYMBOL, handle keyword arguments ARGS.
|
|
434 Third argument TYPE is the custom option type."
|
2544
|
435 (unless (memq :group args)
|
|
436 (custom-add-to-group (custom-current-group) symbol type))
|
428
|
437 (while args
|
|
438 (let ((arg (car args)))
|
|
439 (setq args (cdr args))
|
|
440 (check-argument-type 'keywordp arg)
|
|
441 (let ((keyword arg)
|
|
442 (value (car args)))
|
|
443 (unless args
|
|
444 (signal 'error (list "Keyword is missing an argument" keyword)))
|
|
445 (setq args (cdr args))
|
|
446 (custom-handle-keyword symbol keyword value type)))))
|
|
447
|
|
448 (defun custom-handle-keyword (symbol keyword value type)
|
|
449 "For customization option SYMBOL, handle KEYWORD with VALUE.
|
|
450 Fourth argument TYPE is the custom option type."
|
|
451 (cond ((eq keyword :group)
|
903
|
452 (custom-add-to-group value symbol type))
|
|
453 ((eq keyword :version)
|
|
454 (custom-add-version symbol value))
|
|
455 ((eq keyword :link)
|
|
456 (custom-add-link symbol value))
|
|
457 ((eq keyword :load)
|
|
458 (custom-add-load symbol value))
|
|
459 ((eq keyword :tag)
|
|
460 (put symbol 'custom-tag value))
|
|
461 ((eq keyword :set-after)
|
|
462 (custom-add-dependencies symbol value))
|
|
463 (t
|
|
464 (signal 'error (list "Unknown keyword" keyword)))))
|
|
465
|
|
466 (defun custom-add-dependencies (symbol value)
|
|
467 "To the custom option SYMBOL, add dependencies specified by VALUE.
|
|
468 VALUE should be a list of symbols. For each symbol in that list,
|
|
469 this specifies that SYMBOL should be set after the specified symbol, if
|
|
470 both appear in constructs like `custom-set-variables'."
|
|
471 (unless (listp value)
|
|
472 (error "Invalid custom dependency `%s'" value))
|
|
473 (let* ((deps (get symbol 'custom-dependencies))
|
|
474 (new-deps deps))
|
|
475 (while value
|
|
476 (let ((dep (car value)))
|
|
477 (unless (symbolp dep)
|
|
478 (error "Invalid custom dependency `%s'" dep))
|
|
479 (unless (memq dep new-deps)
|
|
480 (setq new-deps (cons dep new-deps)))
|
|
481 (setq value (cdr value))))
|
|
482 (unless (eq deps new-deps)
|
|
483 (put symbol 'custom-dependencies new-deps))))
|
428
|
484
|
|
485 (defun custom-add-option (symbol option)
|
|
486 "To the variable SYMBOL add OPTION.
|
|
487
|
|
488 If SYMBOL is a hook variable, OPTION should be a hook member.
|
|
489 For other types variables, the effect is undefined."
|
|
490 (let ((options (get symbol 'custom-options)))
|
|
491 (unless (member option options)
|
|
492 (put symbol 'custom-options (cons option options)))))
|
|
493
|
|
494 (defun custom-add-link (symbol widget)
|
|
495 "To the custom option SYMBOL add the link WIDGET."
|
|
496 (let ((links (get symbol 'custom-links)))
|
|
497 (unless (member widget links)
|
|
498 (put symbol 'custom-links (cons widget links)))))
|
|
499
|
|
500 (defun custom-add-version (symbol version)
|
|
501 "To the custom option SYMBOL add the version VERSION."
|
|
502 (put symbol 'custom-version version))
|
|
503
|
|
504 (defun custom-add-load (symbol load)
|
|
505 "To the custom option SYMBOL add the dependency LOAD.
|
|
506 LOAD should be either a library file name, or a feature name."
|
|
507 (puthash symbol t custom-group-hash-table)
|
|
508 (let ((loads (get symbol 'custom-loads)))
|
|
509 (unless (member load loads)
|
|
510 (put symbol 'custom-loads (cons load loads)))))
|
|
511
|
2544
|
512 (defun custom-autoload (symbol load)
|
|
513 "Mark SYMBOL as autoloaded custom variable and add dependency LOAD."
|
|
514 (put symbol 'custom-autoload t)
|
|
515 (custom-add-load symbol load))
|
|
516
|
|
517 ;; This test is also in the C code of `user-variable-p'.
|
|
518 (defun custom-variable-p (variable)
|
|
519 "Return non-nil if VARIABLE is a custom variable."
|
|
520 (or (get variable 'standard-value)
|
|
521 (get variable 'custom-autoload)))
|
|
522
|
|
523 ;;; Loading files needed to customize a symbol.
|
|
524 ;;; This is in custom.el because menu-bar.el needs it for toggle cmds.
|
|
525
|
|
526 (defvar custom-load-recursion nil
|
|
527 "Hack to avoid recursive dependencies.")
|
|
528
|
|
529 (defun custom-load-symbol (symbol)
|
|
530 "Load all dependencies for SYMBOL."
|
|
531 (unless custom-load-recursion
|
|
532 (let ((custom-load-recursion t))
|
|
533 (dolist (load (get symbol 'custom-loads))
|
|
534 (cond ((symbolp load) (condition-case nil (require load) (error nil)))
|
|
535 ;; This is subsumed by the test below, but it's much faster.
|
|
536 ((assoc load load-history))
|
|
537 ;; This was just (assoc (locate-library load) load-history)
|
|
538 ;; but has been optimized not to load locate-library
|
|
539 ;; if not necessary.
|
|
540 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load)
|
|
541 "\\(\\'\\|\\.\\)"))
|
|
542 (found nil))
|
|
543 (dolist (loaded load-history)
|
|
544 (and (stringp (car loaded))
|
|
545 (string-match regexp (car loaded))
|
|
546 (setq found t)))
|
|
547 found))
|
|
548 ;; Without this, we would load cus-edit recursively.
|
|
549 ;; We are still loading it when we call this,
|
|
550 ;; and it is not in load-history yet.
|
|
551 ((equal load "cus-edit"))
|
|
552 (t (condition-case nil (load load) (error nil))))))))
|
428
|
553
|
|
554 (defvar custom-known-themes '(user standard)
|
2544
|
555 "Themes that have been define with `deftheme'.
|
|
556 The default value is the list (user standard). The theme `standard'
|
|
557 contains the Emacs standard settings from the original Lisp files. The
|
|
558 theme `user' contains all the the settings the user customized and saved.
|
|
559 Additional themes declared with the `deftheme' macro will be added to
|
|
560 the front of this list.")
|
428
|
561
|
2544
|
562 (defun custom-declare-theme (theme feature &optional doc &rest args)
|
|
563 "Like `deftheme', but THEME is evaluated as a normal argument.
|
|
564 FEATURE is the feature this theme provides. This symbol is created
|
|
565 from THEME by `custom-make-theme-feature'."
|
|
566 (add-to-list 'custom-known-themes theme)
|
428
|
567 (put theme 'theme-feature feature)
|
2544
|
568 (when doc
|
|
569 (put theme 'theme-documentation doc))
|
|
570 (while args
|
|
571 (let ((arg (car args)))
|
|
572 (setq args (cdr args))
|
|
573 (check-argument-type 'keywordp arg)
|
|
574 (let ((keyword arg)
|
|
575 (value (car args)))
|
|
576 (unless args
|
|
577 (signal 'error (list "Keyword is missing an argument" keyword)))
|
|
578 (setq args (cdr args))
|
|
579 (cond ((eq keyword :short-description)
|
|
580 (put theme 'theme-short-description value))
|
|
581 ((eq keyword :immediate)
|
|
582 (put theme 'theme-immediate value))
|
|
583 ((eq keyword :variable-set-string)
|
|
584 (put theme 'theme-variable-set-string value))
|
|
585 ((eq keyword :variable-reset-string)
|
|
586 (put theme 'theme-variable-reset-string value))
|
|
587 ((eq keyword :face-set-string)
|
|
588 (put theme 'theme-face-set-string value))
|
|
589 ((eq keyword :face-reset-string)
|
|
590 (put theme 'theme-face-reset-string value)))))))
|
|
591
|
|
592 (defmacro deftheme (theme &optional doc &rest args)
|
|
593 "Declare custom theme THEME.
|
|
594 The optional argument DOC is a doc string describing the theme.
|
|
595 The remaining arguments should have the form
|
|
596
|
|
597 [KEYWORD VALUE]...
|
|
598
|
|
599 The following KEYWORD's are defined:
|
|
600
|
|
601 :short-description
|
|
602 VALUE is a short (one line) description of the theme. If not
|
|
603 given, DOC is used.
|
|
604 :immediate
|
|
605 If VALUE is non-nil, variables specified in this theme are set
|
|
606 immediately when loading the theme.
|
|
607 :variable-set-string
|
|
608 VALUE is a string used to indicate that a variable takes its
|
|
609 setting from this theme. It is passed to FORMAT with the name
|
|
610 of the theme as an additional argument. If not given, a
|
|
611 generic description is used.
|
|
612 :variable-reset-string
|
|
613 VALUE is a string used in the case a variable has been forced
|
|
614 to its value in this theme. It is passed to FORMAT with the
|
|
615 name of the theme as an additional argument. If not given, a
|
|
616 generic description is used.
|
|
617 :face-set-string
|
|
618 VALUE is a string used to indicate that a face takes its
|
|
619 setting from this theme. It is passed to FORMAT with the name
|
|
620 of the theme as an additional argument. If not given, a
|
|
621 generic description is used.
|
|
622 :face-reset-string
|
|
623 VALUE is a string used in the case a face has been forced to
|
|
624 its value in this theme. It is passed to FORMAT with the name
|
|
625 of the theme as an additional argument. If not given, a
|
|
626 generic description is used.
|
|
627
|
|
628 Any theme `foo' should be defined in a file called `foo-theme.el';
|
|
629 see `custom-make-theme-feature' for more information."
|
|
630 (let ((feature (custom-make-theme-feature theme)))
|
|
631 ;; It is better not to use backquote in this file,
|
|
632 ;; because that makes a bootstrapping problem
|
|
633 ;; if you need to recompile all the Lisp files using interpreted code.
|
|
634 (nconc (list 'custom-declare-theme
|
|
635 (list 'quote theme)
|
|
636 (list 'quote feature)
|
|
637 doc) args)))
|
428
|
638
|
|
639 (defun custom-make-theme-feature (theme)
|
2544
|
640 "Given a symbol THEME, create a new symbol by appending \"-theme\".
|
|
641 Store this symbol in the `theme-feature' property of THEME.
|
|
642 Calling `provide-theme' to provide THEME actually puts `THEME-theme'
|
|
643 into `features'.
|
428
|
644
|
2544
|
645 This allows for a file-name convention for autoloading themes:
|
|
646 Every theme X has a property `provide-theme' whose value is \"X-theme\".
|
|
647 \(require-theme X) then attempts to load the file `X-theme.el'."
|
|
648 (intern (concat (symbol-name theme) "-theme")))
|
428
|
649
|
|
650 (defsubst custom-theme-p (theme)
|
|
651 "Non-nil when THEME has been defined."
|
|
652 (memq theme custom-known-themes))
|
|
653
|
|
654 (defsubst custom-check-theme (theme)
|
2544
|
655 "Check whether THEME is valid, and signal an error if it is not."
|
428
|
656 (unless (custom-theme-p theme)
|
|
657 (error "Unknown theme `%s'" theme)))
|
|
658
|
|
659 ;;; Initializing.
|
|
660
|
|
661 (defun custom-push-theme (prop symbol theme mode value)
|
2544
|
662 "Add (THEME MODE VALUE) to the list in property PROP of SYMBOL.
|
|
663 If the first element in that list is already (THEME ...),
|
|
664 discard it first.
|
|
665
|
|
666 MODE can be either the symbol `set' or the symbol `reset'. If it is the
|
|
667 symbol `set', then VALUE is the value to use. If it is the symbol
|
|
668 `reset', then VALUE is the mode to query instead.
|
|
669
|
|
670 In the following example for the variable `goto-address-url-face', the
|
|
671 theme `subtle-hacker' uses the same value for the variable as the theme
|
|
672 `gnome2':
|
|
673
|
|
674 \((standard set bold)
|
|
675 \(gnome2 set info-xref)
|
|
676 \(jonadab set underline)
|
|
677 \(subtle-hacker reset gnome2))
|
|
678
|
|
679
|
|
680 If a value has been stored for themes A B and C, and a new value
|
|
681 is to be stored for theme C, then the old value of C is discarded.
|
|
682 If a new value is to be stored for theme B, however, the old value
|
|
683 of B is not discarded because B is not the car of the list.
|
|
684
|
|
685 For variables, list property PROP is `theme-value'.
|
|
686 For faces, list property PROP is `theme-face'.
|
|
687 This is used in `custom-do-theme-reset', for example.
|
|
688
|
|
689 The list looks the same in any case; the examples shows a possible
|
|
690 value of the `theme-face' property for the face `region':
|
|
691
|
|
692 \((gnome2 set ((t (:foreground \"cyan\" :background \"dark cyan\"))))
|
|
693 \(standard set ((((class color) (background dark))
|
|
694 \(:background \"blue\"))
|
|
695 \(t (:background \"gray\")))))
|
|
696
|
|
697 This records values for the `standard' and the `gnome2' themes.
|
|
698 The user has not customized the face; had he done that,
|
|
699 the list would contain an entry for the `user' theme, too.
|
|
700 See `custom-known-themes' for a list of known themes."
|
428
|
701 (let ((old (get symbol prop)))
|
|
702 (if (eq (car-safe (car-safe old)) theme)
|
|
703 (setq old (cdr old)))
|
|
704 (put symbol prop (cons (list theme mode value) old))))
|
|
705
|
988
|
706 (defvar custom-local-buffer nil
|
|
707 "Non-nil, in a Customization buffer, means customize a specific buffer.
|
|
708 If this variable is non-nil, it should be a buffer,
|
|
709 and it means customize the local bindings of that buffer.
|
|
710 This variable is a permanent local, and it normally has a local binding
|
|
711 in every Customization buffer.")
|
|
712 (put 'custom-local-buffer 'permanent-local t)
|
|
713
|
428
|
714 (defun custom-set-variables (&rest args)
|
|
715 "Initialize variables according to user preferences.
|
|
716 The settings are registered as theme `user'.
|
2544
|
717 The arguments should each be a list of the form:
|
428
|
718
|
|
719 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]])
|
|
720
|
|
721 The unevaluated VALUE is stored as the saved value for SYMBOL.
|
|
722 If NOW is present and non-nil, VALUE is also evaluated and bound as
|
|
723 the default value for the SYMBOL.
|
2544
|
724
|
428
|
725 REQUEST is a list of features we must 'require for SYMBOL.
|
|
726 COMMENT is a comment string about SYMBOL."
|
|
727 (apply 'custom-theme-set-variables 'user args))
|
|
728
|
|
729 (defun custom-theme-set-variables (theme &rest args)
|
|
730 "Initialize variables according to settings specified by args.
|
|
731 Records the settings as belonging to THEME.
|
|
732
|
2544
|
733 The arguments should be a list where each entry has the form:
|
|
734
|
|
735 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]])
|
|
736
|
|
737 The unevaluated VALUE is stored as the saved value for SYMBOL.
|
|
738 If NOW is present and non-nil, VALUE is also evaluated and bound as
|
|
739 the default value for the SYMBOL.
|
|
740 REQUEST is a list of features we must 'require for SYMBOL.
|
|
741 COMMENT is a comment string about SYMBOL.
|
|
742
|
|
743 Several properties of THEME and SYMBOL are used in the process:
|
|
744
|
|
745 If THEME property `theme-immediate' is non-nil, this is equivalent of
|
|
746 providing the NOW argument to all symbols in the argument list: SYMBOL
|
|
747 is bound to the evaluated VALUE. The only difference is SYMBOL property
|
|
748 `force-value': if NOW is non-nil, SYMBOL's property `force-value' is set to
|
|
749 the symbol `rogue', else if THEME's property `theme-immediate' is non-nil,
|
|
750 FACE's property `force-face' is set to the symbol `immediate'.
|
|
751
|
|
752 VALUE itself is saved unevaluated as SYMBOL property `saved-value' and
|
|
753 in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
|
428
|
754 (custom-check-theme theme)
|
|
755 (let ((immediate (get theme 'theme-immediate)))
|
2544
|
756 (setq args
|
|
757 (sort args
|
|
758 (lambda (a1 a2)
|
|
759 (let* ((sym1 (car a1))
|
|
760 (sym2 (car a2))
|
|
761 (1-then-2 (memq sym1 (get sym2 'custom-dependencies)))
|
|
762 (2-then-1 (memq sym2 (get sym1 'custom-dependencies))))
|
|
763 (cond ((and 1-then-2 2-then-1)
|
|
764 (error "Circular custom dependency between `%s' and `%s'"
|
|
765 sym1 sym2))
|
|
766 (2-then-1 nil)
|
|
767 ;; Put symbols with :require last. The macro
|
|
768 ;; define-minor-mode generates a defcustom
|
|
769 ;; with a :require and a :set, where the
|
|
770 ;; setter function calls the mode function.
|
|
771 ;; Putting symbols with :require last ensures
|
|
772 ;; that the mode function will see other
|
|
773 ;; customized values rather than default
|
|
774 ;; values.
|
|
775 (t (nth 3 a2)))))))
|
988
|
776 (while args
|
428
|
777 (let ((entry (car args)))
|
2544
|
778 (if (listp entry)
|
|
779 (let* ((symbol (nth 0 entry))
|
|
780 (value (nth 1 entry))
|
|
781 (now (nth 2 entry))
|
|
782 (requests (nth 3 entry))
|
|
783 (comment (nth 4 entry))
|
|
784 set)
|
|
785 (when requests
|
|
786 (put symbol 'custom-requests requests)
|
|
787 (mapc 'require requests))
|
|
788 (setq set (or (get symbol 'custom-set) 'custom-set-default))
|
|
789 (put symbol 'saved-value (list value))
|
|
790 (put symbol 'saved-variable-comment comment)
|
428
|
791 (custom-push-theme 'theme-value symbol theme 'set value)
|
2544
|
792 ;; Allow for errors in the case where the setter has
|
|
793 ;; changed between versions, say, but let the user know.
|
|
794 (condition-case data
|
|
795 (cond ((or now immediate)
|
|
796 ;; Rogue variable, set it now.
|
|
797 (put symbol 'force-value (if now 'rogue 'immediate))
|
|
798 (funcall set symbol (eval value)))
|
|
799 ((default-boundp symbol)
|
|
800 ;; Something already set this, overwrite it.
|
|
801 (funcall set symbol (eval value))))
|
|
802 (error
|
988
|
803 (message "Error setting %s: %s" symbol data)))
|
2544
|
804 (setq args (cdr args))
|
|
805 (and (or now (default-boundp symbol))
|
|
806 (put symbol 'variable-comment comment)))
|
|
807 ;; Old format, a plist of SYMBOL VALUE pairs.
|
|
808 (message "Warning: old format `custom-set-variables'")
|
|
809 (ding)
|
|
810 (sit-for 2)
|
|
811 (let ((symbol (nth 0 args))
|
|
812 (value (nth 1 args)))
|
|
813 (put symbol 'saved-value (list value))
|
428
|
814 (custom-push-theme 'theme-value symbol theme 'set value))
|
2544
|
815 (setq args (cdr (cdr args))))))))
|
428
|
816
|
988
|
817 (defun custom-set-default (variable value)
|
|
818 "Default :set function for a customizable variable.
|
|
819 Normally, this sets the default value of VARIABLE to VALUE,
|
|
820 but if `custom-local-buffer' is non-nil,
|
|
821 this sets the local binding in that buffer instead."
|
|
822 (if custom-local-buffer
|
|
823 (with-current-buffer custom-local-buffer
|
|
824 (set variable value))
|
|
825 (set-default variable value)))
|
428
|
826
|
2544
|
827 (defun custom-quote (sexp)
|
|
828 "Quote SEXP iff it is not self quoting."
|
|
829 (if (or (memq sexp '(t nil))
|
|
830 (keywordp sexp)
|
|
831 (and (listp sexp)
|
|
832 (memq (car sexp) '(lambda)))
|
|
833 (stringp sexp)
|
|
834 (numberp sexp)
|
|
835 (vectorp sexp)
|
|
836 ;;; (and (fboundp 'characterp)
|
|
837 ;;; (characterp sexp))
|
|
838 )
|
|
839 sexp
|
|
840 (list 'quote sexp)))
|
|
841
|
|
842 (defun customize-mark-to-save (symbol)
|
|
843 "Mark SYMBOL for later saving.
|
|
844
|
|
845 If the default value of SYMBOL is different from the standard value,
|
|
846 set the `saved-value' property to a list whose car evaluates to the
|
|
847 default value. Otherwise, set it to nil.
|
|
848
|
|
849 To actually save the value, call `custom-save-all'.
|
|
850
|
|
851 Return non-nil iff the `saved-value' property actually changed."
|
|
852 (let* ((get (or (get symbol 'custom-get) 'default-value))
|
|
853 (value (funcall get symbol))
|
|
854 (saved (get symbol 'saved-value))
|
|
855 (standard (get symbol 'standard-value))
|
|
856 (comment (get symbol 'customized-variable-comment)))
|
|
857 ;; Save default value iff different from standard value.
|
|
858 (if (or (null standard)
|
|
859 (not (equal value (condition-case nil
|
|
860 (eval (car standard))
|
|
861 (error nil)))))
|
|
862 (put symbol 'saved-value (list (custom-quote value)))
|
|
863 (put symbol 'saved-value nil))
|
|
864 ;; Clear customized information (set, but not saved).
|
|
865 (put symbol 'customized-value nil)
|
|
866 ;; Save any comment that might have been set.
|
|
867 (when comment
|
|
868 (put symbol 'saved-variable-comment comment))
|
|
869 (not (equal saved (get symbol 'saved-value)))))
|
|
870
|
|
871 (defun customize-mark-as-set (symbol)
|
|
872 "Mark current value of SYMBOL as being set from customize.
|
|
873
|
|
874 If the default value of SYMBOL is different from the saved value if any,
|
|
875 or else if it is different from the standard value, set the
|
|
876 `customized-value' property to a list whose car evaluates to the
|
|
877 default value. Otherwise, set it to nil.
|
|
878
|
|
879 Return non-nil iff the `customized-value' property actually changed."
|
|
880 (let* ((get (or (get symbol 'custom-get) 'default-value))
|
|
881 (value (funcall get symbol))
|
|
882 (customized (get symbol 'customized-value))
|
|
883 (old (or (get symbol 'saved-value) (get symbol 'standard-value))))
|
|
884 ;; Mark default value as set iff different from old value.
|
|
885 (if (or (null old)
|
|
886 (not (equal value (condition-case nil
|
|
887 (eval (car old))
|
|
888 (error nil)))))
|
|
889 (put symbol 'customized-value (list (custom-quote value)))
|
|
890 (put symbol 'customized-value nil))
|
|
891 ;; Changed?
|
|
892 (not (equal customized (get symbol 'customized-value)))))
|
|
893
|
|
894 ;;; Theme Manipulation
|
|
895
|
|
896 (defvar custom-loaded-themes nil
|
|
897 "Themes in the order they are loaded.")
|
|
898
|
|
899 (defun custom-theme-loaded-p (theme)
|
|
900 "Return non-nil when THEME has been loaded."
|
|
901 (memq theme custom-loaded-themes))
|
|
902
|
|
903 (defun provide-theme (theme)
|
|
904 "Indicate that this file provides THEME.
|
|
905 Add THEME to `custom-loaded-themes' and `provide' whatever
|
|
906 is stored in THEME's property `theme-feature'.
|
|
907
|
|
908 Usually the theme-feature property contains a symbol created
|
|
909 by `custom-make-theme-feature'."
|
|
910 (custom-check-theme theme)
|
|
911 (provide (get theme 'theme-feature))
|
|
912 (setq custom-loaded-themes (nconc (list theme) custom-loaded-themes)))
|
|
913
|
|
914 (defun require-theme (theme)
|
|
915 "Try to load a theme by requiring its feature.
|
|
916 THEME's feature is stored in THEME's `theme-feature' property.
|
|
917
|
|
918 Usually the `theme-feature' property contains a symbol created
|
|
919 by `custom-make-theme-feature'."
|
|
920 ;; Note we do no check for validity of the theme here.
|
|
921 ;; This allows to pull in themes by a file-name convention
|
|
922 (require (or (get theme 'theme-feature)
|
|
923 (custom-make-theme-feature theme))))
|
|
924
|
|
925 (defun custom-remove-theme (spec-alist theme)
|
|
926 "Delete all elements from SPEC-ALIST whose car is THEME."
|
|
927 (let ((elt (assoc theme spec-alist)))
|
|
928 (while elt
|
|
929 (setq spec-alist (delete elt spec-alist)
|
|
930 elt (assoc theme spec-alist))))
|
|
931 spec-alist)
|
|
932
|
|
933 (defun custom-do-theme-reset (theme)
|
|
934 "Undo all settings defined by THEME.
|
|
935
|
|
936 A variable remains unchanged if its property `theme-value' does not
|
|
937 contain a value for THEME. A face remains unchanged if its property
|
|
938 `theme-face' does not contain a value for THEME. In either case, all
|
|
939 settings for THEME are removed from the property and the variable or
|
|
940 face is set to the `user' theme.
|
428
|
941
|
2544
|
942 See `custom-known-themes' for a list of known themes."
|
|
943 (let (spec-list)
|
|
944 (mapatoms (lambda (symbol)
|
|
945 ;; This works even if symbol is both a variable and a
|
|
946 ;; face.
|
|
947 (setq spec-list (get symbol 'theme-value))
|
|
948 (when spec-list
|
|
949 (put symbol 'theme-value (custom-remove-theme spec-list theme))
|
|
950 (custom-theme-reset-internal symbol 'user))
|
|
951 (setq spec-list (get symbol 'theme-face))
|
|
952 (when spec-list
|
|
953 (put symbol 'theme-face (custom-remove-theme spec-list theme))
|
|
954 (custom-theme-reset-internal-face symbol 'user))))))
|
|
955
|
|
956 (defun custom-theme-load-themes (by-theme &rest body)
|
|
957 "Load the themes specified by BODY.
|
|
958 Record them as required by theme BY-THEME. BODY is a sequence of either
|
|
959
|
|
960 THEME
|
|
961 BY-THEME requires THEME
|
|
962 \(reset THEME)
|
|
963 Undo all the settings made by THEME
|
|
964 \(hidden THEME)
|
|
965 Require THEME but hide it from the user
|
|
966
|
|
967 All the themes loaded for BY-THEME are recorded in BY-THEME's property
|
|
968 `theme-loads-themes'. Any theme loaded with the hidden predicate will
|
|
969 be given the property `theme-hidden' unless it has been loaded before.
|
|
970 Whether a theme has been loaded before is determined by the function
|
|
971 `custom-theme-loaded-p'."
|
|
972 (custom-check-theme by-theme)
|
|
973 (let ((theme)
|
|
974 (themes-loaded (get by-theme 'theme-loads-themes)))
|
|
975 (while theme
|
|
976 (setq theme (car body)
|
|
977 body (cdr body))
|
|
978 (cond ((and (consp theme) (eq (car theme) 'reset))
|
|
979 (custom-do-theme-reset (cadr theme)))
|
|
980 ((and (consp theme) (eq (car theme) 'hidden))
|
|
981 (require-theme (cadr theme))
|
|
982 (unless (custom-theme-loaded-p (cadr theme))
|
|
983 (put (cadr theme) 'theme-hidden t)))
|
|
984 (t
|
|
985 (require-theme theme)
|
|
986 (put theme 'theme-hidden nil)))
|
|
987 (setq themes-loaded (nconc (list theme) themes-loaded)))
|
|
988 (put by-theme 'theme-loads-themes themes-loaded)))
|
|
989
|
|
990 (defun custom-load-themes (&rest body)
|
|
991 "Load themes for the USER theme as specified by BODY.
|
|
992
|
|
993 See `custom-theme-load-themes' for more information on BODY."
|
|
994 (apply 'custom-theme-load-themes 'user body))
|
|
995
|
|
996 ; (defsubst copy-upto-last (elt list)
|
|
997 ; "Copy all the elements of the list upto the last occurrence of elt"
|
|
998 ; ;; Is it faster to do more work in C than to do less in elisp?
|
|
999 ; (nreverse (cdr (member elt (reverse list)))))
|
|
1000
|
|
1001 (defun custom-theme-value (theme theme-spec-list)
|
|
1002 "Determine the value for THEME defined by THEME-SPEC-LIST.
|
|
1003 Returns a list with the original value if found; nil otherwise.
|
|
1004
|
|
1005 THEME-SPEC-LIST is an alist with themes as its key. As new themes are
|
|
1006 installed, these are added to the front of THEME-SPEC-LIST.
|
|
1007 Each element has the form
|
|
1008
|
|
1009 \(THEME MODE VALUE)
|
|
1010
|
|
1011 MODE is either the symbol `set' or the symbol `reset'. See
|
|
1012 `custom-push-theme' for more information on the format of
|
|
1013 THEME-SPEC-LIST."
|
|
1014 ;; Note we do _NOT_ signal an error if the theme is unknown
|
|
1015 ;; it might have gone away without the user knowing.
|
|
1016 (let ((value (cdr (assoc theme theme-spec-list))))
|
|
1017 (if value
|
|
1018 (if (eq (car value) 'set)
|
|
1019 (cdr value)
|
|
1020 (custom-theme-value (cadr value) theme-spec-list)))))
|
|
1021
|
|
1022 (defun custom-theme-variable-value (variable theme)
|
|
1023 "Return (list value) indicating value of VARIABLE in THEME.
|
|
1024 If THEME does not define a value for VARIABLE, return nil. The value
|
|
1025 definitions per theme are stored in VARIABLE's property `theme-value'.
|
|
1026 The actual work is done by function `custom-theme-value', which see.
|
|
1027 See `custom-push-theme' for more information on how these definitions
|
|
1028 are stored."
|
|
1029 (custom-theme-value theme (get variable 'theme-value)))
|
|
1030
|
|
1031 (defun custom-theme-reset-internal (symbol to-theme)
|
|
1032 "Reset SYMBOL to the value defined by TO-THEME.
|
|
1033 If SYMBOL is not defined in TO-THEME, reset SYMBOL to the standard
|
|
1034 value. See `custom-theme-variable-value'. The standard value is
|
|
1035 stored in SYMBOL's property `standard-value'."
|
|
1036 (let ((value (custom-theme-variable-value symbol to-theme))
|
|
1037 was-in-theme)
|
|
1038 (setq was-in-theme value)
|
|
1039 (setq value (or value (get symbol 'standard-value)))
|
|
1040 (when value
|
|
1041 (put symbol 'saved-value was-in-theme)
|
|
1042 (if (or (get 'force-value symbol) (default-boundp symbol))
|
|
1043 (funcall (or (get symbol 'custom-set) 'set-default) symbol
|
|
1044 (eval (car value)))))
|
|
1045 value))
|
|
1046
|
|
1047 (defun custom-theme-reset-variables (theme &rest args)
|
|
1048 "Reset the value of the variables to values previously defined.
|
|
1049 Associate this setting with THEME.
|
|
1050
|
|
1051 ARGS is a list of lists of the form
|
|
1052
|
|
1053 (VARIABLE TO-THEME)
|
|
1054
|
|
1055 This means reset VARIABLE to its value in TO-THEME."
|
|
1056 (custom-check-theme theme)
|
4021
|
1057 (mapcar #'(lambda (arg)
|
|
1058 (apply 'custom-theme-reset-internal arg)
|
|
1059 (custom-push-theme 'theme-value (car arg) theme 'reset (cadr arg)))
|
2544
|
1060 args))
|
|
1061
|
|
1062 (defun custom-reset-variables (&rest args)
|
|
1063 "Reset the value of the variables to values previously saved.
|
|
1064 This is the setting associated the `user' theme.
|
|
1065
|
|
1066 ARGS is a list of lists of the form
|
|
1067
|
|
1068 (VARIABLE TO-THEME)
|
|
1069
|
|
1070 This means reset VARIABLE to its value in TO-THEME."
|
|
1071 (apply 'custom-theme-reset-variables 'user args))
|
|
1072
|
|
1073 ;;; The End.
|
1333
|
1074
|
|
1075 ;; Process the defcustoms for variables loaded before this file.
|
1336
|
1076 ;; `custom-declare-variable-list' is defvar'd in subr.el. Utility programs
|
|
1077 ;; run from temacs that do not load subr.el should defvar it themselves.
|
|
1078 ;; (As of 21.5.11, make-docfile.el.)
|
1333
|
1079 (while custom-declare-variable-list
|
|
1080 (apply 'custom-declare-variable (car custom-declare-variable-list))
|
|
1081 (setq custom-declare-variable-list (cdr custom-declare-variable-list)))
|
|
1082
|
428
|
1083 ;; custom.el ends here
|