0

Having

(global-set-key "\M-n" "\C-u1\C-v")
(global-set-key "\M-p" "\C-u1\M-v")

does exactly what I want, but it's exceedingly slow for my machine and for my key-repeat-rate setting. It's as if it's doing way too much by hooking on and invoking "C-v".

My usage is simple: I am coding something and I want to scroll up or down just a little to see a function or two in full, without disturbing the position of the cursor.

I'm on bare-bones Emacs 28.2.

How can I scroll efficiently up/down by one line without disturbing the cursor? Put simply, I'm looking for what you would do with the mouse wheel, but with, say "M-n" and "M-p" so that I do not have to move my hands out of their keyboard rest position.

Sam
  • 317
  • 1
  • 11
  • 1
    `scroll-preserve-screen-position` is a variable, not a function - try `C-h v scroll-preserve-screen-position` to see its doc string. – NickD Dec 31 '22 at 19:29

1 Answers1

0

What about:

(global-set-key (kbd "M-p") #'scroll-up-line)
(global-set-key (kbd "M-n") #'scroll-down-line)
Lindydancer
  • 6,095
  • 1
  • 13
  • 25
  • It might be a hair faster, but not by much. I'd have to time it to know for sure. Might I have been using the wrong solution all along? What do you do when you want to scroll multiple times quickly to align a given segment of the buffer with the frame—optimally using all the "screen real estate" that you have available? Scrolling through the trackpad already solves this perfectly, but that of course requires moving a hand off the keyboard and back. – Sam Jan 01 '23 at 16:27
  • With this approach, you can use the universal argument, e.g. `C-u 2 0 M-p` to scroll up 20 lines. (I haven't checked, but I don't think you can do that with your original bindings.) Of course, you could surely define a number of functions that scroll, say, one, ten, thirty lines and bind them to various keys or using various modifiers. – Lindydancer Jan 01 '23 at 21:57