aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-11-08 23:46:58 -0600
committerCraig Jennings <c@cjennings.net>2025-11-08 23:46:58 -0600
commitc65a67efb7844797761896d77e02c0e883e2a54a (patch)
tree82b2f6584b37632862387d327215578b1e8f603c
parent9074bf41fedbabfeb0e9c0bb7c3427e069bfeaab (diff)
downloademacs-wttrin-c65a67efb7844797761896d77e02c0e883e2a54a.tar.gz
emacs-wttrin-c65a67efb7844797761896d77e02c0e883e2a54a.zip
refactor: core: lazy-load xterm-color dependency
Move xterm-color from top-level require to on-demand loading within functions that actually use it. This simplifies user configuration by eliminating the need for separate xterm-color use-package declarations. Changes: - Replace top-level (require 'xterm-color) with declare-function - Add (require 'xterm-color) in wttrin--process-weather-content - Add (require 'xterm-color) in wttrin--display-weather - Update smoke test to check loadability vs. feature presence Benefits: - Simpler use-package config (no :after xterm-color needed) - xterm-color still auto-installed via Package-Requires on MELPA - Load time optimization (loads only when displaying weather)
-rw-r--r--tests/test-wttrin-smoke.el4
-rw-r--r--wttrin.el6
2 files changed, 7 insertions, 3 deletions
diff --git a/tests/test-wttrin-smoke.el b/tests/test-wttrin-smoke.el
index 5cb4b08..acf7fd5 100644
--- a/tests/test-wttrin-smoke.el
+++ b/tests/test-wttrin-smoke.el
@@ -33,9 +33,9 @@ If we got here, the package loaded successfully via (require 'wttrin)."
;;; Dependency Tests
(ert-deftest test-wttrin-smoke-xterm-color-available ()
- "Test that xterm-color dependency is available.
+ "Test that xterm-color dependency can be loaded when needed.
This is a REQUIRED dependency - wttrin cannot function without it."
- (should (featurep 'xterm-color)))
+ (should (require 'xterm-color nil t)))
(ert-deftest test-wttrin-smoke-url-available ()
"Test that url library is available (built-in)."
diff --git a/wttrin.el b/wttrin.el
index 156b3b9..c0af306 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -35,7 +35,9 @@
(require 'face-remap)
(require 'url)
-(require 'xterm-color) ;; https://github.com/atomontage/xterm-color
+
+;; Declare xterm-color functions (loaded on-demand)
+(declare-function xterm-color-filter "xterm-color" (string))
;; Declare functions from wttrin-debug.el (loaded conditionally)
(declare-function wttrin--debug-mode-line-info "wttrin-debug")
@@ -314,6 +316,7 @@ Return t if valid, nil if missing or contains errors."
(defun wttrin--process-weather-content (raw-string)
"Process RAW-STRING: apply ANSI filtering and remove verbose lines.
Returns processed string ready for display."
+ (require 'xterm-color)
(let ((processed (xterm-color-filter raw-string)))
;; Remove verbose Location: coordinate line
(with-temp-buffer
@@ -347,6 +350,7 @@ Returns processed string ready for display."
(let ((inhibit-read-only t))
(erase-buffer)
;; Initialize xterm-color state AFTER wttrin-mode to prevent it being wiped
+ (require 'xterm-color)
(setq-local xterm-color--state :char)
(insert (wttrin--process-weather-content raw-string))
(wttrin--add-buffer-instructions)