(comment-enter-backward): Fix last fix.
[bpt/emacs.git] / lisp / custom.el
CommitLineData
55535639
PJ
1;;; custom.el --- tools for declaring and initializing options
2;;
0d30b337
TTN
3;; Copyright (C) 1996, 1997, 1999, 2001, 2002, 2003, 2004,
4;; 2005 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
PJ
205:options VALUE should be a list of valid members of the widget type.
206:group VALUE should be a customization group.
207 Add SYMBOL to that group.
3dc5f18e 208:link LINK-DATA
00644b82
EZ
209 Include an external link after the documentation string for this
210 item. This is a sentence containing an active field which
211 references some other documentation.
71296446 212
00644b82 213 There are three alternatives you can use for LINK-DATA:
71296446 214
3dc5f18e 215 (custom-manual INFO-NODE)
00644b82 216 Link to an Info node; INFO-NODE is a string which specifies
3dc5f18e 217 the node name, as in \"(emacs)Top\". The link appears as
00644b82 218 `[manual]' in the customization buffer.
71296446 219
3dc5f18e 220 (info-link INFO-NODE)
00644b82
EZ
221 Like `custom-manual' except that the link appears in the
222 customization buffer with the Info node name.
71296446 223
3dc5f18e 224 (url-link URL)
00644b82
EZ
225 Link to a web page; URL is a string which specifies the URL.
226 The link appears in the customization buffer as URL.
71296446 227
00644b82
EZ
228 You can specify the text to use in the customization buffer by
229 adding `:tag NAME' after the first element of the LINK-DATA; for
3dc5f18e 230 example, (info-link :tag \"foo\" \"(emacs)Top\") makes a link to the
00644b82 231 Emacs manual which appears in the buffer as `foo'.
71296446 232
00644b82
EZ
233 An item can have more than one external link; however, most items
234 have none at all.
55535639
PJ
235:initialize
236 VALUE should be a function used to initialize the
237 variable. It takes two arguments, the symbol and value
238 given in the `defcustom' call. The default is
a01639a3 239 `custom-initialize-reset'.
55535639
PJ
240:set VALUE should be a function to set the value of the symbol.
241 It takes two arguments, the symbol to set and the value to
242 give it. The default choice of function is `custom-set-default'.
243:get VALUE should be a function to extract the value of symbol.
244 The function takes one argument, a symbol, and should return
245 the current value for that symbol. The default choice of function
246 is `custom-default-value'.
247:require
248 VALUE should be a feature symbol. If you save a value
249 for this option, then when your `.emacs' file loads the value,
250 it does (require VALUE) first.
251:version
252 VALUE should be a string specifying that the variable was
253 first introduced, or its default value was changed, in Emacs
254 version VERSION.
00644b82
EZ
255:tag LABEL
256 Use LABEL, a string, instead of the item's name, to label the item
1c1da418 257 in customization menus and buffers.
00644b82
EZ
258:load FILE
259 Load file FILE (a string) before displaying this customization
29512a0f 260 item. Loading is done with `load', and only if the file is
00644b82 261 not already loaded.
64e9f9d9
DL
262:set-after VARIABLES
263 Specifies that SYMBOL should be set after the list of variables
264 VARIABLES when both have been customized.
55535639 265
19229e5e
LT
266If SYMBOL has a local binding, then this form affects the local
267binding. This is normally not what you want. Thus, if you need
268to load a file defining variables with this form, or with
269`defvar' or `defconst', you should always load that file
270_outside_ any bindings for these variables. \(`defvar' and
271`defconst' behave similarly in this respect.)
272
55535639
PJ
273Read the section about customization in the Emacs Lisp manual for more
274information."
67a60caa 275 (declare (doc-string 3))
55535639
PJ
276 ;; It is better not to use backquote in this file,
277 ;; because that makes a bootstrapping problem
278 ;; if you need to recompile all the Lisp files using interpreted code.
279 (nconc (list 'custom-declare-variable
280 (list 'quote symbol)
281 (list 'quote value)
282 doc)
283 args))
284
285;;; The `defface' Macro.
286
287(defmacro defface (face spec doc &rest args)
288 "Declare FACE as a customizable face that defaults to SPEC.
289FACE does not need to be quoted.
290
291Third argument DOC is the face documentation.
292
2a69edce 293If FACE has been set with `custom-set-faces', set the face attributes
55535639
PJ
294as specified by that function, otherwise set the face attributes
295according to SPEC.
296
297The remaining arguments should have the form
298
299 [KEYWORD VALUE]...
300
301The following KEYWORDs are defined:
302
303:group VALUE should be a customization group.
304 Add FACE to that group.
305
306SPEC should be an alist of the form ((DISPLAY ATTS)...).
307
9c27debd
RS
308In the first element, DISPLAY can be :default. The ATTS in that
309element then act as defaults for all the following elements.
310
311Aside from that, DISPLAY specifies conditions to match some or
312all frames. For each frame, the first element of SPEC where the
313DISPLAY conditions are satisfied is the one that applies to that
314frame. The ATTRs in this element take effect, and the following
315elements are ignored, on that frame.
316
317In the last element, DISPLAY can be t. That element applies to a
318frame if none of the previous elements (except the :default if
319any) did.
55535639
PJ
320
321ATTS is a list of face attributes followed by their values:
322 (ATTR VALUE ATTR VALUE...)
323
324The possible attributes are `:family', `:width', `:height', `:weight',
325`:slant', `:underline', `:overline', `:strike-through', `:box',
3d58b15e 326`:foreground', `:background', `:stipple', `:inverse-video', and `:inherit'.
55535639 327
9c27debd
RS
328DISPLAY can be `:default' (only in the first element), the symbol
329t (only in the last element) to match all frames, or an alist of
330conditions of the form \(REQ ITEM...). For such an alist to
331match a frame, each of the conditions must be satisfied, meaning
332that the REQ property of the frame must match one of the
333corresponding ITEMs. These are the defined REQ values:
55535639
PJ
334
335`type' (the value of `window-system')
336 Under X, in addition to the values `window-system' can take,
9b44aa8b
JD
337 `motif', `lucid', `gtk' and `x-toolkit' are allowed, and match when
338 the Motif toolkit, Lucid toolkit, GTK toolkit or any X toolkit is in use.
55535639
PJ
339
340`class' (the frame's color support)
341 Should be one of `color', `grayscale', or `mono'.
342
343`background' (what color is used for the background text)
344 Should be one of `light' or `dark'.
345
6e166990
EZ
346`min-colors' (the minimum number of colors the frame should support)
347 Should be an integer, it is compared with the result of
348 `display-color-cells'.
349
ec85856c
JL
350`supports' (only match frames that support the specified face attributes)
351 Should be a list of face attributes. See the documentation for
352 the function `display-supports-face-attributes-p' for more
353 information on exactly how testing is done.
354
55535639
PJ
355Read the section about customization in the Emacs Lisp manual for more
356information."
67a60caa 357 (declare (doc-string 3))
55535639
PJ
358 ;; It is better not to use backquote in this file,
359 ;; because that makes a bootstrapping problem
360 ;; if you need to recompile all the Lisp files using interpreted code.
361 (nconc (list 'custom-declare-face (list 'quote face) spec doc) args))
362
363;;; The `defgroup' Macro.
364
d3b80e9b
SM
365(defun custom-current-group ()
366 (cdr (assoc load-file-name custom-current-group-alist)))
367
55535639
PJ
368(defun custom-declare-group (symbol members doc &rest args)
369 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
370 (while members
371 (apply 'custom-add-to-group symbol (car members))
372 (setq members (cdr members)))
55535639
PJ
373 (when doc
374 ;; This text doesn't get into DOC.
375 (put symbol 'group-documentation (purecopy doc)))
376 (while args
377 (let ((arg (car args)))
378 (setq args (cdr args))
379 (unless (symbolp arg)
380 (error "Junk in args %S" args))
381 (let ((keyword arg)
382 (value (car args)))
383 (unless args
384 (error "Keyword %s is missing an argument" keyword))
385 (setq args (cdr args))
386 (cond ((eq keyword :prefix)
387 (put symbol 'custom-prefix value))
388 (t
389 (custom-handle-keyword symbol keyword value
390 'custom-group))))))
d3b80e9b
SM
391 ;; Record the group on the `current' list.
392 (let ((elt (assoc load-file-name custom-current-group-alist)))
393 (if elt (setcdr elt symbol)
394 (push (cons load-file-name symbol) custom-current-group-alist)))
55535639
PJ
395 (run-hooks 'custom-define-hook)
396 symbol)
397
398(defmacro defgroup (symbol members doc &rest args)
399 "Declare SYMBOL as a customization group containing MEMBERS.
400SYMBOL does not need to be quoted.
401
402Third arg DOC is the group documentation.
403
404MEMBERS should be an alist of the form ((NAME WIDGET)...) where
405NAME is a symbol and WIDGET is a widget for editing that symbol.
406Useful widgets are `custom-variable' for editing variables,
407`custom-face' for edit faces, and `custom-group' for editing groups.
408
409The remaining arguments should have the form
410
411 [KEYWORD VALUE]...
412
413The following KEYWORDs are defined:
414
415:group VALUE should be a customization group.
416 Add SYMBOL to that group.
417
418:version VALUE should be a string specifying that the group was introduced
419 in Emacs version VERSION.
420
421Read the section about customization in the Emacs Lisp manual for more
422information."
423 ;; It is better not to use backquote in this file,
424 ;; because that makes a bootstrapping problem
425 ;; if you need to recompile all the Lisp files using interpreted code.
426 (nconc (list 'custom-declare-group (list 'quote symbol) members doc) args))
427
428(defun custom-add-to-group (group option widget)
429 "To existing GROUP add a new OPTION of type WIDGET.
430If there already is an entry for OPTION and WIDGET, nothing is done."
431 (let ((members (get group 'custom-group))
432 (entry (list option widget)))
433 (unless (member entry members)
434 (put group 'custom-group (nconc members (list entry))))))
435
29512a0f
SM
436(defun custom-group-of-mode (mode)
437 "Return the custom group corresponding to the major or minor MODE.
438If no such group is found, return nil."
439 (or (get mode 'custom-mode-group)
440 (if (or (get mode 'custom-group)
441 (and (string-match "-mode\\'" (symbol-name mode))
442 (get (setq mode (intern (substring (symbol-name mode)
443 0 (match-beginning 0))))
444 'custom-group)))
445 mode)))
446
55535639
PJ
447;;; Properties.
448
449(defun custom-handle-all-keywords (symbol args type)
450 "For customization option SYMBOL, handle keyword arguments ARGS.
451Third argument TYPE is the custom option type."
d3b80e9b 452 (unless (memq :group args)
9b6098b9 453 (custom-add-to-group (custom-current-group) symbol type))
55535639
PJ
454 (while args
455 (let ((arg (car args)))
456 (setq args (cdr args))
457 (unless (symbolp arg)
458 (error "Junk in args %S" args))
459 (let ((keyword arg)
460 (value (car args)))
461 (unless args
462 (error "Keyword %s is missing an argument" keyword))
463 (setq args (cdr args))
464 (custom-handle-keyword symbol keyword value type)))))
465
466(defun custom-handle-keyword (symbol keyword value type)
467 "For customization option SYMBOL, handle KEYWORD with VALUE.
468Fourth argument TYPE is the custom option type."
469 (if purify-flag
470 (setq value (purecopy value)))
471 (cond ((eq keyword :group)
472 (custom-add-to-group value symbol type))
473 ((eq keyword :version)
474 (custom-add-version symbol value))
475 ((eq keyword :link)
476 (custom-add-link symbol value))
477 ((eq keyword :load)
478 (custom-add-load symbol value))
479 ((eq keyword :tag)
480 (put symbol 'custom-tag value))
481 ((eq keyword :set-after)
482 (custom-add-dependencies symbol value))
483 (t
484 (error "Unknown keyword %s" keyword))))
485
486(defun custom-add-dependencies (symbol value)
487 "To the custom option SYMBOL, add dependencies specified by VALUE.
488VALUE should be a list of symbols. For each symbol in that list,
489this specifies that SYMBOL should be set after the specified symbol, if
490both appear in constructs like `custom-set-variables'."
491 (unless (listp value)
492 (error "Invalid custom dependency `%s'" value))
493 (let* ((deps (get symbol 'custom-dependencies))
494 (new-deps deps))
495 (while value
496 (let ((dep (car value)))
497 (unless (symbolp dep)
498 (error "Invalid custom dependency `%s'" dep))
499 (unless (memq dep new-deps)
500 (setq new-deps (cons dep new-deps)))
501 (setq value (cdr value))))
502 (unless (eq deps new-deps)
503 (put symbol 'custom-dependencies new-deps))))
e1bab181 504
55535639
PJ
505(defun custom-add-option (symbol option)
506 "To the variable SYMBOL add OPTION.
507
a4842ffa
RS
508If SYMBOL's custom type is a hook, OPTION should be a hook member.
509If SYMBOL's custom type is an alist, OPTION specifies a symbol
510to offer to the user as a possible key in the alist.
511For other custom types, this has no effect."
55535639
PJ
512 (let ((options (get symbol 'custom-options)))
513 (unless (member option options)
514 (put symbol 'custom-options (cons option options)))))
515
516(defun custom-add-link (symbol widget)
517 "To the custom option SYMBOL add the link WIDGET."
518 (let ((links (get symbol 'custom-links)))
519 (unless (member widget links)
520 (put symbol 'custom-links (cons (purecopy widget) links)))))
521
522(defun custom-add-version (symbol version)
523 "To the custom option SYMBOL add the version VERSION."
524 (put symbol 'custom-version (purecopy version)))
525
526(defun custom-add-load (symbol load)
527 "To the custom option SYMBOL add the dependency LOAD.
528LOAD should be either a library file name, or a feature name."
529 (let ((loads (get symbol 'custom-loads)))
530 (unless (member load loads)
531 (put symbol 'custom-loads (cons (purecopy load) loads)))))
532
1669290d
MR
533(defun custom-autoload (symbol load)
534 "Mark SYMBOL as autoloaded custom variable and add dependency LOAD."
535 (put symbol 'custom-autoload t)
536 (custom-add-load symbol load))
537
538;; This test is also in the C code of `user-variable-p'.
539(defun custom-variable-p (variable)
289e1999
LT
540 "Return non-nil if VARIABLE is a custom variable.
541This recursively follows aliases."
542 (setq variable (indirect-variable variable))
1669290d
MR
543 (or (get variable 'standard-value)
544 (get variable 'custom-autoload)))
545
8f772dfd
RS
546;;; Loading files needed to customize a symbol.
547;;; This is in custom.el because menu-bar.el needs it for toggle cmds.
548
549(defvar custom-load-recursion nil
550 "Hack to avoid recursive dependencies.")
551
552(defun custom-load-symbol (symbol)
553 "Load all dependencies for SYMBOL."
554 (unless custom-load-recursion
29512a0f 555 (let ((custom-load-recursion t))
a8c78057
RS
556 ;; Load these files if not already done,
557 ;; to make sure we know all the dependencies of SYMBOL.
558 (condition-case nil
559 (require 'cus-load)
560 (error nil))
561 (condition-case nil
562 (require 'cus-start)
563 (error nil))
29512a0f
SM
564 (dolist (load (get symbol 'custom-loads))
565 (cond ((symbolp load) (condition-case nil (require load) (error nil)))
566 ;; This is subsumed by the test below, but it's much faster.
8f772dfd
RS
567 ((assoc load load-history))
568 ;; This was just (assoc (locate-library load) load-history)
569 ;; but has been optimized not to load locate-library
570 ;; if not necessary.
29512a0f
SM
571 ((let ((regexp (concat "\\(\\`\\|/\\)" (regexp-quote load)
572 "\\(\\'\\|\\.\\)"))
573 (found nil))
8f772dfd 574 (dolist (loaded load-history)
c3891447
RS
575 (and (stringp (car loaded))
576 (string-match regexp (car loaded))
8f772dfd
RS
577 (setq found t)))
578 found))
579 ;; Without this, we would load cus-edit recursively.
580 ;; We are still loading it when we call this,
581 ;; and it is not in load-history yet.
582 ((equal load "cus-edit"))
29512a0f 583 (t (condition-case nil (load load) (error nil))))))))
46ce5feb 584\f
e1bab181 585(defvar custom-known-themes '(user standard)
9c4b6e94 586 "Themes that have been defined with `deftheme'.
e1bab181 587The default value is the list (user standard). The theme `standard'
79a0aa11 588contains the settings before custom themes are applied. The
9b05fb22 589theme `user' contains all the settings the user customized and saved.
e1bab181
RS
590Additional themes declared with the `deftheme' macro will be added to
591the front of this list.")
592
e1bab181
RS
593(defsubst custom-theme-p (theme)
594 "Non-nil when THEME has been defined."
595 (memq theme custom-known-themes))
596
597(defsubst custom-check-theme (theme)
598 "Check whether THEME is valid, and signal an error if it is not."
599 (unless (custom-theme-p theme)
600 (error "Unknown theme `%s'" theme)))
601
55535639
PJ
602;;; Initializing.
603
e1bab181 604(defun custom-push-theme (prop symbol theme mode value)
46ce5feb
RS
605 "Record a value for face or variable SYMBOL in custom theme THEME.
606PROP is`theme-face' for a face, `theme-value' for a variable.
607The value is specified by (THEME MODE VALUE), which is interpreted
608by `custom-theme-value'.
e1bab181
RS
609
610MODE can be either the symbol `set' or the symbol `reset'. If it is the
611symbol `set', then VALUE is the value to use. If it is the symbol
46ce5feb
RS
612`reset', then VALUE is another theme, whose value for this face or
613variable should be used.
e1bab181
RS
614
615In the following example for the variable `goto-address-url-face', the
616theme `subtle-hacker' uses the same value for the variable as the theme
617`gnome2':
618
619 \((standard set bold)
620 \(gnome2 set info-xref)
621 \(jonadab set underline)
622 \(subtle-hacker reset gnome2))
623
624
625If a value has been stored for themes A B and C, and a new value
626is to be stored for theme C, then the old value of C is discarded.
627If a new value is to be stored for theme B, however, the old value
628of B is not discarded because B is not the car of the list.
629
630For variables, list property PROP is `theme-value'.
631For faces, list property PROP is `theme-face'.
632This is used in `custom-do-theme-reset', for example.
633
634The list looks the same in any case; the examples shows a possible
635value of the `theme-face' property for the face `region':
636
637 \((gnome2 set ((t (:foreground \"cyan\" :background \"dark cyan\"))))
638 \(standard set ((((class color) (background dark))
639 \(:background \"blue\"))
640 \(t (:background \"gray\")))))
641
642This records values for the `standard' and the `gnome2' themes.
643The user has not customized the face; had he done that,
644the list would contain an entry for the `user' theme, too.
645See `custom-known-themes' for a list of known themes."
46ce5feb
RS
646 (let* ((old (get symbol prop))
647 (setting (assq theme old)))
648 ;; Alter an existing theme-setting for the symbol,
649 ;; or add a new one.
650 (if setting
651 (progn
652 (setcar (cdr setting) mode)
653 (setcar (cddr setting) value))
d5c16b05
CY
654 ;; If no custom theme has been applied yet, first save the
655 ;; current values to the 'standard theme.
656 (if (null old)
657 (if (and (eq prop 'theme-value)
658 (boundp symbol))
659 (setq old
660 (list (list 'standard 'set (symbol-value symbol))))
661 (if (facep symbol)
662 (setq old (list (list 'standard 'set (list
663 (append '(t) (custom-face-attributes-get symbol nil)))))))))
46ce5feb
RS
664 (put symbol prop (cons (list theme mode value) old)))
665 ;; Record, for each theme, all its settings.
666 (put theme 'theme-settings
667 (cons (list prop symbol theme mode value)
668 (get theme 'theme-settings)))))
669\f
55535639
PJ
670(defvar custom-local-buffer nil
671 "Non-nil, in a Customization buffer, means customize a specific buffer.
672If this variable is non-nil, it should be a buffer,
673and it means customize the local bindings of that buffer.
674This variable is a permanent local, and it normally has a local binding
675in every Customization buffer.")
676(put 'custom-local-buffer 'permanent-local t)
677
678(defun custom-set-variables (&rest args)
f1a262ed
RS
679 "Install user customizations of variable values specified in ARGS.
680These settings are registered as theme `user'.
64e9f9d9 681The arguments should each be a list of the form:
55535639 682
f1a262ed 683 (SYMBOL EXP [NOW [REQUEST [COMMENT]]])
55535639 684
f1a262ed
RS
685This stores EXP (without evaluating it) as the saved value for SYMBOL.
686If NOW is present and non-nil, then also evaluate EXP and set
687the default value for the SYMBOL to the value of EXP.
e1bab181 688
f1a262ed
RS
689REQUEST is a list of features we must require in order to
690handle SYMBOL properly.
55535639 691COMMENT is a comment string about SYMBOL."
e1bab181
RS
692 (apply 'custom-theme-set-variables 'user args))
693
059290d6 694(defun custom-reevaluate-setting (symbol)
05126894
LT
695 "Reset the value of SYMBOL by re-evaluating its saved or standard value.
696Use the :set function to do so. This is useful for customizable options
697that are defined before their standard value can really be computed.
698E.g. dumped variables whose default depends on run-time information."
059290d6
SM
699 (funcall (or (get symbol 'custom-set) 'set-default)
700 symbol
701 (eval (car (or (get symbol 'saved-value) (get symbol 'standard-value))))))
702
e1bab181 703(defun custom-theme-set-variables (theme &rest args)
f1a262ed
RS
704 "Initialize variables for theme THEME according to settings in ARGS.
705Each of the arguments in ARGS should be a list of this form:
e1bab181 706
f1a262ed 707 (SYMBOL EXP [NOW [REQUEST [COMMENT]]])
e1bab181 708
f1a262ed
RS
709This stores EXP (without evaluating it) as the saved value for SYMBOL.
710If NOW is present and non-nil, then also evaluate EXP and set
711the default value for the SYMBOL to the value of EXP.
e1bab181 712
f1a262ed
RS
713REQUEST is a list of features we must require in order to
714handle SYMBOL properly.
e1bab181
RS
715COMMENT is a comment string about SYMBOL.
716
717Several properties of THEME and SYMBOL are used in the process:
718
f1a262ed
RS
719If THEME's property `theme-immediate' is non-nil, this is equivalent of
720providing the NOW argument to all symbols in the argument list:
721evaluate each EXP and set the corresponding SYMBOL. However,
722there's a difference in the handling of SYMBOL's property
e1bab181
RS
723`force-value': if NOW is non-nil, SYMBOL's property `force-value' is set to
724the symbol `rogue', else if THEME's property `theme-immediate' is non-nil,
f1a262ed 725SYMBOL's property `force-value' is set to the symbol `immediate'.
e1bab181 726
f1a262ed 727EXP itself is saved unevaluated as SYMBOL property `saved-value' and
e1bab181
RS
728in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
729 (custom-check-theme theme)
059290d6
SM
730 (setq args
731 (sort args
732 (lambda (a1 a2)
733 (let* ((sym1 (car a1))
734 (sym2 (car a2))
735 (1-then-2 (memq sym1 (get sym2 'custom-dependencies)))
736 (2-then-1 (memq sym2 (get sym1 'custom-dependencies))))
737 (cond ((and 1-then-2 2-then-1)
738 (error "Circular custom dependency between `%s' and `%s'"
739 sym1 sym2))
740 (2-then-1 nil)
b6790c3e
SM
741 ;; Put minor modes and symbols with :require last.
742 ;; Putting minor modes last ensures that the mode
743 ;; function will see other customized values rather
744 ;; than default values.
745 (t (or (nth 3 a2)
746 (eq (get sym2 'custom-set)
747 'custom-set-minor-mode))))))))
059290d6
SM
748 (while args
749 (let ((entry (car args)))
750 (if (listp entry)
751 (let* ((symbol (indirect-variable (nth 0 entry)))
752 (value (nth 1 entry))
753 (now (nth 2 entry))
754 (requests (nth 3 entry))
755 (comment (nth 4 entry))
756 set)
757 (when requests
758 (put symbol 'custom-requests requests)
759 (mapc 'require requests))
760 (setq set (or (get symbol 'custom-set) 'custom-set-default))
761 (put symbol 'saved-value (list value))
762 (put symbol 'saved-variable-comment comment)
763 (custom-push-theme 'theme-value symbol theme 'set value)
764 ;; Allow for errors in the case where the setter has
55535639
PJ
765 ;; changed between versions, say, but let the user know.
766 (condition-case data
767 (cond (now
768 ;; Rogue variable, set it now.
769 (put symbol 'force-value t)
770 (funcall set symbol (eval value)))
771 ((default-boundp symbol)
772 ;; Something already set this, overwrite it.
773 (funcall set symbol (eval value))))
71296446 774 (error
55535639 775 (message "Error setting %s: %s" symbol data)))
059290d6
SM
776 (setq args (cdr args))
777 (and (or now (default-boundp symbol))
778 (put symbol 'variable-comment comment)))
779 ;; Old format, a plist of SYMBOL VALUE pairs.
780 (message "Warning: old format `custom-set-variables'")
781 (ding)
782 (sit-for 2)
783 (let ((symbol (indirect-variable (nth 0 args)))
784 (value (nth 1 args)))
785 (put symbol 'saved-value (list value))
786 (custom-push-theme 'theme-value symbol theme 'set value))
787 (setq args (cdr (cdr args)))))))
55535639
PJ
788
789(defun custom-set-default (variable value)
790 "Default :set function for a customizable variable.
791Normally, this sets the default value of VARIABLE to VALUE,
792but if `custom-local-buffer' is non-nil,
793this sets the local binding in that buffer instead."
794 (if custom-local-buffer
795 (with-current-buffer custom-local-buffer
796 (set variable value))
797 (set-default variable value)))
798
df380962
SM
799(defun custom-set-minor-mode (variable value)
800 ":set function for minor mode variables.
801Normally, this sets the default value of VARIABLE to nil if VALUE
802is nil and to t otherwise,
803but if `custom-local-buffer' is non-nil,
804this sets the local binding in that buffer instead."
805 (if custom-local-buffer
806 (with-current-buffer custom-local-buffer
5c5fc296
LT
807 (funcall variable (if value 1 0)))
808 (funcall variable (if value 1 0))))
df380962 809
6d912ee1
MB
810(defun custom-quote (sexp)
811 "Quote SEXP iff it is not self quoting."
812 (if (or (memq sexp '(t nil))
813 (keywordp sexp)
814 (and (listp sexp)
815 (memq (car sexp) '(lambda)))
816 (stringp sexp)
817 (numberp sexp)
818 (vectorp sexp)
819;;; (and (fboundp 'characterp)
820;;; (characterp sexp))
821 )
822 sexp
823 (list 'quote sexp)))
824
825(defun customize-mark-to-save (symbol)
826 "Mark SYMBOL for later saving.
827
71296446 828If the default value of SYMBOL is different from the standard value,
6d912ee1 829set the `saved-value' property to a list whose car evaluates to the
e2cd29bd 830default value. Otherwise, set it to nil.
6d912ee1
MB
831
832To actually save the value, call `custom-save-all'.
833
834Return non-nil iff the `saved-value' property actually changed."
835 (let* ((get (or (get symbol 'custom-get) 'default-value))
836 (value (funcall get symbol))
837 (saved (get symbol 'saved-value))
838 (standard (get symbol 'standard-value))
839 (comment (get symbol 'customized-variable-comment)))
840 ;; Save default value iff different from standard value.
841 (if (or (null standard)
842 (not (equal value (condition-case nil
843 (eval (car standard))
844 (error nil)))))
845 (put symbol 'saved-value (list (custom-quote value)))
846 (put symbol 'saved-value nil))
847 ;; Clear customized information (set, but not saved).
848 (put symbol 'customized-value nil)
849 ;; Save any comment that might have been set.
850 (when comment
851 (put symbol 'saved-variable-comment comment))
852 (not (equal saved (get symbol 'saved-value)))))
853
854(defun customize-mark-as-set (symbol)
855 "Mark current value of SYMBOL as being set from customize.
856
71296446 857If the default value of SYMBOL is different from the saved value if any,
6d912ee1 858or else if it is different from the standard value, set the
71296446 859`customized-value' property to a list whose car evaluates to the
e2cd29bd 860default value. Otherwise, set it to nil.
6d912ee1
MB
861
862Return non-nil iff the `customized-value' property actually changed."
863 (let* ((get (or (get symbol 'custom-get) 'default-value))
864 (value (funcall get symbol))
865 (customized (get symbol 'customized-value))
866 (old (or (get symbol 'saved-value) (get symbol 'standard-value))))
867 ;; Mark default value as set iff different from old value.
868 (if (or (null old)
71296446 869 (not (equal value (condition-case nil
6d912ee1
MB
870 (eval (car old))
871 (error nil)))))
872 (put symbol 'customized-value (list (custom-quote value)))
873 (put symbol 'customized-value nil))
874 ;; Changed?
875 (not (equal customized (get symbol 'customized-value)))))
46ce5feb
RS
876\f
877;;; Defining themes.
878
879;; deftheme is used at the beginning of the file that records a theme.
880
881(defmacro deftheme (theme &optional doc &rest args)
882 "Declare custom theme THEME.
883The optional argument DOC is a doc string describing the theme.
884The remaining arguments should have the form
885
886 [KEYWORD VALUE]...
6d912ee1 887
46ce5feb
RS
888The following KEYWORD's are defined:
889
890:short-description
891 VALUE is a short (one line) description of the theme. If not
892 given, DOC is used.
893:immediate
894 If VALUE is non-nil, variables specified in this theme are set
895 immediately when loading the theme.
896:variable-set-string
897 VALUE is a string used to indicate that a variable takes its
898 setting from this theme. It is passed to FORMAT with the name
899 of the theme as an additional argument. If not given, a
900 generic description is used.
901:variable-reset-string
902 VALUE is a string used in the case a variable has been forced
903 to its value in this theme. It is passed to FORMAT with the
904 name of the theme as an additional argument. If not given, a
905 generic description is used.
906:face-set-string
907 VALUE is a string used to indicate that a face takes its
908 setting from this theme. It is passed to FORMAT with the name
909 of the theme as an additional argument. If not given, a
910 generic description is used.
911:face-reset-string
912 VALUE is a string used in the case a face has been forced to
913 its value in this theme. It is passed to FORMAT with the name
914 of the theme as an additional argument. If not given, a
915 generic description is used.
916
917Any theme `foo' should be defined in a file called `foo-theme.el';
918see `custom-make-theme-feature' for more information."
919 (let ((feature (custom-make-theme-feature theme)))
920 ;; It is better not to use backquote in this file,
921 ;; because that makes a bootstrapping problem
922 ;; if you need to recompile all the Lisp files using interpreted code.
923 (nconc (list 'custom-declare-theme
924 (list 'quote theme)
925 (list 'quote feature)
926 doc)
927 args)))
928
929(defun custom-declare-theme (theme feature &optional doc &rest args)
930 "Like `deftheme', but THEME is evaluated as a normal argument.
931FEATURE is the feature this theme provides. This symbol is created
932from THEME by `custom-make-theme-feature'."
933 (add-to-list 'custom-known-themes theme)
934 (put theme 'theme-feature feature)
935 (when doc
936 (put theme 'theme-documentation doc))
937 (while args
938 (let ((arg (car args)))
939 (setq args (cdr args))
940 (unless (symbolp arg)
941 (error "Junk in args %S" args))
942 (let ((keyword arg)
943 (value (car args)))
944 (unless args
945 (error "Keyword %s is missing an argument" keyword))
946 (setq args (cdr args))
947 (cond ((eq keyword :short-description)
948 (put theme 'theme-short-description value))
949 ((eq keyword :immediate)
950 (put theme 'theme-immediate value))
951 ((eq keyword :variable-set-string)
952 (put theme 'theme-variable-set-string value))
953 ((eq keyword :variable-reset-string)
954 (put theme 'theme-variable-reset-string value))
955 ((eq keyword :face-set-string)
956 (put theme 'theme-face-set-string value))
957 ((eq keyword :face-reset-string)
958 (put theme 'theme-face-reset-string value)))))))
959
960(defun custom-make-theme-feature (theme)
961 "Given a symbol THEME, create a new symbol by appending \"-theme\".
962Store this symbol in the `theme-feature' property of THEME.
963Calling `provide-theme' to provide THEME actually puts `THEME-theme'
964into `features'.
965
966This allows for a file-name convention for autoloading themes:
967Every theme X has a property `provide-theme' whose value is \"X-theme\".
87d737ae 968\(load-theme X) then attempts to load the file `X-theme.el'."
46ce5feb
RS
969 (intern (concat (symbol-name theme) "-theme")))
970\f
971;;; Loading themes.
972
973;; The variable and face settings of a theme are recorded in
974;; the `theme-settings' property of the theme name.
975;; This property's value is a list of elements, each of the form
976;; (PROP SYMBOL THEME MODE VALUE), where PROP is `theme-value' or `theme-face'
977;; and SYMBOL is the face or variable name.
978;; THEME is the theme name itself; that's redundant, but simplifies things.
979;; MODE is `set' or `reset'.
980;; If MODE is `set', then VALUE is an expression that specifies the
981;; theme's setting for SYMBOL.
982;; If MODE is `reset', then VALUE is another theme,
983;; and it means to use the value from that theme.
984
985;; Each variable has a `theme-value' property that describes all the
986;; settings of enabled themes that apply to it.
987;; Each face name has a `theme-face' property that describes all the
988;; settings of enabled themes that apply to it.
989;; The property value is a list of settings, each with the form
990;; (THEME MODE VALUE). THEME, MODE and VALUE are as above.
d2dafb85
RS
991;; Each of these lists is ordered by decreasing theme precedence.
992;; Thus, the first element is always the one that is in effect.
46ce5feb 993
d2dafb85
RS
994;; Disabling a theme removes its settings from the `theme-value' and
995;; `theme-face' properties, but the theme's own `theme-settings'
996;; property remains unchanged.
997
998;; Loading a theme implicitly enables it. Enabling a theme adds its
999;; settings to the symbols' `theme-value' and `theme-face' properties,
1000;; or moves them to the front of those lists if they're already present.
e1bab181
RS
1001
1002(defvar custom-loaded-themes nil
46ce5feb 1003 "Custom themes that have been loaded.")
e1bab181 1004
9c4b6e94
LT
1005(defcustom custom-theme-directory
1006 (if (eq system-type 'ms-dos)
1007 ;; MS-DOS cannot have initial dot.
1008 "~/_emacs.d/"
1009 "~/.emacs.d/")
1010 "Directory in which Custom theme files should be written.
87d737ae 1011`load-theme' searches this directory in addition to load-path.
9c4b6e94
LT
1012The command `customize-create-theme' writes the files it produces
1013into this directory."
1014 :type 'string
1015 :group 'customize
1016 :version "22.1")
1017
e1bab181 1018(defun custom-theme-loaded-p (theme)
46ce5feb 1019 "Return non-nil if THEME has been loaded."
e1bab181
RS
1020 (memq theme custom-loaded-themes))
1021
46ce5feb
RS
1022(defvar custom-enabled-themes '(user)
1023 "Custom themes currently enabled, highest precedence first.
1024The first one is always `user'.")
1025
1026(defun custom-theme-enabled-p (theme)
1027 "Return non-nil if THEME is enabled."
1028 (memq theme custom-enabled-themes))
1029
e1bab181
RS
1030(defun provide-theme (theme)
1031 "Indicate that this file provides THEME.
46ce5feb
RS
1032Add THEME to `custom-loaded-themes', and `provide' whatever
1033feature name is stored in THEME's property `theme-feature'.
e1bab181 1034
46ce5feb 1035Usually the `theme-feature' property contains a symbol created
e1bab181
RS
1036by `custom-make-theme-feature'."
1037 (custom-check-theme theme)
1038 (provide (get theme 'theme-feature))
46ce5feb
RS
1039 (push theme custom-loaded-themes)
1040 ;; Loading a theme also installs its settings,
1041 ;; so mark it as "enabled".
1042 (push theme custom-enabled-themes)
1043 ;; `user' must always be the highest-precedence enabled theme.
1044 ;; Make that remain true. (This has the effect of making user settings
1045 ;; override the ones just loaded, too.)
87d737ae 1046 (enable-theme 'user))
e1bab181 1047
87d737ae 1048(defun load-theme (theme)
46ce5feb 1049 "Try to load a theme's settings from its file.
87d737ae 1050This also enables the theme; use `disable-theme' to disable it."
46ce5feb
RS
1051
1052 ;; THEME's feature is stored in THEME's `theme-feature' property.
1053 ;; Usually the `theme-feature' property contains a symbol created
1054 ;; by `custom-make-theme-feature'.
e1bab181 1055
e1bab181
RS
1056 ;; Note we do no check for validity of the theme here.
1057 ;; This allows to pull in themes by a file-name convention
87d737ae 1058 (interactive "SCustom theme name: ")
9c4b6e94
LT
1059 (let ((load-path (if (file-directory-p custom-theme-directory)
1060 (cons custom-theme-directory load-path)
1061 load-path)))
1062 (require (or (get theme 'theme-feature)
1063 (custom-make-theme-feature theme)))))
46ce5feb
RS
1064\f
1065;;; How to load and enable various themes as part of `user'.
e1bab181
RS
1066
1067(defun custom-theme-load-themes (by-theme &rest body)
1068 "Load the themes specified by BODY.
46ce5feb
RS
1069Record them as required by theme BY-THEME.
1070
1071BODY is a sequence of either
e1bab181
RS
1072
1073THEME
46ce5feb 1074 Load THEME and enable it.
e1bab181
RS
1075\(reset THEME)
1076 Undo all the settings made by THEME
1077\(hidden THEME)
46ce5feb 1078 Load THEME but do not enable it.
e1bab181
RS
1079
1080All the themes loaded for BY-THEME are recorded in BY-THEME's property
46ce5feb 1081`theme-loads-themes'."
e1bab181 1082 (custom-check-theme by-theme)
46ce5feb
RS
1083 (let ((themes-loaded (get by-theme 'theme-loads-themes)))
1084 (dolist (theme body)
e1bab181 1085 (cond ((and (consp theme) (eq (car theme) 'reset))
87d737ae 1086 (disable-theme (cadr theme)))
e1bab181 1087 ((and (consp theme) (eq (car theme) 'hidden))
87d737ae
CY
1088 (load-theme (cadr theme))
1089 (disable-theme (cadr theme)))
e1bab181 1090 (t
87d737ae 1091 (load-theme theme)))
46ce5feb 1092 (push theme themes-loaded))
e1bab181
RS
1093 (put by-theme 'theme-loads-themes themes-loaded)))
1094
1095(defun custom-load-themes (&rest body)
1096 "Load themes for the USER theme as specified by BODY.
1097
1098See `custom-theme-load-themes' for more information on BODY."
1099 (apply 'custom-theme-load-themes 'user body))
46ce5feb
RS
1100\f
1101;;; Enabling and disabling loaded themes.
1102
87d737ae 1103(defun enable-theme (theme)
46ce5feb
RS
1104 "Reenable all variable and face settings defined by THEME.
1105The newly enabled theme gets the highest precedence (after `user').
1106If it is already enabled, just give it highest precedence (after `user')."
87d737ae 1107 (interactive "SEnable Custom theme: ")
46ce5feb
RS
1108 (let ((settings (get theme 'theme-settings)))
1109 (dolist (s settings)
1110 (let* ((prop (car s))
1111 (symbol (cadr s))
1112 (spec-list (get symbol prop)))
1113 (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list)))
1114 (if (eq prop 'theme-value)
1115 (custom-theme-recalc-variable symbol)
1116 (custom-theme-recalc-face symbol)))))
ba2c4279
JB
1117 (setq custom-enabled-themes
1118 (cons theme (delq theme custom-enabled-themes)))
46ce5feb
RS
1119 ;; `user' must always be the highest-precedence enabled theme.
1120 (unless (eq theme 'user)
87d737ae 1121 (enable-theme 'user)))
46ce5feb 1122
87d737ae 1123(defun disable-theme (theme)
46ce5feb
RS
1124 "Disable all variable and face settings defined by THEME.
1125See `custom-known-themes' for a list of known themes."
87d737ae 1126 (interactive "SDisable Custom theme: ")
46ce5feb
RS
1127 (let ((settings (get theme 'theme-settings)))
1128 (dolist (s settings)
1129 (let* ((prop (car s))
1130 (symbol (cadr s))
1131 (spec-list (get symbol prop)))
79a0aa11 1132 (put symbol prop (assq-delete-all theme spec-list))
46ce5feb
RS
1133 (if (eq prop 'theme-value)
1134 (custom-theme-recalc-variable symbol)
1135 (custom-theme-recalc-face symbol)))))
1136 (setq custom-enabled-themes
1137 (delq theme custom-enabled-themes)))
1138
1139(defun custom-theme-value (theme setting-list)
1140 "Determine the value specified for THEME according to SETTING-LIST.
1141Returns a list whose car is the specified value, if we
1142find one; nil otherwise.
1143
1144SETTING-LIST is an alist with themes as its key.
1145Each element has the form:
e1bab181
RS
1146
1147 \(THEME MODE VALUE)
1148
1149MODE is either the symbol `set' or the symbol `reset'. See
1150`custom-push-theme' for more information on the format of
46ce5feb 1151SETTING-LIST."
e1bab181
RS
1152 ;; Note we do _NOT_ signal an error if the theme is unknown
1153 ;; it might have gone away without the user knowing.
46ce5feb
RS
1154 (let ((elt (cdr (assoc theme setting-list))))
1155 (if elt
1156 (if (eq (car elt) 'set)
1157 (cdr elt)
1158 ;; `reset' means refer to another theme's value in the same alist.
1159 (custom-theme-value (cadr elt) setting-list)))))
1160
1161(defun custom-variable-theme-value (variable)
1162 "Return (list VALUE) indicating the custom theme value of VARIABLE.
1163That is to say, it specifies what the value should be according to
1164currently enabled custom themes.
1165
1166This function returns nil if no custom theme specifies a value for VARIABLE."
1167 (let* ((theme-value (get variable 'theme-value)))
1168 (if theme-value
1169 (custom-theme-value (car (car theme-value)) theme-value))))
1170
46ce5feb
RS
1171(defun custom-theme-recalc-variable (variable)
1172 "Set VARIABLE according to currently enabled custom themes."
1173 (let ((valspec (custom-variable-theme-value variable)))
1174 (when valspec
1175 (put variable 'saved-value valspec))
1176 (unless valspec
1177 (setq valspec (get variable 'standard-value)))
1178 (when valspec
1179 (if (or (get 'force-value variable) (default-boundp variable))
1180 (funcall (or (get variable 'custom-set) 'set-default) variable
1181 (eval (car valspec)))))))
1182
1183(defun custom-theme-recalc-face (face)
1184 "Set FACE according to currently enabled custom themes."
79a0aa11
CY
1185 (let ((theme-faces (reverse (get face 'theme-face))))
1186 (dolist (spec theme-faces)
1187 (face-spec-set face (car (cddr spec))))))
46ce5feb 1188\f
e1bab181 1189(defun custom-theme-reset-variables (theme &rest args)
46ce5feb
RS
1190 "Reset the specs in THEME of some variables to their values in other themes.
1191Each of the arguments ARGS has this form:
e1bab181 1192
46ce5feb 1193 (VARIABLE FROM-THEME)
e1bab181 1194
46ce5feb 1195This means reset VARIABLE to its value in FROM-THEME."
e1bab181 1196 (custom-check-theme theme)
46ce5feb
RS
1197 (dolist (arg args)
1198 (custom-push-theme 'theme-value (car arg) theme 'reset (cadr arg))))
e1bab181
RS
1199
1200(defun custom-reset-variables (&rest args)
46ce5feb
RS
1201 "Reset the specs of some variables to their values in certain themes.
1202This creates settings in the `user' theme.
e1bab181 1203
46ce5feb 1204Each of the arguments ARGS has this form:
e1bab181 1205
46ce5feb 1206 (VARIABLE FROM-THEME)
e1bab181 1207
46ce5feb 1208This means reset VARIABLE to its value in FROM-THEME."
e1bab181
RS
1209 (apply 'custom-theme-reset-variables 'user args))
1210
55535639
PJ
1211;;; The End.
1212
1213;; Process the defcustoms for variables loaded before this file.
1214(while custom-declare-variable-list
1215 (apply 'custom-declare-variable (car custom-declare-variable-list))
1216 (setq custom-declare-variable-list (cdr custom-declare-variable-list)))
1217
1218(provide 'custom)
1219
059290d6 1220;; arch-tag: 041b6116-aabe-4f9a-902d-74092bc3dab2
55535639 1221;;; custom.el ends here