Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make as much as possible of buffer visible in window instead of showing empty space after buffer

Tags:

emacs

elisp

It is possible to "scroll past the end of the buffer" in a window. This is useful because Emacs has to somehow use the extra space when the buffer does not fill the whole area available to the window used to display it.

However sometimes when the whole buffer would fit completely into the window the top part still isn't displayed and more space than necessary is wasted below the buffer content to fill the available space. It would be better if the window were automatically scrolled to show the complete buffer or if it is bigger than the window as much as possible.

In other words the only time when a window displays something "below the buffer end" is when the window is to big.

Is there a mode or option to do that?

enter image description here

like image 610
tarsius Avatar asked Nov 03 '22 22:11

tarsius


1 Answers

Edit: So something like this?

(add-hook 'post-command-hook 'my-eob-recenter)
(defun my-eob-recenter ()
  (when (pos-visible-in-window-p (point-max))
    (save-excursion
      (goto-char (point-max))
      (recenter -1))))

Original answer:

If you have a window which is larger than its contents and you want to shrink it to fit, there's a binding for that.

C-x- runs shrink-window-if-larger-than-buffer

Personally I suspect this would be annoying if it happened automatically, but you might try this:

(defadvice split-window (after my-split-window-shrink)
  "Shrink the selected window after a window split
if it is larger than its contents."
  (shrink-window-if-larger-than-buffer))
(ad-activate 'split-window)
like image 156
phils Avatar answered Dec 12 '22 03:12

phils