The Hyperpessimist

The grandest failure.

Disabling Mouse in Spacemacs

Those of you following me on Twitter already heard that I’ve been trying out Spacemacs lately — a GNU Emacs configuration to emulate Vim. The reason behind it is, I want to check out whether writing Clojure in Emacs works better than in Vim (which is pretty decent, actually).

Now there is one thing that bothered me the most, coming from console vim: every time I switch focus to Emacs by clicking in a random place on the window, the cursor moves to this place. Incredibly inconvenient, since I don’t want to move my cursor accidentally. Since I never use the mouse for anything in my editor anyway, I decided to disable it.

Turn’s out, it is not that easy, since it is not a global key binding, but one that is local to the Evil mode. Frustrating to figure out, so here’s how to do it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
(defun dotspacemacs/config ()
  ;; your configuration stuff here

  ;; dummy
  (defun silence ()
    (interactive))

  ;; don't jump the cursor around in the window on clicking
  (define-key evil-motion-state-map [down-mouse-1] 'silence)
  ;; also avoid any '<mouse-1> is undefined' when setting to 'undefined
  (define-key evil-motion-state-map [mouse-1] 'silence)

  ;; more of your config, maybe
)

Hope that helps and watch this space for more adventures/rants in Space(macs)!