46

I find myself wanting to use Emacs, mostly because of org-mode, but I'm having a lot of trouble getting used to the jerky scrolling behavior. I know this is a well-known problem/eccentricity of Emacs and that there are various ways to minimize jerkiness when scrolling. But nothing I've tried so far works very well at all.

The main suggestions I've seen are (setq scroll-conservatively 10000) or to use the more comprehensive fix available in smooth-scrolling.el . I think both of these might work okay for me, but both fail miserably when I hold down the up-arrow and down-arrow key to get repeated scrolling up or down. When I do this the screen freezes and I see the scroll-indicator-bar in the scroll margin move up or down. The screen does not refresh until I stop holding down the up-arrow or down-arrow key.

If I repeatedly press up-arrow or down-arrow then I do get behavior close to what I want, i.e., the screen scrolls smoothly and cursor key does not get reset to middle of screen. But this is undesirable because (1) it requires repeated keypresses and (2) I assume the scrolling is at a slower rate than what I should be able to get in better solution.

The problem with holding the cursor keys down seems to me to be that the repeat rate of up-arrow or down-arrow is so fast that it triggers emacs to stop the screen refresh until key is released. I wonder whether a possible fix for me would be to add some lag into the key-repeat rate or the rate at which the next/previous line function is called in emacs.

I haven't seen this reported as a problem by others and I wonder whether other people have experienced same behavior. What's best way to fix things so I can hold the up/down arrow keys down and have repeat rate that's slow enough so that the screen doesn't freeze?

UPDATE: The above behavior is what I get when I run emacs on Win7/64. On same machine when I run emacs inside a VirtualBox VM running Ubuntu 10.04 it's no problem to get scrolling that works fine even when cursor keys are held down.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Herbert Sitz
  • 21,858
  • 9
  • 50
  • 54
  • The large value of `scroll-conservatively` worked to solve this for me... maybe your computer is slower than your keyboard? :) – Trey Jackson Sep 02 '10 at 21:08
  • Trey -- Thanks, I was wondering whether that might be the case. So it seems I'll need some further step to get smooth scrolling. My computer is not a monster machine, but I wouldn't call it slow; it's a laptop with a Pentium SU4100, dual core 1.3GHz chip and 4GB RAM. – Herbert Sitz Sep 02 '10 at 21:23
  • please, could you tell us if you have emacs on Windows, Un*x, whether it's in a terminal window (-nw) inside a desktop environment like gnome or outside a GUI (screen) ? – Jérôme Radix Sep 03 '10 at 09:17

7 Answers7

55

I had the same problem! Tried all the scroll-* settings, didn't help when holding down arrow. But found this on gnu.emacs.help which finally worked (for me at least):

(setq redisplay-dont-pause t)

This is what I have in .emacs for now:

(setq redisplay-dont-pause t
  scroll-margin 1
  scroll-step 1
  scroll-conservatively 10000
  scroll-preserve-screen-position 1)
Ken Goh
  • 1,049
  • 11
  • 8
  • 2
    +1; encountered the same problem as OP on a fairly powerful Win7 x64 machine; this fix makes scrolling tolerable (although not as good as on other platforms with smooth-scrolling.el enabled) – Leo Alekseyev Dec 30 '10 at 22:26
  • 2
    I also needed (setq-default scroll-up-aggressively 0.01 scroll-down-aggressively 0.01) to make things reasonable (see http://zhangda.wordpress.com/2009/05/21/customize-emacs-automatic-scrolling-and-stop-the-cursor-from-jumping-around-as-i-move-it/) – Jared Forsyth May 13 '13 at 17:28
  • 2
    I noticed that docs on `redisplay-dont-pause` is obsolete since 24.5. However, I'm not sure why. – willbush Aug 11 '19 at 02:02
  • Omitting `scroll-step 1` worked for me. Viewing the help for `scroll-step` emacs recommends just using scroll-conservatively. That internal documentation may have changed since this question was initially posed. – ian Sep 26 '20 at 06:50
9

scroll-conservatively helps, but I also like a margin so that I can see what's coming up as a scroll -- it keeps context on the screen for me. These settings have worked well for me an a wide variety of computers for a few years:

(setq scroll-conservatively 10)
(setq scroll-margin 7)
R. P. Dillon
  • 2,780
  • 1
  • 18
  • 20
  • Thanks, but I've experimented with different values of scroll-conservatively and scroll-margin and they don't fix the problem. Scrolling is smooth enough if I discretely depress cursor key for each up or down movement, but if I hold the cursor key down the screen freezes while the scroll indicator shows position moving through file. Screen doesn't refresh until I take finger off the key. – Herbert Sitz Sep 02 '10 at 22:38
  • Yeah, I noticed that you said that in your post...I've used these settings in GNU Emacs on everything from an Atom netbook running Ubuntu to a Core 2 Duo running OS X and a quad-core Windows desktop at work... What brand and build of Emacs are you using? – R. P. Dillon Sep 02 '10 at 22:41
  • I'm running this on 64-bit windows 7: GNU Emacs 23.1.50.1 (i386-mingw-nt6.1.7600) of 2009-11-03 on LENNART-69DE564 (patched). I'd have to check, but I'm pretty sure I have same behavior on my other computers, which include an atom netbook and several other notebooks. – Herbert Sitz Sep 02 '10 at 22:45
  • 1
    Also, you didn't mention it although I assumed you already tried it: Adam Spiers smooth-scrolling.el. If not, here's a link to it: http://adamspiers.org/computing/elisp/smooth-scrolling.el The scrolling stuff is a well-known problem, although I've never needed much besides what I posted above to fix it. – R. P. Dillon Sep 02 '10 at 22:48
  • Accepted this answer as it does point to accepted way to improve scrolling, however neither this nor the smooth-scrolling.el fix helped the problem on my main Emacs, which is running on Win7/64. They work fine for me on Ubuntu, though. – Herbert Sitz Nov 04 '10 at 01:18
  • +1... Thank you, thank you. This is *so* much better. I had abandoned the buggy smooth-scrolling a while ago, and had never heard of this. – harpo Feb 08 '11 at 22:11
  • Having said that... it is surprisingly CPU-intensive for something so seemingly basic to a text editor. – harpo Feb 08 '11 at 22:18
6

Try this:

;; scroll one line at a time (less "jumpy" than defaults)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ; one line at a time
(setq mouse-wheel-progressive-speed nil)            ; don't accelerate scrolling
(setq-default smooth-scroll-margin 0)
(setq scroll-step 1
      scroll-margin 1
      scroll-conservatively 100000)

And use pager.el.

;; Pager
(require 'pager-default-keybindings)

That's what I want :) Enjoy!

seagle0128
  • 131
  • 2
  • 3
3

Note that this isn't mentioned anywhere here, but I found for larger files I ended up running into some irritating lag, where scrolling would get behind font updating.

This relies on redrawing not being so slow that the system gets too far behind in its updating.

See this question for details.


These settings worked well for me:

(setq
 scroll-conservatively 1000                     ;; only 'jump' when moving this far
 scroll-margin 4                                ;; scroll N lines to screen edge
 scroll-step 1                                  ;; keyboard scroll one line at a time
 mouse-wheel-scroll-amount '(6 ((shift) . 1))   ;; mouse scroll N lines
 mouse-wheel-progressive-speed nil              ;; don't accelerate scrolling

 redisplay-dont-pause t                         ;; don't pause display on input

 ;; Always redraw immediately when scrolling,
 ;; more responsive and doesn't hang!
 fast-but-imprecise-scrolling nil
 jit-lock-defer-time 0
 )
Community
  • 1
  • 1
ideasman42
  • 42,413
  • 44
  • 197
  • 320
2

This behavior is not encountered on all platforms. For those platforms that pose problem, I would recommend to use this setting :

(setq scroll-conservatively 0)

It places the cursor on the middle of the screen each time you scroll to another page.

Jérôme Radix
  • 10,285
  • 4
  • 34
  • 40
  • 2
    That's the default setting on all platforms, I think. Problem is it doesn't even really scroll, screen just jumps half a page up when you get to the bottom. Maybe people who have used emacs for years accept this as the way things work, but it's different from virtually every other editor. Other text editors (and other applications, like browsers and word processors) scroll. To have the buffer window suddenly shift up half a screen is unsettling and non-user-friendly. – Herbert Sitz Sep 03 '10 at 16:57
1

I'm very happy with Adam Spiers' smooth-scrolling, as rpdillon suggested. I thought it deserves an answer of its own.

Thomas Kappler
  • 3,795
  • 1
  • 22
  • 21
  • I've tried smooth-scrolling.el, too, as I said in original post. It works no better for me than scroll-conservatively solution. – Herbert Sitz Sep 03 '10 at 16:58
0

I can scroll by only one line with M-Up / M-Down by adding this to my .emacs :

(global-set-key (kbd "M-<down>") (lambda () (interactive) (scroll-up   1)))
(global-set-key (kbd "M-<up>")   (lambda () (interactive) (scroll-down 1)))
ychaouche
  • 4,922
  • 2
  • 44
  • 52