bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#55169: Can't combine window-min-height with window-height


From: Juri Linkov
Subject: bug#55169: Can't combine window-min-height with window-height
Date: Wed, 18 May 2022 21:20:05 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

> (defun shrink-window-if-larger-than-buffer (&optional window min-height)
>   "Shrink height of WINDOW if its buffer doesn't need so many lines.
> More precisely, shrink WINDOW vertically to be as small as
> possible, while still showing the full contents of its buffer.
> WINDOW must be a live window and defaults to the selected one.
>
> The optional argument MIN-HEIGHT specifies the minimum number of
> lines to which WINDOW may be shrunk and defaults to
> `window-min-height'.
>
> Do nothing if the buffer contains more lines than the present
> height of WINDOW, some of WINDOW's contents are scrolled out of
> view, shrinking WINDOW would also shrink another window, or
> WINDOW is the root window of its frame.
>
> Return non-nil if WINDOW was shrunk, nil otherwise."
>   (interactive)
>   (setq window (window-normalize-window window t))
>   ;; Make sure that WINDOW is vertically combined and `point-min' is
>   ;; visible (for whatever reason that's needed).  The remaining issues
>   ;; should be taken care of by `fit-window-to-buffer'.
>   (when (and (window-combined-p window)
>            (pos-visible-in-window-p (point-min) window))
>     (let ((old-height (window-pixel-height window)))
>       (fit-window-to-buffer
>        window (window-total-height window) nil min-height)

Thanks, this works fine, after removing nil above.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]