diff options
| -rw-r--r-- | modules/system-defaults.el | 16 | ||||
| -rw-r--r-- | tests/test-system-defaults.el | 20 |
2 files changed, 36 insertions, 0 deletions
diff --git a/modules/system-defaults.el b/modules/system-defaults.el index 8ef6181a..eccc6c35 100644 --- a/modules/system-defaults.el +++ b/modules/system-defaults.el @@ -104,6 +104,22 @@ Used to disable functionality with defalias \='somefunc \='cj/disabled)." (setq custom-file (make-temp-file "emacs-customizations-trashbin-")) +(defun cj/--warn-customize-discarded (&rest _) + "Warn once that Customize edits land in a throwaway `custom-file'. +`custom-file' is a temp file that is never read back, so anything saved +through the Customize interface is lost on exit. This advice fires the +first time `custom-save-all' writes, then removes itself so the warning +appears only once per session." + (advice-remove 'custom-save-all #'cj/--warn-customize-discarded) + (display-warning + 'cj/system-defaults + (concat "Customize edits are discarded: `custom-file' is a throwaway " + "temp file that is never loaded back. Edit configuration in the " + "Elisp init files instead.") + :warning)) + +(advice-add 'custom-save-all :before #'cj/--warn-customize-discarded) + ;; ------------------------- Re-Enabling Functionality ------------------------- (put 'narrow-to-region 'disabled nil) ;; narrow-to-region is extremely useful! diff --git a/tests/test-system-defaults.el b/tests/test-system-defaults.el index bc3694db..3c5e5977 100644 --- a/tests/test-system-defaults.el +++ b/tests/test-system-defaults.el @@ -64,5 +64,25 @@ they are actually wired onto the minibuffer hooks." (should (memq 'cj/minibuffer-setup-hook minibuffer-setup-hook)) (should (memq 'cj/minibuffer-exit-hook minibuffer-exit-hook))))) +;;; Customize-save warning + +(ert-deftest test-system-defaults-customize-save-warns-once () + "Normal: the first custom-save-all warns; the second does not (one-shot). +Customize writes land in a throwaway custom-file, so the user must be told +their edit will not persist. The advice removes itself after warning once." + (test-system-defaults--with-load-environment + (let ((warnings '())) + (cl-letf (((symbol-function 'display-warning) + (lambda (group &rest _) (push group warnings))) + ((symbol-function 'custom-save-all) #'ignore)) + (test-system-defaults--load) + ;; No warning merely from loading the module. + (should (null warnings)) + (custom-save-all) + (should (equal warnings '(cj/system-defaults))) + ;; Second save must not warn again. + (custom-save-all) + (should (equal warnings '(cj/system-defaults))))))) + (provide 'test-system-defaults) ;;; test-system-defaults.el ends here |
