summaryrefslogtreecommitdiff
path: root/wttrin.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-11-08 11:37:29 -0600
committerCraig Jennings <c@cjennings.net>2025-11-08 11:37:29 -0600
commitf18f1c90e362d84f4978b4365ae0a88807afb6e4 (patch)
treee1c4b0aa7cabc6a118f588da5ede23b94eaec7b6 /wttrin.el
parent19e88c1ed7ecde966372adefeb3d468374ef1dd7 (diff)
downloademacs-wttrin-f18f1c90e362d84f4978b4365ae0a88807afb6e4.tar.gz
emacs-wttrin-f18f1c90e362d84f4978b4365ae0a88807afb6e4.zip
refactor: mode-line: extract inline keymap to shared defvar
Replace inline keymap construction with shared wttrin--mode-line-map defvar. Before (line 474-479): Keymap recreated on every mode-line update - (let ((map (make-sparse-keymap))) ...) - Allocates new keymap object each time - 6 lines of repetitive code After (line 183-190 + line 483): Shared keymap created once - (defvar wttrin--mode-line-map ...) - Reference: 'local-map wttrin--mode-line-map - Single allocation, no repeated construction Added comprehensive tests (8 tests, all passing): - Keymap existence and structure verification - Keybinding tests (mouse-1, mouse-3, no mouse-2) - Integration test verifying mode-line uses shared map Benefits: - More efficient (no allocation on every update) - Clearer code structure - Easier to add new keybindings - Self-documenting with inline documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'wttrin.el')
-rw-r--r--wttrin.el16
1 files changed, 10 insertions, 6 deletions
diff --git a/wttrin.el b/wttrin.el
index afc0d2f..1ea8e11 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -180,6 +180,15 @@ Set this to t BEFORE loading wttrin, typically in your init file:
(defvar wttrin--mode-line-tooltip-data nil
"Cached full weather data for tooltip display.")
+(defvar wttrin--mode-line-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map [mode-line mouse-1] 'wttrin-mode-line-click)
+ (define-key map [mode-line mouse-3] 'wttrin-mode-line-force-refresh)
+ map)
+ "Keymap for mode-line weather widget interactions.
+Left-click (mouse-1): refresh weather and open buffer.
+Right-click (mouse-3): force-refresh cache and update tooltip.")
+
(defun wttrin-additional-url-params ()
"Concatenates extra information into the URL."
(if wttrin-unit-system
@@ -471,12 +480,7 @@ WEATHER-STRING format: \"Location: emoji temp conditions\" (e.g., \"Paris: ☀ï¸
(format "Weather for %s\nClick to refresh"
wttrin-mode-line-favorite-location)))
'mouse-face 'mode-line-highlight
- 'local-map (let ((map (make-sparse-keymap)))
- (define-key map [mode-line mouse-1]
- 'wttrin-mode-line-click)
- (define-key map [mode-line mouse-3]
- 'wttrin-mode-line-force-refresh)
- map))))
+ 'local-map wttrin--mode-line-map)))
(force-mode-line-update t)
(when (featurep 'wttrin-debug)
(message "wttrin mode-line: Display updated, mode-line-string = %S, tooltip = %S"