While toying around with not functioning scroll-enhancing packages and scripts I have seen cases of scrolling down beyond the end of the buffer, but haven't seen scrolling up beyond the top of the buffer.

In order to implement a scrolling behavior which keeps the line with the point stable always in the center of the displayed window it would be necessary to be able to scroll up beyond the first line in the buffer.

Can it be done? And if yes, how?

Update (because of no answers/comments):

In between I mean to have found out that the scrolling behavior is "hard-wired" somewhere in the C-code of Emacs. So the question comes down to the question where exactly can I find the appropriate C-code sections to investigate the difference between the code for scrolling up and scrolling down?

Update (considering the comments):

Digging in the C-code of Emacs graphics engine xdisp.c is the wrong way of approaching the goal of scrolling up beyond the top line while keeping the point at the center line, not only because it would require to get familiar with around 40 thousand lines of C-code, but because there exist another approach (using overlays to create a margin above the first line of text in the buffer).

  • The display engine is xdisp.c, however, each platform has additional files that affect drawing to the glass, etc. There are only a few people on the planet who really understand xdisp.c, one of whom is the maintainer Eli Z.
    – lawlist
    Commented Apr 9, 2023 at 4:06
  • A brief Google search revealed that there were attempts by one or more people to create a minor mode that places overlays at the top of the buffer to force the text to move downward when scrolling upward, but such a solution is less than optimal.
    – lawlist
    Commented Apr 9, 2023 at 4:15
  • 1
    As to questions that tend to open a Pandora's Box, I generally only comment providing some direction. My comments were not meant as a critique, but merely designed to limit the depth of the rabbit hole should I be tempted to go inside. I have spent a good chunk of free time over the years tinkering / hacking xdisp.c / dispnew.c, and the related glass-drawing libraries for the 3 major platforms. It is a bottomless abyss, not merely a rabbit hole. Keywords: scroll-margin top buffer margin emacs. Eli Z. commented somewhere a few years ago on this limitation, but I couldn't find it.
    – lawlist
    Commented Apr 9, 2023 at 17:35
  • @Drew : citation > I don't think this is possible in Emacs. But perhaps someone will provide an answer saying how to do it. ;-) – Drew Mar 14, 2021 at 3:34 . The OP at stackoverflow has in between provided an answer and a MELPA package ( see my answer for the link ).
    – oOosys
    Commented Apr 9, 2023 at 22:37
  • In Lisp, overlays are used to alter buffer appearance, without altering the text of the buffer itself. The topspace library uses overlays to visually push the text downward when scrolling upward. There will undoubtedly be some edge cases, but the library should work okay for its intended purpose most of the time. Unfortunately, the Emacs user can never programmatically determine with 100% certainty the window-start and/or window-end -- that can only be known in C while redisplay is finishing its calculations. [That uncertainty was the genesis of my journey into tinkering with C.]
    – lawlist
    Commented Apr 10, 2023 at 6:13

1 Answer 1


How to continue scrolling up with point at top of the buffer? Can it be done? And if yes, how?

See here for a ready to use solution available for installation from MELPA using <menu><Options><Manage Emacs Packages> topspace (recenter first line with scrollable upper margin/padding)

It allows centered scrolling for all lines including the top line of the buffer and shows the same marks in the upper part of the fringe which are shown past the end.

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.