0

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

Note:

  • 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.

Edit:

Apparently, I need something like this:

(defun sds-improve-window-utilization ()
  "Ensure that there is no empty space below EOB in the current window"
  (interactive)
  (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...

1 Answer 1

0

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

4
  • 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 that you have read and understand our privacy policy and code of conduct.

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