I have a ThinkPad with a trackpad, and emacs exits from C-s and also from interactive replace using M-%, whenever I brush my hand over the trackpad while touch-typing - which happens far too often. With my previous laptop I worked around this problem by disabling the trackpad completely, but I can't do that here because the trackpad is an important fallback for when my erratic Bluetooth mouse stops working. How can I make C-s and M-% ignore touchpad scrolling?

UPDATE: It's not caused by mouse movement as I originally thought, but by mouse scrolling, or something even more obscure. From C-h l I can see that emacs is interpreting my brushing the touchpad as mouse-4/5/6/7, so I've tried

(global-set-key (kbd "<mouse-4>") (lambda () (interactive)))
(global-set-key (kbd "<mouse-5>") (lambda () (interactive)))
(global-set-key (kbd "<mouse-6>") (lambda () (interactive)))
(global-set-key (kbd "<mouse-7>") (lambda () (interactive)))

but that doesn't fix the problem, it just stops emacs complaining.

  • 1
    Depending on your OS, you may be able to disable the trackpad only while typing; that is, when a key is pressed, the trackpad is disabled for a second (or so) after the key is pressed. – zck Mar 14 '16 at 18:20
  • That doesn't really help because I might stop to think for an indeterminate period of time. – Robin Green Mar 14 '16 at 18:26
  • 1
    Is the problem that the mouse moves while Emacs is getting input from the minibuffer, or that the laptop touchpad is clicking? Moving the mouse shouldn't cause this, but clicking (say, in a buffer) would cause something like this. – zck Mar 14 '16 at 18:39
  • Regarding M-%, is the problem when entering the search query and replacement text, or only at the “query replacing …” prompt? Are you running Emacs in a terminal or a GUI, which version, and on which OS? Type C-s, then move the mouse just enough to exit incremental search, and type C-h l; this shows the last input that Emacs received from the OS. Copy-paste the part after C-s. – Gilles 'SO- stop being evil' Mar 14 '16 at 19:52
  • Clearly people who are trying to help are guessing, right and left. OP: Please edit your question to make it clearer. Describe the symptoms more completely, preferably using a step-by-step description, saying what you see and what you expected to see instead. And mention your platform, Emacs version, etc. And either start from emacs -Q (no init file) or mention whatever libraries etc. are needed to reproduce the problem. – Drew Mar 14 '16 at 20:22

How can I make C-s and M-% ignore mouse movement?

For just disabling accidental clicks, try this:

(dolist (k '([mouse-1] [down-mouse-1] [drag-mouse-1] [double-mouse-1] [triple-mouse-1]))
(global-unset-key k))

I worked around it by disabling touchpad scrolling in the operating system settings (disabling it just within emacs didn't help). But this isn't ideal.


It turns out that customising search-exit-option to nil will make isearch much more resilient to random inputs from the mouse.

The behaviour of isearch is now a bit odd - I can happily navigate around in emacs with the cursor keys and still be in isearch - but it does what I wanted!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.