Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let Emacs move the cursor off-screen

Is it possible to let Emacs have the cursor be moved off-screen, like most GUI text editors work? This is one of the biggest things that bothers me when I use Emacs over any GUI editor. When I scroll down, the cursor is "pushed forward" by the top of the buffer.

I had previously thought that this was completely impossible, because this is hard-wired into the architecture of Emacs, but then I saw multiple-cursors, which does exactly this for the secondary cursors (assuming you prevent the scrolling functions from acting on the secondary cursors). Is it maybe possible to use multiple-cursors to have the main cursor in some hidden buffer, and the effective cursor being what I actually edit with? Or maybe some other clever trick? Or maybe my Googling has failed me and this is really already possible without any magic?

like image 807
asmeurer Avatar asked Apr 09 '13 06:04

asmeurer


People also ask

How do I move cursor in Emacs?

Cursor positioning can be done with arrow keys or the left mouse button. Documentation and options can be found in menus at top of screen. Move the cursor Forward/Backward one character.

How to go to end of line in Emacs?

Unlike C-n and C-p , most of the Emacs commands that work on lines work on logical lines. For instance, C-a ( move-beginning-of-line ) and C-e ( move-end-of-line ) respectively move to the beginning and end of the logical line.


2 Answers

There is a new package available on GNU ELPA called scroll-restore that attempts to remedy this problem. So far, I have encountered a few bugs, but the package seems to work as-advertised for the most part.

You can test it out by installing it with

M-x package-install RET scroll-restore RET

After the package is installed, you can enable the minor mode with

M-x scroll-restore-mode

Personally, I am binding it to the Scroll Lock key because it seems so incredibly apropos! This is what I am adding to my init file:

(require 'scroll-restore)
(scroll-restore-mode 1)
;; Allow scroll-restore to modify the cursor face
(setq scroll-restore-handle-cursor t)
;; Make the cursor invisible while POINT is off-screen
(setq scroll-restore-cursor-type nil)
;; Jump back to the original cursor position after scrolling
(setq scroll-restore-jump-back t)
;; Toggle scroll-restore-mode with the Scroll Lock key
(global-set-key (kbd "<Scroll_Lock>") 'scroll-restore-mode)

This is a direct copy of an answer posted here: https://emacs.stackexchange.com/a/2273/93

like image 69
nispio Avatar answered Oct 03 '22 00:10

nispio


Strictly, speaking you can't move the cursor offscreen, because the underlying C code won't let you do it.

This said, I suspect that your problem can be fixed. Basically, there are 2 aspects:

  • you don't like the way things look when "the cursor is pushed forward". You could work around that by (temporarily) making the cursor invisible.
  • you want to "jump back" to the pre-scrolling position as soon as you issue a non-scrolling command. There's probably some package out there that does it for you, but you can do it yourself with some pre-command-hook hacking.

BTW, I'd welcome patches in Emacs which provide some of that functionality. I hate the "auto jump-back" behavior of other editors, but it would be good to record the "pre-scroll" position and then offer a way to jump back to it.

like image 23
Stefan Avatar answered Oct 03 '22 02:10

Stefan