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