aboutsummaryrefslogtreecommitdiff
path: root/wttrin.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-25 01:10:49 -0400
committerCraig Jennings <c@cjennings.net>2026-06-25 01:10:49 -0400
commit4266923daf6f137fbe2897334b7669f7fb4633c8 (patch)
tree42144ed5202f4c19e6f774cbc3688b0273777b7a /wttrin.el
parentefd3cdce5b3aebfdb3e02460d1ec0434cef85949 (diff)
downloademacs-wttrin-4266923daf6f137fbe2897334b7669f7fb4633c8.tar.gz
emacs-wttrin-4266923daf6f137fbe2897334b7669f7fb4633c8.zip
fix: refresh mode-line weather when the default location changes
Pressing d to promote a displayed location to the favorite changed wttrin-favorite-location but left the mode-line untouched. Its cache still held the old location's weather. The next scheduled refetch could be up to an hour away, so the hover tooltip kept showing the previous default. wttrin--set-favorite-location now detects a real change and, when the mode-line is active, clears the stale cache and fetches the new location at once via a new wttrin--mode-line-refresh-now helper. The tooltip switches within seconds instead of waiting for the timer.
Diffstat (limited to 'wttrin.el')
-rw-r--r--wttrin.el17
1 files changed, 15 insertions, 2 deletions
diff --git a/wttrin.el b/wttrin.el
index c4b31bc..89db893 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -857,8 +857,11 @@ Persistence is handled by `wttrin--savehist-register', which registers the
variable when savehist loads and again on `savehist-save-hook', so the value
survives restarts without the Emacs custom-variable mechanism, and setting it
here works whether or not savehist is loaded."
- (setq wttrin-favorite-location location)
- (setq wttrin--location-history (delete location wttrin--location-history)))
+ (let ((changed (not (equal location wttrin-favorite-location))))
+ (setq wttrin-favorite-location location)
+ (setq wttrin--location-history (delete location wttrin--location-history))
+ (when (and changed (bound-and-true-p wttrin-mode-line-mode))
+ (wttrin--mode-line-refresh-now))))
(defun wttrin-make-default ()
"Make the location shown in this buffer the favorite (persisted) default.
@@ -1049,6 +1052,16 @@ Force-refresh cache and update tooltip without opening buffer."
(format "Fetching weather for %s..."
(or (wttrin--favorite-location-display-name) "favorite"))))
+(defun wttrin--mode-line-refresh-now ()
+ "Discard the cached mode-line weather and fetch fresh data immediately.
+Called when `wttrin-favorite-location' changes so the mode-line stops
+showing the previous location's weather instead of waiting for the next
+scheduled refresh."
+ (setq wttrin--mode-line-cache nil)
+ (setq wttrin--mode-line-rendered-stale nil)
+ (wttrin--mode-line-set-placeholder)
+ (wttrin--mode-line-fetch-weather))
+
(defvar wttrin--buffer-refresh-timer nil
"Timer object for proactive buffer cache refresh.")