Emacs C-l command only recenters screen, and doesn't cycle through top and bottom repositioning

StackOverflow https://stackoverflow.com/questions/21973534

  •  15-10-2022
  •  | 
  •  

Question

Repeatedly running the emacs command C-l on my machine does not cycle through the three positions, only the first position (center of screen).

From the GNU Emacs documentation:

C-l (recenter-top-bottom)

Scroll the selected window so the current line is the center-most text line; on subsequent consecutive invocations, make the current line the top line, the bottom line, and so on in cyclic order. Possibly redisplay the screen too (recenter-top-bottom).

Typing C-l twice in a row (C-l C-l) scrolls the window so that point is on the topmost screen line. Typing a third C-l scrolls the window so that point is on the bottom-most screen line. Each successive C-l cycles through these three positions.

When I run C-l, it only scrolls the window so that the current line is at the center-most text line. But upon subsequent invocations, the command just keeps recentering the window at the same point. I've used emacs on other machines where the cycling works, and the 2nd and 3rd iterations do scroll the window to the top-most and bottom-most lines, so I know there's something wrong with my version.

How can I fix this?

(Please let me know in the comments what files or information you need to see in order to diagnose the problem.)

Était-ce utile?

La solution

As @legoscia mentioned, I added this command to Emacs in release 23.

But you can get the original, which works with all Emacs versions, by loading library misc-cmds.el. Or just grab the code for functions recenter-top-bottom* from there, if you do not want the other commands defined there.

Autres conseils

Try this in your init.el file

(setq recenter-positions '(middle top bottom))

Ref: https://www.gnu.org/software/emacs/manual/html_node/emacs/Recentering.html

This functionality was introduced in Emacs 23.1. In earlier versions, C-l behaved just like you describe: it always recenters the buffer, never cycles between top and bottom.

From the "Emacs 22 Antinews" section of the Emacs 23 manual:

For those users who live backwards in time, here is information about downgrading to Emacs version 22.3.

...

C-l now runs recenter instead of recenter-top-bottom. This always sets the current line at the center of the window, instead of cycling through the center, top, and bottom of the window on successive invocations. This lets you type C-l C-l C-l C-l to be absolutely sure that you have recentered the line.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top