Show
Ignore:
Timestamp:
01/28/06 09:46:44 (3 years ago)
Author:
miyoshi
Message:

Update.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • vendor/emacs-CVS_HEAD/lisp/custom.el

    r3988 r4018  
    600600              (t (condition-case nil (load load) (error nil)))))))) 
    601601  
    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   
    687602(defvar custom-local-buffer nil 
    688603  "Non-nil, in a Customization buffer, means customize a specific buffer. 
     
    693608(put 'custom-local-buffer 'permanent-local t) 
    694609 
    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. 
     612Normally, this sets the default value of VARIABLE to VALUE, 
     613but if `custom-local-buffer' is non-nil, 
     614this 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. 
     622Normally, this sets the default value of VARIABLE to nil if VALUE 
     623is nil and to t otherwise, 
     624but if `custom-local-buffer' is non-nil, 
     625this 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 
     649If the default value of SYMBOL is different from the standard value, 
     650set the `saved-value' property to a list whose car evaluates to the 
     651default value.  Otherwise, set it to nil. 
     652 
     653To actually save the value, call `custom-save-all'. 
     654 
     655Return 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 
     678If the default value of SYMBOL is different from the saved value if any, 
     679or else if it is different from the standard value, set the 
     680`customized-value' property to a list whose car evaluates to the 
     681default value.  Otherwise, set it to nil. 
     682 
     683Return 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))))) 
    710697 
    711698(defun custom-reevaluate-setting (symbol) 
     
    718705           (eval (car (or (get symbol 'saved-value) (get symbol 'standard-value)))))) 
    719706 
     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'. 
     755The default value is the list (user changed).  The theme `changed' 
     756contains the settings before custom themes are applied.  The 
     757theme `user' contains all the settings the user customized and saved. 
     758Additional themes declared with the `deftheme' macro will be added to 
     759the 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. 
     772PROP is `theme-face' for a face, `theme-value' for a variable. 
     773 
     774MODE can be either the symbol `set' or the symbol `reset'.  If it is the 
     775symbol `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 
     778See `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. 
     829These settings are registered as theme `user'. 
     830The arguments should each be a list of the form: 
     831 
     832  (SYMBOL EXP [NOW [REQUEST [COMMENT]]]) 
     833 
     834This stores EXP (without evaluating it) as the saved value for SYMBOL. 
     835If NOW is present and non-nil, then also evaluate EXP and set 
     836the default value for the SYMBOL to the value of EXP. 
     837 
     838REQUEST is a list of features we must require in order to 
     839handle SYMBOL properly. 
     840COMMENT is a comment string about SYMBOL." 
     841  (apply 'custom-theme-set-variables 'user args)) 
     842 
    720843(defun custom-theme-set-variables (theme &rest args) 
    721844  "Initialize variables for theme THEME according to settings in ARGS. 
     
    731854handle SYMBOL properly. 
    732855COMMENT is a comment string about SYMBOL. 
    733  
    734 Several properties of THEME and SYMBOL are used in the process: 
    735  
    736 If THEME's property `theme-immediate' is non-nil, this is equivalent of 
    737 providing the NOW argument to all symbols in the argument list: 
    738 evaluate each EXP and set the corresponding SYMBOL.  However, 
    739 there's a difference in the handling of SYMBOL's property 
    740 `force-value': if NOW is non-nil, SYMBOL's property `force-value' is set to 
    741 the symbol `rogue', else if THEME's property `theme-immediate' is non-nil, 
    742 SYMBOL's property `force-value' is set to the symbol `immediate'. 
    743856 
    744857EXP itself is saved unevaluated as SYMBOL property `saved-value' and 
     
    804917        (setq args (cdr (cdr args))))))) 
    805918 
    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))))) 
    893919  
    894920;;; Defining themes. 
    895921 
    896 ;; deftheme is used at the beginning of the file that records a theme. 
    897  
    898 (defmacro deftheme (theme &optional doc &rest args) 
    899   "Declare custom theme THEME. 
     922;; A theme file should be named `THEME-theme.el' (where THEME is the theme 
     923;; name), and found in either `custom-theme-directory' or the load path. 
     924;; It has the following format: 
     925;; 
     926;;   (deftheme THEME 
     927;;     DOCSTRING) 
     928;; 
     929;;   (custom-theme-set-variables 
     930;;    'THEME 
     931;;    [THEME-VARIABLES]) 
     932;; 
     933;;   (custom-theme-set-faces 
     934;;    'THEME 
     935;;    [THEME-FACES]) 
     936;; 
     937;;   (provide-theme 'THEME) 
     938 
     939 
     940;; The IGNORED arguments to deftheme come from the XEmacs theme code, where 
     941;; they were used to supply keyword-value pairs like `:immediate', 
     942;; `:variable-reset-string', etc.  We don't use any of these, so ignore them. 
     943 
     944(defmacro deftheme (theme &optional doc &rest ignored) 
     945  "Declare THEME to be a Custom theme. 
    900946The optional argument DOC is a doc string describing the theme. 
    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. 
    933947 
    934948Any theme `foo' should be defined in a file called `foo-theme.el'; 
     
    938952    ;; because that makes a bootstrapping problem 
    939953    ;; if you need to recompile all the Lisp files using interpreted code. 
    940     (nconc (list 'custom-declare-theme 
    941                  (list 'quote theme) 
    942                  (list 'quote feature) 
    943                  doc) 
    944            args))) 
    945  
    946 (defun custom-declare-theme (theme feature &optional doc &rest args) 
     954    (list 'custom-declare-theme (list 'quote theme) (list 'quote feature) doc))) 
     955 
     956(defun custom-declare-theme (theme feature &optional doc &rest ignored) 
    947957  "Like `deftheme', but THEME is evaluated as a normal argument. 
    948 FEATURE is the feature this theme provides.  This symbol is created 
    949 from THEME by `custom-make-theme-feature'." 
     958FEATURE is the feature this theme provides.  Normally, this is a symbol 
     959created from THEME by `custom-make-theme-feature'." 
     960  (if (memq theme '(user changed)) 
     961      (error "Custom theme cannot be named %S" theme)) 
    950962  (add-to-list 'custom-known-themes theme) 
    951963  (put theme 'theme-feature feature) 
    952   (when doc 
    953     (put theme 'theme-documentation doc)) 
    954   (while args 
    955     (let ((arg (car args))) 
    956       (setq args (cdr args)) 
    957       (unless (symbolp arg) 
    958         (error "Junk in args %S" args)) 
    959       (let ((keyword arg) 
    960             (value (car args))) 
    961         (unless args 
    962           (error "Keyword %s is missing an argument" keyword)) 
    963         (setq args (cdr args)) 
    964         (cond ((eq keyword :short-description) 
    965                (put theme 'theme-short-description value)) 
    966               ((eq keyword :immediate) 
    967                (put theme 'theme-immediate value)) 
    968               ((eq keyword :variable-set-string) 
    969                (put theme 'theme-variable-set-string value)) 
    970               ((eq keyword :variable-reset-string) 
    971                (put theme 'theme-variable-reset-string value)) 
    972               ((eq keyword :face-set-string) 
    973                (put theme 'theme-face-set-string value)) 
    974               ((eq keyword :face-reset-string) 
    975                (put theme 'theme-face-reset-string value))))))) 
     964  (when doc (put theme 'theme-documentation doc))) 
    976965 
    977966(defun custom-make-theme-feature (theme) 
     
    987976  
    988977;;; Loading themes. 
    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.") 
    1021978 
    1022979(defcustom custom-theme-directory 
     
    1033990  :version "22.1") 
    1034991 
    1035 (defun custom-theme-loaded-p (theme) 
    1036   "Return non-nil if THEME has been loaded." 
    1037   (memq theme custom-loaded-themes)) 
    1038  
    1039 (defvar custom-enabled-themes '(user) 
    1040   "Custom themes currently enabled, highest precedence first. 
    1041 The first one is always `user'.") 
    1042  
    1043 (defun custom-theme-enabled-p (theme) 
    1044   "Return non-nil if THEME is enabled." 
    1045   (memq theme custom-enabled-themes)) 
    1046  
    1047992(defun provide-theme (theme) 
    1048993  "Indicate that this file provides THEME. 
    1049 Add THEME to `custom-loaded-themes', and `provide' whatever 
    1050 feature name is stored in THEME's property `theme-feature'. 
    1051  
    1052 Usually the `theme-feature' property contains a symbol created 
    1053 by `custom-make-theme-feature'." 
     994This calls `provide' to provide the feature name stored in THEME's 
     995property `theme-feature' (which is usually a symbol created by 
     996`custom-make-theme-feature')." 
     997  (if (memq theme '(user changed)) 
     998      (error "Custom theme cannot be named %S" theme)) 
    1054999  (custom-check-theme theme) 
    10551000  (provide (get theme 'theme-feature)) 
    1056   (push theme custom-loaded-themes) 
    1057   ;; Loading a theme also installs its settings, 
    1058   ;; so mark it as "enabled". 
     1001  ;; Loading a theme also enables it. 
    10591002  (push theme custom-enabled-themes) 
    10601003  ;; `user' must always be the highest-precedence enabled theme. 
    10611004  ;; Make that remain true.  (This has the effect of making user settings 
    10621005  ;; override the ones just loaded, too.) 
    1063   (enable-theme 'user)) 
     1006  (let ((custom-enabling-themes t)) 
     1007    (enable-theme 'user))) 
    10641008 
    10651009(defun load-theme (theme) 
    1066   "Try to load a theme's settings from its file. 
     1010  "Load a theme's settings from its file. 
    10671011This also enables the theme; use `disable-theme' to disable it." 
    1068  
    1069   ;; THEME's feature is stored in THEME's `theme-feature' property. 
    1070   ;; Usually the `theme-feature' property contains a symbol created 
    1071   ;; by `custom-make-theme-feature'. 
    1072  
    10731012  ;; Note we do no check for validity of the theme here. 
    10741013  ;; This allows to pull in themes by a file-name convention 
    10751014  (interactive "SCustom theme name: ") 
     1015  ;; If reloading, clear out the old theme settings. 
     1016  (when (custom-theme-p theme) 
     1017    (disable-theme theme) 
     1018    (put theme 'theme-settings nil) 
     1019    (put theme 'theme-feature nil) 
     1020    (put theme 'theme-documentation nil)) 
    10761021  (let ((load-path (if (file-directory-p custom-theme-directory) 
    10771022                       (cons custom-theme-directory load-path) 
    10781023                     load-path))) 
    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))))) 
    11171025  
    11181026;;; Enabling and disabling loaded themes. 
     1027 
     1028(defvar custom-enabling-themes nil) 
    11191029 
    11201030(defun enable-theme (theme) 
     
    11231033If it is already enabled, just give it highest precedence (after `user'). 
    11241034 
    1125 This signals an error if THEME does not specify any theme 
    1126 settings.  Theme settings are set using `load-theme'." 
     1035If THEME does not specify any theme settings, this tries to load 
     1036the theme from its theme file, by calling `load-theme'." 
    11271037  (interactive "SEnable Custom 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 
     1059This does not include the `user' theme, which is set by Customize, 
     1060and 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)) 
    11451088 
    11461089(defun disable-theme (theme) 
    11471090  "Disable all variable and face settings defined by THEME. 
    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))))) 
     1091See `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)))) 
    11831109 
    11841110(defun custom-variable-theme-value (variable) 
     
    11901116  (let* ((theme-value (get variable 'theme-value))) 
    11911117    (if theme-value 
    1192         (custom-theme-value (car (car theme-value)) theme-value)))) 
     1118        (cdr (car theme-value))))) 
    11931119 
    11941120(defun custom-theme-recalc-variable (variable) 
    11951121  "Set VARIABLE according to currently enabled custom themes." 
    11961122  (let ((valspec (custom-variable-theme-value variable))) 
    1197     (when valspec 
    1198       (put variable 'saved-value valspec)) 
    1199     (unless valspec 
     1123    (if valspec 
     1124        (put variable 'saved-value valspec) 
    12001125      (setq valspec (get variable 'standard-value))) 
    1201     (when valspec 
    1202       (if (or (get 'force-value variable) (default-boundp variable)) 
    1203           (funcall (or (get variable 'custom-set) 'set-default) variable 
    1204                    (eval (car valspec))))))) 
     1126    (if (and valspec 
     1127             (or (get variable 'force-value) 
     1128                 (default-boundp variable))) 
     1129        (funcall (or (get variable 'custom-set) 'set-default) variable 
     1130                 (eval (car valspec)))))) 
    12051131 
    12061132(defun custom-theme-recalc-face (face) 
    12071133  "Set FACE according to currently enabled custom themes." 
    1208   (let ((theme-faces (reverse (get face 'theme-face)))) 
    1209     (dolist (spec theme-faces) 
    1210       (face-spec-set face (car (cddr spec)))))) 
     1134  (if (facep face) 
     1135      (let ((theme-faces (reverse (get face 'theme-face)))) 
     1136        (dolist (spec theme-faces) 
     1137          (face-spec-set face (cadr spec)))))) 
    12111138  
     1139;;; XEmacs compability functions 
     1140 
     1141;; In XEmacs, when you reset a Custom Theme, you have to specify the 
     1142;; theme to reset it to.  We just apply the next available theme, so 
     1143;; just ignore the IGNORED arguments. 
     1144 
    12121145(defun custom-theme-reset-variables (theme &rest args) 
    1213   "Reset the specs in THEME of some variables to their values in other themes. 
     1146  "Reset some variable settings in THEME to their values in other themes. 
    12141147Each of the arguments ARGS has this form: 
    12151148 
    1216     (VARIABLE FROM-THEME
    1217  
    1218 This means reset VARIABLE to its value in FROM-THEME." 
     1149    (VARIABLE IGNORED
     1150 
     1151This means reset VARIABLE.  (The argument IGNORED is ignored)." 
    12191152  (custom-check-theme theme) 
    12201153  (dolist (arg args) 
    1221     (custom-push-theme 'theme-value (car arg) theme 'reset (cadr arg)))) 
     1154    (custom-push-theme 'theme-value (car arg) theme 'reset))) 
    12221155 
    12231156(defun custom-reset-variables (&rest args) 
    1224   "Reset the specs of some variables to their values in certain themes. 
     1157  "Reset the specs of some variables to their values in other themes. 
    12251158This creates settings in the `user' theme. 
    12261159 
    12271160Each of the arguments ARGS has this form: 
    12281161 
    1229     (VARIABLE FROM-THEME
    1230  
    1231 This means reset VARIABLE to its value in FROM-THEME." 
     1162    (VARIABLE IGNORED
     1163 
     1164This means reset VARIABLE.  (The argument IGNORED is ignored)." 
    12321165    (apply 'custom-theme-reset-variables 'user args)) 
    12331166