How can I make Emacs scroll horizontally more smoothly?

I already use scroll-conservatively to smooth the vertical scrolling behaviour of Emacs. The horizontal scrolling is still pretty bad. The screen jumps by many columns, and I often lose track of where I am.

Is it possible to make this more smoothly?


Solution 1:

There appears no direct equivalent of scroll-conservatively for horizontal scrolling, but customizing hscroll-step (and perhaps also hscroll-margin) should produce something at least close to the same behavior. From the manual:

The variable hscroll-margin controls how close point can get to the window's left and right edges before automatic scrolling occurs. It is measured in columns. For example, if the value is 5, then moving point within 5 columns of an edge causes horizontal scrolling away from that edge.

The variable hscroll-step determines how many columns to scroll the window when point gets too close to the edge. Zero, the default value, means to center point horizontally within the window. A positive integer value specifies the number of columns to scroll by. A floating-point number specifies the fraction of the window's width to scroll by.

Solution 2:

This is off-topic to scrolling with my trackpad, but who knows:

(global-set-key (kbd "<mouse-7>") '(lambda ()
                                     (interactive)
                                     (scroll-left 4)))
(global-set-key (kbd "<mouse-6>") '(lambda ()
                                     (interactive)
                                     (scroll-right 4)))

If you want to discover what Emacs thinks your horizontal scroll "button" is, try C-h k (describe-key) and then use your horizontal scroll. So in my current setup, Emacs reports <mouse-7> and <mouse-6>. I started with (scroll-left 1), but replaced with 4 to get faster scrolling.