aboutsummaryrefslogtreecommitdiff
path: root/README.org
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-05 10:06:20 -0500
committerCraig Jennings <c@cjennings.net>2026-05-05 10:06:20 -0500
commit541586e3ff0606afcf0581210a62c95f5ee65c71 (patch)
treed67d1f08323879e72a10b42f945edff9004675a8 /README.org
parentec00dbe1c03527ec46a0faa20545a7acd382da84 (diff)
downloademacs-wttrin-541586e3ff0606afcf0581210a62c95f5ee65c71.tar.gz
emacs-wttrin-541586e3ff0606afcf0581210a62c95f5ee65c71.zip
feat: support t for auto-detect via geolocation in wttrin-favorite-location
Completes the three-mode configuration the favorite-location feature was always meant to have: - nil — disabled (default; unchanged) - a string — explicit location (unchanged) - t — auto-detect via IP geolocation (NEW) When the user sets `wttrin-favorite-location` to t, wttrin runs the geolocation lookup once on first use and caches the result for the session. Subsequent reads return the cached string. The lookup happens in the background via the existing `wttrin-geolocation-detect`, so Emacs startup is never blocked. I added two private state vars (`wttrin--resolved-favorite-location`, `wttrin--favorite-location-pending`) and a resolver `wttrin--resolve-favorite-location` that maps the three modes onto a returned string or nil. When t is set and the cache is empty, the resolver kicks off the lookup and returns nil for that call — the next consumer tick after the callback completes gets the cached string. The pending flag prevents duplicate concurrent lookups when several consumers ask during the resolution window. Five consumer call sites now go through the resolver instead of reading `wttrin-favorite-location` directly: `wttrin--mode-line-fetch-weather`, `wttrin-mode-line-click`, `wttrin-mode-line-force-refresh`, `wttrin--buffer-cache-refresh`, and `wttrin--mode-line-start`. Two display sites (the placeholder and error tooltips) use a new `wttrin--favorite-location-display-name` helper that returns "current location" while a t-mode lookup is pending, instead of showing the literal `t` to the user. Tests cover the resolver across all three modes, including the pending state, the duplicate-suppression behavior, and detection-failure retry. Existing consumer tests stay green because the resolver returns the bound string unchanged when the variable is a string. One care: the test file requires wttrin-geolocation up front so cl-letf mocks of `wttrin-geolocation-detect` aren't undone by the resolver's lazy require — without that, the first run hit ipapi.co for real. README documents the new mode under "Setting the Favorite Location from IP Geolocation".
Diffstat (limited to 'README.org')
-rw-r--r--README.org12
1 files changed, 11 insertions, 1 deletions
diff --git a/README.org b/README.org
index e3e5c98..b6a824d 100644
--- a/README.org
+++ b/README.org
@@ -247,7 +247,9 @@ If a refresh fails, the emoji dims to gray and the tooltip tells you what went w
*Note:* If the weather emoji appears as a monochrome symbol instead of a color icon, try setting `wttrin-mode-line-emoji-font` to match a color emoji font installed on your system. Use `M-x fc-list` or check your system fonts to see what's available.
*** Setting the Favorite Location from IP Geolocation
-If you don't want to type your city by hand, wttrin can detect it for you:
+If you don't want to type your city by hand, wttrin can detect it for you. Two ways:
+
+**Manual detection with confirmation:**
#+begin_src emacs-lisp
M-x wttrin-set-location-from-geolocation
@@ -255,6 +257,14 @@ If you don't want to type your city by hand, wttrin can detect it for you:
This looks up your city via IP geolocation, shows the detected location, and sets =wttrin-favorite-location= after you confirm. To make the setting persist across Emacs sessions, run =M-x customize-save-variable RET wttrin-favorite-location RET=, or add =(setq wttrin-favorite-location "Your City, State")= to your init file.
+**Automatic detection on first use:**
+
+#+begin_src emacs-lisp
+ (setq wttrin-favorite-location t)
+#+end_src
+
+When set to =t=, wttrin runs the geolocation lookup once on first use (when the mode-line first fetches, when the buffer cache first refreshes, etc.) and caches the result for the rest of the session. The lookup happens in the background, so Emacs startup isn't blocked. The first display tick shows a placeholder until the lookup returns; everything proceeds normally after that.
+
The default lookup provider is =ipapi.co=. Two alternatives ship with the package, both free and key-less:
#+begin_src emacs-lisp