Mercurial > emacs
comparison lisp/custom.el @ 67978:f313a5c7323b
Change ordering so all the Custom Themes code is in one place.
Fix docstring for custom-theme-set-variables.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 02 Jan 2006 15:18:08 +0000 |
parents | 03ee9bccbfeb |
children | c36b45ec6e81 |
comparison
equal
deleted
inserted
replaced
67977:03ee9bccbfeb | 67978:f313a5c7323b |
---|---|
597 ;; We are still loading it when we call this, | 597 ;; We are still loading it when we call this, |
598 ;; and it is not in load-history yet. | 598 ;; and it is not in load-history yet. |
599 ((equal load "cus-edit")) | 599 ((equal load "cus-edit")) |
600 (t (condition-case nil (load load) (error nil)))))))) | 600 (t (condition-case nil (load load) (error nil)))))))) |
601 | 601 |
602 (defvar custom-local-buffer nil | |
603 "Non-nil, in a Customization buffer, means customize a specific buffer. | |
604 If this variable is non-nil, it should be a buffer, | |
605 and it means customize the local bindings of that buffer. | |
606 This variable is a permanent local, and it normally has a local binding | |
607 in every Customization buffer.") | |
608 (put 'custom-local-buffer 'permanent-local t) | |
609 | |
610 (defun custom-set-default (variable value) | |
611 "Default :set function for a customizable variable. | |
612 Normally, this sets the default value of VARIABLE to VALUE, | |
613 but if `custom-local-buffer' is non-nil, | |
614 this sets the local binding in that buffer instead." | |
615 (if custom-local-buffer | |
616 (with-current-buffer custom-local-buffer | |
617 (set variable value)) | |
618 (set-default variable value))) | |
619 | |
620 (defun custom-set-minor-mode (variable value) | |
621 ":set function for minor mode variables. | |
622 Normally, this sets the default value of VARIABLE to nil if VALUE | |
623 is nil and to t otherwise, | |
624 but if `custom-local-buffer' is non-nil, | |
625 this sets the local binding in that buffer instead." | |
626 (if custom-local-buffer | |
627 (with-current-buffer custom-local-buffer | |
628 (funcall variable (if value 1 0))) | |
629 (funcall variable (if value 1 0)))) | |
630 | |
631 (defun custom-quote (sexp) | |
632 "Quote SEXP iff it is not self quoting." | |
633 (if (or (memq sexp '(t nil)) | |
634 (keywordp sexp) | |
635 (and (listp sexp) | |
636 (memq (car sexp) '(lambda))) | |
637 (stringp sexp) | |
638 (numberp sexp) | |
639 (vectorp sexp) | |
640 ;;; (and (fboundp 'characterp) | |
641 ;;; (characterp sexp)) | |
642 ) | |
643 sexp | |
644 (list 'quote sexp))) | |
645 | |
646 (defun customize-mark-to-save (symbol) | |
647 "Mark SYMBOL for later saving. | |
648 | |
649 If the default value of SYMBOL is different from the standard value, | |
650 set the `saved-value' property to a list whose car evaluates to the | |
651 default value. Otherwise, set it to nil. | |
652 | |
653 To actually save the value, call `custom-save-all'. | |
654 | |
655 Return non-nil iff the `saved-value' property actually changed." | |
656 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
657 (value (funcall get symbol)) | |
658 (saved (get symbol 'saved-value)) | |
659 (standard (get symbol 'standard-value)) | |
660 (comment (get symbol 'customized-variable-comment))) | |
661 ;; Save default value iff different from standard value. | |
662 (if (or (null standard) | |
663 (not (equal value (condition-case nil | |
664 (eval (car standard)) | |
665 (error nil))))) | |
666 (put symbol 'saved-value (list (custom-quote value))) | |
667 (put symbol 'saved-value nil)) | |
668 ;; Clear customized information (set, but not saved). | |
669 (put symbol 'customized-value nil) | |
670 ;; Save any comment that might have been set. | |
671 (when comment | |
672 (put symbol 'saved-variable-comment comment)) | |
673 (not (equal saved (get symbol 'saved-value))))) | |
674 | |
675 (defun customize-mark-as-set (symbol) | |
676 "Mark current value of SYMBOL as being set from customize. | |
677 | |
678 If the default value of SYMBOL is different from the saved value if any, | |
679 or else if it is different from the standard value, set the | |
680 `customized-value' property to a list whose car evaluates to the | |
681 default value. Otherwise, set it to nil. | |
682 | |
683 Return non-nil iff the `customized-value' property actually changed." | |
684 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
685 (value (funcall get symbol)) | |
686 (customized (get symbol 'customized-value)) | |
687 (old (or (get symbol 'saved-value) (get symbol 'standard-value)))) | |
688 ;; Mark default value as set iff different from old value. | |
689 (if (or (null old) | |
690 (not (equal value (condition-case nil | |
691 (eval (car old)) | |
692 (error nil))))) | |
693 (put symbol 'customized-value (list (custom-quote value))) | |
694 (put symbol 'customized-value nil)) | |
695 ;; Changed? | |
696 (not (equal customized (get symbol 'customized-value))))) | |
697 | |
698 (defun custom-reevaluate-setting (symbol) | |
699 "Reset the value of SYMBOL by re-evaluating its saved or standard value. | |
700 Use the :set function to do so. This is useful for customizable options | |
701 that are defined before their standard value can really be computed. | |
702 E.g. dumped variables whose default depends on run-time information." | |
703 (funcall (or (get symbol 'custom-set) 'set-default) | |
704 symbol | |
705 (eval (car (or (get symbol 'saved-value) (get symbol 'standard-value)))))) | |
706 | |
707 | |
602 ;;; Custom Themes | 708 ;;; Custom Themes |
603 | 709 |
604 ;; Custom themes are collections of settings that can be enabled or | 710 ;; Custom themes are collections of settings that can be enabled or |
605 ;; disabled as a unit. | 711 ;; disabled as a unit. |
606 | 712 |
716 (append '(t) (custom-face-attributes-get symbol nil))))))))) | 822 (append '(t) (custom-face-attributes-get symbol nil))))))))) |
717 (put symbol prop (cons (list theme value) old)) | 823 (put symbol prop (cons (list theme value) old)) |
718 (put theme 'theme-settings | 824 (put theme 'theme-settings |
719 (cons (list prop symbol theme value) | 825 (cons (list prop symbol theme value) |
720 theme-settings)))))) | 826 theme-settings)))))) |
827 | |
721 | 828 |
722 (defvar custom-local-buffer nil | |
723 "Non-nil, in a Customization buffer, means customize a specific buffer. | |
724 If this variable is non-nil, it should be a buffer, | |
725 and it means customize the local bindings of that buffer. | |
726 This variable is a permanent local, and it normally has a local binding | |
727 in every Customization buffer.") | |
728 (put 'custom-local-buffer 'permanent-local t) | |
729 | |
730 (defun custom-set-variables (&rest args) | 829 (defun custom-set-variables (&rest args) |
731 "Install user customizations of variable values specified in ARGS. | 830 "Install user customizations of variable values specified in ARGS. |
732 These settings are registered as theme `user'. | 831 These settings are registered as theme `user'. |
733 The arguments should each be a list of the form: | 832 The arguments should each be a list of the form: |
734 | 833 |
741 REQUEST is a list of features we must require in order to | 840 REQUEST is a list of features we must require in order to |
742 handle SYMBOL properly. | 841 handle SYMBOL properly. |
743 COMMENT is a comment string about SYMBOL." | 842 COMMENT is a comment string about SYMBOL." |
744 (apply 'custom-theme-set-variables 'user args)) | 843 (apply 'custom-theme-set-variables 'user args)) |
745 | 844 |
746 (defun custom-reevaluate-setting (symbol) | |
747 "Reset the value of SYMBOL by re-evaluating its saved or standard value. | |
748 Use the :set function to do so. This is useful for customizable options | |
749 that are defined before their standard value can really be computed. | |
750 E.g. dumped variables whose default depends on run-time information." | |
751 (funcall (or (get symbol 'custom-set) 'set-default) | |
752 symbol | |
753 (eval (car (or (get symbol 'saved-value) (get symbol 'standard-value)))))) | |
754 | |
755 (defun custom-theme-set-variables (theme &rest args) | 845 (defun custom-theme-set-variables (theme &rest args) |
756 "Initialize variables for theme THEME according to settings in ARGS. | 846 "Initialize variables for theme THEME according to settings in ARGS. |
757 Each of the arguments in ARGS should be a list of this form: | 847 Each of the arguments in ARGS should be a list of this form: |
758 | 848 |
759 (SYMBOL EXP [NOW [REQUEST [COMMENT]]]) | 849 (SYMBOL EXP [NOW [REQUEST [COMMENT]]]) |
763 the default value for the SYMBOL to the value of EXP. | 853 the default value for the SYMBOL to the value of EXP. |
764 | 854 |
765 REQUEST is a list of features we must require in order to | 855 REQUEST is a list of features we must require in order to |
766 handle SYMBOL properly. | 856 handle SYMBOL properly. |
767 COMMENT is a comment string about SYMBOL. | 857 COMMENT is a comment string about SYMBOL. |
768 | |
769 Several properties of THEME and SYMBOL are used in the process: | |
770 | |
771 If THEME's property `theme-immediate' is non-nil, this is equivalent of | |
772 providing the NOW argument to all symbols in the argument list: | |
773 evaluate each EXP and set the corresponding SYMBOL. However, | |
774 there's a difference in the handling of SYMBOL's property | |
775 `force-value': if NOW is non-nil, SYMBOL's property `force-value' is set to | |
776 the symbol `rogue', else if THEME's property `theme-immediate' is non-nil, | |
777 SYMBOL's property `force-value' is set to the symbol `immediate'. | |
778 | 858 |
779 EXP itself is saved unevaluated as SYMBOL property `saved-value' and | 859 EXP itself is saved unevaluated as SYMBOL property `saved-value' and |
780 in SYMBOL's list property `theme-value' \(using `custom-push-theme')." | 860 in SYMBOL's list property `theme-value' \(using `custom-push-theme')." |
781 (custom-check-theme theme) | 861 (custom-check-theme theme) |
782 (setq args | 862 (setq args |
836 (value (nth 1 args))) | 916 (value (nth 1 args))) |
837 (put symbol 'saved-value (list value)) | 917 (put symbol 'saved-value (list value)) |
838 (custom-push-theme 'theme-value symbol theme 'set value)) | 918 (custom-push-theme 'theme-value symbol theme 'set value)) |
839 (setq args (cdr (cdr args))))))) | 919 (setq args (cdr (cdr args))))))) |
840 | 920 |
841 (defun custom-set-default (variable value) | |
842 "Default :set function for a customizable variable. | |
843 Normally, this sets the default value of VARIABLE to VALUE, | |
844 but if `custom-local-buffer' is non-nil, | |
845 this sets the local binding in that buffer instead." | |
846 (if custom-local-buffer | |
847 (with-current-buffer custom-local-buffer | |
848 (set variable value)) | |
849 (set-default variable value))) | |
850 | |
851 (defun custom-set-minor-mode (variable value) | |
852 ":set function for minor mode variables. | |
853 Normally, this sets the default value of VARIABLE to nil if VALUE | |
854 is nil and to t otherwise, | |
855 but if `custom-local-buffer' is non-nil, | |
856 this sets the local binding in that buffer instead." | |
857 (if custom-local-buffer | |
858 (with-current-buffer custom-local-buffer | |
859 (funcall variable (if value 1 0))) | |
860 (funcall variable (if value 1 0)))) | |
861 | |
862 (defun custom-quote (sexp) | |
863 "Quote SEXP iff it is not self quoting." | |
864 (if (or (memq sexp '(t nil)) | |
865 (keywordp sexp) | |
866 (and (listp sexp) | |
867 (memq (car sexp) '(lambda))) | |
868 (stringp sexp) | |
869 (numberp sexp) | |
870 (vectorp sexp) | |
871 ;;; (and (fboundp 'characterp) | |
872 ;;; (characterp sexp)) | |
873 ) | |
874 sexp | |
875 (list 'quote sexp))) | |
876 | |
877 (defun customize-mark-to-save (symbol) | |
878 "Mark SYMBOL for later saving. | |
879 | |
880 If the default value of SYMBOL is different from the standard value, | |
881 set the `saved-value' property to a list whose car evaluates to the | |
882 default value. Otherwise, set it to nil. | |
883 | |
884 To actually save the value, call `custom-save-all'. | |
885 | |
886 Return non-nil iff the `saved-value' property actually changed." | |
887 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
888 (value (funcall get symbol)) | |
889 (saved (get symbol 'saved-value)) | |
890 (standard (get symbol 'standard-value)) | |
891 (comment (get symbol 'customized-variable-comment))) | |
892 ;; Save default value iff different from standard value. | |
893 (if (or (null standard) | |
894 (not (equal value (condition-case nil | |
895 (eval (car standard)) | |
896 (error nil))))) | |
897 (put symbol 'saved-value (list (custom-quote value))) | |
898 (put symbol 'saved-value nil)) | |
899 ;; Clear customized information (set, but not saved). | |
900 (put symbol 'customized-value nil) | |
901 ;; Save any comment that might have been set. | |
902 (when comment | |
903 (put symbol 'saved-variable-comment comment)) | |
904 (not (equal saved (get symbol 'saved-value))))) | |
905 | |
906 (defun customize-mark-as-set (symbol) | |
907 "Mark current value of SYMBOL as being set from customize. | |
908 | |
909 If the default value of SYMBOL is different from the saved value if any, | |
910 or else if it is different from the standard value, set the | |
911 `customized-value' property to a list whose car evaluates to the | |
912 default value. Otherwise, set it to nil. | |
913 | |
914 Return non-nil iff the `customized-value' property actually changed." | |
915 (let* ((get (or (get symbol 'custom-get) 'default-value)) | |
916 (value (funcall get symbol)) | |
917 (customized (get symbol 'customized-value)) | |
918 (old (or (get symbol 'saved-value) (get symbol 'standard-value)))) | |
919 ;; Mark default value as set iff different from old value. | |
920 (if (or (null old) | |
921 (not (equal value (condition-case nil | |
922 (eval (car old)) | |
923 (error nil))))) | |
924 (put symbol 'customized-value (list (custom-quote value))) | |
925 (put symbol 'customized-value nil)) | |
926 ;; Changed? | |
927 (not (equal customized (get symbol 'customized-value))))) | |
928 | 921 |
929 ;;; Defining themes. | 922 ;;; Defining themes. |
930 | 923 |
931 ;; A theme file should be named `THEME-theme.el' (where THEME is the theme | 924 ;; A theme file should be named `THEME-theme.el' (where THEME is the theme |
932 ;; name), and found in either `custom-theme-directory' or the load path. | 925 ;; name), and found in either `custom-theme-directory' or the load path. |