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.

  • 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 9 '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 9 '16 at 22:52
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.

  • thanks, your solution definitely works and should been marked as solution – Xi Xiao Oct 5 '16 at 11:21
  • This answer worked great! – JuanCaicedo Dec 9 '16 at 13:58
  • Actually, I've unaccepted this because for me it works for a while after I either start spacemacs or resync my dotfile. After a while the change disappears though. Any idea why that could be? – JuanCaicedo Dec 9 '16 at 20:46
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".

  • 2
    I submitted the incomplete documentation of with-eval-after-load as an emacs bug. – Harald Hanche-Olsen Apr 10 '16 at 6: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
1

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

  • Unfortunately this didn't work for me :/ – JuanCaicedo Dec 9 '16 at 13:56
  • 1
    Perhaps you could provide more specific information, or maybe even file a quick issue on github? – sanityinc Dec 10 '16 at 22:01
0

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)
)
  • I'm using 0.300 without those problem :/ The other thing I ended up doing is (dolist (mouse '("<down-mouse-1>" "<mouse-1>")) (global-unset-key (kbd mouse))). Hopefully that helps! – JuanCaicedo May 14 '18 at 18:14
  • github.com/purcell/disable-mouse seems like a better solution – Compro Prasad Jul 18 '18 at 6:51

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.