Skip to content

Commit b023957

Browse files
committed
Fix: Account for modeline when hiding footer
1 parent 6c816ae commit b023957

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

sparkweather.el

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; Author: Robin Stephenson <robin@aglet.net>
66
;; Keywords: convenience, weather
7-
;; Version: 0.3.0
7+
;; Version: 0.3.1
88
;; Package-Requires: ((emacs "29.1"))
99
;; URL: https://github.com/aglet/sparkweather
1010

@@ -475,16 +475,12 @@ CURRENT-HOUR, if provided, inserts a narrow no-break space before that hour."
475475
cursor-type nil)
476476
(setq-local show-help-function nil))
477477

478-
(add-to-list 'display-buffer-alist
479-
`(,(regexp-quote sparkweather--buffer-name)
480-
(display-buffer-reuse-window display-buffer-below-selected)
481-
(window-height . fit-window-to-buffer)
482-
(window-max-height . sparkweather--window-max-height)
483-
(body-function . ,#'select-window)))
484-
485478
(defun sparkweather--format-footer ()
486479
"Generate footer text with timestamp and optional location.
487-
Returns string suitable for insertion at buffer end."
480+
Returns string suitable for insertion at buffer end.
481+
Leading newline provides spacing and allows hiding only timestamp when footer is hidden."
482+
;; Leading \n creates blank line for visual spacing.
483+
;; sparkweather--window-max-height relies on this to hide only the timestamp line.
488484
(concat "\n" (format-time-string "%A %F %R")
489485
(when (and (boundp 'calendar-location-name) calendar-location-name)
490486
(concat " " calendar-location-name))))
@@ -497,11 +493,23 @@ Returns string suitable for insertion at buffer end."
497493

498494
(defun sparkweather--window-max-height (window)
499495
"Calculate maximum height for sparkweather WINDOW.
500-
Returns reduced height when `sparkweather-hide-footer' is enabled, nil otherwise."
496+
Returns reduced height when `sparkweather-hide-footer' is enabled, nil otherwise.
497+
Keeps blank line visible as buffer, hiding only timestamp/location line."
501498
(when (and sparkweather-add-footer sparkweather-hide-footer)
502499
(with-current-buffer (window-buffer window)
503-
(- (count-lines (point-min) (point-max))
504-
(sparkweather--footer-line-count)))))
500+
;; Calculate desired body lines (total - 1 to hide timestamp)
501+
;; Relies on sparkweather--format-footer's leading newline to provide neat spacing
502+
;; Then add overhead (mode line, etc.) to get total window height
503+
(let* ((desired-body-lines (1- (count-lines (point-min) (point-max))))
504+
(overhead (- (window-height window) (window-body-height window))))
505+
(+ desired-body-lines overhead)))))
506+
507+
(add-to-list 'display-buffer-alist
508+
`(,(regexp-quote sparkweather--buffer-name)
509+
(display-buffer-reuse-window display-buffer-below-selected)
510+
(window-height . ,(lambda (window)
511+
(fit-window-to-buffer window (sparkweather--window-max-height window))))
512+
(body-function . ,#'select-window)))
505513

506514
(defun sparkweather--display-window-entry (window-plist)
507515
"Create table entry from WINDOW-PLIST.

sparkweather.org

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
;; Author: Robin Stephenson <robin@aglet.net>
1414
;; Keywords: convenience, weather
15-
;; Version: 0.3.0
15+
;; Version: 0.3.1
1616
;; Package-Requires: ((emacs "29.1"))
1717
;; URL: https://github.com/aglet/sparkweather
1818

@@ -536,12 +536,6 @@ Special mode with keybindings for the weather display buffer.
536536
cursor-type nil)
537537
(setq-local show-help-function nil))
538538

539-
(add-to-list 'display-buffer-alist
540-
`(,(regexp-quote sparkweather--buffer-name)
541-
(display-buffer-reuse-window display-buffer-below-selected)
542-
(window-height . fit-window-to-buffer)
543-
(window-max-height . sparkweather--window-max-height)
544-
(body-function . ,#'select-window)))
545539
#+end_src
546540

547541
** Footer
@@ -552,6 +546,8 @@ Footer generation and window height calculation to optionally hide footer lines.
552546
(defun sparkweather--format-footer ()
553547
"Generate footer text with timestamp and optional location.
554548
Returns string suitable for insertion at buffer end."
549+
;; Leading \n creates blank line for visual spacing.
550+
;; sparkweather--window-max-height relies on this to hide only the timestamp line.
555551
(concat "\n" (format-time-string "%A %F %R")
556552
(when (and (boundp 'calendar-location-name) calendar-location-name)
557553
(concat " " calendar-location-name))))
@@ -564,11 +560,23 @@ Returns string suitable for insertion at buffer end."
564560

565561
(defun sparkweather--window-max-height (window)
566562
"Calculate maximum height for sparkweather WINDOW.
567-
Returns reduced height when `sparkweather-hide-footer' is enabled, nil otherwise."
563+
Returns reduced height when `sparkweather-hide-footer' is enabled, nil otherwise.
564+
Keeps blank line visible as buffer, hiding only timestamp/location line."
568565
(when (and sparkweather-add-footer sparkweather-hide-footer)
569566
(with-current-buffer (window-buffer window)
570-
(- (count-lines (point-min) (point-max))
571-
(sparkweather--footer-line-count)))))
567+
;; Calculate desired body lines (total - 1 to hide timestamp)
568+
;; Relies on sparkweather--format-footer's leading newline to provide neat spacing
569+
;; Then add overhead (mode line, etc.) to get total window height
570+
(let* ((desired-body-lines (1- (count-lines (point-min) (point-max))))
571+
(overhead (- (window-height window) (window-body-height window))))
572+
(+ desired-body-lines overhead)))))
573+
574+
(add-to-list 'display-buffer-alist
575+
`(,(regexp-quote sparkweather--buffer-name)
576+
(display-buffer-reuse-window display-buffer-below-selected)
577+
(window-height . ,(lambda (window)
578+
(fit-window-to-buffer window (sparkweather--window-max-height window))))
579+
(body-function . ,#'select-window)))
572580
#+end_src
573581

574582
** Entry formatting

0 commit comments

Comments
 (0)