Created
May 26, 2025 18:11
-
-
Save mmarshall540/e7f078500f81f9a5f6a8e01e6e3a1fe9 to your computer and use it in GitHub Desktop.
Use customize-themes but not custom-file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; I generally don't like to use the Customize system. It's great for | |
;; browsing settings, but for actually maintaining them, things | |
;; somehow always end up in a mess with little indication of the | |
;; cause. (In most cases, the root cause is probably the "Options: | |
;; Save Options" menu item, which tends to save far more than you'd | |
;; expect, but that's another topic.) | |
;; | |
;; However, the `customize-themes' interface is quite nice, and I like | |
;; using it to select and save a theme. So how to continue doing that | |
;; without otherwise using the Customize system? Like this... | |
(setopt custom-file "foobar.el") ; never loads | |
(setopt custom-safe-themes t) | |
;; Set the file to use for saving the theme. | |
(defvar my/theme-file | |
(expand-file-name "my-themeset.el" user-emacs-directory)) | |
;; Save it to that file instead of the `custom-file'. | |
(defun my/custom-theme-save-advice (&rest _ignore) | |
"Override advice for saving chosen themes in `my/theme-file'. | |
This makes it possible to save the theme chosen in `customize-themes' | |
even though we don't load any other settings saved by Customize." | |
(interactive) | |
(with-temp-file my/theme-file | |
(insert | |
(format "(setopt custom-enabled-themes '%s) (provide 'my-themeset)" | |
custom-enabled-themes))) | |
(message "Custom themes saved in %s." my/theme-file)) | |
(advice-add 'custom-theme-save :override 'my/custom-theme-save-advice) | |
(require 'my-themeset my/theme-file :noerror) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment