diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-23 23:04:46 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-23 23:04:46 -0400 |
| commit | 4d46eafaa087f5570ece9d2e5f5d2ba6bc0d824e (patch) | |
| tree | 19c24dc27a1f72e8b05a98b43a429c49f917fc4a /wttrin.el | |
| parent | eaabae3b01b8bdc05a5892492c06a8131c195a45 (diff) | |
| download | emacs-wttrin-4d46eafaa087f5570ece9d2e5f5d2ba6bc0d824e.tar.gz emacs-wttrin-4d46eafaa087f5570ece9d2e5f5d2ba6bc0d824e.zip | |
feat: expose themeable faces for mode-line and buffer text
I added four customizable faces so themes and customize-face can restyle the text wttrin draws itself: wttrin-mode-line-stale (the dimmed stale mode-line emoji), wttrin-staleness-header (the "Last updated:" line), wttrin-instructions (the footer prose), and wttrin-key (the [a]/[g]/[q] chords).
The package exposed no faces before and hardcoded one color. The stale-emoji dimming used a literal "gray60". Now it inherits a face, so the color tracks the theme. I changed make-emoji-icon's second argument from a color string to a face symbol applied via :inherit.
wttrin-key inherits bold rather than help-key-binding, which is Emacs 28+ while the package supports 24.4.
The weather ASCII art stays colored by xterm-color's ANSI faces. Only the package's own text is newly faced.
Diffstat (limited to 'wttrin.el')
| -rw-r--r-- | wttrin.el | 61 |
1 files changed, 49 insertions, 12 deletions
@@ -57,6 +57,32 @@ :prefix "wttrin-" :group 'comm) +(defface wttrin-mode-line-stale + '((t :inherit shadow)) + "Face for the mode-line weather emoji when its data is stale. +Applied when a scheduled refresh has failed and the cached reading is +older than twice `wttrin-mode-line-refresh-interval'. A color emoji +font may ignore the foreground, in which case the dimming is only +visible on monochrome glyphs." + :group 'wttrin) + +(defface wttrin-staleness-header + '((t :inherit shadow)) + "Face for the \"Last updated: ...\" line in the weather buffer." + :group 'wttrin) + +(defface wttrin-instructions + '((t :inherit shadow)) + "Face for the key-hint footer prose in the weather buffer." + :group 'wttrin) + +(defface wttrin-key + '((t :inherit bold)) + "Face for the bracketed key chords in the weather buffer footer. +`help-key-binding' would be the natural parent, but it only exists in +Emacs 28+, and wttrin supports 24.4, so the default inherits `bold'." + :group 'wttrin) + (defcustom wttrin-font-name "Liberation Mono" "Preferred monospaced font name for weather display." :group 'wttrin @@ -628,9 +654,19 @@ Returns processed string ready for display." (buffer-string)))) (defun wttrin--add-buffer-instructions () - "Add user instructions at bottom of current buffer." + "Add the key-hint footer at the bottom of the current buffer. +Bracketed key chords use `wttrin-key'; the surrounding prose uses +`wttrin-instructions'." (goto-char (point-max)) - (insert "\n\nPress: [a] for another location [g] to refresh [q] to quit")) + (insert "\n\n") + (dolist (segment '(("Press: " . wttrin-instructions) + ("[a]" . wttrin-key) + (" for another location " . wttrin-instructions) + ("[g]" . wttrin-key) + (" to refresh " . wttrin-instructions) + ("[q]" . wttrin-key) + (" to quit" . wttrin-instructions))) + (insert (propertize (car segment) 'face (cdr segment))))) (defun wttrin--format-staleness-header (location) "Return a staleness header string for LOCATION, or nil if no cache entry. @@ -643,7 +679,8 @@ Looks up the cache timestamp for LOCATION and formats a line like (age (- (float-time) timestamp)) (time-str (format-time-string "%l:%M %p" (seconds-to-time timestamp))) (age-str (wttrin--format-age age))) - (format "Last updated: %s (%s)" (string-trim time-str) age-str))))) + (propertize (format "Last updated: %s (%s)" (string-trim time-str) age-str) + 'face 'wttrin-staleness-header))))) (defun wttrin--display-weather (location-name raw-string &optional error-msg) "Display weather data RAW-STRING for LOCATION-NAME in weather buffer. @@ -809,19 +846,19 @@ user's original casing so tooltips display what the user expects." (concat location (substring response (match-beginning 0))) response)) -(defun wttrin--make-emoji-icon (emoji &optional foreground) - "Create EMOJI string with optional font face and FOREGROUND color. -Uses `wttrin-mode-line-emoji-font' when configured. -Omits `:foreground' from the face plist when FOREGROUND is nil — a literal -`:foreground nil' entry triggers \"Invalid face attribute\" warnings on every +(defun wttrin--make-emoji-icon (emoji &optional face) + "Create EMOJI string, optionally styled with FACE and the emoji font. +Uses `wttrin-mode-line-emoji-font' when configured. FACE, when non-nil, +is applied via `:inherit'. Omitting it avoids a literal `:inherit nil' +entry, which triggers \"Invalid face attribute\" warnings on every redisplay." (if wttrin-mode-line-emoji-font (propertize emoji 'face `(:family ,wttrin-mode-line-emoji-font :height 1.0 - ,@(when foreground (list :foreground foreground)))) - (if foreground - (propertize emoji 'face (list :foreground foreground)) + ,@(when face (list :inherit face)))) + (if face + (propertize emoji 'face (list :inherit face)) emoji))) (defun wttrin--set-mode-line-string (icon tooltip) @@ -947,7 +984,7 @@ shows staleness info in tooltip." emoji stale-p) (setq wttrin--mode-line-rendered-stale stale-p) (setq wttrin-mode-line-string - (propertize (concat " " (wttrin--make-emoji-icon emoji (when stale-p "gray60"))) + (propertize (concat " " (wttrin--make-emoji-icon emoji (when stale-p 'wttrin-mode-line-stale))) 'help-echo #'wttrin--mode-line-tooltip 'mouse-face 'mode-line-highlight 'local-map wttrin--mode-line-map))))) |
