Sometimes I have the current buffer in the current window displayed sub-optimally: there is a lot of buffer not shown, and there is a lot of empty space at the bottom below the EOB. E.g.:

  • the buffer is 100 lines
  • the window is 10 lines
  • the point is on the line 3 of the window
  • EOB is on the line 5 of the window

so that the bottom 5 lines of the window are empty and the first 95 lines of the buffer are not shown.

I want a function that would "move the window 5 lines up along the buffer" so that

  • the EOB is on the bottom line of the window
  • the last 10 lines of the buffer are shown
  • the point is on the line 8(=3+5) or the window, the value of (point) did not change


  • I do not want the point to move
  • I do not want to change window configuration
  • I do not want to change the current window size

I am pretty sure something like that exists already, I just cannot figure out how to find it.


Apparently, I need something like this:

(defun sds-improve-window-utilization ()
  "Ensure that there is no empty space below EOB in the current window"
  (when-let ((w (selected-window))
             (eob-pos (cadr (pos-visible-in-window-p (point-max) w t)))
             (point (cadr (pos-visible-in-window-p (point) w t)))
             (height-c (window-total-height w))
             (height-p (window-pixel-height w)))
    (recenter (/ (- point eob-pos) (/ height-p height-c)))))

I wonder, again, if something like that already exists...

2 Answers 2


If you just want to move EOB to the bottom of the window without moving point, then the simplest thing I can think of is

   (goto-char (point-max))
   (recenter-top-bottom (window-height)))

It's effectively a no-op if the EOB is not visible in the window and otherwise saves point, positions EOB at the bottom of the window and restores point.

  • Nah, this still leaves a few un-used lines at the bottom ;-(
    – sds
    Jan 2 at 2:58
  • What's the value of scroll-margin? Try let-binding it to 0 around the recenter call.
    – NickD
    Jan 2 at 3:14
  • scroll-margin is 0
    – sds
    Jan 2 at 5:31
  • Then it's probably because EOB is on an empty line after the last visible text. If you have trailing newlines, try deleting them; although if you insist on having a final newline (which is always a good idea IMO), there is going to be an empty line at the bottom: you'd have to position EOB on the line given by (1+ (window-height)) - you might try that, but I wouldn't hold my breath.
    – NickD
    Jan 2 at 15:31

Use recenter-top-bottom, normally bound to C-l.

  • Nope, C-l makes the current line center, but there is still empty space at the bottom.
    – sds
    Apr 10, 2022 at 2:25
  • Hit C-l twice more. Seriously.
    – db48x
    Apr 10, 2022 at 13:41
  • I know how C-l works, I tried it and I read the code. It does NOT do what I need. I want EOB to be the bottom of the window, not the point.
    – sds
    Apr 10, 2022 at 14:52
  • I think you’re being particular enough that you’re going to have to write your own.
    – db48x
    Apr 10, 2022 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.