22

Is there a way to stop Emacs from automatically moving my text-cursor position (aka, point) while I'm scrolling? I keep losing my location and marks with this annoying behavior.

I tested the following suggestion, with no success:

(setq scroll-preserve-screen-position t
scroll-conservatively 0)

(I'm running Emacs 24.2 on Ubuntu and on OS X.)

4 Answers 4

12

I think you want the behavior of cursor(point) and visible area should be like in notepad, gedit, others modern editors: ability to change visible area independently of point position and to immediately return visible area to point position after moving point. But emacs has another conception: the visible area always follows the point position and vise versa.

See also https://stackoverflow.com/questions/9616623/ctrl-up-down-style-scrolling-in-emacs

Previous answer shows special idiom: if you want to move the visible area (with the point together) far from current position and then to return the point in exactly the previous position you should have a habit to use mark-ring. There always is a way through mark ring to current working position: many commands, like isearch-forward, beginning-of-buffer, ace-jump-mode automatically save previous position in mark ring and you shouldn't use C-<SPC> C-<SPC> before, but only C-u C-<SPC> for jumping back. Scrolling commands, like scroll-up or mwheel-scroll, don't automatically save previous position by default because it may produce too many excessive marks.

You can use commands clone-indirect-buffer or view-buffer-other-window for independent work with buffer in few places. And use command recenter-top-bottom (C-l) to continuously hold point in center of visible area.

3
  • 2
    Thanks. Interesting answer. There seems to be a problem with my Emacs, though (both in Mac and in Ubuntu): C-u C-<SPC> doesn't seem to be working. I don't know if it's a problem of cua-mode or something. I tried running Emacs with -q option, but nothing changed. Any ideas?
    – NVaughan
    Jan 8, 2013 at 23:44
  • 3
    That's too bad... I find this super annoying, because I use highlight-symbol-mode. I set the cursor on one variable and it highlights all occurences. When I start scrolling, the cursor leaves the variable and all highlights are lost. Emacs would be much better if at least it would behave like other contemporary editors regarding scrolling stuff.
    – itmuckel
    Jul 12, 2019 at 22:27
  • Why are these shortcuts not listed with C-h b?
    – zoechi
    Feb 25, 2020 at 9:42
9

I don't know if there is a way to stop emacs from moving your point when scrolling. But if you would like to save your location to return to it later, you can use the mark ring.

That is, type C-<SPC> C-<SPC> to push the current point location onto the mark ring, then later type C-u C-<SPC> to set point to the previous location in the mark ring.

4

I use this:

;;; scrollers - M-f, M-b
(global-set-key "\M-f" "\C-u1\C-v")
(global-set-key "\M-b" "\C-u1\M-v")
0
0

The following works for me:

(custom-set-variables
 '(scroll-conservatively 1000)
 '(scroll-margin 3)
 )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .