diff options
| -rw-r--r-- | modules/system-defaults.el | 11 | ||||
| -rw-r--r-- | tests/test-system-defaults.el | 14 |
2 files changed, 21 insertions, 4 deletions
diff --git a/modules/system-defaults.el b/modules/system-defaults.el index 1703b1bf7..0062a82cf 100644 --- a/modules/system-defaults.el +++ b/modules/system-defaults.el @@ -101,8 +101,11 @@ Used to disable functionality with defalias \='somefunc \='cj/disabled)." ;; CUSTOMIZATIONS ;; All customizations should be declared in Emacs init files. ;; Add accidental customizations via the customization interface to a temp file that's never read. -(setq custom-file (make-temp-file - "emacs-customizations-trashbin-")) +;; Guarded so a batch module load (make validate-modules, byte-compile) doesn't +;; create a throwaway temp file on every run. +(unless noninteractive + (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'. @@ -137,7 +140,9 @@ appears only once per session." ;; -------------------------------- Emacs Server ------------------------------- ;; Start server so emacsclient can connect (needed for pinentry-emacs in terminal) -(unless (or (daemonp) (server-running-p)) +;; noninteractive guard: a raw module load under --batch (make validate-modules +;; on a machine with no daemon socket) would otherwise start a server. +(unless (or noninteractive (daemonp) (server-running-p)) (server-start)) (setq system-time-locale "C") ;; use en_US locale to format time. diff --git a/tests/test-system-defaults.el b/tests/test-system-defaults.el index 3c5e59777..928124f56 100644 --- a/tests/test-system-defaults.el +++ b/tests/test-system-defaults.el @@ -24,7 +24,10 @@ "Normal: custom-file points at a throwaway temp file, never the repo. This is what stops accidental Customize writes from landing in tracked init." (test-system-defaults--with-load-environment - (let ((custom-file nil)) + ;; noninteractive is t under ERT batch; bind it nil so the interactive + ;; redirect runs (the module guards the redirect to interactive sessions). + (let ((custom-file nil) + (noninteractive nil)) (test-system-defaults--load) (should (stringp custom-file)) (should (string-prefix-p (file-name-as-directory @@ -35,6 +38,15 @@ This is what stops accidental Customize writes from landing in tracked init." (should-not (string-prefix-p (expand-file-name user-emacs-directory) (expand-file-name custom-file)))))) +(ert-deftest test-system-defaults-custom-file-not-littered-in-batch () + "Boundary: a noninteractive (batch) load does not create a trashbin custom-file. +Guards make validate-modules / byte-compile from dropping a temp file per run." + (test-system-defaults--with-load-environment + (let ((custom-file nil) + (noninteractive t)) + (test-system-defaults--load) + (should-not custom-file)))) + ;;; backup directory (ert-deftest test-system-defaults-backups-redirected-under-user-emacs-dir () |
