I once wrote: > I have a suggestion to make, but I'm not sure it is possible since > color-theme itself interacts with customization. It would be good > if users could set a theme without editing their .emacs file themselves, > but rather by customizing a variable. > > The defcustom would have a radio selection of all available themes and > would set the theme using defcustom keywords :require to load the > library and :set to call the function. > > What do you think? This would be the preferred method of setting a > theme in the `emacs-goodies-el' package (where just about everything can > be enabled via the custom interface).
The attached `color-theme-sel.el' has sample code to show what I mean. If you load it and then do: M-x customize-variable [RET] color-theme-selection [RET] when you set the selection, the change is made. If you save the selection as a customization for a future session, the theme is set correctly using CVS Emacs but fails with Emacs-21 loading color-theme.el: Debugger entered--Lisp error: (wrong-type-argument keymapp nil) define-key(nil [menu-bar Tools] ("Tools" keymap "Tools")) This is fixed by changing lines 589 and 590 in color-theme.el to: (easy-menu-add-item nil '("tools") "--") (easy-menu-add-item nil '("tools") ["Color Themes" color-theme-select t]) Note the "tools" vs "Tools". So the code works. Of course I'd merge the defcustom into color-theme.el and change the :load and :require lines accordingly (removing the :load and renaming the :require). It could stay as this parallel way to set the theme, but perhaps you'd want the two methods to interoperate. You might want this defcustom to get correctly set when the theme is set using an alternate method, but setting defcustoms outside of the custom interface is a no-no so maybe not. Also, the entry for "None" doesn't work. I haven't figured out the "proper" way to undo a theme. What do you guys think? Peter
(require 'color-theme) (defcustom color-theme-selection nil "Color theme selection." :type (append '(radio) (cons '(const :tag "None" nil) (mapcar (function (lambda (arg) `(const ,arg))) (mapcar '(lambda (x) (elt x 1)) color-themes)))) :set (lambda (symbol value) (set-default symbol value) (when value (eval (delq nil (mapcar '(lambda (x) (if (string-equal (elt x 1) value) (car x))) color-themes))))) :require 'color-theme-sel :load 'color-theme-sel) (provide 'color-theme-sel)