6

I'd like to completely disable my mouse in Spacemacs. Following the advice in this answer, I set up the following in my .spacemacs file as

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration. You are free to put any user code."
  ;;(add-hook 'after-change-major-mode-hook 'fci-mode)
  (add-hook 'change-major-mode-after-body-hook 'fci-mode)
  (neotree-show)
  (with-eval-after-load FILE
    ;; 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)
    )
  )

I see this in the Help menu that FILE

FILE is normally a feature name, but it can also be a file name, in case that file does not provide any feature.

But I'm not sure what value I should use here.

JuanCaicedo
  • 679
  • 1
  • 6
  • 11
  • 1
    You need to find out what file defines `evil-motion-state-map`. You can probably find out with the help of `C-h v`. At the end of that file, there will most likely be a line `(provide 'FEATURE)`. That feature name is what you should use. (Why am I not making this an answer? Because I am not really answering the question; I am only pointing the way to the answer.) – Harald Hanche-Olsen Apr 09 '16 at 22:19
  • 1
    Teach a man to fish ;) I found `evil-motion-state-map is a variable defined in 'evil-states.el'.` However if I change `FILE` to `evil-states.el` and reload my dotfile, I can still use click with the mouse – JuanCaicedo Apr 09 '16 at 22:52

4 Answers4

4

According to your example you don't need the function with-eval-after-load.
In Spacemacs it works simple like that:

(defun dotspacemacs/user-config ()
  "…"
  ;; …
  ;; dummy silence definition
  (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))

To get it working for me I had to add the definition of silence before like Marek Kubica did.

tasmo
  • 86
  • 3
2

You might want to try out my recently-published disable-mouse package.

sanityinc
  • 2,871
  • 13
  • 17
2

I used an approach that was almost the same as @tasmo provided above

(define-key evil-motion-state-map [down-mouse-1] 'ignore)
(define-key evil-motion-state-map [mouse-1] 'ignore)

But for the current Spacemacs 0.300 (at develop branch), it stops working if I switch buffer or open a new file unless reloading the dot file. There is another way to completely disable all mouse interactions -- turn off the xterm-mouse-mode:

(defun dotspacemacs/user-config ()
    (xterm-mouse-mode 0)
)
Chris.Q
  • 121
  • 4
1

The variable evil-motion-state-map turns out to be defined in "evil-state.el", as you have discovered. So you need to ensure that your code is run after that file is loaded.

Now with-eval-after-load is just a thin wrapper around eval-after-load. The latter documents the use of the FILE argument more carefully. If you read it, you will realize that using "evil-states" is more likely to succeed than using "evil-states.el". Even better, however, is to use 'evil-states (note the single quote). For, looking at the source, I notice the expected line (provide 'evil-states) at the bottom.

To expand a bit on this, it is likely that the file is going to be loaded via (require 'evil-states). This will in turn become a call to (load "evil-states") – note the lack of the .el extension. The code reponsible for loading will then look for code to run in the variable after-load-alist. It will look for entries specified with the file name as provided, namely "evil-states", and it will look for entries with the symbol evil-states, because the file executed (provide 'evil-states). But it will not look for "evil-states.el".

Harald Hanche-Olsen
  • 2,401
  • 12
  • 15
  • 2
    I submitted the incomplete documentation of `with-eval-after-load` as an [emacs bug](http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23258). – Harald Hanche-Olsen Apr 10 '16 at 06:46
  • Thanks for the awesome answer! However, if I try this, it doesn't work as I first load Spacemacs. The changes do apply if I resync my dotfile though. It also added a ton of time to my startup time? – JuanCaicedo Apr 10 '16 at 14:42
  • Well, since I don't use spacemacs myself, and don't know how it works, I can't help you there. Nor do I know what you mean by “resync my dotfile”. But this I do know: Under no reasonable circumstance will a `with-eval-after-load` whose body simply (re)defines two keys lead to a noticable startup time. The reason for that must be elsewhere. – Harald Hanche-Olsen Apr 10 '16 at 15:35