From f2d3f6c6586ede7f757ca74ea699982562f069a7 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 1 Jul 2026 13:51:28 -0400 Subject: fix: keep a d-set favorite from reverting to the init value on restart wttrin-favorite-location did two jobs: a defcustom the user sets in init, and the savehist-persisted value that `d`/make-default mutated. Setting it in init (setopt) clobbered the `d` choice on every startup. So a favorite promoted with `d` reverted to the init value after a restart, and the mode-line showed the wrong location's weather. wttrin-saved-locations had the same defect. I split the two roles. The defcustoms stay as the init-set base. New savehist-persisted runtime vars, wttrin--favorite-override and wttrin--saved-locations-runtime, hold what `d`, save, rename, remove, and the geolocation commands write. Reads go through resolvers: wttrin--favorite-location returns the override or the configured favorite, and wttrin--saved-locations overlays the runtime directory on the configured one (runtime wins on a name collision). Init and `d` now write different variables, so neither clobbers the other. Removing a saved location that only comes from init can't delete it, since the runtime removal has nothing to touch. The command now says so instead of reporting a removal that didn't happen. There's no automatic migration. A favorite set in init is unaffected, and a favorite set only with `d` before this version is re-set once with `d`. The README documents the behavior. --- tests/test-wttrin-set-location-from-geolocation.el | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'tests/test-wttrin-set-location-from-geolocation.el') diff --git a/tests/test-wttrin-set-location-from-geolocation.el b/tests/test-wttrin-set-location-from-geolocation.el index f16b2ae..10e5cc0 100644 --- a/tests/test-wttrin-set-location-from-geolocation.el +++ b/tests/test-wttrin-set-location-from-geolocation.el @@ -20,16 +20,24 @@ (defvar test-wttrin-set-location-from-geolocation--saved-favorite nil "Snapshot of `wttrin-favorite-location' restored in teardown.") +(defvar test-wttrin-set-location-from-geolocation--saved-override nil + "Snapshot of `wttrin--favorite-override' restored in teardown.") + (defun test-wttrin-set-location-from-geolocation-setup () - "Snapshot `wttrin-favorite-location' and clear it for the test." + "Snapshot the configured favorite and runtime override, clearing both." (setq test-wttrin-set-location-from-geolocation--saved-favorite wttrin-favorite-location) - (setq wttrin-favorite-location nil)) + (setq test-wttrin-set-location-from-geolocation--saved-override + wttrin--favorite-override) + (setq wttrin-favorite-location nil) + (setq wttrin--favorite-override nil)) (defun test-wttrin-set-location-from-geolocation-teardown () - "Restore `wttrin-favorite-location' to its pre-test value." + "Restore the configured favorite and runtime override to pre-test values." (setq wttrin-favorite-location - test-wttrin-set-location-from-geolocation--saved-favorite)) + test-wttrin-set-location-from-geolocation--saved-favorite) + (setq wttrin--favorite-override + test-wttrin-set-location-from-geolocation--saved-override)) ;;; Helpers @@ -51,7 +59,7 @@ (progn (test-wttrin-set-location--with-detected "Berkeley, California" t (wttrin-set-location-from-geolocation)) - (should (string= "Berkeley, California" wttrin-favorite-location))) + (should (string= "Berkeley, California" (wttrin--favorite-location)))) (test-wttrin-set-location-from-geolocation-teardown))) (ert-deftest test-wttrin-set-location-from-geolocation-normal-decline-leaves-variable-unchanged () @@ -84,7 +92,7 @@ favorite immediately instead of at the next scheduled fetch." ((symbol-function 'wttrin--mode-line-set-placeholder) (lambda () nil))) (wttrin-set-location-from-geolocation)) - (should (string= "Berkeley, California" wttrin-favorite-location)) + (should (string= "Berkeley, California" (wttrin--favorite-location))) (should fetched)) (test-wttrin-set-location-from-geolocation-teardown))) @@ -97,7 +105,7 @@ favorite immediately instead of at the next scheduled fetch." (progn (test-wttrin-set-location--with-detected "München, Bayern" t (wttrin-set-location-from-geolocation)) - (should (string= "München, Bayern" wttrin-favorite-location))) + (should (string= "München, Bayern" (wttrin--favorite-location)))) (test-wttrin-set-location-from-geolocation-teardown))) ;;; Error Cases -- cgit v1.2.3