(cfengine-font-lock-syntactic-keywords): New var.
[bpt/emacs.git] / lisp / custom.el
CommitLineData
55535639
PJ
1;;; custom.el --- tools for declaring and initializing options
2;;
0d30b337 3;; Copyright (C) 1996, 1997, 1999, 2001, 2002, 2003, 2004,
aaef169d 4;; 2005, 2006 Free Software Foundation, Inc.
55535639
PJ
5;;
6;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7;; Maintainer: FSF
8;; Keywords: help, faces
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25;; Boston, MA 02110-1301, USA.
55535639
PJ
26
27;;; Commentary:
28;;
e6bb31f3 29;; This file only contains the code needed to declare and initialize
55535639
PJ
30;; user options. The code to customize options is autoloaded from
31;; `cus-edit.el' and is documented in the Emacs Lisp Reference manual.
32
e6bb31f3 33;; The code implementing face declarations is in `cus-face.el'.
55535639
PJ
34
35;;; Code:
36
37(require 'widget)
38
39(defvar custom-define-hook nil
40 ;; Customize information for this option is in `cus-edit.el'.
41 "Hook called after defining each customize option.")
42
6da43544
RS
43(defvar custom-dont-initialize nil
44 "Non-nil means `defcustom' should not initialize the variable.
45That is used for the sake of `custom-make-dependencies'.
46Users should not set it.")
47
d3b80e9b
SM
48(defvar custom-current-group-alist nil
49 "Alist of (FILE . GROUP) indicating the current group to use for FILE.")
50
55535639
PJ
51;;; The `defcustom' Macro.
52
53(defun custom-initialize-default (symbol value)
54 "Initialize SYMBOL with VALUE.
55This will do nothing if symbol already has a default binding.
56Otherwise, if symbol has a `saved-value' property, it will evaluate
494bcd27 57the car of that and use it as the default binding for symbol.
55535639
PJ
58Otherwise, VALUE will be evaluated and used as the default binding for
59symbol."
60 (unless (default-boundp symbol)
61 ;; Use the saved value if it exists, otherwise the standard setting.
62 (set-default symbol (if (get symbol 'saved-value)
63 (eval (car (get symbol 'saved-value)))
64 (eval value)))))
65
66(defun custom-initialize-set (symbol value)
67 "Initialize SYMBOL based on VALUE.
68If the symbol doesn't have a default binding already,
69then set it using its `:set' function (or `set-default' if it has none).
70The value is either the value in the symbol's `saved-value' property,
71if any, or VALUE."
72 (unless (default-boundp symbol)
73 (funcall (or (get symbol 'custom-set) 'set-default)
74 symbol
75 (if (get symbol 'saved-value)
76 (eval (car (get symbol 'saved-value)))
77 (eval value)))))
78
ff48d7e6
LT
79(defun custom-initialize-safe-set (symbol value)
80 "Like `custom-initialize-set', but catches errors.
81If an error occurs during initialization, SYMBOL is set to nil
82and no error is thrown. This is meant for use in pre-loaded files
f0856b6f 83where some variables or functions used to compute VALUE may not yet
c94112bf 84be defined. You can then re-evaluate VALUE in startup.el, for instance
a042b6ae 85using `custom-reevaluate-setting'."
ff48d7e6
LT
86 (condition-case nil
87 (custom-initialize-set symbol value)
88 (error (set-default symbol nil))))
89
90(defun custom-initialize-safe-default (symbol value)
91 "Like `custom-initialize-default', but catches errors.
92If an error occurs during initialization, SYMBOL is set to nil
93and no error is thrown. This is meant for use in pre-loaded files
f0856b6f 94where some variables or functions used to compute VALUE may not yet
c94112bf 95be defined. You can then re-evaluate VALUE in startup.el, for instance
a042b6ae 96using `custom-reevaluate-setting'."
ff48d7e6
LT
97 (condition-case nil
98 (custom-initialize-default symbol value)
99 (error (set-default symbol nil))))
100
55535639
PJ
101(defun custom-initialize-reset (symbol value)
102 "Initialize SYMBOL based on VALUE.
103Set the symbol, using its `:set' function (or `set-default' if it has none).
104The value is either the symbol's current value
105 \(as obtained using the `:get' function), if any,
106or the value in the symbol's `saved-value' property if any,
107or (last of all) VALUE."
108 (funcall (or (get symbol 'custom-set) 'set-default)
109 symbol
110 (cond ((default-boundp symbol)
111 (funcall (or (get symbol 'custom-get) 'default-value)
112 symbol))
113 ((get symbol 'saved-value)
114 (eval (car (get symbol 'saved-value))))
115 (t
116 (eval value)))))
117
118(defun custom-initialize-changed (symbol value)
119 "Initialize SYMBOL with VALUE.
120Like `custom-initialize-reset', but only use the `:set' function if
121not using the standard setting.
122For the standard setting, use `set-default'."
123 (cond ((default-boundp symbol)
124 (funcall (or (get symbol 'custom-set) 'set-default)
125 symbol
126 (funcall (or (get symbol 'custom-get) 'default-value)
127 symbol)))
128 ((get symbol 'saved-value)
129 (funcall (or (get symbol 'custom-set) 'set-default)
130 symbol
131 (eval (car (get symbol 'saved-value)))))
132 (t
133 (set-default symbol (eval value)))))
134
135(defun custom-declare-variable (symbol default doc &rest args)
136 "Like `defcustom', but SYMBOL and DEFAULT are evaluated as normal arguments.
137DEFAULT should be an expression to evaluate to compute the default value,
e1bab181
RS
138not the default value itself.
139
8989771d 140DEFAULT is stored as SYMBOL's standard value, in SYMBOL's property
e1bab181
RS
141`standard-value'. At the same time, SYMBOL's property `force-value' is
142set to nil, as the value is no longer rogue."
55535639
PJ
143 (put symbol 'standard-value (list default))
144 ;; Maybe this option was rogue in an earlier version. It no longer is.
145 (when (get symbol 'force-value)
146 (put symbol 'force-value nil))
147 (when doc
148 (put symbol 'variable-documentation doc))
149 (let ((initialize 'custom-initialize-reset)
150 (requests nil))
d3b80e9b
SM
151 (unless (memq :group args)
152 (custom-add-to-group (custom-current-group) symbol 'custom-variable))
55535639
PJ
153 (while args
154 (let ((arg (car args)))
155 (setq args (cdr args))
156 (unless (symbolp arg)
157 (error "Junk in args %S" args))
158 (let ((keyword arg)
159 (value (car args)))
160 (unless args
161 (error "Keyword %s is missing an argument" keyword))
162 (setq args (cdr args))
163 (cond ((eq keyword :initialize)
164 (setq initialize value))
165 ((eq keyword :set)
166 (put symbol 'custom-set value))
167 ((eq keyword :get)
168 (put symbol 'custom-get value))
169 ((eq keyword :require)
6f0d61bf 170 (push value requests))
55535639
PJ
171 ((eq keyword :type)
172 (put symbol 'custom-type (purecopy value)))
173 ((eq keyword :options)
174 (if (get symbol 'custom-options)
175 ;; Slow safe code to avoid duplicates.
176 (mapc (lambda (option)
177 (custom-add-option symbol option))
6f0d61bf 178 value)
55535639
PJ
179 ;; Fast code for the common case.
180 (put symbol 'custom-options (copy-sequence value))))
181 (t
182 (custom-handle-keyword symbol keyword value
183 'custom-variable))))))
184 (put symbol 'custom-requests requests)
185 ;; Do the actual initialization.
6da43544
RS
186 (unless custom-dont-initialize
187 (funcall initialize symbol default)))
80888260 188 (push symbol current-load-list)
55535639
PJ
189 (run-hooks 'custom-define-hook)
190 symbol)
191
192(defmacro defcustom (symbol value doc &rest args)
193 "Declare SYMBOL as a customizable variable that defaults to VALUE.
194DOC is the variable documentation.
195
494bcd27 196Neither SYMBOL nor VALUE need to be quoted.
55535639
PJ
197If SYMBOL is not already bound, initialize it to VALUE.
198The remaining arguments should have the form
199
200 [KEYWORD VALUE]...
201
202The following keywords are meaningful:
203
693d0bd3 204:type VALUE should be a widget type for editing the symbol's value.
55535639 205:options VALUE should be a list of valid members of the widget type.
81117bdd
BW
206:initialize
207 VALUE should be a function used to initialize the
208 variable. It takes two arguments, the symbol and value
209 given in the `defcustom' call. The default is
210 `custom-initialize-reset'.
211:set VALUE should be a function to set the value of the symbol.
212 It takes two arguments, the symbol to set and the value to
213 give it. The default choice of function is `custom-set-default'.
214:get VALUE should be a function to extract the value of symbol.
215 The function takes one argument, a symbol, and should return
216 the current value for that symbol. The default choice of function
217 is `custom-default-value'.
218:require
219 VALUE should be a feature symbol. If you save a value
220 for this option, then when your `.emacs' file loads the value,
221 it does (require VALUE) first.
222
223The following common keywords are also meaningful.
224
55535639 225:group VALUE should be a customization group.
81117bdd 226 Add SYMBOL (or FACE with `defface') to that group.
3dc5f18e 227:link LINK-DATA
00644b82
EZ
228 Include an external link after the documentation string for this
229 item. This is a sentence containing an active field which
230 references some other documentation.
71296446 231
11ee7d4e 232 There are several alternatives you can use for LINK-DATA:
71296446 233
3dc5f18e 234 (custom-manual INFO-NODE)
00644b82 235 Link to an Info node; INFO-NODE is a string which specifies
11ee7d4e 236 the node name, as in \"(emacs)Top\".
71296446 237
3dc5f18e 238 (info-link INFO-NODE)
00644b82
EZ
239 Like `custom-manual' except that the link appears in the
240 customization buffer with the Info node name.
71296446 241
3dc5f18e 242 (url-link URL)
00644b82 243 Link to a web page; URL is a string which specifies the URL.
11ee7d4e
JL
244
245 (emacs-commentary-link LIBRARY)
246 Link to the commentary section of LIBRARY.
247
248 (emacs-library-link LIBRARY)
249 Link to an Emacs Lisp LIBRARY file.
250
251 (file-link FILE)
252 Link to FILE.
253
254 (function-link FUNCTION)
255 Link to the documentation of FUNCTION.
256
257 (variable-link VARIABLE)
258 Link to the documentation of VARIABLE.
259
260 (custom-group-link GROUP)
261 Link to another customization GROUP.
71296446 262
00644b82
EZ
263 You can specify the text to use in the customization buffer by
264 adding `:tag NAME' after the first element of the LINK-DATA; for
3dc5f18e 265 example, (info-link :tag \"foo\" \"(emacs)Top\") makes a link to the
00644b82 266 Emacs manual which appears in the buffer as `foo'.
71296446 267
00644b82
EZ
268 An item can have more than one external link; however, most items
269 have none at all.
55535639
PJ
270:version
271 VALUE should be a string specifying that the variable was
272 first introduced, or its default value was changed, in Emacs
273 version VERSION.
4e9c705e 274:package-version
994019df 275 VALUE should be a list with the form (PACKAGE . VERSION)
4e9c705e
BW
276 specifying that the variable was first introduced, or its
277 default value was changed, in PACKAGE version VERSION. This
278 keyword takes priority over :version. The PACKAGE and VERSION
279 must appear in the alist `customize-package-emacs-version-alist'.
994019df
BW
280 Since PACKAGE must be unique and the user might see it in an
281 error message, a good choice is the official name of the
282 package, such as MH-E or Gnus.
00644b82
EZ
283:tag LABEL
284 Use LABEL, a string, instead of the item's name, to label the item
1c1da418 285 in customization menus and buffers.
00644b82
EZ
286:load FILE
287 Load file FILE (a string) before displaying this customization
29512a0f 288 item. Loading is done with `load', and only if the file is
00644b82 289 not already loaded.
64e9f9d9
DL
290:set-after VARIABLES
291 Specifies that SYMBOL should be set after the list of variables
292 VARIABLES when both have been customized.
55535639 293
19229e5e
LT
294If SYMBOL has a local binding, then this form affects the local
295binding. This is normally not what you want. Thus, if you need
296to load a file defining variables with this form, or with
297`defvar' or `defconst', you should always load that file
298_outside_ any bindings for these variables. \(`defvar' and
299`defconst' behave similarly in this respect.)
300
81117bdd
BW
301See Info node `(elisp) Customization' in the Emacs Lisp manual
302for more information."
67a60caa 303 (declare (doc-string 3))
55535639
PJ
304 ;; It is better not to use backquote in this file,
305 ;; because that makes a bootstrapping problem
306 ;; if you need to recompile all the Lisp files using interpreted code.
307 (nconc (list 'custom-declare-variable
308 (list 'quote symbol)
309 (list 'quote value)
310 doc)
311 args))
312
313;;; The `defface' Macro.
314
315(defmacro defface (face spec doc &rest args)
316 "Declare FACE as a customizable face that defaults to SPEC.
317FACE does not need to be quoted.
318
319Third argument DOC is the face documentation.
320
2a69edce 321If FACE has been set with `custom-set-faces', set the face attributes
55535639
PJ
322as specified by that function, otherwise set the face attributes
323according to SPEC.
324
325The remaining arguments should have the form
326
327 [KEYWORD VALUE]...
328
81117bdd
BW
329For a list of valid keywords, see the common keywords listed in
330`defcustom'.
55535639
PJ
331
332SPEC should be an alist of the form ((DISPLAY ATTS)...).
333
9c27debd
RS
334In the first element, DISPLAY can be :default. The ATTS in that
335element then act as defaults for all the following elements.
336
337Aside from that, DISPLAY specifies conditions to match some or
338all frames. For each frame, the first element of SPEC where the
339DISPLAY conditions are satisfied is the one that applies to that
340frame. The ATTRs in this element take effect, and the following
341elements are ignored, on that frame.
342
343In the last element, DISPLAY can be t. That element applies to a
344frame if none of the previous elements (except the :default if
345any) did.
55535639
PJ
346
347ATTS is a list of face attributes followed by their values:
348 (ATTR VALUE ATTR VALUE...)
349
350The possible attributes are `:family', `:width', `:height', `:weight',
351`:slant', `:underline', `:overline', `:strike-through', `:box',
3d58b15e 352`:foreground', `:background', `:stipple', `:inverse-video', and `:inherit'.
55535639 353
9c27debd
RS
354DISPLAY can be `:default' (only in the first element), the symbol
355t (only in the last element) to match all frames, or an alist of
356conditions of the form \(REQ ITEM...). For such an alist to
357match a frame, each of the conditions must be satisfied, meaning
358that the REQ property of the frame must match one of the
359corresponding ITEMs. These are the defined REQ values:
55535639
PJ
360
361`type' (the value of `window-system')
362 Under X, in addition to the values `window-system' can take,
9b44aa8b
JD
363 `motif', `lucid', `gtk' and `x-toolkit' are allowed, and match when
364 the Motif toolkit, Lucid toolkit, GTK toolkit or any X toolkit is in use.
55535639
PJ
365
366`class' (the frame's color support)
367 Should be one of `color', `grayscale', or `mono'.
368
369`background' (what color is used for the background text)
370 Should be one of `light' or `dark'.
371
6e166990
EZ
372`min-colors' (the minimum number of colors the frame should support)
373 Should be an integer, it is compared with the result of
374 `display-color-cells'.
375
ec85856c
JL
376`supports' (only match frames that support the specified face attributes)
377 Should be a list of face attributes. See the documentation for
378 the function `display-supports-face-attributes-p' for more
379 information on exactly how testing is done.
380
81117bdd
BW
381See Info node `(elisp) Customization' in the Emacs Lisp manual
382for more information."
67a60caa 383 (declare (doc-string 3))
55535639
PJ
384 ;; It is better not to use backquote in this file,
385 ;; because that makes a bootstrapping problem
386 ;; if you need to recompile all the Lisp files using interpreted code.
387 (nconc (list 'custom-declare-face (list 'quote face) spec doc) args))
388
389;;; The `defgroup' Macro.
390
d3b80e9b
SM
391(defun custom-current-group ()
392 (cdr (assoc load-file-name custom-current-group-alist)))
393
55535639
PJ
394(defun custom-declare-group (symbol members doc &rest args)
395 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
396 (while members
397 (apply 'custom-add-to-group symbol (car members))
398 (setq members (cdr members)))
55535639
PJ
399 (when doc
400 ;; This text doesn't get into DOC.
401 (put symbol 'group-documentation (purecopy doc)))
402 (while args
403 (let ((arg (car args)))
404 (setq args (cdr args))
405 (unless (symbolp arg)
406 (error "Junk in args %S" args))
407 (let ((keyword arg)
408 (value (car args)))
409 (unless args
410 (error "Keyword %s is missing an argument" keyword))
411 (setq args (cdr args))
412 (cond ((eq keyword :prefix)
413 (put symbol 'custom-prefix value))
414 (t
415 (custom-handle-keyword symbol keyword value
416 'custom-group))))))
d3b80e9b
SM
417 ;; Record the group on the `current' list.
418 (let ((elt (assoc load-file-name custom-current-group-alist)))
419 (if elt (setcdr elt symbol)
420 (push (cons load-file-name symbol) custom-current-group-alist)))
55535639
PJ
421 (run-hooks 'custom-define-hook)
422 symbol)
423
424(defmacro defgroup (symbol members doc &rest args)
425 "Declare SYMBOL as a customization group containing MEMBERS.
426SYMBOL does not need to be quoted.
427
428Third arg DOC is the group documentation.
429
430MEMBERS should be an alist of the form ((NAME WIDGET)...) where
431NAME is a symbol and WIDGET is a widget for editing that symbol.
432Useful widgets are `custom-variable' for editing variables,
433`custom-face' for edit faces, and `custom-group' for editing groups.
434
435The remaining arguments should have the form
436
437 [KEYWORD VALUE]...
438
81117bdd
BW
439For a list of valid keywords, see the common keywords listed in
440`defcustom'.
55535639 441
81117bdd
BW
442See Info node `(elisp) Customization' in the Emacs Lisp manual
443for more information."
45aacac6 444 (declare (doc-string 3))
55535639
PJ
445 ;; It is better not to use backquote in this file,
446 ;; because that makes a bootstrapping problem
447 ;; if you need to recompile all the Lisp files using interpreted code.
448 (nconc (list 'custom-declare-group (list 'quote symbol) members doc) args))
449
450(defun custom-add-to-group (group option widget)
451 "To existing GROUP add a new OPTION of type WIDGET.
452If there already is an entry for OPTION and WIDGET, nothing is done."
453 (let ((members (get group 'custom-group))
454 (entry (list option widget)))
455 (unless (member entry members)
456 (put group 'custom-group (nconc members (list entry))))))
457
29512a0f
SM
458(defun custom-group-of-mode (mode)
459 "Return the custom group corresponding to the major or minor MODE.
460If no such group is found, return nil."
461 (or (get mode 'custom-mode-group)
462 (if (or (get mode 'custom-group)
463 (and (string-match "-mode\\'" (symbol-name mode))
464 (get (setq mode (intern (substring (symbol-name mode)
465 0 (match-beginning 0))))
466 'custom-group)))
467 mode)))
468
55535639
PJ
469;;; Properties.
470
471(defun custom-handle-all-keywords (symbol args type)
472 "For customization option SYMBOL, handle keyword arguments ARGS.
473Third argument TYPE is the custom option type."
d3b80e9b 474 (unless (memq :group args)
9b6098b9 475 (custom-add-to-group (custom-current-group) symbol type))
55535639
PJ
476 (while args
477 (let ((arg (car args)))
478 (setq args (cdr args))
479 (unless (symbolp arg)
480 (error "Junk in args %S" args))
481 (let ((keyword arg)
482 (value (car args)))
483 (unless args
484 (error "Keyword %s is missing an argument" keyword))
485 (setq args (cdr args))
486 (custom-handle-keyword symbol keyword value type)))))
487
488(defun custom-handle-keyword (symbol keyword value type)
489 "For customization option SYMBOL, handle KEYWORD with VALUE.
490Fourth argument TYPE is the custom option type."
491 (if purify-flag
492 (setq value (purecopy value)))
493 (cond ((eq keyword :group)
494 (custom-add-to-group value symbol type))
495 ((eq keyword :version)
496 (custom-add-version symbol value))
4e9c705e
BW
497 ((eq keyword :package-version)
498 (custom-add-package-version symbol value))
55535639
PJ
499 ((eq keyword :link)
500 (custom-add-link symbol value))
501 ((eq keyword :load)
502 (custom-add-load symbol value))
503 ((eq keyword :tag)
504 (put symbol 'custom-tag value))
505 ((eq keyword :set-after)
506 (custom-add-dependencies symbol value))
507 (t
508 (error "Unknown keyword %s" keyword))))
509
510(defun custom-add-dependencies (symbol value)
511 "To the custom option SYMBOL, add dependencies specified by VALUE.
512VALUE should be a list of symbols. For each symbol in that list,
513this specifies that SYMBOL should be set after the specified symbol, if
514both appear in constructs like `custom-set-variables'."
515 (unless (listp value)
516 (error "Invalid custom dependency `%s'" value))
517 (let* ((deps (get symbol 'custom-dependencies))
518 (new-deps deps))
519 (while value
520 (let ((dep (car value)))
521 (unless (symbolp dep)
522 (error "Invalid custom dependency `%s'" dep))
523 (unless (memq dep new-deps)
524 (setq new-deps (cons dep new-deps)))
525 (setq value (cdr value))))
526 (unless (eq deps new-deps)
527 (put symbol 'custom-dependencies new-deps))))
e1bab181 528
55535639
PJ
529(defun custom-add-option (symbol option)
530 "To the variable SYMBOL add OPTION.
531
a4842ffa
RS
532If SYMBOL's custom type is a hook, OPTION should be a hook member.
533If SYMBOL's custom type is an alist, OPTION specifies a symbol
534to offer to the user as a possible key in the alist.
535For other custom types, this has no effect."
55535639
PJ
536 (let ((options (get symbol 'custom-options)))
537 (unless (member option options)
538 (put symbol 'custom-options (cons option options)))))
539
540(defun custom-add-link (symbol widget)
541 "To the custom option SYMBOL add the link WIDGET."
542 (let ((links (get symbol 'custom-links)))
543 (unless (member widget links)
544 (put symbol 'custom-links (cons (purecopy widget) links)))))
545
546(defun custom-add-version (symbol version)
547 "To the custom option SYMBOL add the version VERSION."
548 (put symbol 'custom-version (purecopy version)))
549
4e9c705e
BW
550(defun custom-add-package-version (symbol version)
551 "To the custom option SYMBOL add the package version VERSION."
552 (put symbol 'custom-package-version (purecopy version)))
553
55535639
PJ
554(defun custom-add-load (symbol load)
555 "To the custom option SYMBOL add the dependency LOAD.
556LOAD should be either a library file name, or a feature name."
557 (let ((loads (get symbol 'custom-loads)))
558 (unless (member load loads)
559 (put symbol 'custom-loads (cons (purecopy load) loads)))))
560
d54fbdfd
SM
561(defun custom-autoload (symbol load &optional noset)
562 "Mark SYMBOL as autoloaded custom variable and add dependency LOAD.
563If NOSET is non-nil, don't bother autoloading LOAD when setting the variable."
564 (put symbol 'custom-autoload (if noset 'noset t))
1669290d
MR
565 (custom-add-load symbol load))
566
567;; This test is also in the C code of `user-variable-p'.
568(defun custom-variable-p (variable)
289e1999
LT
569 "Return non-nil if VARIABLE is a custom variable.
570This recursively follows aliases."
571 (setq variable (indirect-variable variable))
1669290d
MR
572 (or (get variable 'standard-value)
573 (get variable 'custom-autoload)))
574
8f772dfd
RS
575;;; Loading files needed to customize a symbol.
576;;; This is in custom.el because menu-bar.el needs it for toggle cmds.
577
578(defvar custom-load-recursion nil
579 "Hack to avoid recursive dependencies.")
580
581(defun custom-load-symbol (symbol)
582 "Load all dependencies for SYMBOL."
583 (unless custom-load-recursion
29512a0f 584 (let ((custom-load-recursion t))
a8c78057
RS
585 ;; Load these files if not already done,
586 ;; to make sure we know all the dependencies of SYMBOL.
587 (condition-case nil
588 (require 'cus-load)
589 (error nil))
590 (condition-case nil
591 (require 'cus-start)
592 (error nil))
29512a0f
SM
593 (dolist (load (get symbol 'custom-loads))
594 (cond ((symbolp load) (condition-case nil (require load) (error nil)))
595 ;; This is subsumed by the test below, but it's much faster.
8f772dfd
RS
596 ((assoc load load-history))
597 ;; This was just (assoc (locate-library load) load-history)
598 ;; but has been optimized not to load locate-library
599 ;; if not necessary.
29512a0f
SM
600 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load)
601 "\\(\\'\\|\\.\\)"))
602 (found nil))
8f772dfd 603 (dolist (loaded load-history)
c3891447
RS
604 (and (stringp (car loaded))
605 (string-match regexp (car loaded))
8f772dfd
RS
606 (setq found t)))
607 found))
608 ;; Without this, we would load cus-edit recursively.
609 ;; We are still loading it when we call this,
610 ;; and it is not in load-history yet.
611 ((equal load "cus-edit"))
29512a0f 612 (t (condition-case nil (load load) (error nil))))))))
46ce5feb 613\f
c2e2f9be
CY
614(defvar custom-local-buffer nil
615 "Non-nil, in a Customization buffer, means customize a specific buffer.
616If this variable is non-nil, it should be a buffer,
617and it means customize the local bindings of that buffer.
618This variable is a permanent local, and it normally has a local binding
619in every Customization buffer.")
620(put 'custom-local-buffer 'permanent-local t)
621
622(defun custom-set-default (variable value)
623 "Default :set function for a customizable variable.
624Normally, this sets the default value of VARIABLE to VALUE,
625but if `custom-local-buffer' is non-nil,
626this sets the local binding in that buffer instead."
627 (if custom-local-buffer
628 (with-current-buffer custom-local-buffer
629 (set variable value))
630 (set-default variable value)))
631
632(defun custom-set-minor-mode (variable value)
633 ":set function for minor mode variables.
634Normally, this sets the default value of VARIABLE to nil if VALUE
635is nil and to t otherwise,
636but if `custom-local-buffer' is non-nil,
637this sets the local binding in that buffer instead."
638 (if custom-local-buffer
639 (with-current-buffer custom-local-buffer
640 (funcall variable (if value 1 0)))
641 (funcall variable (if value 1 0))))
642
643(defun custom-quote (sexp)
644 "Quote SEXP iff it is not self quoting."
645 (if (or (memq sexp '(t nil))
646 (keywordp sexp)
647 (and (listp sexp)
648 (memq (car sexp) '(lambda)))
649 (stringp sexp)
650 (numberp sexp)
651 (vectorp sexp)
652;;; (and (fboundp 'characterp)
653;;; (characterp sexp))
654 )
655 sexp
656 (list 'quote sexp)))
657
658(defun customize-mark-to-save (symbol)
659 "Mark SYMBOL for later saving.
660
661If the default value of SYMBOL is different from the standard value,
662set the `saved-value' property to a list whose car evaluates to the
663default value. Otherwise, set it to nil.
664
665To actually save the value, call `custom-save-all'.
666
667Return non-nil iff the `saved-value' property actually changed."
ec9f0a62 668 (custom-load-symbol symbol)
c2e2f9be
CY
669 (let* ((get (or (get symbol 'custom-get) 'default-value))
670 (value (funcall get symbol))
671 (saved (get symbol 'saved-value))
672 (standard (get symbol 'standard-value))
673 (comment (get symbol 'customized-variable-comment)))
674 ;; Save default value iff different from standard value.
675 (if (or (null standard)
676 (not (equal value (condition-case nil
677 (eval (car standard))
678 (error nil)))))
679 (put symbol 'saved-value (list (custom-quote value)))
680 (put symbol 'saved-value nil))
681 ;; Clear customized information (set, but not saved).
682 (put symbol 'customized-value nil)
683 ;; Save any comment that might have been set.
684 (when comment
685 (put symbol 'saved-variable-comment comment))
686 (not (equal saved (get symbol 'saved-value)))))
687
688(defun customize-mark-as-set (symbol)
689 "Mark current value of SYMBOL as being set from customize.
690
691If the default value of SYMBOL is different from the saved value if any,
692or else if it is different from the standard value, set the
693`customized-value' property to a list whose car evaluates to the
694default value. Otherwise, set it to nil.
695
696Return non-nil iff the `customized-value' property actually changed."
ec9f0a62 697 (custom-load-symbol symbol)
c2e2f9be
CY
698 (let* ((get (or (get symbol 'custom-get) 'default-value))
699 (value (funcall get symbol))
700 (customized (get symbol 'customized-value))
701 (old (or (get symbol 'saved-value) (get symbol 'standard-value))))
702 ;; Mark default value as set iff different from old value.
d54fbdfd
SM
703 (if (not (and old
704 (equal value (condition-case nil
705 (eval (car old))
706 (error nil)))))
fccf2784
CY
707 (progn (put symbol 'customized-value (list (custom-quote value)))
708 (custom-push-theme 'theme-value symbol 'user 'set
709 (custom-quote value)))
c2e2f9be
CY
710 (put symbol 'customized-value nil))
711 ;; Changed?
712 (not (equal customized (get symbol 'customized-value)))))
713
714(defun custom-reevaluate-setting (symbol)
715 "Reset the value of SYMBOL by re-evaluating its saved or standard value.
716Use the :set function to do so. This is useful for customizable options
717that are defined before their standard value can really be computed.
718E.g. dumped variables whose default depends on run-time information."
719 (funcall (or (get symbol 'custom-set) 'set-default)
720 symbol
721 (eval (car (or (get symbol 'saved-value) (get symbol 'standard-value))))))
722
723\f
d358aa10
CY
724;;; Custom Themes
725
726;; Custom themes are collections of settings that can be enabled or
727;; disabled as a unit.
728
729;; Each Custom theme is defined by a symbol, called the theme name.
730;; The `theme-settings' property of the theme name records the
731;; variable and face settings of the theme. This property is a list
732;; of elements, each of the form
733;;
734;; (PROP SYMBOL THEME VALUE)
735;;
736;; - PROP is either `theme-value' or `theme-face'
737;; - SYMBOL is the face or variable name
738;; - THEME is the theme name (redundant, but simplifies the code)
739;; - VALUE is an expression that gives the theme's setting for SYMBOL.
740;;
741;; The theme name also has a `theme-feature' property, whose value is
742;; specified when the theme is defined (see `custom-declare-theme').
743;; Usually, this is just a symbol named THEME-theme. This lets
744;; external libraries call (require 'foo-theme).
745
746;; In addition, each symbol (either a variable or a face) affected by
747;; an *enabled* theme has a `theme-value' or `theme-face' property,
748;; which is a list of elements each of the form
749;;
750;; (THEME VALUE)
751;;
752;; which have the same meanings as in `theme-settings'.
753;;
754;; The `theme-value' and `theme-face' lists are ordered by decreasing
755;; theme precedence. Thus, the first element is always the one that
756;; is in effect.
757
758;; Each theme is stored in a theme file, with filename THEME-theme.el.
759;; Loading a theme basically involves calling (load "THEME-theme")
760;; This is done by the function `load-theme'. Loading a theme
761;; automatically enables it.
762;;
763;; When a theme is enabled, the `theme-value' and `theme-face'
764;; properties for the affected symbols are set. When a theme is
765;; disabled, its settings are removed from the `theme-value' and
766;; `theme-face' properties, but the theme's own `theme-settings'
767;; property remains unchanged.
768
d358aa10 769(defvar custom-known-themes '(user changed)
9c4b6e94 770 "Themes that have been defined with `deftheme'.
d358aa10 771The default value is the list (user changed). The theme `changed'
79a0aa11 772contains the settings before custom themes are applied. The
9b05fb22 773theme `user' contains all the settings the user customized and saved.
e1bab181
RS
774Additional themes declared with the `deftheme' macro will be added to
775the front of this list.")
776
e1bab181
RS
777(defsubst custom-theme-p (theme)
778 "Non-nil when THEME has been defined."
779 (memq theme custom-known-themes))
780
781(defsubst custom-check-theme (theme)
782 "Check whether THEME is valid, and signal an error if it is not."
783 (unless (custom-theme-p theme)
784 (error "Unknown theme `%s'" theme)))
785
d358aa10
CY
786(defun custom-push-theme (prop symbol theme mode &optional value)
787 "Record VALUE for face or variable SYMBOL in custom theme THEME.
788PROP is `theme-face' for a face, `theme-value' for a variable.
e1bab181
RS
789
790MODE can be either the symbol `set' or the symbol `reset'. If it is the
791symbol `set', then VALUE is the value to use. If it is the symbol
d358aa10 792`reset', then SYMBOL will be removed from THEME (VALUE is ignored).
e1bab181 793
e1bab181 794See `custom-known-themes' for a list of known themes."
b2a41d12 795 (unless (memq prop '(theme-value theme-face))
d820f1fb 796 (error "Unknown theme property"))
46ce5feb 797 (let* ((old (get symbol prop))
d358aa10
CY
798 (setting (assq theme old)) ; '(theme value)
799 (theme-settings ; '(prop symbol theme value)
800 (get theme 'theme-settings)))
801 (if (eq mode 'reset)
d820f1fb
CY
802 ;; Remove a setting.
803 (when setting
804 (let (res)
805 (dolist (theme-setting theme-settings)
806 (if (and (eq (car theme-setting) prop)
807 (eq (cadr theme-setting) symbol))
808 (setq res theme-setting)))
809 (put theme 'theme-settings (delq res theme-settings)))
810 (put symbol prop (delq setting old)))
811 (if setting
812 ;; Alter an existing setting.
813 (let (res)
814 (dolist (theme-setting theme-settings)
815 (if (and (eq (car theme-setting) prop)
816 (eq (cadr theme-setting) symbol))
817 (setq res theme-setting)))
818 (put theme 'theme-settings
d358aa10 819 (cons (list prop symbol theme value)
d820f1fb 820 (delq res theme-settings)))
d358aa10 821 (setcar (cdr setting) value))
d820f1fb
CY
822 ;; Add a new setting.
823 ;; If the user changed the value outside of Customize, we
d358aa10 824 ;; first save the current value to a fake theme, `changed'.
d820f1fb
CY
825 ;; This ensures that the user-set value comes back if the
826 ;; theme is later disabled.
827 (if (null old)
828 (if (and (eq prop 'theme-value)
e58d8ef5
CY
829 (boundp symbol))
830 (let ((sv (get symbol 'standard-value)))
d54fbdfd
SM
831 (unless (and sv
832 (equal (eval (car sv)) (symbol-value symbol)))
833 (setq old (list (list 'changed (symbol-value symbol))))))
e02577b7
CY
834 (if (and (facep symbol)
835 (not (face-spec-match-p symbol (get symbol 'face-defface-spec))))
d358aa10 836 (setq old (list (list 'changed (list
d820f1fb 837 (append '(t) (custom-face-attributes-get symbol nil)))))))))
d358aa10 838 (put symbol prop (cons (list theme value) old))
d820f1fb 839 (put theme 'theme-settings
d358aa10 840 (cons (list prop symbol theme value)
d820f1fb 841 theme-settings))))))
55535639 842
c2e2f9be 843\f
55535639 844(defun custom-set-variables (&rest args)
f1a262ed
RS
845 "Install user customizations of variable values specified in ARGS.
846These settings are registered as theme `user'.
64e9f9d9 847The arguments should each be a list of the form:
55535639 848
f1a262ed 849 (SYMBOL EXP [NOW [REQUEST [COMMENT]]])
55535639 850
f1a262ed
RS
851This stores EXP (without evaluating it) as the saved value for SYMBOL.
852If NOW is present and non-nil, then also evaluate EXP and set
853the default value for the SYMBOL to the value of EXP.
e1bab181 854
f1a262ed
RS
855REQUEST is a list of features we must require in order to
856handle SYMBOL properly.
55535639 857COMMENT is a comment string about SYMBOL."
e1bab181
RS
858 (apply 'custom-theme-set-variables 'user args))
859
860(defun custom-theme-set-variables (theme &rest args)
f1a262ed
RS
861 "Initialize variables for theme THEME according to settings in ARGS.
862Each of the arguments in ARGS should be a list of this form:
e1bab181 863
f1a262ed 864 (SYMBOL EXP [NOW [REQUEST [COMMENT]]])
e1bab181 865
f1a262ed
RS
866This stores EXP (without evaluating it) as the saved value for SYMBOL.
867If NOW is present and non-nil, then also evaluate EXP and set
868the default value for the SYMBOL to the value of EXP.
e1bab181 869
f1a262ed
RS
870REQUEST is a list of features we must require in order to
871handle SYMBOL properly.
e1bab181
RS
872COMMENT is a comment string about SYMBOL.
873
f1a262ed 874EXP itself is saved unevaluated as SYMBOL property `saved-value' and
e1bab181
RS
875in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
876 (custom-check-theme theme)
9277ee6c
SM
877
878 ;; Process all the needed autoloads before anything else, so that the
879 ;; subsequent code has all the info it needs (e.g. which var corresponds
880 ;; to a minor mode), regardless of the ordering of the variables.
881 (dolist (entry args)
882 (let* ((symbol (indirect-variable (nth 0 entry))))
883 (unless (or (get symbol 'standard-value)
884 (memq (get symbol 'custom-autoload) '(nil noset)))
885 ;; This symbol needs to be autoloaded, even just for a `set'.
886 (custom-load-symbol symbol))))
887
888 ;; Move minor modes and variables with explicit requires to the end.
059290d6
SM
889 (setq args
890 (sort args
891 (lambda (a1 a2)
892 (let* ((sym1 (car a1))
893 (sym2 (car a2))
894 (1-then-2 (memq sym1 (get sym2 'custom-dependencies)))
895 (2-then-1 (memq sym2 (get sym1 'custom-dependencies))))
896 (cond ((and 1-then-2 2-then-1)
897 (error "Circular custom dependency between `%s' and `%s'"
898 sym1 sym2))
899 (2-then-1 nil)
b6790c3e
SM
900 ;; Put minor modes and symbols with :require last.
901 ;; Putting minor modes last ensures that the mode
902 ;; function will see other customized values rather
903 ;; than default values.
904 (t (or (nth 3 a2)
905 (eq (get sym2 'custom-set)
906 'custom-set-minor-mode))))))))
059290d6
SM
907 (while args
908 (let ((entry (car args)))
909 (if (listp entry)
910 (let* ((symbol (indirect-variable (nth 0 entry)))
911 (value (nth 1 entry))
912 (now (nth 2 entry))
913 (requests (nth 3 entry))
914 (comment (nth 4 entry))
915 set)
916 (when requests
917 (put symbol 'custom-requests requests)
918 (mapc 'require requests))
919 (setq set (or (get symbol 'custom-set) 'custom-set-default))
920 (put symbol 'saved-value (list value))
921 (put symbol 'saved-variable-comment comment)
922 (custom-push-theme 'theme-value symbol theme 'set value)
923 ;; Allow for errors in the case where the setter has
55535639
PJ
924 ;; changed between versions, say, but let the user know.
925 (condition-case data
926 (cond (now
927 ;; Rogue variable, set it now.
928 (put symbol 'force-value t)
929 (funcall set symbol (eval value)))
930 ((default-boundp symbol)
931 ;; Something already set this, overwrite it.
932 (funcall set symbol (eval value))))
71296446 933 (error
55535639 934 (message "Error setting %s: %s" symbol data)))
059290d6
SM
935 (setq args (cdr args))
936 (and (or now (default-boundp symbol))
937 (put symbol 'variable-comment comment)))
d54fbdfd
SM
938 ;; I believe this is dead-code, because the `sort' code above would
939 ;; have burped before we could get here. --Stef
059290d6
SM
940 ;; Old format, a plist of SYMBOL VALUE pairs.
941 (message "Warning: old format `custom-set-variables'")
942 (ding)
943 (sit-for 2)
944 (let ((symbol (indirect-variable (nth 0 args)))
945 (value (nth 1 args)))
946 (put symbol 'saved-value (list value))
947 (custom-push-theme 'theme-value symbol theme 'set value))
948 (setq args (cdr (cdr args)))))))
55535639 949
46ce5feb
RS
950\f
951;;; Defining themes.
952
d358aa10
CY
953;; A theme file should be named `THEME-theme.el' (where THEME is the theme
954;; name), and found in either `custom-theme-directory' or the load path.
955;; It has the following format:
956;;
957;; (deftheme THEME
958;; DOCSTRING)
959;;
960;; (custom-theme-set-variables
961;; 'THEME
962;; [THEME-VARIABLES])
963;;
964;; (custom-theme-set-faces
965;; 'THEME
966;; [THEME-FACES])
967;;
968;; (provide-theme 'THEME)
46ce5feb 969
46ce5feb 970
d358aa10
CY
971;; The IGNORED arguments to deftheme come from the XEmacs theme code, where
972;; they were used to supply keyword-value pairs like `:immediate',
973;; `:variable-reset-string', etc. We don't use any of these, so ignore them.
6d912ee1 974
d358aa10
CY
975(defmacro deftheme (theme &optional doc &rest ignored)
976 "Declare THEME to be a Custom theme.
977The optional argument DOC is a doc string describing the theme.
46ce5feb
RS
978
979Any theme `foo' should be defined in a file called `foo-theme.el';
980see `custom-make-theme-feature' for more information."
981 (let ((feature (custom-make-theme-feature theme)))
982 ;; It is better not to use backquote in this file,
983 ;; because that makes a bootstrapping problem
984 ;; if you need to recompile all the Lisp files using interpreted code.
d358aa10 985 (list 'custom-declare-theme (list 'quote theme) (list 'quote feature) doc)))
46ce5feb 986
d358aa10 987(defun custom-declare-theme (theme feature &optional doc &rest ignored)
46ce5feb 988 "Like `deftheme', but THEME is evaluated as a normal argument.
d358aa10
CY
989FEATURE is the feature this theme provides. Normally, this is a symbol
990created from THEME by `custom-make-theme-feature'."
991 (if (memq theme '(user changed))
992 (error "Custom theme cannot be named %S" theme))
46ce5feb
RS
993 (add-to-list 'custom-known-themes theme)
994 (put theme 'theme-feature feature)
d358aa10 995 (when doc (put theme 'theme-documentation doc)))
46ce5feb
RS
996
997(defun custom-make-theme-feature (theme)
998 "Given a symbol THEME, create a new symbol by appending \"-theme\".
999Store this symbol in the `theme-feature' property of THEME.
1000Calling `provide-theme' to provide THEME actually puts `THEME-theme'
1001into `features'.
1002
1003This allows for a file-name convention for autoloading themes:
1004Every theme X has a property `provide-theme' whose value is \"X-theme\".
87d737ae 1005\(load-theme X) then attempts to load the file `X-theme.el'."
46ce5feb
RS
1006 (intern (concat (symbol-name theme) "-theme")))
1007\f
1008;;; Loading themes.
1009
9c4b6e94
LT
1010(defcustom custom-theme-directory
1011 (if (eq system-type 'ms-dos)
1012 ;; MS-DOS cannot have initial dot.
1013 "~/_emacs.d/"
1014 "~/.emacs.d/")
1015 "Directory in which Custom theme files should be written.
87d737ae 1016`load-theme' searches this directory in addition to load-path.
9c4b6e94
LT
1017The command `customize-create-theme' writes the files it produces
1018into this directory."
1019 :type 'string
1020 :group 'customize
1021 :version "22.1")
1022
e1bab181 1023(defun provide-theme (theme)
d358aa10
CY
1024 "Indicate that this file provides THEME.
1025This calls `provide' to provide the feature name stored in THEME's
1026property `theme-feature' (which is usually a symbol created by
1027`custom-make-theme-feature')."
1028 (if (memq theme '(user changed))
1029 (error "Custom theme cannot be named %S" theme))
e1bab181
RS
1030 (custom-check-theme theme)
1031 (provide (get theme 'theme-feature))
d358aa10 1032 ;; Loading a theme also enables it.
46ce5feb
RS
1033 (push theme custom-enabled-themes)
1034 ;; `user' must always be the highest-precedence enabled theme.
1035 ;; Make that remain true. (This has the effect of making user settings
1036 ;; override the ones just loaded, too.)
d358aa10
CY
1037 (let ((custom-enabling-themes t))
1038 (enable-theme 'user)))
e1bab181 1039
87d737ae 1040(defun load-theme (theme)
73e60f53 1041 "Load a theme's settings from its file.
87d737ae 1042This also enables the theme; use `disable-theme' to disable it."
e1bab181
RS
1043 ;; Note we do no check for validity of the theme here.
1044 ;; This allows to pull in themes by a file-name convention
87d737ae 1045 (interactive "SCustom theme name: ")
73e60f53
CY
1046 ;; If reloading, clear out the old theme settings.
1047 (when (custom-theme-p theme)
1048 (disable-theme theme)
1049 (put theme 'theme-settings nil)
1050 (put theme 'theme-feature nil)
1051 (put theme 'theme-documentation nil))
9c4b6e94
LT
1052 (let ((load-path (if (file-directory-p custom-theme-directory)
1053 (cons custom-theme-directory load-path)
1054 load-path)))
d358aa10 1055 (load (symbol-name (custom-make-theme-feature theme)))))
46ce5feb
RS
1056\f
1057;;; Enabling and disabling loaded themes.
1058
b2a41d12
CY
1059(defvar custom-enabling-themes nil)
1060
87d737ae 1061(defun enable-theme (theme)
46ce5feb
RS
1062 "Reenable all variable and face settings defined by THEME.
1063The newly enabled theme gets the highest precedence (after `user').
e335f09e
CY
1064If it is already enabled, just give it highest precedence (after `user').
1065
d358aa10
CY
1066If THEME does not specify any theme settings, this tries to load
1067the theme from its theme file, by calling `load-theme'."
87d737ae 1068 (interactive "SEnable Custom theme: ")
d358aa10
CY
1069 (if (not (custom-theme-p theme))
1070 (load-theme theme)
1071 ;; This could use a bit of optimization -- cyd
1072 (let ((settings (get theme 'theme-settings)))
1073 (dolist (s settings)
1074 (let* ((prop (car s))
1075 (symbol (cadr s))
1076 (spec-list (get symbol prop)))
1077 (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list)))
1078 (if (eq prop 'theme-value)
1079 (custom-theme-recalc-variable symbol)
1080 (custom-theme-recalc-face symbol)))))
1081 (unless (eq theme 'user)
1082 (setq custom-enabled-themes
1083 (cons theme (delq theme custom-enabled-themes)))
1084 (unless custom-enabling-themes
1085 (enable-theme 'user)))))
b2a41d12
CY
1086
1087(defcustom custom-enabled-themes nil
1088 "List of enabled Custom Themes, highest precedence first.
1089
1090This does not include the `user' theme, which is set by Customize,
1091and always takes precedence over other Custom Themes."
1092 :group 'customize
1093 :type '(repeat symbol)
1094 :set (lambda (symbol themes)
1095 ;; Avoid an infinite loop when custom-enabled-themes is
1096 ;; defined in a theme (e.g. `user'). Enabling the theme sets
1097 ;; custom-enabled-themes, which enables the theme...
1098 (unless custom-enabling-themes
d358aa10 1099 (let ((custom-enabling-themes t) failures)
b2a41d12
CY
1100 (setq themes (delq 'user (delete-dups themes)))
1101 (if (boundp symbol)
1102 (dolist (theme (symbol-value symbol))
1103 (if (not (memq theme themes))
1104 (disable-theme theme))))
1105 (dolist (theme (reverse themes))
d358aa10 1106 (condition-case nil
b2a41d12 1107 (enable-theme theme)
d358aa10
CY
1108 (error (progn (push theme failures)
1109 (setq themes (delq theme themes))))))
b2a41d12 1110 (enable-theme 'user)
d358aa10
CY
1111 (custom-set-default symbol themes)
1112 (if failures
1113 (message "Failed to enable themes: %s"
1114 (mapconcat 'symbol-name failures " ")))))))
b2a41d12 1115
d358aa10 1116(defsubst custom-theme-enabled-p (theme)
b2a41d12
CY
1117 "Return non-nil if THEME is enabled."
1118 (memq theme custom-enabled-themes))
46ce5feb 1119
87d737ae 1120(defun disable-theme (theme)
46ce5feb 1121 "Disable all variable and face settings defined by THEME.
b2a41d12 1122See `custom-enabled-themes' for a list of enabled themes."
d358aa10
CY
1123 (interactive (list (intern
1124 (completing-read
1125 "Disable Custom theme: "
1126 (mapcar 'symbol-name custom-enabled-themes)
1127 nil t))))
1128 (when (custom-theme-enabled-p theme)
8913f945
RS
1129 (let ((settings (get theme 'theme-settings)))
1130 (dolist (s settings)
1131 (let* ((prop (car s))
1132 (symbol (cadr s))
1133 (spec-list (get symbol prop)))
1134 (put symbol prop (assq-delete-all theme spec-list))
1135 (if (eq prop 'theme-value)
1136 (custom-theme-recalc-variable symbol)
b2a41d12
CY
1137 (custom-theme-recalc-face symbol)))))
1138 (setq custom-enabled-themes
1139 (delq theme custom-enabled-themes))))
46ce5feb 1140
46ce5feb
RS
1141(defun custom-variable-theme-value (variable)
1142 "Return (list VALUE) indicating the custom theme value of VARIABLE.
1143That is to say, it specifies what the value should be according to
1144currently enabled custom themes.
1145
1146This function returns nil if no custom theme specifies a value for VARIABLE."
1147 (let* ((theme-value (get variable 'theme-value)))
1148 (if theme-value
d358aa10 1149 (cdr (car theme-value)))))
46ce5feb 1150
46ce5feb
RS
1151(defun custom-theme-recalc-variable (variable)
1152 "Set VARIABLE according to currently enabled custom themes."
1153 (let ((valspec (custom-variable-theme-value variable)))
d358aa10
CY
1154 (if valspec
1155 (put variable 'saved-value valspec)
46ce5feb 1156 (setq valspec (get variable 'standard-value)))
d358aa10
CY
1157 (if (and valspec
1158 (or (get variable 'force-value)
1159 (default-boundp variable)))
1160 (funcall (or (get variable 'custom-set) 'set-default) variable
1161 (eval (car valspec))))))
46ce5feb
RS
1162
1163(defun custom-theme-recalc-face (face)
1164 "Set FACE according to currently enabled custom themes."
b2a41d12
CY
1165 (if (facep face)
1166 (let ((theme-faces (reverse (get face 'theme-face))))
1167 (dolist (spec theme-faces)
d358aa10 1168 (face-spec-set face (cadr spec))))))
46ce5feb 1169\f
d358aa10
CY
1170;;; XEmacs compability functions
1171
1172;; In XEmacs, when you reset a Custom Theme, you have to specify the
1173;; theme to reset it to. We just apply the next available theme, so
1174;; just ignore the IGNORED arguments.
1175
e1bab181 1176(defun custom-theme-reset-variables (theme &rest args)
d358aa10 1177 "Reset some variable settings in THEME to their values in other themes.
46ce5feb 1178Each of the arguments ARGS has this form:
e1bab181 1179
d358aa10 1180 (VARIABLE IGNORED)
e1bab181 1181
7e8b9dc3 1182This means reset VARIABLE. (The argument IGNORED is ignored)."
e1bab181 1183 (custom-check-theme theme)
46ce5feb 1184 (dolist (arg args)
d358aa10 1185 (custom-push-theme 'theme-value (car arg) theme 'reset)))
e1bab181
RS
1186
1187(defun custom-reset-variables (&rest args)
d358aa10 1188 "Reset the specs of some variables to their values in other themes.
46ce5feb 1189This creates settings in the `user' theme.
e1bab181 1190
46ce5feb 1191Each of the arguments ARGS has this form:
e1bab181 1192
d358aa10 1193 (VARIABLE IGNORED)
e1bab181 1194
7e8b9dc3 1195This means reset VARIABLE. (The argument IGNORED is ignored)."
e1bab181
RS
1196 (apply 'custom-theme-reset-variables 'user args))
1197
55535639
PJ
1198;;; The End.
1199
1200;; Process the defcustoms for variables loaded before this file.
1201(while custom-declare-variable-list
1202 (apply 'custom-declare-variable (car custom-declare-variable-list))
1203 (setq custom-declare-variable-list (cdr custom-declare-variable-list)))
1204
1205(provide 'custom)
1206
059290d6 1207;; arch-tag: 041b6116-aabe-4f9a-902d-74092bc3dab2
55535639 1208;;; custom.el ends here