|
4 | 4 |
|
5 | 5 | ;; Author: Robin Stephenson <robin@aglet.net> |
6 | 6 | ;; Keywords: convenience, weather |
7 | | -;; Version: 0.2.0 |
| 7 | +;; Version: 0.3.0 |
8 | 8 | ;; Package-Requires: ((emacs "29.1")) |
9 | 9 | ;; URL: https://github.com/aglet/sparkweather |
10 | 10 |
|
@@ -99,8 +99,14 @@ Examples: |
99 | 99 | (symbol :tag "Highlight face")))) |
100 | 100 | :group 'sparkweather) |
101 | 101 |
|
102 | | -(defcustom sparkweather-show-footer t |
103 | | - "Whether to show timestamp and location at bottom of forecast." |
| 102 | +(defcustom sparkweather-add-footer t |
| 103 | + "Whether to add timestamp and location footer to buffer." |
| 104 | + :type 'boolean |
| 105 | + :group 'sparkweather) |
| 106 | + |
| 107 | +(defcustom sparkweather-hide-footer nil |
| 108 | + "Whether to size window to hide footer. |
| 109 | +Has no effect if `sparkweather-add-footer' is nil." |
104 | 110 | :type 'boolean |
105 | 111 | :group 'sparkweather) |
106 | 112 |
|
@@ -473,8 +479,30 @@ CURRENT-HOUR, if provided, inserts a narrow no-break space before that hour." |
473 | 479 | `(,(regexp-quote sparkweather--buffer-name) |
474 | 480 | (display-buffer-reuse-window display-buffer-below-selected) |
475 | 481 | (window-height . fit-window-to-buffer) |
| 482 | + (window-max-height . sparkweather--window-max-height) |
476 | 483 | (body-function . ,#'select-window))) |
477 | 484 |
|
| 485 | +(defun sparkweather--format-footer () |
| 486 | + "Generate footer text with timestamp and optional location. |
| 487 | +Returns string suitable for insertion at buffer end." |
| 488 | + (concat "\n" (format-time-string "%A %F %R") |
| 489 | + (when (and (boundp 'calendar-location-name) calendar-location-name) |
| 490 | + (concat " " calendar-location-name)))) |
| 491 | + |
| 492 | +(defun sparkweather--footer-line-count () |
| 493 | + "Count number of lines in footer." |
| 494 | + (with-temp-buffer |
| 495 | + (insert (sparkweather--format-footer)) |
| 496 | + (count-lines (point-min) (point-max)))) |
| 497 | + |
| 498 | +(defun sparkweather--window-max-height (window) |
| 499 | + "Calculate maximum height for sparkweather WINDOW. |
| 500 | +Returns reduced height when `sparkweather-hide-footer' is enabled, nil otherwise." |
| 501 | + (when (and sparkweather-add-footer sparkweather-hide-footer) |
| 502 | + (with-current-buffer (window-buffer window) |
| 503 | + (- (count-lines (point-min) (point-max)) |
| 504 | + (sparkweather--footer-line-count))))) |
| 505 | + |
478 | 506 | (defun sparkweather--display-window-entry (window-plist) |
479 | 507 | "Create table entry from WINDOW-PLIST. |
480 | 508 | Returns (symbol vector) for tabulated-list-entries, or nil if no weather info." |
@@ -541,12 +569,10 @@ Returns list of entries for tabulated-list-mode." |
541 | 569 | (setq tabulated-list-entries entries |
542 | 570 | tabulated-list-use-header-line nil) |
543 | 571 | (tabulated-list-print t) |
544 | | - (when sparkweather-show-footer |
| 572 | + (when sparkweather-add-footer |
545 | 573 | (let ((inhibit-read-only t)) |
546 | 574 | (goto-char (point-max)) |
547 | | - (insert "\n" (format-time-string "%A %F %R")) |
548 | | - (when (and (boundp 'calendar-location-name) calendar-location-name) |
549 | | - (insert " " calendar-location-name)))) |
| 575 | + (insert (sparkweather--format-footer)))) |
550 | 576 | (goto-char (point-min)) |
551 | 577 | (display-buffer (current-buffer)))) |
552 | 578 |
|
|
0 commit comments