From 8b461ecd3d4fae3be0a93523d19932e0a3d21c6c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 2 Jul 2026 22:37:06 -0400 Subject: fix: persist runtime favorite and saved locations in a state file savehist rewrites its whole file on every save, keeping only the variables registered in the running process. Any Emacs that saved savehist without wttrin loaded (a batch tool, a session that never opened wttrin) silently deleted the persisted favorite and saved-location entries. A d-set default then reverted to the init value on the next restart. The runtime favorite and directory now live in wttrin-state-file, written only by wttrin: write-through on every location command, atomic temp-file + rename, UTF-8 pinned both ways, read with read (never eval), versioned plist. Values restore at load and re-assert on savehist-mode-hook, so a stale legacy savehist restore can't clobber them. With no state file present, legacy savehist values are adopted and written once, so existing users migrate with zero steps. Search history stays on savehist. It's scrub-tolerant throwaway data, exactly what savehist is for. Also: the README documents the mode-line tooltip forecast option, and the gitignore covers one more local tooling artifact. --- tests/testutil-wttrin.el | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tests/testutil-wttrin.el') diff --git a/tests/testutil-wttrin.el b/tests/testutil-wttrin.el index e4e2e4e..1373813 100644 --- a/tests/testutil-wttrin.el +++ b/tests/testutil-wttrin.el @@ -136,17 +136,32 @@ Other mocks BODY needs can be set in a nested `cl-letf'." ;;; Test Setup and Teardown +;; Redirect state-file writes for the whole batch: any test that exercises a +;; location setter triggers `wttrin--state-save', which must never touch the +;; developer's real `wttrin-state-file'. Process-wide, set once at load. +(setq wttrin-state-file + (expand-file-name (format "wttrin-test-state-%d.el" (emacs-pid)) + temporary-file-directory)) + (defun testutil-wttrin-setup () "Common setup for wttrin tests. Call this at the beginning of each test." (testutil-wttrin-clear-cache) - (setq wttrin--force-refresh nil)) + (setq wttrin--force-refresh nil) + (setq wttrin--favorite-override nil) + (setq wttrin--saved-locations-runtime nil) + (when (file-exists-p wttrin-state-file) + (delete-file wttrin-state-file))) (defun testutil-wttrin-teardown () "Common teardown for wttrin tests. Call this at the end of each test." (testutil-wttrin-clear-cache) - (setq wttrin--force-refresh nil)) + (setq wttrin--force-refresh nil) + (setq wttrin--favorite-override nil) + (setq wttrin--saved-locations-runtime nil) + (when (file-exists-p wttrin-state-file) + (delete-file wttrin-state-file))) (provide 'testutil-wttrin) ;;; testutil-wttrin.el ends here -- cgit v1.2.3