1

How can I use my trackpad to scroll left and right, when in horizontal-scroll-bar-mode?

I am running GNU Emacs 25.3.3 (x86_64-apple-darwin13.4.0, Carbon Version 157 AppKit 1265.21) of 2017-09-28.

This is the MacPorts edition by Mitsuharu Yamamoto.

Thanks!

UPDATE:

Following the advice of @lawlist (below) I needed to first find out what actions my trackpad left/right swipe are currently bound to (if any). So I entered C-h k and then scrolled right with my track pad. Here is the message that came back:

<wheel-right> at that spot runs the command mac-mwheel-scroll (found
in global-map), which is an interactive compiled Lisp function in
‘term/mac-win.el’.

It is bound to <C-wheel-right>, <S-wheel-right>, <wheel-right>,
<C-wheel-left>, <S-wheel-left>, <wheel-left>, <C-wheel-down>,
<S-wheel-down>, <wheel-down>, <C-wheel-up>, <S-wheel-up>, <wheel-up>.

(mac-mwheel-scroll EVENT)

Scroll up or down according to the EVENT.
Mostly like ‘mwheel-scroll’, but try scrolling by pixel unit if
EVENT has no modifier keys, ‘mac-mouse-wheel-smooth-scroll’ is
non-nil, and the input device supports it.
Adam
  • 1,857
  • 11
  • 32
  • Is there a certain swiping gesture that you make where Emacs does something else, or instead generates a message stating that your gesture is undefined? If it is defined to something, then you can first type `C-h k` and then the gesture to see what function it is assigned to. If it is not defined, you can look in the `*Messages*` buffer and see what key it is and then subsequently you can assign any function to that gesture. Since there are so many gestures and different versions of OSX, it may help if you be really specific regarding what OS version and answers to the above tests. – lawlist Jun 23 '18 at 15:48
  • Thanks @lawlist. I am running 10.11.6 (El Capitan). I opened the *Messages* buffer and tried swiping left/right with my magic mouse. But it no messages are generated. Up/down works fine though... – Adam Jun 23 '18 at 18:08
  • Based upon your comment above, we now know that your mouse gestures are not generating any messages as keys being *undefined*. However, we still do not know what Emacs functions are presently assigned to those keys (mouse gestures) given your particular setup. The reason we do not know this, is because you have apparently not yet typed `C-h k` and made your mouse gestures (in each direction) and then updated your question with the results of those tests. – lawlist Jun 23 '18 at 23:10
  • Ah, sorry. Missed the first part of your comment. Please see above, thanks. – Adam Jun 24 '18 at 05:58
  • It looks like you are using a modified version of Emacs by Mitsuharu Yamamoto: https://bitbucket.org/mituharu/emacs-mac/overview -- `mac-mwheel-scroll` is defined in `mac-win.el`, which is a library that is not included in the vanilla version of Emacs. It may behoove you to add that Emacs version information to your question so that someone who has that version, or is willing to install that version, can help you further. – lawlist Jun 24 '18 at 06:51

2 Answers2

1

I searched github, the following code works

(defun my/scroll-right() (interactive) (scroll-right 2))
(defun my/scroll-left() (interactive) (scroll-left 2))
(global-set-key (kbd "<left-margin> <triple-wheel-left>")  'my/scroll-left)
(global-set-key (kbd "<left-margin> <triple-wheel-right>")  'my/scroll-right)

(global-set-key (kbd "<right-margin> <triple-wheel-right>") 'my/scroll-left)
(global-set-key (kbd "<right-margin> <triple-wheel-left>") 'my/scroll-right)


(global-set-key (kbd "<wheel-left>") 'my/scroll-right)
(global-set-key (kbd "<double-wheel-left>") 'my/scroll-right)
(global-set-key (kbd "<triple-wheel-left>") 'my/scroll-right)
(global-set-key (kbd "<wheel-right>") 'my/scroll-left)
(global-set-key (kbd "<double-wheel-right>") 'my/scroll-left)
(global-set-key (kbd "<triple-wheel-right>") 'my/scroll-left)

author: https://github.com/jamesrtemple/emacs/blob/7e203ef35a6006cf501f976e0ce0d14019f9d680/lisp/conf.keybindings.el

Frank Wu
  • 51
  • 2
0

Thanks @frank-wu for that answer, it worked. However, it always scrolls the currently active window, while I'd like to scroll the one under the mouse pointer, so I modified the first two functions:

(defun my/scroll-right() (interactive)
       (save-selected-window
         (select-window (window-at (cadr (mouse-position))
                                   (cddr (mouse-position))
                                   (car (mouse-position))))
         (scroll-right 2)))
(defun my/scroll-left() (interactive)
       (save-selected-window
         (select-window (window-at (cadr (mouse-position))
                                   (cddr (mouse-position))
                                   (car (mouse-position))))
         (scroll-left 2)))

(defun my/scroll-left() (interactive) (scroll-left 2))
(global-set-key (kbd "<left-margin> <triple-wheel-left>")  'my/scroll-left)
(global-set-key (kbd "<left-margin> <triple-wheel-right>")  'my/scroll-right)

(global-set-key (kbd "<right-margin> <triple-wheel-right>") 'my/scroll-left)
(global-set-key (kbd "<right-margin> <triple-wheel-left>") 'my/scroll-right)
njlarsson
  • 111
  • 4