comparison lisp/custom.el @ 60413:28b5c27160e8

(custom-reevaluate-setting): Simple function to handle variables that are defined before their default value can really be computed. (custom-theme-set-variables): Remove unused var `immediate'.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 06 Mar 2005 00:27:53 +0000
parents 58cb209560a7
children 7279141eb80e 29e773288013
comparison
equal deleted inserted replaced
60412:9b15aeb1b3f1 60413:28b5c27160e8
1 ;;; custom.el --- tools for declaring and initializing options 1 ;;; custom.el --- tools for declaring and initializing options
2 ;; 2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2001, 2002, 2004 3 ;; Copyright (C) 1996, 1997, 1999, 2001, 2002, 2004, 2005
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 ;; 5 ;;
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> 6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Maintainer: FSF 7 ;; Maintainer: FSF
8 ;; Keywords: help, faces 8 ;; Keywords: help, faces
724 REQUEST is a list of features we must require in order to 724 REQUEST is a list of features we must require in order to
725 handle SYMBOL properly. 725 handle SYMBOL properly.
726 COMMENT is a comment string about SYMBOL." 726 COMMENT is a comment string about SYMBOL."
727 (apply 'custom-theme-set-variables 'user args)) 727 (apply 'custom-theme-set-variables 'user args))
728 728
729 (defun custom-reevaluate-setting (symbol)
730 "Reset the value of SYMBOL by re-evaluating its saved or default value.
731 This is useful for variables that are defined before their default value
732 can really be computed. E.g. dumped variables whose default depends on
733 run-time information."
734 (funcall (or (get symbol 'custom-set) 'set-default)
735 symbol
736 (eval (car (or (get symbol 'saved-value) (get symbol 'standard-value))))))
737
729 (defun custom-theme-set-variables (theme &rest args) 738 (defun custom-theme-set-variables (theme &rest args)
730 "Initialize variables for theme THEME according to settings in ARGS. 739 "Initialize variables for theme THEME according to settings in ARGS.
731 Each of the arguments in ARGS should be a list of this form: 740 Each of the arguments in ARGS should be a list of this form:
732 741
733 (SYMBOL EXP [NOW [REQUEST [COMMENT]]]) 742 (SYMBOL EXP [NOW [REQUEST [COMMENT]]])
751 SYMBOL's property `force-value' is set to the symbol `immediate'. 760 SYMBOL's property `force-value' is set to the symbol `immediate'.
752 761
753 EXP itself is saved unevaluated as SYMBOL property `saved-value' and 762 EXP itself is saved unevaluated as SYMBOL property `saved-value' and
754 in SYMBOL's list property `theme-value' \(using `custom-push-theme')." 763 in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
755 (custom-check-theme theme) 764 (custom-check-theme theme)
756 (let ((immediate (get theme 'theme-immediate))) 765 (setq args
757 (setq args 766 (sort args
758 (sort args 767 (lambda (a1 a2)
759 (lambda (a1 a2) 768 (let* ((sym1 (car a1))
760 (let* ((sym1 (car a1)) 769 (sym2 (car a2))
761 (sym2 (car a2)) 770 (1-then-2 (memq sym1 (get sym2 'custom-dependencies)))
762 (1-then-2 (memq sym1 (get sym2 'custom-dependencies))) 771 (2-then-1 (memq sym2 (get sym1 'custom-dependencies))))
763 (2-then-1 (memq sym2 (get sym1 'custom-dependencies)))) 772 (cond ((and 1-then-2 2-then-1)
764 (cond ((and 1-then-2 2-then-1) 773 (error "Circular custom dependency between `%s' and `%s'"
765 (error "Circular custom dependency between `%s' and `%s'" 774 sym1 sym2))
766 sym1 sym2)) 775 (2-then-1 nil)
767 (2-then-1 nil) 776 ;; Put symbols with :require last. The macro
768 ;; Put symbols with :require last. The macro 777 ;; define-minor-mode generates a defcustom
769 ;; define-minor-mode generates a defcustom 778 ;; with a :require and a :set, where the
770 ;; with a :require and a :set, where the 779 ;; setter function calls the mode function.
771 ;; setter function calls the mode function. 780 ;; Putting symbols with :require last ensures
772 ;; Putting symbols with :require last ensures 781 ;; that the mode function will see other
773 ;; that the mode function will see other 782 ;; customized values rather than default
774 ;; customized values rather than default 783 ;; values.
775 ;; values. 784 (t (nth 3 a2)))))))
776 (t (nth 3 a2))))))) 785 (while args
777 (while args 786 (let ((entry (car args)))
778 (let ((entry (car args))) 787 (if (listp entry)
779 (if (listp entry) 788 (let* ((symbol (indirect-variable (nth 0 entry)))
780 (let* ((symbol (indirect-variable (nth 0 entry))) 789 (value (nth 1 entry))
781 (value (nth 1 entry)) 790 (now (nth 2 entry))
782 (now (nth 2 entry)) 791 (requests (nth 3 entry))
783 (requests (nth 3 entry)) 792 (comment (nth 4 entry))
784 (comment (nth 4 entry)) 793 set)
785 set) 794 (when requests
786 (when requests 795 (put symbol 'custom-requests requests)
787 (put symbol 'custom-requests requests) 796 (mapc 'require requests))
788 (mapc 'require requests)) 797 (setq set (or (get symbol 'custom-set) 'custom-set-default))
789 (setq set (or (get symbol 'custom-set) 'custom-set-default)) 798 (put symbol 'saved-value (list value))
790 (put symbol 'saved-value (list value)) 799 (put symbol 'saved-variable-comment comment)
791 (put symbol 'saved-variable-comment comment) 800 (custom-push-theme 'theme-value symbol theme 'set value)
792 (custom-push-theme 'theme-value symbol theme 'set value) 801 ;; Allow for errors in the case where the setter has
793 ;; Allow for errors in the case where the setter has
794 ;; changed between versions, say, but let the user know. 802 ;; changed between versions, say, but let the user know.
795 (condition-case data 803 (condition-case data
796 (cond (now 804 (cond (now
797 ;; Rogue variable, set it now. 805 ;; Rogue variable, set it now.
798 (put symbol 'force-value t) 806 (put symbol 'force-value t)
800 ((default-boundp symbol) 808 ((default-boundp symbol)
801 ;; Something already set this, overwrite it. 809 ;; Something already set this, overwrite it.
802 (funcall set symbol (eval value)))) 810 (funcall set symbol (eval value))))
803 (error 811 (error
804 (message "Error setting %s: %s" symbol data))) 812 (message "Error setting %s: %s" symbol data)))
805 (setq args (cdr args)) 813 (setq args (cdr args))
806 (and (or now (default-boundp symbol)) 814 (and (or now (default-boundp symbol))
807 (put symbol 'variable-comment comment))) 815 (put symbol 'variable-comment comment)))
808 ;; Old format, a plist of SYMBOL VALUE pairs. 816 ;; Old format, a plist of SYMBOL VALUE pairs.
809 (message "Warning: old format `custom-set-variables'") 817 (message "Warning: old format `custom-set-variables'")
810 (ding) 818 (ding)
811 (sit-for 2) 819 (sit-for 2)
812 (let ((symbol (indirect-variable (nth 0 args))) 820 (let ((symbol (indirect-variable (nth 0 args)))
813 (value (nth 1 args))) 821 (value (nth 1 args)))
814 (put symbol 'saved-value (list value)) 822 (put symbol 'saved-value (list value))
815 (custom-push-theme 'theme-value symbol theme 'set value)) 823 (custom-push-theme 'theme-value symbol theme 'set value))
816 (setq args (cdr (cdr args)))))))) 824 (setq args (cdr (cdr args)))))))
817 825
818 (defun custom-set-default (variable value) 826 (defun custom-set-default (variable value)
819 "Default :set function for a customizable variable. 827 "Default :set function for a customizable variable.
820 Normally, this sets the default value of VARIABLE to VALUE, 828 Normally, this sets the default value of VARIABLE to VALUE,
821 but if `custom-local-buffer' is non-nil, 829 but if `custom-local-buffer' is non-nil,
1089 (apply 'custom-declare-variable (car custom-declare-variable-list)) 1097 (apply 'custom-declare-variable (car custom-declare-variable-list))
1090 (setq custom-declare-variable-list (cdr custom-declare-variable-list))) 1098 (setq custom-declare-variable-list (cdr custom-declare-variable-list)))
1091 1099
1092 (provide 'custom) 1100 (provide 'custom)
1093 1101
1094 ;;; arch-tag: 041b6116-aabe-4f9a-902d-74092bc3dab2 1102 ;; arch-tag: 041b6116-aabe-4f9a-902d-74092bc3dab2
1095 ;;; custom.el ends here 1103 ;;; custom.el ends here