0

I work on a laptop most of the time and it happens somewhat often that while inserting some text (in evil mode) I will accidentally hit the touchpad with my thumb, changing the cursor position and causing the next few words to be inserted into some unrelated paragraph. The somewhat annoying thing is that undo is usually of no help here, because the last saved undo state is whenever I entered insert mode and I might have written several sentences since then that I don't want to lose. I'd rather not completely disable use of the mouse, so I'm hoping to implement one of the following acceptable fixes:

  • Don't allow mouse clicks to change position while in evil insert mode, only in normal mode (this sounds the simplest).
  • Update the undo state whenever I change cursor position with the mouse, if there is a callback for that.

Are either of these possible?

  • The function undo-boundary looks like it might be helpful if you call it when setting point with the mouse .... gnu.org/software/emacs/manual/html_node/elisp/Undo.html My recollection is that there is more than one mouse-set-point related functions, so it may depend upon the mode. You can type C-h k and see what your mouse click is bound to. – lawlist Mar 25 at 0:06
  • If you run a terminal specific build of emacs (emacs-nox) the mouse clicks will never have any effect (except to shift focus to your window). That's not what you asked for - but this is only a comment, not an answer. – Craig Hicks Mar 25 at 0:16
  • AFAIK the undo behavior you describe only kicks in after you exit insert mode: while in insert mode, undo should be able to undo just the last few chars inserted rather than undo all the way to the state where you entered insert mode. – Stefan Mar 26 at 16:20
0

Two potential answers:

1) This is not exactly an emacs fix for your question, and may or may not apply in your situation. The exact steps will depend on your os and desktop environment:

If you're using linux with one of many desktop environments (gnome3, MATE, openbox, etc.) there is a setting under "mouse" settings (sometimes on the "touchpad" tab of the mouse-settings window) that says something to the effect of "disable touchpad while typing" (see also "synaptic"). This will not help if you pause typing and then touch the touchpad.

2) emacs solution: Stolen directly from: https://www.reddit.com/r/emacs/comments/a799um/how_to_disable_mouse_in_emacs/

This involves setting the keybinding for the mouse to do nothing (nil):

(use-package evil
  :ensure t
  :diminish evil
  :init (evil-mode 1)
  (setq evil-insert-state-cursor '((bar . 1) "white")
  evil-visual-state-cursor '(box "dark orange")
  evil-normal-state-cursor '(box "white"))
  :bind (:map
   evil-insert-state-map
   ([S-left]     . windmove-left)
   ([S-right]    . windmove-right)
   ([S-up]     . windmove-up)
   ([S-down]    . windmove-down)
   ("<down-mouse-1>" . nil)
   ("<mouse-1>" . nil)
   ("<down-mouse-3>" . nil)
   ("<mouse-3>" . nil)
   ("SPC" . nil)
   :map
   evil-normal-state-map
   (";" . evil-ex)
   (":"   .       evil-repeat-find-char)
   ("<down-mouse-1>" . nil)
   ("<mouse-1>" . nil)
   ("<down-mouse-3>" . nil)
   ("<mouse-3>" . nil)
   ("SPC" . nil)
   :map    evil-motion-state-map
   ([S-left]     . windmove-left)
   ([S-right]    . windmove-right)
   ([S-up]     . windmove-up)
   ([S-down]    . windmove-down)
   ("<down-mouse-1>" . nil)
   ("<mouse-1>" . nil)
   ("<down-mouse-3>" . nil)
   ("<mouse-3>" . nil)
   ("SPC" . nil)
   ))

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.