Function: shrink-window-if-larger-than-buffer
shrink-window-if-larger-than-buffer is an interactive and
byte-compiled function defined in window.el.gz.
Signature
(shrink-window-if-larger-than-buffer &optional WINDOW)
Documentation
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.
Do not shrink WINDOW to less than window-min-height lines. Do
nothing if the buffer contains more lines than the present window
height, or if some of the window's contents are scrolled out of
view, or if shrinking this window would also shrink another
window, or if the window is the only window of its frame.
Return non-nil if the window was shrunk, nil otherwise.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun shrink-window-if-larger-than-buffer (&optional window)
"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.
Do not shrink WINDOW to less than `window-min-height' lines. Do
nothing if the buffer contains more lines than the present window
height, or if some of the window's contents are scrolled out of
view, or if shrinking this window would also shrink another
window, or if the window is the only window of its frame.
Return non-nil if the 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))
(fit-window-to-buffer window (window-total-height window))))