From eaabae3b01b8bdc05a5892492c06a8131c195a45 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 21 Jun 2026 09:11:38 -0400 Subject: fix: keep location history registered after a savehist setq A one-time add-to-list put wttrin--location-history into savehist-additional-variables when savehist loaded. Any user who later setqs that list, a common config pattern for curating which histories persist, replaces it and drops the entry. The search history then silently never saves. Re-assert the registration on savehist-save-hook, which runs at the top of every savehist-save. The variable is now in the list whenever a save happens, regardless of init order or a clobbering setq. Restore was never affected, since savehist reloads the value from explicit setq forms in its file. The README persistence note now reflects this: the variable stays registered even if you set savehist-additional-variables yourself. --- tests/test-wttrin-location-history.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/test-wttrin-location-history.el b/tests/test-wttrin-location-history.el index d03430d..d23bdcd 100644 --- a/tests/test-wttrin-location-history.el +++ b/tests/test-wttrin-location-history.el @@ -203,5 +203,32 @@ (require 'savehist) (should (memq 'wttrin--location-history savehist-additional-variables))) +(ert-deftest test-wttrin-location-history-normal-savehist-register-adds-var () + "wttrin--savehist-register adds the history variable to the save list." + (require 'savehist) + (let ((savehist-additional-variables '(kill-ring))) + (wttrin--savehist-register) + (should (memq 'wttrin--location-history savehist-additional-variables)))) + +(ert-deftest test-wttrin-location-history-boundary-savehist-register-idempotent () + "Registering when already present does not duplicate the entry." + (require 'savehist) + (let ((savehist-additional-variables '(wttrin--location-history))) + (wttrin--savehist-register) + (should (equal '(wttrin--location-history) savehist-additional-variables)))) + +(ert-deftest test-wttrin-location-history-integration-savehist-register-on-save-hook () + "The registration runs on `savehist-save-hook' so it survives a clobber." + (require 'savehist) + (should (memq 'wttrin--savehist-register savehist-save-hook))) + +(ert-deftest test-wttrin-location-history-integration-savehist-survives-clobber () + "A user setq that drops the variable is repaired before the next save." + (require 'savehist) + (let ((savehist-additional-variables '(kill-ring search-ring))) + ;; simulate the save path: savehist-save runs this hook first + (run-hooks 'savehist-save-hook) + (should (memq 'wttrin--location-history savehist-additional-variables)))) + (provide 'test-wttrin-location-history) ;;; test-wttrin-location-history.el ends here -- cgit v1.2.3