2

As the title states, I expect some behavior like the GIF shown.

By contrast, here is what my Emacs does now.

It keeps scrolling even when the last line has appeared, so you can see the empty area was moved to screen.

You can reproduce this by:

  1. emacs.exe -Q
  2. C-h v emacs-version
  3. C-x 0
  4. Press SPC, SPC, ...

v29.1 on MS-Windows

shynur
  • 5,253
  • 1
  • 4
  • 25
  • The app shown in the 1st GIF is the latest version of notepad on MS-Windows. – shynur Nov 14 '23 at 11:13
  • I don't know how to do what you want and I don't have any concrete suggestion, but one vague suggestion is to play around with the auto-scrolling settings and seeif that helps. – NickD Nov 14 '23 at 19:54
  • In your 2nd gif, are you scrolling w/ the mouse wheel? – nega Nov 20 '23 at 15:13
  • @nega: "In your 2nd gif, are you scrolling w/ the mouse wheel?" -- yes – shynur Nov 21 '23 at 04:55
  • probably not helpful but i seem to recall a variable (or maybe an old "package") that would ensure some percentage of the buffer contents always remained visible, but i can't seem to find it. (it might have been an XEmacs only thing.) cua-mode enables some behavior that i think you're looking for, but then you get all of cua-mode :( – nega Nov 21 '23 at 15:48
  • this might be helpful https://emacs.stackexchange.com/questions/57479/can-page-down-clamp-the-last-line-to-the-bottom-of-the-window – nega Nov 21 '23 at 15:49

1 Answers1

1

I am not sure if the following code will give any problems, but I did not experience any while testing it quickly:

(defun limit-scrolling (&optional win start)
  (let ((visible-lines (count-lines (or start (window-start)) (buffer-size)))
        (lines-to-end (count-lines (point) (buffer-size))))
    (when (< visible-lines (window-text-height))
      (recenter (- lines-to-end)))))

;; (add-hook 'window-scroll-functions #'limit-scrolling) (add-hook 'post-command-hook #'limit-scrolling)

I have initially written the function to be used as a window-scroll-function (which takes two arguments), which seems to work fine. But as the docstring of window-scroll-functions warns that such functions should not be used to 'alter the way a window is scrolled', I figured it would be wiser to add the function to the post-command-hook instead. I have written the function so that it can be used in any of those two hooks (but make sure to not use it in both hooks at the same time).

Also, remember that, if you experience some 'weird' scrolling problems somewhere, you should remove the function from the hook to see if the problems disappear.

dalanicolai
  • 7,795
  • 8
  • 24