aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-24 00:37:00 -0400
committerCraig Jennings <c@cjennings.net>2026-09-13 09:34:41 -0500
commitcb7019387d8b5bd7ebd385272126accfd37e4b1b (patch)
tree09942e20cf6923d614b8c88ff892e93637805449
parent37e1c94d523e1d9b96ac8d8acbb488636f31c2cc (diff)
downloademacs-wttrin-cb7019387d8b5bd7ebd385272126accfd37e4b1b.tar.gz
emacs-wttrin-cb7019387d8b5bd7ebd385272126accfd37e4b1b.zip
feat: add wttrin-hide-follow-line to hide the wttr.in follow line
I added a boolean defcustom, wttrin-hide-follow-line (default nil), that suppresses the "Follow @igor_chubin for wttr.in updates" line in the weather buffer. When it's on, wttrin--build-url adds the wttr.in F flag to the request, so the service omits the line server-side. That stays correct across languages, where a local regex on the English text would miss translated responses. The helper wttrin--effective-display-options folds F into wttrin-display-options when hiding and F isn't already there, so the toggle and the options string compose without duplicating the flag. The default is off to keep current behavior on upgrade and to leave the upstream author's follow request in place unless the user opts out. It affects the weather buffer only. The mode-line uses its own compact format with no follow line.
-rw-r--r--README.org8
-rw-r--r--tests/test-wttrin-hide-follow-line.el75
-rw-r--r--wttrin.el21
3 files changed, 103 insertions, 1 deletions
diff --git a/README.org b/README.org
index 56b0cb9..ce4b420 100644
--- a/README.org
+++ b/README.org
@@ -218,6 +218,14 @@ wttr.in supports a handful of single-character flags that change what the report
The full list of flags is at https://wttr.in/:help. Skip =A= and =T= — wttrin manages ANSI output internally so the colored glyphs render correctly.
+If the one flag you want is the "Follow" line off, there's a dedicated toggle so you don't have to remember =F=:
+
+#+begin_src emacs-lisp
+ (setq wttrin-hide-follow-line t) ;; hide "Follow @igor_chubin for wttr.in updates"
+#+end_src
+
+It composes with =wttrin-display-options= (setting either one hides the line) and affects the weather buffer only, not the mode-line.
+
*** Cache Settings
Wttrin caches weather data and refreshes it in the background. By default it refreshes every hour and keeps up to 50 entries. You can adjust both:
diff --git a/tests/test-wttrin-hide-follow-line.el b/tests/test-wttrin-hide-follow-line.el
new file mode 100644
index 0000000..fcfb906
--- /dev/null
+++ b/tests/test-wttrin-hide-follow-line.el
@@ -0,0 +1,75 @@
+;;; test-wttrin-hide-follow-line.el --- Tests for hiding the follow line -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2026 Craig Jennings
+
+;;; Commentary:
+
+;; Unit tests for wttrin--effective-display-options and its effect on
+;; wttrin--build-url: the wttr.in F flag is added to the buffer request when
+;; wttrin-hide-follow-line is non-nil, composing with wttrin-display-options.
+
+;;; Code:
+
+(require 'ert)
+(require 'wttrin)
+
+;;; --------------------------------------------------------------------------
+;;; wttrin--effective-display-options
+;;; --------------------------------------------------------------------------
+
+;;; Normal Cases
+
+(ert-deftest test-wttrin--effective-display-options-normal-hide-empty-adds-f ()
+ "Normal: hiding with no other options yields just the F flag."
+ (let ((wttrin-display-options nil)
+ (wttrin-hide-follow-line t))
+ (should (equal (wttrin--effective-display-options) "F"))))
+
+(ert-deftest test-wttrin--effective-display-options-normal-hide-appends-f ()
+ "Normal: hiding appends F to existing options."
+ (let ((wttrin-display-options "0q")
+ (wttrin-hide-follow-line t))
+ (should (equal (wttrin--effective-display-options) "0qF"))))
+
+(ert-deftest test-wttrin--effective-display-options-normal-no-hide-unchanged ()
+ "Normal: not hiding leaves the options untouched."
+ (let ((wttrin-display-options "0q")
+ (wttrin-hide-follow-line nil))
+ (should (equal (wttrin--effective-display-options) "0q"))))
+
+;;; Boundary Cases
+
+(ert-deftest test-wttrin--effective-display-options-boundary-f-already-present ()
+ "Boundary: F already in the options is not duplicated."
+ (let ((wttrin-display-options "0Fq")
+ (wttrin-hide-follow-line t))
+ (should (equal (wttrin--effective-display-options) "0Fq"))))
+
+(ert-deftest test-wttrin--effective-display-options-boundary-no-hide-nil-options ()
+ "Boundary: not hiding with nil options yields an empty string."
+ (let ((wttrin-display-options nil)
+ (wttrin-hide-follow-line nil))
+ (should (equal (wttrin--effective-display-options) ""))))
+
+;;; --------------------------------------------------------------------------
+;;; wttrin--build-url integration
+;;; --------------------------------------------------------------------------
+
+;;; Normal Cases
+
+(ert-deftest test-wttrin--build-url-normal-hide-appends-f-to-url ()
+ "Normal: hiding the follow line puts the F flag at the end of the URL."
+ (let ((wttrin-display-options nil)
+ (wttrin-hide-follow-line t)
+ (wttrin-unit-system nil))
+ (should (string-suffix-p "F" (wttrin--build-url "Tokyo")))))
+
+(ert-deftest test-wttrin--build-url-normal-no-hide-no-trailing-f ()
+ "Normal: with hiding off, the URL does not end in the F flag."
+ (let ((wttrin-display-options nil)
+ (wttrin-hide-follow-line nil)
+ (wttrin-unit-system nil))
+ (should-not (string-suffix-p "F" (wttrin--build-url "Tokyo")))))
+
+(provide 'test-wttrin-hide-follow-line)
+;;; test-wttrin-hide-follow-line.el ends here
diff --git a/wttrin.el b/wttrin.el
index a524d84..449fb80 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -176,6 +176,15 @@ xterm-color rendering produces the colored glyphs."
:type '(choice (const :tag "None" nil)
(string :tag "Options")))
+(defcustom wttrin-hide-follow-line nil
+ "When non-nil, hide the \"Follow @igor_chubin for wttr.in updates\" line.
+Adds the wttr.in F flag to the weather-buffer request so the service omits
+the line. This is the discoverable toggle for the same effect as putting
+F in `wttrin-display-options'; setting either one hides the line, and they
+do not conflict. Affects the `wttrin' buffer only, not the mode-line."
+ :group 'wttrin
+ :type 'boolean)
+
(define-obsolete-variable-alias 'wttrin-cache-ttl 'wttrin-refresh-interval "0.3.0")
@@ -519,6 +528,16 @@ ERROR-MSG has no class."
(> (length error-msg) 0)
(get-text-property 0 'wttrin-error-type error-msg)))
+(defun wttrin--effective-display-options ()
+ "Return the wttr.in display flags for the weather-buffer request.
+Starts from `wttrin-display-options' and appends the F flag (\"do not show
+the Follow line\") when `wttrin-hide-follow-line' is non-nil and F is not
+already present, so the two controls compose without duplicating the flag."
+ (let ((opts (or wttrin-display-options "")))
+ (if (and wttrin-hide-follow-line (not (string-match-p "F" opts)))
+ (concat opts "F")
+ opts)))
+
(defun wttrin--build-url (query)
"Build wttr.in URL for QUERY with configured parameters."
(when (null query)
@@ -527,7 +546,7 @@ ERROR-MSG has no class."
(url-hexify-string query)
(wttrin-additional-url-params)
"A"
- (or wttrin-display-options "")))
+ (wttrin--effective-display-options)))
(defun wttrin--extract-http-status ()
"Return the HTTP status code from the current buffer, or nil.