Let Emacs move the cursor off-screen

巧了我就是萌 提交于 2019-11-30 11:12:11
nispio

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

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.

souser12345

Judging by the context and description of your problem, it looks like you want to browse the buffer while preserving your place of editing. There are at least two tricks for that purpose: marks/registers and splitting in two windows.

https://stackoverflow.com/a/3777598/308668 describes the Emacs' registers that act like Vim's marks. You can check in your place in the file with keying C-x r SPC a (a being a letter of your choice) and you can always come back with C-x r j a.

Some sort of automation is achieved by an external script (goto-last-change.el), described here: https://superuser.com/a/184402/49046.

Alternatively, split the window in two with C-x 2. The newly split windows both show the same location and you can use the other to explore. C-x 0 closes a window when you're done.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!