diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-04 19:21:34 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-04 19:21:34 -0600 |
| commit | 7673e72ed4dc4af9c3db9a5962c4673bd1ce90e3 (patch) | |
| tree | 555ad7fdfbcf852a37f142063cd18c88032a4499 /wttrin.el | |
| parent | 629d09a69d4fbb75f0d36fb44d750c515873834d (diff) | |
| download | emacs-wttrin-7673e72ed4dc4af9c3db9a5962c4673bd1ce90e3.tar.gz emacs-wttrin-7673e72ed4dc4af9c3db9a5962c4673bd1ce90e3.zip | |
fix(wttrin): Fix ANSI color rendering on fresh Emacs launch
Critical bug fix: On fresh Emacs launch, weather displayed with only
double quotes colored blue, all other text white. Pressing 'g' to
refresh brought colors back.
Root cause: wttrin-mode (derived mode) calls kill-all-local-variables
internally. The code was setting xterm-color--state buffer-local BEFORE
calling wttrin-mode, so the state was immediately wiped out. On refresh,
the mode was already active (no-op), so the state survived.
Fix: Call wttrin-mode FIRST, then set buffer-local variables after.
This ensures kill-all-local-variables runs before we set any state.
Changes:
- Reorder initialization in wttrin--display-weather (wttrin.el:277-285)
- Add regression tests for mode initialization order (2 new tests)
Test results: 65 tests, all passing
Diffstat (limited to 'wttrin.el')
| -rw-r--r-- | wttrin.el | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -230,8 +230,8 @@ CALLBACK is called with the weather data string when ready, or nil on error." (defvar wttrin-mode-map (let ((map (make-sparse-keymap))) - (define-key map (kbd "g") 'wttrin-requery) - (define-key map (kbd "r") 'wttrin-requery-force) + (define-key map (kbd "a") 'wttrin-requery) + (define-key map (kbd "g") 'wttrin-requery-force) ;; Note: 'q' is bound to quit-window by special-mode map) "Keymap for wttrin-mode.") @@ -243,9 +243,10 @@ Weather data is displayed in a read-only buffer with the following keybindings: \\{wttrin-mode-map}" (buffer-disable-undo) - (setq buffer-face-mode-face `(:family ,wttrin-font-name - :height ,wttrin-font-height)) - (buffer-face-mode t)) + ;; Use face-remap instead of buffer-face-mode to preserve xterm-color faces + (face-remap-add-relative 'default + :family wttrin-font-name + :height wttrin-font-height)) (defun wttrin--save-debug-data (location-name raw-string) "Save RAW-STRING to a timestamped debug file for LOCATION-NAME. @@ -273,9 +274,15 @@ Returns the path to the saved file." (let ((buffer (get-buffer-create (format "*wttr.in*")))) (switch-to-buffer buffer) - ;; Temporarily allow editing (in case mode is already active) + ;; Enable wttrin-mode first (calls kill-all-local-variables) + ;; This must be done before setting any buffer-local variables + (wttrin-mode) + + ;; Temporarily allow editing (let ((inhibit-read-only t)) (erase-buffer) + ;; Initialize xterm-color state AFTER wttrin-mode to prevent it being wiped + (setq-local xterm-color--state :char) (insert (xterm-color-filter raw-string)) ;; Remove verbose Location: coordinate line @@ -285,24 +292,17 @@ Returns the path to the saved file." ;; Add user instructions at the bottom (goto-char (point-max)) - (insert "\n\nPress: [g] to query another location [r] to refresh [q] to quit") + (insert "\n\nPress: [a] for another location [g] to refresh [q] to quit") ;; align buffer to top (goto-char (point-min))) - ;; Enable wttrin-mode (sets up keybindings, read-only, font, etc.) - ;; Must be called before setting buffer-local variables - (wttrin-mode) - ;; Set location after mode initialization (mode calls kill-all-local-variables) (setq-local wttrin--current-location location-name) ;; Auto-generate debug diagnostics if debug mode is enabled (when (featurep 'wttrin-debug) - (wttrin--debug-mode-line-info)) - - ;; Clear any lingering messages from url-retrieve - (message nil)))) + (wttrin--debug-mode-line-info))))) (defun wttrin-query (location-name) "Asynchronously query weather of LOCATION-NAME, display result when ready." |
