| 602 | | (defvar custom-known-themes '(user standard) |
|---|
| 603 | | "Themes that have been defined with `deftheme'. |
|---|
| 604 | | The default value is the list (user standard). The theme `standard' |
|---|
| 605 | | contains the settings before custom themes are applied. The |
|---|
| 606 | | theme `user' contains all the settings the user customized and saved. |
|---|
| 607 | | Additional themes declared with the `deftheme' macro will be added to |
|---|
| 608 | | the front of this list.") |
|---|
| 609 | | |
|---|
| 610 | | (defsubst custom-theme-p (theme) |
|---|
| 611 | | "Non-nil when THEME has been defined." |
|---|
| 612 | | (memq theme custom-known-themes)) |
|---|
| 613 | | |
|---|
| 614 | | (defsubst custom-check-theme (theme) |
|---|
| 615 | | "Check whether THEME is valid, and signal an error if it is not." |
|---|
| 616 | | (unless (custom-theme-p theme) |
|---|
| 617 | | (error "Unknown theme `%s'" theme))) |
|---|
| 618 | | |
|---|
| 619 | | ;;; Initializing. |
|---|
| 620 | | |
|---|
| 621 | | (defun custom-push-theme (prop symbol theme mode value) |
|---|
| 622 | | "Record a value for face or variable SYMBOL in custom theme THEME. |
|---|
| 623 | | PROP is`theme-face' for a face, `theme-value' for a variable. |
|---|
| 624 | | The value is specified by (THEME MODE VALUE), which is interpreted |
|---|
| 625 | | by `custom-theme-value'. |
|---|
| 626 | | |
|---|
| 627 | | MODE can be either the symbol `set' or the symbol `reset'. If it is the |
|---|
| 628 | | symbol `set', then VALUE is the value to use. If it is the symbol |
|---|
| 629 | | `reset', then VALUE is another theme, whose value for this face or |
|---|
| 630 | | variable should be used. |
|---|
| 631 | | |
|---|
| 632 | | In the following example for the variable `goto-address-url-face', the |
|---|
| 633 | | theme `subtle-hacker' uses the same value for the variable as the theme |
|---|
| 634 | | `gnome2': |
|---|
| 635 | | |
|---|
| 636 | | \((standard set bold) |
|---|
| 637 | | \(gnome2 set info-xref) |
|---|
| 638 | | \(jonadab set underline) |
|---|
| 639 | | \(subtle-hacker reset gnome2)) |
|---|
| 640 | | |
|---|
| 641 | | |
|---|
| 642 | | If a value has been stored for themes A B and C, and a new value |
|---|
| 643 | | is to be stored for theme C, then the old value of C is discarded. |
|---|
| 644 | | If a new value is to be stored for theme B, however, the old value |
|---|
| 645 | | of B is not discarded because B is not the car of the list. |
|---|
| 646 | | |
|---|
| 647 | | For variables, list property PROP is `theme-value'. |
|---|
| 648 | | For faces, list property PROP is `theme-face'. |
|---|
| 649 | | This is used in `custom-do-theme-reset', for example. |
|---|
| 650 | | |
|---|
| 651 | | The list looks the same in any case; the examples shows a possible |
|---|
| 652 | | value of the `theme-face' property for the face `region': |
|---|
| 653 | | |
|---|
| 654 | | \((gnome2 set ((t (:foreground \"cyan\" :background \"dark cyan\")))) |
|---|
| 655 | | \(standard set ((((class color) (background dark)) |
|---|
| 656 | | \(:background \"blue\")) |
|---|
| 657 | | \(t (:background \"gray\"))))) |
|---|
| 658 | | |
|---|
| 659 | | This records values for the `standard' and the `gnome2' themes. |
|---|
| 660 | | The user has not customized the face; had he done that, |
|---|
| 661 | | the list would contain an entry for the `user' theme, too. |
|---|
| 662 | | See `custom-known-themes' for a list of known themes." |
|---|
| 663 | | (let* ((old (get symbol prop)) |
|---|
| 664 | | (setting (assq theme old))) |
|---|
| 665 | | ;; Alter an existing theme-setting for the symbol, |
|---|
| 666 | | ;; or add a new one. |
|---|
| 667 | | (if setting |
|---|
| 668 | | (progn |
|---|
| 669 | | (setcar (cdr setting) mode) |
|---|
| 670 | | (setcar (cddr setting) value)) |
|---|
| 671 | | ;; If no custom theme has been applied yet, first save the |
|---|
| 672 | | ;; current values to the 'standard theme. |
|---|
| 673 | | (if (null old) |
|---|
| 674 | | (if (and (eq prop 'theme-value) |
|---|
| 675 | | (boundp symbol)) |
|---|
| 676 | | (setq old |
|---|
| 677 | | (list (list 'standard 'set (symbol-value symbol)))) |
|---|
| 678 | | (if (facep symbol) |
|---|
| 679 | | (setq old (list (list 'standard 'set (list |
|---|
| 680 | | (append '(t) (custom-face-attributes-get symbol nil))))))))) |
|---|
| 681 | | (put symbol prop (cons (list theme mode value) old))) |
|---|
| 682 | | ;; Record, for each theme, all its settings. |
|---|
| 683 | | (put theme 'theme-settings |
|---|
| 684 | | (cons (list prop symbol theme mode value) |
|---|
| 685 | | (get theme 'theme-settings))))) |
|---|
| 686 | | |
|---|
| 695 | | (defun custom-set-variables (&rest args) |
|---|
| 696 | | "Install user customizations of variable values specified in ARGS. |
|---|
| 697 | | These settings are registered as theme `user'. |
|---|
| 698 | | The arguments should each be a list of the form: |
|---|
| 699 | | |
|---|
| 700 | | (SYMBOL EXP [NOW [REQUEST [COMMENT]]]) |
|---|
| 701 | | |
|---|
| 702 | | This stores EXP (without evaluating it) as the saved value for SYMBOL. |
|---|
| 703 | | If NOW is present and non-nil, then also evaluate EXP and set |
|---|
| 704 | | the default value for the SYMBOL to the value of EXP. |
|---|
| 705 | | |
|---|
| 706 | | REQUEST is a list of features we must require in order to |
|---|
| 707 | | handle SYMBOL properly. |
|---|
| 708 | | COMMENT is a comment string about SYMBOL." |
|---|
| 709 | | (apply 'custom-theme-set-variables 'user args)) |
|---|
| | 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))))) |
|---|
| | 707 | |
|---|
| | 708 | ;;; Custom Themes |
|---|
| | 709 | |
|---|
| | 710 | ;; Custom themes are collections of settings that can be enabled or |
|---|
| | 711 | ;; disabled as a unit. |
|---|
| | 712 | |
|---|
| | 713 | ;; Each Custom theme is defined by a symbol, called the theme name. |
|---|
| | 714 | ;; The `theme-settings' property of the theme name records the |
|---|
| | 715 | ;; variable and face settings of the theme. This property is a list |
|---|
| | 716 | ;; of elements, each of the form |
|---|
| | 717 | ;; |
|---|
| | 718 | ;; (PROP SYMBOL THEME VALUE) |
|---|
| | 719 | ;; |
|---|
| | 720 | ;; - PROP is either `theme-value' or `theme-face' |
|---|
| | 721 | ;; - SYMBOL is the face or variable name |
|---|
| | 722 | ;; - THEME is the theme name (redundant, but simplifies the code) |
|---|
| | 723 | ;; - VALUE is an expression that gives the theme's setting for SYMBOL. |
|---|
| | 724 | ;; |
|---|
| | 725 | ;; The theme name also has a `theme-feature' property, whose value is |
|---|
| | 726 | ;; specified when the theme is defined (see `custom-declare-theme'). |
|---|
| | 727 | ;; Usually, this is just a symbol named THEME-theme. This lets |
|---|
| | 728 | ;; external libraries call (require 'foo-theme). |
|---|
| | 729 | |
|---|
| | 730 | ;; In addition, each symbol (either a variable or a face) affected by |
|---|
| | 731 | ;; an *enabled* theme has a `theme-value' or `theme-face' property, |
|---|
| | 732 | ;; which is a list of elements each of the form |
|---|
| | 733 | ;; |
|---|
| | 734 | ;; (THEME VALUE) |
|---|
| | 735 | ;; |
|---|
| | 736 | ;; which have the same meanings as in `theme-settings'. |
|---|
| | 737 | ;; |
|---|
| | 738 | ;; The `theme-value' and `theme-face' lists are ordered by decreasing |
|---|
| | 739 | ;; theme precedence. Thus, the first element is always the one that |
|---|
| | 740 | ;; is in effect. |
|---|
| | 741 | |
|---|
| | 742 | ;; Each theme is stored in a theme file, with filename THEME-theme.el. |
|---|
| | 743 | ;; Loading a theme basically involves calling (load "THEME-theme") |
|---|
| | 744 | ;; This is done by the function `load-theme'. Loading a theme |
|---|
| | 745 | ;; automatically enables it. |
|---|
| | 746 | ;; |
|---|
| | 747 | ;; When a theme is enabled, the `theme-value' and `theme-face' |
|---|
| | 748 | ;; properties for the affected symbols are set. When a theme is |
|---|
| | 749 | ;; disabled, its settings are removed from the `theme-value' and |
|---|
| | 750 | ;; `theme-face' properties, but the theme's own `theme-settings' |
|---|
| | 751 | ;; property remains unchanged. |
|---|
| | 752 | |
|---|
| | 753 | (defvar custom-known-themes '(user changed) |
|---|
| | 754 | "Themes that have been defined with `deftheme'. |
|---|
| | 755 | The default value is the list (user changed). The theme `changed' |
|---|
| | 756 | contains the settings before custom themes are applied. The |
|---|
| | 757 | theme `user' contains all the settings the user customized and saved. |
|---|
| | 758 | Additional themes declared with the `deftheme' macro will be added to |
|---|
| | 759 | the front of this list.") |
|---|
| | 760 | |
|---|
| | 761 | (defsubst custom-theme-p (theme) |
|---|
| | 762 | "Non-nil when THEME has been defined." |
|---|
| | 763 | (memq theme custom-known-themes)) |
|---|
| | 764 | |
|---|
| | 765 | (defsubst custom-check-theme (theme) |
|---|
| | 766 | "Check whether THEME is valid, and signal an error if it is not." |
|---|
| | 767 | (unless (custom-theme-p theme) |
|---|
| | 768 | (error "Unknown theme `%s'" theme))) |
|---|
| | 769 | |
|---|
| | 770 | (defun custom-push-theme (prop symbol theme mode &optional value) |
|---|
| | 771 | "Record VALUE for face or variable SYMBOL in custom theme THEME. |
|---|
| | 772 | PROP is `theme-face' for a face, `theme-value' for a variable. |
|---|
| | 773 | |
|---|
| | 774 | MODE can be either the symbol `set' or the symbol `reset'. If it is the |
|---|
| | 775 | symbol `set', then VALUE is the value to use. If it is the symbol |
|---|
| | 776 | `reset', then SYMBOL will be removed from THEME (VALUE is ignored). |
|---|
| | 777 | |
|---|
| | 778 | See `custom-known-themes' for a list of known themes." |
|---|
| | 779 | (unless (memq prop '(theme-value theme-face)) |
|---|
| | 780 | (error "Unknown theme property")) |
|---|
| | 781 | (let* ((old (get symbol prop)) |
|---|
| | 782 | (setting (assq theme old)) ; '(theme value) |
|---|
| | 783 | (theme-settings ; '(prop symbol theme value) |
|---|
| | 784 | (get theme 'theme-settings))) |
|---|
| | 785 | (if (eq mode 'reset) |
|---|
| | 786 | ;; Remove a setting. |
|---|
| | 787 | (when setting |
|---|
| | 788 | (let (res) |
|---|
| | 789 | (dolist (theme-setting theme-settings) |
|---|
| | 790 | (if (and (eq (car theme-setting) prop) |
|---|
| | 791 | (eq (cadr theme-setting) symbol)) |
|---|
| | 792 | (setq res theme-setting))) |
|---|
| | 793 | (put theme 'theme-settings (delq res theme-settings))) |
|---|
| | 794 | (put symbol prop (delq setting old))) |
|---|
| | 795 | (if setting |
|---|
| | 796 | ;; Alter an existing setting. |
|---|
| | 797 | (let (res) |
|---|
| | 798 | (dolist (theme-setting theme-settings) |
|---|
| | 799 | (if (and (eq (car theme-setting) prop) |
|---|
| | 800 | (eq (cadr theme-setting) symbol)) |
|---|
| | 801 | (setq res theme-setting))) |
|---|
| | 802 | (put theme 'theme-settings |
|---|
| | 803 | (cons (list prop symbol theme value) |
|---|
| | 804 | (delq res theme-settings))) |
|---|
| | 805 | (setcar (cdr setting) value)) |
|---|
| | 806 | ;; Add a new setting. |
|---|
| | 807 | ;; If the user changed the value outside of Customize, we |
|---|
| | 808 | ;; first save the current value to a fake theme, `changed'. |
|---|
| | 809 | ;; This ensures that the user-set value comes back if the |
|---|
| | 810 | ;; theme is later disabled. |
|---|
| | 811 | (if (null old) |
|---|
| | 812 | (if (and (eq prop 'theme-value) |
|---|
| | 813 | (boundp symbol) |
|---|
| | 814 | (or (null (get symbol 'standard-value)) |
|---|
| | 815 | (not (equal (eval (car (get symbol 'standard-value))) |
|---|
| | 816 | (symbol-value symbol))))) |
|---|
| | 817 | (setq old (list (list 'changed (symbol-value symbol)))) |
|---|
| | 818 | (if (facep symbol) |
|---|
| | 819 | (setq old (list (list 'changed (list |
|---|
| | 820 | (append '(t) (custom-face-attributes-get symbol nil))))))))) |
|---|
| | 821 | (put symbol prop (cons (list theme value) old)) |
|---|
| | 822 | (put theme 'theme-settings |
|---|
| | 823 | (cons (list prop symbol theme value) |
|---|
| | 824 | theme-settings)))))) |
|---|
| | 825 | |
|---|
| | 826 | |
|---|
| | 827 | (defun custom-set-variables (&rest args) |
|---|
| | 828 | "Install user customizations of variable values specified in ARGS. |
|---|
| | 829 | These settings are registered as theme `user'. |
|---|
| | 830 | The arguments should each be a list of the form: |
|---|
| | 831 | |
|---|
| | 832 | (SYMBOL EXP [NOW [REQUEST [COMMENT]]]) |
|---|
| | 833 | |
|---|
| | 834 | This stores EXP (without evaluating it) as the saved value for SYMBOL. |
|---|
| | 835 | If NOW is present and non-nil, then also evaluate EXP and set |
|---|
| | 836 | the default value for the SYMBOL to the value of EXP. |
|---|
| | 837 | |
|---|
| | 838 | REQUEST is a list of features we must require in order to |
|---|
| | 839 | handle SYMBOL properly. |
|---|
| | 840 | COMMENT is a comment string about SYMBOL." |
|---|
| | 841 | (apply 'custom-theme-set-variables 'user args)) |
|---|
| | 842 | |
|---|
| 806 | | (defun custom-set-default (variable value) |
|---|
| 807 | | "Default :set function for a customizable variable. |
|---|
| 808 | | Normally, this sets the default value of VARIABLE to VALUE, |
|---|
| 809 | | but if `custom-local-buffer' is non-nil, |
|---|
| 810 | | this sets the local binding in that buffer instead." |
|---|
| 811 | | (if custom-local-buffer |
|---|
| 812 | | (with-current-buffer custom-local-buffer |
|---|
| 813 | | (set variable value)) |
|---|
| 814 | | (set-default variable value))) |
|---|
| 815 | | |
|---|
| 816 | | (defun custom-set-minor-mode (variable value) |
|---|
| 817 | | ":set function for minor mode variables. |
|---|
| 818 | | Normally, this sets the default value of VARIABLE to nil if VALUE |
|---|
| 819 | | is nil and to t otherwise, |
|---|
| 820 | | but if `custom-local-buffer' is non-nil, |
|---|
| 821 | | this sets the local binding in that buffer instead." |
|---|
| 822 | | (if custom-local-buffer |
|---|
| 823 | | (with-current-buffer custom-local-buffer |
|---|
| 824 | | (funcall variable (if value 1 0))) |
|---|
| 825 | | (funcall variable (if value 1 0)))) |
|---|
| 826 | | |
|---|
| 827 | | (defun custom-quote (sexp) |
|---|
| 828 | | "Quote SEXP iff it is not self quoting." |
|---|
| 829 | | (if (or (memq sexp '(t nil)) |
|---|
| 830 | | (keywordp sexp) |
|---|
| 831 | | (and (listp sexp) |
|---|
| 832 | | (memq (car sexp) '(lambda))) |
|---|
| 833 | | (stringp sexp) |
|---|
| 834 | | (numberp sexp) |
|---|
| 835 | | (vectorp sexp) |
|---|
| 836 | | ;;; (and (fboundp 'characterp) |
|---|
| 837 | | ;;; (characterp sexp)) |
|---|
| 838 | | ) |
|---|
| 839 | | sexp |
|---|
| 840 | | (list 'quote sexp))) |
|---|
| 841 | | |
|---|
| 842 | | (defun customize-mark-to-save (symbol) |
|---|
| 843 | | "Mark SYMBOL for later saving. |
|---|
| 844 | | |
|---|
| 845 | | If the default value of SYMBOL is different from the standard value, |
|---|
| 846 | | set the `saved-value' property to a list whose car evaluates to the |
|---|
| 847 | | default value. Otherwise, set it to nil. |
|---|
| 848 | | |
|---|
| 849 | | To actually save the value, call `custom-save-all'. |
|---|
| 850 | | |
|---|
| 851 | | Return non-nil iff the `saved-value' property actually changed." |
|---|
| 852 | | (let* ((get (or (get symbol 'custom-get) 'default-value)) |
|---|
| 853 | | (value (funcall get symbol)) |
|---|
| 854 | | (saved (get symbol 'saved-value)) |
|---|
| 855 | | (standard (get symbol 'standard-value)) |
|---|
| 856 | | (comment (get symbol 'customized-variable-comment))) |
|---|
| 857 | | ;; Save default value iff different from standard value. |
|---|
| 858 | | (if (or (null standard) |
|---|
| 859 | | (not (equal value (condition-case nil |
|---|
| 860 | | (eval (car standard)) |
|---|
| 861 | | (error nil))))) |
|---|
| 862 | | (put symbol 'saved-value (list (custom-quote value))) |
|---|
| 863 | | (put symbol 'saved-value nil)) |
|---|
| 864 | | ;; Clear customized information (set, but not saved). |
|---|
| 865 | | (put symbol 'customized-value nil) |
|---|
| 866 | | ;; Save any comment that might have been set. |
|---|
| 867 | | (when comment |
|---|
| 868 | | (put symbol 'saved-variable-comment comment)) |
|---|
| 869 | | (not (equal saved (get symbol 'saved-value))))) |
|---|
| 870 | | |
|---|
| 871 | | (defun customize-mark-as-set (symbol) |
|---|
| 872 | | "Mark current value of SYMBOL as being set from customize. |
|---|
| 873 | | |
|---|
| 874 | | If the default value of SYMBOL is different from the saved value if any, |
|---|
| 875 | | or else if it is different from the standard value, set the |
|---|
| 876 | | `customized-value' property to a list whose car evaluates to the |
|---|
| 877 | | default value. Otherwise, set it to nil. |
|---|
| 878 | | |
|---|
| 879 | | Return non-nil iff the `customized-value' property actually changed." |
|---|
| 880 | | (let* ((get (or (get symbol 'custom-get) 'default-value)) |
|---|
| 881 | | (value (funcall get symbol)) |
|---|
| 882 | | (customized (get symbol 'customized-value)) |
|---|
| 883 | | (old (or (get symbol 'saved-value) (get symbol 'standard-value)))) |
|---|
| 884 | | ;; Mark default value as set iff different from old value. |
|---|
| 885 | | (if (or (null old) |
|---|
| 886 | | (not (equal value (condition-case nil |
|---|
| 887 | | (eval (car old)) |
|---|
| 888 | | (error nil))))) |
|---|
| 889 | | (put symbol 'customized-value (list (custom-quote value))) |
|---|
| 890 | | (put symbol 'customized-value nil)) |
|---|
| 891 | | ;; Changed? |
|---|
| 892 | | (not (equal customized (get symbol 'customized-value))))) |
|---|
| 901 | | The remaining arguments should have the form |
|---|
| 902 | | |
|---|
| 903 | | [KEYWORD VALUE]... |
|---|
| 904 | | |
|---|
| 905 | | The following KEYWORD's are defined: |
|---|
| 906 | | |
|---|
| 907 | | :short-description |
|---|
| 908 | | VALUE is a short (one line) description of the theme. If not |
|---|
| 909 | | given, DOC is used. |
|---|
| 910 | | :immediate |
|---|
| 911 | | If VALUE is non-nil, variables specified in this theme are set |
|---|
| 912 | | immediately when loading the theme. |
|---|
| 913 | | :variable-set-string |
|---|
| 914 | | VALUE is a string used to indicate that a variable takes its |
|---|
| 915 | | setting from this theme. It is passed to FORMAT with the name |
|---|
| 916 | | of the theme as an additional argument. If not given, a |
|---|
| 917 | | generic description is used. |
|---|
| 918 | | :variable-reset-string |
|---|
| 919 | | VALUE is a string used in the case a variable has been forced |
|---|
| 920 | | to its value in this theme. It is passed to FORMAT with the |
|---|
| 921 | | name of the theme as an additional argument. If not given, a |
|---|
| 922 | | generic description is used. |
|---|
| 923 | | :face-set-string |
|---|
| 924 | | VALUE is a string used to indicate that a face takes its |
|---|
| 925 | | setting from this theme. It is passed to FORMAT with the name |
|---|
| 926 | | of the theme as an additional argument. If not given, a |
|---|
| 927 | | generic description is used. |
|---|
| 928 | | :face-reset-string |
|---|
| 929 | | VALUE is a string used in the case a face has been forced to |
|---|
| 930 | | its value in this theme. It is passed to FORMAT with the name |
|---|
| 931 | | of the theme as an additional argument. If not given, a |
|---|
| 932 | | generic description is used. |
|---|
| 989 | | |
|---|
| 990 | | ;; The variable and face settings of a theme are recorded in |
|---|
| 991 | | ;; the `theme-settings' property of the theme name. |
|---|
| 992 | | ;; This property's value is a list of elements, each of the form |
|---|
| 993 | | ;; (PROP SYMBOL THEME MODE VALUE), where PROP is `theme-value' or `theme-face' |
|---|
| 994 | | ;; and SYMBOL is the face or variable name. |
|---|
| 995 | | ;; THEME is the theme name itself; that's redundant, but simplifies things. |
|---|
| 996 | | ;; MODE is `set' or `reset'. |
|---|
| 997 | | ;; If MODE is `set', then VALUE is an expression that specifies the |
|---|
| 998 | | ;; theme's setting for SYMBOL. |
|---|
| 999 | | ;; If MODE is `reset', then VALUE is another theme, |
|---|
| 1000 | | ;; and it means to use the value from that theme. |
|---|
| 1001 | | |
|---|
| 1002 | | ;; Each variable has a `theme-value' property that describes all the |
|---|
| 1003 | | ;; settings of enabled themes that apply to it. |
|---|
| 1004 | | ;; Each face name has a `theme-face' property that describes all the |
|---|
| 1005 | | ;; settings of enabled themes that apply to it. |
|---|
| 1006 | | ;; The property value is a list of settings, each with the form |
|---|
| 1007 | | ;; (THEME MODE VALUE). THEME, MODE and VALUE are as above. |
|---|
| 1008 | | ;; Each of these lists is ordered by decreasing theme precedence. |
|---|
| 1009 | | ;; Thus, the first element is always the one that is in effect. |
|---|
| 1010 | | |
|---|
| 1011 | | ;; Disabling a theme removes its settings from the `theme-value' and |
|---|
| 1012 | | ;; `theme-face' properties, but the theme's own `theme-settings' |
|---|
| 1013 | | ;; property remains unchanged. |
|---|
| 1014 | | |
|---|
| 1015 | | ;; Loading a theme implicitly enables it. Enabling a theme adds its |
|---|
| 1016 | | ;; settings to the symbols' `theme-value' and `theme-face' properties, |
|---|
| 1017 | | ;; or moves them to the front of those lists if they're already present. |
|---|
| 1018 | | |
|---|
| 1019 | | (defvar custom-loaded-themes nil |
|---|
| 1020 | | "Custom themes that have been loaded.") |
|---|
| 1079 | | (require (or (get theme 'theme-feature) |
|---|
| 1080 | | (custom-make-theme-feature theme))))) |
|---|
| 1081 | | |
|---|
| 1082 | | ;;; How to load and enable various themes as part of `user'. |
|---|
| 1083 | | |
|---|
| 1084 | | (defun custom-theme-load-themes (by-theme &rest body) |
|---|
| 1085 | | "Load the themes specified by BODY. |
|---|
| 1086 | | Record them as required by theme BY-THEME. |
|---|
| 1087 | | |
|---|
| 1088 | | BODY is a sequence of either |
|---|
| 1089 | | |
|---|
| 1090 | | THEME |
|---|
| 1091 | | Load THEME and enable it. |
|---|
| 1092 | | \(reset THEME) |
|---|
| 1093 | | Undo all the settings made by THEME |
|---|
| 1094 | | \(hidden THEME) |
|---|
| 1095 | | Load THEME but do not enable it. |
|---|
| 1096 | | |
|---|
| 1097 | | All the themes loaded for BY-THEME are recorded in BY-THEME's property |
|---|
| 1098 | | `theme-loads-themes'." |
|---|
| 1099 | | (custom-check-theme by-theme) |
|---|
| 1100 | | (let ((themes-loaded (get by-theme 'theme-loads-themes))) |
|---|
| 1101 | | (dolist (theme body) |
|---|
| 1102 | | (cond ((and (consp theme) (eq (car theme) 'reset)) |
|---|
| 1103 | | (disable-theme (cadr theme))) |
|---|
| 1104 | | ((and (consp theme) (eq (car theme) 'hidden)) |
|---|
| 1105 | | (load-theme (cadr theme)) |
|---|
| 1106 | | (disable-theme (cadr theme))) |
|---|
| 1107 | | (t |
|---|
| 1108 | | (load-theme theme))) |
|---|
| 1109 | | (push theme themes-loaded)) |
|---|
| 1110 | | (put by-theme 'theme-loads-themes themes-loaded))) |
|---|
| 1111 | | |
|---|
| 1112 | | (defun custom-load-themes (&rest body) |
|---|
| 1113 | | "Load themes for the USER theme as specified by BODY. |
|---|
| 1114 | | |
|---|
| 1115 | | See `custom-theme-load-themes' for more information on BODY." |
|---|
| 1116 | | (apply 'custom-theme-load-themes 'user body)) |
|---|
| | 1024 | (load (symbol-name (custom-make-theme-feature theme))))) |
|---|
| 1128 | | (let ((settings (get theme 'theme-settings))) |
|---|
| 1129 | | (if (and (not (eq theme 'user)) (null settings)) |
|---|
| 1130 | | (error "No theme settings defined in %s." (symbol-name theme))) |
|---|
| 1131 | | (dolist (s settings) |
|---|
| 1132 | | (let* ((prop (car s)) |
|---|
| 1133 | | (symbol (cadr s)) |
|---|
| 1134 | | (spec-list (get symbol prop))) |
|---|
| 1135 | | (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list))) |
|---|
| 1136 | | (if (eq prop 'theme-value) |
|---|
| 1137 | | (custom-theme-recalc-variable symbol) |
|---|
| 1138 | | (if (facep symbol) |
|---|
| 1139 | | (custom-theme-recalc-face symbol)))))) |
|---|
| 1140 | | (setq custom-enabled-themes |
|---|
| 1141 | | (cons theme (delq theme custom-enabled-themes))) |
|---|
| 1142 | | ;; `user' must always be the highest-precedence enabled theme. |
|---|
| 1143 | | (unless (eq theme 'user) |
|---|
| 1144 | | (enable-theme 'user))) |
|---|
| | 1038 | (if (not (custom-theme-p theme)) |
|---|
| | 1039 | (load-theme theme) |
|---|
| | 1040 | ;; This could use a bit of optimization -- cyd |
|---|
| | 1041 | (let ((settings (get theme 'theme-settings))) |
|---|
| | 1042 | (dolist (s settings) |
|---|
| | 1043 | (let* ((prop (car s)) |
|---|
| | 1044 | (symbol (cadr s)) |
|---|
| | 1045 | (spec-list (get symbol prop))) |
|---|
| | 1046 | (put symbol prop (cons (cddr s) (assq-delete-all theme spec-list))) |
|---|
| | 1047 | (if (eq prop 'theme-value) |
|---|
| | 1048 | (custom-theme-recalc-variable symbol) |
|---|
| | 1049 | (custom-theme-recalc-face symbol))))) |
|---|
| | 1050 | (unless (eq theme 'user) |
|---|
| | 1051 | (setq custom-enabled-themes |
|---|
| | 1052 | (cons theme (delq theme custom-enabled-themes))) |
|---|
| | 1053 | (unless custom-enabling-themes |
|---|
| | 1054 | (enable-theme 'user))))) |
|---|
| | 1055 | |
|---|
| | 1056 | (defcustom custom-enabled-themes nil |
|---|
| | 1057 | "List of enabled Custom Themes, highest precedence first. |
|---|
| | 1058 | |
|---|
| | 1059 | This does not include the `user' theme, which is set by Customize, |
|---|
| | 1060 | and always takes precedence over other Custom Themes." |
|---|
| | 1061 | :group 'customize |
|---|
| | 1062 | :type '(repeat symbol) |
|---|
| | 1063 | :set (lambda (symbol themes) |
|---|
| | 1064 | ;; Avoid an infinite loop when custom-enabled-themes is |
|---|
| | 1065 | ;; defined in a theme (e.g. `user'). Enabling the theme sets |
|---|
| | 1066 | ;; custom-enabled-themes, which enables the theme... |
|---|
| | 1067 | (unless custom-enabling-themes |
|---|
| | 1068 | (let ((custom-enabling-themes t) failures) |
|---|
| | 1069 | (setq themes (delq 'user (delete-dups themes))) |
|---|
| | 1070 | (if (boundp symbol) |
|---|
| | 1071 | (dolist (theme (symbol-value symbol)) |
|---|
| | 1072 | (if (not (memq theme themes)) |
|---|
| | 1073 | (disable-theme theme)))) |
|---|
| | 1074 | (dolist (theme (reverse themes)) |
|---|
| | 1075 | (condition-case nil |
|---|
| | 1076 | (enable-theme theme) |
|---|
| | 1077 | (error (progn (push theme failures) |
|---|
| | 1078 | (setq themes (delq theme themes)))))) |
|---|
| | 1079 | (enable-theme 'user) |
|---|
| | 1080 | (custom-set-default symbol themes) |
|---|
| | 1081 | (if failures |
|---|
| | 1082 | (message "Failed to enable themes: %s" |
|---|
| | 1083 | (mapconcat 'symbol-name failures " "))))))) |
|---|
| | 1084 | |
|---|
| | 1085 | (defsubst custom-theme-enabled-p (theme) |
|---|
| | 1086 | "Return non-nil if THEME is enabled." |
|---|
| | 1087 | (memq theme custom-enabled-themes)) |
|---|
| 1148 | | See `custom-known-themes' for a list of known themes." |
|---|
| 1149 | | (interactive "SDisable Custom theme: ") |
|---|
| 1150 | | (let ((settings (get theme 'theme-settings))) |
|---|
| 1151 | | (dolist (s settings) |
|---|
| 1152 | | (let* ((prop (car s)) |
|---|
| 1153 | | (symbol (cadr s)) |
|---|
| 1154 | | (spec-list (get symbol prop))) |
|---|
| 1155 | | (put symbol prop (assq-delete-all theme spec-list)) |
|---|
| 1156 | | (if (eq prop 'theme-value) |
|---|
| 1157 | | (custom-theme-recalc-variable symbol) |
|---|
| 1158 | | (custom-theme-recalc-face symbol))))) |
|---|
| 1159 | | (setq custom-enabled-themes |
|---|
| 1160 | | (delq theme custom-enabled-themes))) |
|---|
| 1161 | | |
|---|
| 1162 | | (defun custom-theme-value (theme setting-list) |
|---|
| 1163 | | "Determine the value specified for THEME according to SETTING-LIST. |
|---|
| 1164 | | Returns a list whose car is the specified value, if we |
|---|
| 1165 | | find one; nil otherwise. |
|---|
| 1166 | | |
|---|
| 1167 | | SETTING-LIST is an alist with themes as its key. |
|---|
| 1168 | | Each element has the form: |
|---|
| 1169 | | |
|---|
| 1170 | | \(THEME MODE VALUE) |
|---|
| 1171 | | |
|---|
| 1172 | | MODE is either the symbol `set' or the symbol `reset'. See |
|---|
| 1173 | | `custom-push-theme' for more information on the format of |
|---|
| 1174 | | SETTING-LIST." |
|---|
| 1175 | | ;; Note we do _NOT_ signal an error if the theme is unknown |
|---|
| 1176 | | ;; it might have gone away without the user knowing. |
|---|
| 1177 | | (let ((elt (cdr (assoc theme setting-list)))) |
|---|
| 1178 | | (if elt |
|---|
| 1179 | | (if (eq (car elt) 'set) |
|---|
| 1180 | | (cdr elt) |
|---|
| 1181 | | ;; `reset' means refer to another theme's value in the same alist. |
|---|
| 1182 | | (custom-theme-value (cadr elt) setting-list))))) |
|---|
| | 1091 | See `custom-enabled-themes' for a list of enabled themes." |
|---|
| | 1092 | (interactive (list (intern |
|---|
| | 1093 | (completing-read |
|---|
| | 1094 | "Disable Custom theme: " |
|---|
| | 1095 | (mapcar 'symbol-name custom-enabled-themes) |
|---|
| | 1096 | nil t)))) |
|---|
| | 1097 | (when (custom-theme-enabled-p theme) |
|---|
| | 1098 | (let ((settings (get theme 'theme-settings))) |
|---|
| | 1099 | (dolist (s settings) |
|---|
| | 1100 | (let* ((prop (car s)) |
|---|
| | 1101 | (symbol (cadr s)) |
|---|
| | 1102 | (spec-list (get symbol prop))) |
|---|
| | 1103 | (put symbol prop (assq-delete-all theme spec-list)) |
|---|
| | 1104 | (if (eq prop 'theme-value) |
|---|
| | 1105 | (custom-theme-recalc-variable symbol) |
|---|
| | 1106 | (custom-theme-recalc-face symbol))))) |
|---|
| | 1107 | (setq custom-enabled-themes |
|---|
| | 1108 | (delq theme custom-enabled-themes)))) |
|---|