2

I already use middle mouse to paste/yank. However flyspell seems to hijack this, making it impossible to paste in the vicinity of a correctable word.

With the help of this question I have discovered that I can add the correct-word functionality to the more sane right-mouse button with

(eval-after-load "flyspell"
  '(progn
     (define-key flyspell-mouse-map [down-mouse-3] #'flyspell-correct-word)
     (define-key flyspell-mouse-map [mouse-3] #'undefined)))

however this doesn't change the middle mouse button behaviour.

How do I clear flyspell's default binding of the middle mouse so I can always use middle mouse to paste? It would also be appreciated if the relevant lisp could be explained. Although I managed to copy and paste the above to good effect, it's inner workings are a mystery to me.

  • 2
    Just a guess, by maybe bind [mouse-2] and [down-mouse-2] to nil in flyspell-mouse-map? – Dan Jun 22 '15 at 23:22
  • @Dan That's the answer. mouse-2 is middle mouse button. To confirm, hit C-h c <middle mouse button click> – nanny Jun 23 '15 at 14:38
1

You can extend your current code to bind [mouse-2] and [down-mouse-2] to nil in flyspell-mouse-map:

(eval-after-load "flyspell"
  '(progn
     (define-key flyspell-mouse-map [down-mouse-3] #'flyspell-correct-word)
     (define-key flyspell-mouse-map [mouse-3] #'undefined)
     (define-key flyspell-mouse-map [down-mouse-2] nil)
     (define-key flyspell-mouse-map [mouse-2] nil)))

Thanks to @nanny for testing it out.

What the code is doing is:

  • Telling emacs that you want to make some modifications only after it loads flyspell (that's the eval-after-load part).
  • The progn tells emacs that you're going to tell it to do a number of things.
  • Each of the define-key lines tells emacs that you're going to change something in the flyspell-mouse-map.
  • Setting a binding to nil tells emacs that it should do nothing in that map.

In other words: unbinding it in flyspell-mouse-map means that flyspell won't override your existing middle-mouse-as-yank setup.

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.