(unload-feature): When undefining a variable, delete its buffer-local bindings.
[bpt/emacs.git] / lisp / custom.el
CommitLineData
55535639
PJ
1;;; custom.el --- tools for declaring and initializing options
2;;
00644b82 3;; Copyright (C) 1996, 1997, 1999, 2001, 2002 Free Software Foundation, Inc.
55535639
PJ
4;;
5;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6;; Maintainer: FSF
7;; Keywords: help, faces
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
26;;; Commentary:
27;;
28;; This file only contain the code needed to declare and initialize
29;; user options. The code to customize options is autoloaded from
30;; `cus-edit.el' and is documented in the Emacs Lisp Reference manual.
31
32;; The code implementing face declarations is in `cus-face.el'
33
34;;; Code:
35
36(require 'widget)
37
38(defvar custom-define-hook nil
39 ;; Customize information for this option is in `cus-edit.el'.
40 "Hook called after defining each customize option.")
41
6da43544
RS
42(defvar custom-dont-initialize nil
43 "Non-nil means `defcustom' should not initialize the variable.
44That is used for the sake of `custom-make-dependencies'.
45Users should not set it.")
46
d3b80e9b
SM
47(defvar custom-current-group-alist nil
48 "Alist of (FILE . GROUP) indicating the current group to use for FILE.")
49
55535639
PJ
50;;; The `defcustom' Macro.
51
52(defun custom-initialize-default (symbol value)
53 "Initialize SYMBOL with VALUE.
54This will do nothing if symbol already has a default binding.
55Otherwise, if symbol has a `saved-value' property, it will evaluate
56the car of that and used as the default binding for symbol.
57Otherwise, VALUE will be evaluated and used as the default binding for
58symbol."
59 (unless (default-boundp symbol)
60 ;; Use the saved value if it exists, otherwise the standard setting.
61 (set-default symbol (if (get symbol 'saved-value)
62 (eval (car (get symbol 'saved-value)))
63 (eval value)))))
64
65(defun custom-initialize-set (symbol value)
66 "Initialize SYMBOL based on VALUE.
67If the symbol doesn't have a default binding already,
68then set it using its `:set' function (or `set-default' if it has none).
69The value is either the value in the symbol's `saved-value' property,
70if any, or VALUE."
71 (unless (default-boundp symbol)
72 (funcall (or (get symbol 'custom-set) 'set-default)
73 symbol
74 (if (get symbol 'saved-value)
75 (eval (car (get symbol 'saved-value)))
76 (eval value)))))
77
78(defun custom-initialize-reset (symbol value)
79 "Initialize SYMBOL based on VALUE.
80Set the symbol, using its `:set' function (or `set-default' if it has none).
81The value is either the symbol's current value
82 \(as obtained using the `:get' function), if any,
83or the value in the symbol's `saved-value' property if any,
84or (last of all) VALUE."
85 (funcall (or (get symbol 'custom-set) 'set-default)
86 symbol
87 (cond ((default-boundp symbol)
88 (funcall (or (get symbol 'custom-get) 'default-value)
89 symbol))
90 ((get symbol 'saved-value)
91 (eval (car (get symbol 'saved-value))))
92 (t
93 (eval value)))))
94
95(defun custom-initialize-changed (symbol value)
96 "Initialize SYMBOL with VALUE.
97Like `custom-initialize-reset', but only use the `:set' function if
98not using the standard setting.
99For the standard setting, use `set-default'."
100 (cond ((default-boundp symbol)
101 (funcall (or (get symbol 'custom-set) 'set-default)
102 symbol
103 (funcall (or (get symbol 'custom-get) 'default-value)
104 symbol)))
105 ((get symbol 'saved-value)
106 (funcall (or (get symbol 'custom-set) 'set-default)
107 symbol
108 (eval (car (get symbol 'saved-value)))))
109 (t
110 (set-default symbol (eval value)))))
111
112(defun custom-declare-variable (symbol default doc &rest args)
113 "Like `defcustom', but SYMBOL and DEFAULT are evaluated as normal arguments.
114DEFAULT should be an expression to evaluate to compute the default value,
115not the default value itself."
116 ;; Remember the standard setting.
117 (put symbol 'standard-value (list default))
118 ;; Maybe this option was rogue in an earlier version. It no longer is.
119 (when (get symbol 'force-value)
120 (put symbol 'force-value nil))
121 (when doc
122 (put symbol 'variable-documentation doc))
123 (let ((initialize 'custom-initialize-reset)
124 (requests nil))
d3b80e9b
SM
125 (unless (memq :group args)
126 (custom-add-to-group (custom-current-group) symbol 'custom-variable))
55535639
PJ
127 (while args
128 (let ((arg (car args)))
129 (setq args (cdr args))
130 (unless (symbolp arg)
131 (error "Junk in args %S" args))
132 (let ((keyword arg)
133 (value (car args)))
134 (unless args
135 (error "Keyword %s is missing an argument" keyword))
136 (setq args (cdr args))
137 (cond ((eq keyword :initialize)
138 (setq initialize value))
139 ((eq keyword :set)
140 (put symbol 'custom-set value))
141 ((eq keyword :get)
142 (put symbol 'custom-get value))
143 ((eq keyword :require)
144 (setq requests (cons value requests)))
145 ((eq keyword :type)
146 (put symbol 'custom-type (purecopy value)))
147 ((eq keyword :options)
148 (if (get symbol 'custom-options)
149 ;; Slow safe code to avoid duplicates.
150 (mapc (lambda (option)
151 (custom-add-option symbol option))
152 value)
153 ;; Fast code for the common case.
154 (put symbol 'custom-options (copy-sequence value))))
155 (t
156 (custom-handle-keyword symbol keyword value
157 'custom-variable))))))
158 (put symbol 'custom-requests requests)
159 ;; Do the actual initialization.
6da43544
RS
160 (unless custom-dont-initialize
161 (funcall initialize symbol default)))
55535639
PJ
162 (setq current-load-list (cons symbol current-load-list))
163 (run-hooks 'custom-define-hook)
164 symbol)
165
166(defmacro defcustom (symbol value doc &rest args)
167 "Declare SYMBOL as a customizable variable that defaults to VALUE.
168DOC is the variable documentation.
169
170Neither SYMBOL nor VALUE needs to be quoted.
171If SYMBOL is not already bound, initialize it to VALUE.
172The remaining arguments should have the form
173
174 [KEYWORD VALUE]...
175
176The following keywords are meaningful:
177
178:type VALUE should be a widget type for editing the symbols value.
179:options VALUE should be a list of valid members of the widget type.
180:group VALUE should be a customization group.
181 Add SYMBOL to that group.
3dc5f18e 182:link LINK-DATA
00644b82
EZ
183 Include an external link after the documentation string for this
184 item. This is a sentence containing an active field which
185 references some other documentation.
186
187 There are three alternatives you can use for LINK-DATA:
188
3dc5f18e 189 (custom-manual INFO-NODE)
00644b82 190 Link to an Info node; INFO-NODE is a string which specifies
3dc5f18e 191 the node name, as in \"(emacs)Top\". The link appears as
00644b82
EZ
192 `[manual]' in the customization buffer.
193
3dc5f18e 194 (info-link INFO-NODE)
00644b82
EZ
195 Like `custom-manual' except that the link appears in the
196 customization buffer with the Info node name.
197
3dc5f18e 198 (url-link URL)
00644b82
EZ
199 Link to a web page; URL is a string which specifies the URL.
200 The link appears in the customization buffer as URL.
201
202 You can specify the text to use in the customization buffer by
203 adding `:tag NAME' after the first element of the LINK-DATA; for
3dc5f18e 204 example, (info-link :tag \"foo\" \"(emacs)Top\") makes a link to the
00644b82
EZ
205 Emacs manual which appears in the buffer as `foo'.
206
207 An item can have more than one external link; however, most items
208 have none at all.
55535639
PJ
209:initialize
210 VALUE should be a function used to initialize the
211 variable. It takes two arguments, the symbol and value
212 given in the `defcustom' call. The default is
a01639a3 213 `custom-initialize-reset'.
55535639
PJ
214:set VALUE should be a function to set the value of the symbol.
215 It takes two arguments, the symbol to set and the value to
216 give it. The default choice of function is `custom-set-default'.
217:get VALUE should be a function to extract the value of symbol.
218 The function takes one argument, a symbol, and should return
219 the current value for that symbol. The default choice of function
220 is `custom-default-value'.
221:require
222 VALUE should be a feature symbol. If you save a value
223 for this option, then when your `.emacs' file loads the value,
224 it does (require VALUE) first.
225:version
226 VALUE should be a string specifying that the variable was
227 first introduced, or its default value was changed, in Emacs
228 version VERSION.
00644b82
EZ
229:tag LABEL
230 Use LABEL, a string, instead of the item's name, to label the item
1c1da418 231 in customization menus and buffers.
00644b82
EZ
232:load FILE
233 Load file FILE (a string) before displaying this customization
234 item. Loading is done with `load-library', and only if the file is
235 not already loaded.
a2b38e51
GM
236:set-after VARIABLE
237 Specifies that SYMBOL should be set after VARIABLE when
238 both have been customized.
55535639
PJ
239
240Read the section about customization in the Emacs Lisp manual for more
241information."
242 ;; It is better not to use backquote in this file,
243 ;; because that makes a bootstrapping problem
244 ;; if you need to recompile all the Lisp files using interpreted code.
245 (nconc (list 'custom-declare-variable
246 (list 'quote symbol)
247 (list 'quote value)
248 doc)
249 args))
250
251;;; The `defface' Macro.
252
253(defmacro defface (face spec doc &rest args)
254 "Declare FACE as a customizable face that defaults to SPEC.
255FACE does not need to be quoted.
256
257Third argument DOC is the face documentation.
258
259If FACE has been set with `custom-set-face', set the face attributes
260as specified by that function, otherwise set the face attributes
261according to SPEC.
262
263The remaining arguments should have the form
264
265 [KEYWORD VALUE]...
266
267The following KEYWORDs are defined:
268
269:group VALUE should be a customization group.
270 Add FACE to that group.
271
272SPEC should be an alist of the form ((DISPLAY ATTS)...).
273
274The first element of SPEC where the DISPLAY matches the frame
275is the one that takes effect in that frame. The ATTRs in this
276element take effect; the other elements are ignored, on that frame.
277
278ATTS is a list of face attributes followed by their values:
279 (ATTR VALUE ATTR VALUE...)
280
281The possible attributes are `:family', `:width', `:height', `:weight',
282`:slant', `:underline', `:overline', `:strike-through', `:box',
3d58b15e 283`:foreground', `:background', `:stipple', `:inverse-video', and `:inherit'.
55535639
PJ
284
285DISPLAY can either be the symbol t, which will match all frames, or an
286alist of the form \((REQ ITEM...)...). For the DISPLAY to match a
287FRAME, the REQ property of the frame must match one of the ITEM. The
288following REQ are defined:
289
290`type' (the value of `window-system')
291 Under X, in addition to the values `window-system' can take,
292 `motif', `lucid' and `x-toolkit' are allowed, and match when
293 the Motif toolkit, Lucid toolkit, or any X toolkit is in use.
294
295`class' (the frame's color support)
296 Should be one of `color', `grayscale', or `mono'.
297
298`background' (what color is used for the background text)
299 Should be one of `light' or `dark'.
300
301Read the section about customization in the Emacs Lisp manual for more
302information."
303 ;; It is better not to use backquote in this file,
304 ;; because that makes a bootstrapping problem
305 ;; if you need to recompile all the Lisp files using interpreted code.
306 (nconc (list 'custom-declare-face (list 'quote face) spec doc) args))
307
308;;; The `defgroup' Macro.
309
d3b80e9b
SM
310(defun custom-current-group ()
311 (cdr (assoc load-file-name custom-current-group-alist)))
312
55535639
PJ
313(defun custom-declare-group (symbol members doc &rest args)
314 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
315 (while members
316 (apply 'custom-add-to-group symbol (car members))
317 (setq members (cdr members)))
318 (put symbol 'custom-group (nconc members (get symbol 'custom-group)))
319 (when doc
320 ;; This text doesn't get into DOC.
321 (put symbol 'group-documentation (purecopy doc)))
322 (while args
323 (let ((arg (car args)))
324 (setq args (cdr args))
325 (unless (symbolp arg)
326 (error "Junk in args %S" args))
327 (let ((keyword arg)
328 (value (car args)))
329 (unless args
330 (error "Keyword %s is missing an argument" keyword))
331 (setq args (cdr args))
332 (cond ((eq keyword :prefix)
333 (put symbol 'custom-prefix value))
334 (t
335 (custom-handle-keyword symbol keyword value
336 'custom-group))))))
d3b80e9b
SM
337 ;; Record the group on the `current' list.
338 (let ((elt (assoc load-file-name custom-current-group-alist)))
339 (if elt (setcdr elt symbol)
340 (push (cons load-file-name symbol) custom-current-group-alist)))
55535639
PJ
341 (run-hooks 'custom-define-hook)
342 symbol)
343
344(defmacro defgroup (symbol members doc &rest args)
345 "Declare SYMBOL as a customization group containing MEMBERS.
346SYMBOL does not need to be quoted.
347
348Third arg DOC is the group documentation.
349
350MEMBERS should be an alist of the form ((NAME WIDGET)...) where
351NAME is a symbol and WIDGET is a widget for editing that symbol.
352Useful widgets are `custom-variable' for editing variables,
353`custom-face' for edit faces, and `custom-group' for editing groups.
354
355The remaining arguments should have the form
356
357 [KEYWORD VALUE]...
358
359The following KEYWORDs are defined:
360
361:group VALUE should be a customization group.
362 Add SYMBOL to that group.
363
364:version VALUE should be a string specifying that the group was introduced
365 in Emacs version VERSION.
366
367Read the section about customization in the Emacs Lisp manual for more
368information."
369 ;; It is better not to use backquote in this file,
370 ;; because that makes a bootstrapping problem
371 ;; if you need to recompile all the Lisp files using interpreted code.
372 (nconc (list 'custom-declare-group (list 'quote symbol) members doc) args))
373
374(defun custom-add-to-group (group option widget)
375 "To existing GROUP add a new OPTION of type WIDGET.
376If there already is an entry for OPTION and WIDGET, nothing is done."
377 (let ((members (get group 'custom-group))
378 (entry (list option widget)))
379 (unless (member entry members)
380 (put group 'custom-group (nconc members (list entry))))))
381
382;;; Properties.
383
384(defun custom-handle-all-keywords (symbol args type)
385 "For customization option SYMBOL, handle keyword arguments ARGS.
386Third argument TYPE is the custom option type."
d3b80e9b
SM
387 (unless (memq :group args)
388 (custom-add-to-group (custom-current-group) symbol 'custom-face))
55535639
PJ
389 (while args
390 (let ((arg (car args)))
391 (setq args (cdr args))
392 (unless (symbolp arg)
393 (error "Junk in args %S" args))
394 (let ((keyword arg)
395 (value (car args)))
396 (unless args
397 (error "Keyword %s is missing an argument" keyword))
398 (setq args (cdr args))
399 (custom-handle-keyword symbol keyword value type)))))
400
401(defun custom-handle-keyword (symbol keyword value type)
402 "For customization option SYMBOL, handle KEYWORD with VALUE.
403Fourth argument TYPE is the custom option type."
404 (if purify-flag
405 (setq value (purecopy value)))
406 (cond ((eq keyword :group)
407 (custom-add-to-group value symbol type))
408 ((eq keyword :version)
409 (custom-add-version symbol value))
410 ((eq keyword :link)
411 (custom-add-link symbol value))
412 ((eq keyword :load)
413 (custom-add-load symbol value))
414 ((eq keyword :tag)
415 (put symbol 'custom-tag value))
416 ((eq keyword :set-after)
417 (custom-add-dependencies symbol value))
418 (t
419 (error "Unknown keyword %s" keyword))))
420
421(defun custom-add-dependencies (symbol value)
422 "To the custom option SYMBOL, add dependencies specified by VALUE.
423VALUE should be a list of symbols. For each symbol in that list,
424this specifies that SYMBOL should be set after the specified symbol, if
425both appear in constructs like `custom-set-variables'."
426 (unless (listp value)
427 (error "Invalid custom dependency `%s'" value))
428 (let* ((deps (get symbol 'custom-dependencies))
429 (new-deps deps))
430 (while value
431 (let ((dep (car value)))
432 (unless (symbolp dep)
433 (error "Invalid custom dependency `%s'" dep))
434 (unless (memq dep new-deps)
435 (setq new-deps (cons dep new-deps)))
436 (setq value (cdr value))))
437 (unless (eq deps new-deps)
438 (put symbol 'custom-dependencies new-deps))))
439
440(defun custom-add-option (symbol option)
441 "To the variable SYMBOL add OPTION.
442
443If SYMBOL is a hook variable, OPTION should be a hook member.
444For other types variables, the effect is undefined."
445 (let ((options (get symbol 'custom-options)))
446 (unless (member option options)
447 (put symbol 'custom-options (cons option options)))))
448
449(defun custom-add-link (symbol widget)
450 "To the custom option SYMBOL add the link WIDGET."
451 (let ((links (get symbol 'custom-links)))
452 (unless (member widget links)
453 (put symbol 'custom-links (cons (purecopy widget) links)))))
454
455(defun custom-add-version (symbol version)
456 "To the custom option SYMBOL add the version VERSION."
457 (put symbol 'custom-version (purecopy version)))
458
459(defun custom-add-load (symbol load)
460 "To the custom option SYMBOL add the dependency LOAD.
461LOAD should be either a library file name, or a feature name."
462 (let ((loads (get symbol 'custom-loads)))
463 (unless (member load loads)
464 (put symbol 'custom-loads (cons (purecopy load) loads)))))
465
8f772dfd
RS
466;;; Loading files needed to customize a symbol.
467;;; This is in custom.el because menu-bar.el needs it for toggle cmds.
468
469(defvar custom-load-recursion nil
470 "Hack to avoid recursive dependencies.")
471
472(defun custom-load-symbol (symbol)
473 "Load all dependencies for SYMBOL."
474 (unless custom-load-recursion
475 (let ((custom-load-recursion t)
476 (loads (get symbol 'custom-loads))
477 load)
478 (while loads
479 (setq load (car loads)
480 loads (cdr loads))
481 (cond ((symbolp load)
482 (condition-case nil
483 (require load)
484 (error nil)))
485 ;; Don't reload a file already loaded.
486 ((and (boundp 'preloaded-file-list)
487 (member load preloaded-file-list)))
488 ((assoc load load-history))
489 ;; This was just (assoc (locate-library load) load-history)
490 ;; but has been optimized not to load locate-library
491 ;; if not necessary.
492 ((let (found (regexp (regexp-quote load)))
493 (dolist (loaded load-history)
c3891447
RS
494 (and (stringp (car loaded))
495 (string-match regexp (car loaded))
8f772dfd
RS
496 (eq (locate-library load) (car loaded))
497 (setq found t)))
498 found))
499 ;; Without this, we would load cus-edit recursively.
500 ;; We are still loading it when we call this,
501 ;; and it is not in load-history yet.
502 ((equal load "cus-edit"))
503 (t
504 (condition-case nil
505 (load-library load)
506 (error nil))))))))
507
55535639
PJ
508;;; Initializing.
509
510(defvar custom-local-buffer nil
511 "Non-nil, in a Customization buffer, means customize a specific buffer.
512If this variable is non-nil, it should be a buffer,
513and it means customize the local bindings of that buffer.
514This variable is a permanent local, and it normally has a local binding
515in every Customization buffer.")
516(put 'custom-local-buffer 'permanent-local t)
517
518(defun custom-set-variables (&rest args)
519 "Initialize variables according to user preferences.
520
521The arguments should be a list where each entry has the form:
522
523 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]])
524
525The unevaluated VALUE is stored as the saved value for SYMBOL.
526If NOW is present and non-nil, VALUE is also evaluated and bound as
527the default value for the SYMBOL.
528REQUEST is a list of features we must require for SYMBOL.
529COMMENT is a comment string about SYMBOL."
530 (setq args
531 (sort args
532 (lambda (a1 a2)
533 (let* ((sym1 (car a1))
534 (sym2 (car a2))
535 (1-then-2 (memq sym1 (get sym2 'custom-dependencies)))
536 (2-then-1 (memq sym2 (get sym1 'custom-dependencies))))
537 (cond ((and 1-then-2 2-then-1)
538 (error "Circular custom dependency between `%s' and `%s'"
539 sym1 sym2))
540 (1-then-2 t)
cb3f945f
GM
541 (2-then-1 nil)
542 ;; Put symbols with :require last. The macro
543 ;; define-minor-mode generates a defcustom
544 ;; with a :require and a :set, where the
545 ;; setter function calls the mode function.
546 ;; Putting symbols with :require last ensures
547 ;; that the mode function will see other
548 ;; customized values rather than default
549 ;; values.
be48584d 550 (t (nth 3 a2)))))))
55535639
PJ
551 (while args
552 (let ((entry (car args)))
553 (if (listp entry)
554 (let* ((symbol (nth 0 entry))
555 (value (nth 1 entry))
556 (now (nth 2 entry))
557 (requests (nth 3 entry))
558 (comment (nth 4 entry))
559 set)
560 (when requests
561 (put symbol 'custom-requests requests)
562 (mapc 'require requests))
563 (setq set (or (get symbol 'custom-set) 'custom-set-default))
564 (put symbol 'saved-value (list value))
565 (put symbol 'saved-variable-comment comment)
566 ;; Allow for errors in the case where the setter has
567 ;; changed between versions, say, but let the user know.
568 (condition-case data
569 (cond (now
570 ;; Rogue variable, set it now.
571 (put symbol 'force-value t)
572 (funcall set symbol (eval value)))
573 ((default-boundp symbol)
574 ;; Something already set this, overwrite it.
575 (funcall set symbol (eval value))))
576 (error
577 (message "Error setting %s: %s" symbol data)))
578 (setq args (cdr args))
579 (and (or now (default-boundp symbol))
580 (put symbol 'variable-comment comment)))
581 ;; Old format, a plist of SYMBOL VALUE pairs.
582 (message "Warning: old format `custom-set-variables'")
583 (ding)
584 (sit-for 2)
585 (let ((symbol (nth 0 args))
586 (value (nth 1 args)))
587 (put symbol 'saved-value (list value)))
588 (setq args (cdr (cdr args)))))))
589
590(defun custom-set-default (variable value)
591 "Default :set function for a customizable variable.
592Normally, this sets the default value of VARIABLE to VALUE,
593but if `custom-local-buffer' is non-nil,
594this sets the local binding in that buffer instead."
595 (if custom-local-buffer
596 (with-current-buffer custom-local-buffer
597 (set variable value))
598 (set-default variable value)))
599
6d912ee1
MB
600(defun custom-quote (sexp)
601 "Quote SEXP iff it is not self quoting."
602 (if (or (memq sexp '(t nil))
603 (keywordp sexp)
604 (and (listp sexp)
605 (memq (car sexp) '(lambda)))
606 (stringp sexp)
607 (numberp sexp)
608 (vectorp sexp)
609;;; (and (fboundp 'characterp)
610;;; (characterp sexp))
611 )
612 sexp
613 (list 'quote sexp)))
614
615(defun customize-mark-to-save (symbol)
616 "Mark SYMBOL for later saving.
617
618If the default value of SYMBOL is different from the standard value,
619set the `saved-value' property to a list whose car evaluates to the
620default value. Otherwise, set it til nil.
621
622To actually save the value, call `custom-save-all'.
623
624Return non-nil iff the `saved-value' property actually changed."
625 (let* ((get (or (get symbol 'custom-get) 'default-value))
626 (value (funcall get symbol))
627 (saved (get symbol 'saved-value))
628 (standard (get symbol 'standard-value))
629 (comment (get symbol 'customized-variable-comment)))
630 ;; Save default value iff different from standard value.
631 (if (or (null standard)
632 (not (equal value (condition-case nil
633 (eval (car standard))
634 (error nil)))))
635 (put symbol 'saved-value (list (custom-quote value)))
636 (put symbol 'saved-value nil))
637 ;; Clear customized information (set, but not saved).
638 (put symbol 'customized-value nil)
639 ;; Save any comment that might have been set.
640 (when comment
641 (put symbol 'saved-variable-comment comment))
642 (not (equal saved (get symbol 'saved-value)))))
643
644(defun customize-mark-as-set (symbol)
645 "Mark current value of SYMBOL as being set from customize.
646
647If the default value of SYMBOL is different from the saved value if any,
648or else if it is different from the standard value, set the
649`customized-value' property to a list whose car evaluates to the
650default value. Otherwise, set it til nil.
651
652Return non-nil iff the `customized-value' property actually changed."
653 (let* ((get (or (get symbol 'custom-get) 'default-value))
654 (value (funcall get symbol))
655 (customized (get symbol 'customized-value))
656 (old (or (get symbol 'saved-value) (get symbol 'standard-value))))
657 ;; Mark default value as set iff different from old value.
658 (if (or (null old)
659 (not (equal value (condition-case nil
660 (eval (car old))
661 (error nil)))))
662 (put symbol 'customized-value (list (custom-quote value)))
663 (put symbol 'customized-value nil))
664 ;; Changed?
665 (not (equal customized (get symbol 'customized-value)))))
666
55535639
PJ
667;;; The End.
668
669;; Process the defcustoms for variables loaded before this file.
670(while custom-declare-variable-list
671 (apply 'custom-declare-variable (car custom-declare-variable-list))
672 (setq custom-declare-variable-list (cdr custom-declare-variable-list)))
673
674(provide 'custom)
675
676;;; custom.el ends here