5

When I click with the middle mouse button that usually inserts the primary selection at the point where I clicked. However, the same button opens flyspell's context menu when I click on a misspelled word. The problem is that when I use the context menu to, e.g., save a word to the dictionary, this also inserts the primary selection after the flyspell action is finished. I thought that this problem may be due to a mess-up in my configuration but I can also reproduce this with emacs -Q. How can I fix this?

Steps to reproduce:

  1. Start emacs -Q.

  2. Insert the following sentence (in the scratch buffer):

    Here is a sentence with a mistaake.

  3. M-x flyspell-buffer, the word mistaake is highlighted.

  4. Double click on sentence to select it.

  5. Click middle mouse button (mouse-2) on mistaake, choose the correct spelling mistake from the context memu.

Result: mistaake is replaced with missentecetake.

I found some really old bug reports that sound related (going back to 2005) but no working solution.

Drew
  • 75,699
  • 9
  • 109
  • 225
tmalsburg
  • 2,540
  • 1
  • 14
  • 29

1 Answers1

7

Sounds like you are being bitten by the fact that one command is bound to mouse-2, another command is bound to down-mouse-2, and the two commands do not play well together.

Do C-h k and then click mouse-2 on text (e.g. mistaake). The help should tell you what mouse-2 and down-mouse-2 are bound to.

If I'm right in my guess, you can try doing one of these things:

  • Move your yank command to a different key sequence (but I would keep it as a yank).
  • Move the flyspell command to another key sequence.
  • Swap the two bindings (for click down and up). Worth a try, at least.
  • Put a renamed copy of the flyspell command on the up action and modify the copy so that it ignores the down event. IOW, make the flyspell command play well with a non-menu command bound to the down event.

Personally, I would count this as a (key-binding) bug in flyspell -- clicking mouse-2 should usually yank in Emacs, in one form or another. The flyspell developers should be able to make flyspell cohabit with down or up clicks that yank text. (But I imagine that the flyspell people won't see it that way.)

(Disclosure: I am not a flyspell user. With luck, someone who uses it will provide a simple solution and explanation.)


Looking at the flyspell.el code, I see that it does this:

(if (featurep 'xemacs)
    (define-key map [button2] #'flyspell-correct-word)
  (define-key map [down-mouse-2] #'flyspell-correct-word)
  (define-key map [mouse-2] 'undefined))

Are you using XEmacs? If not, try changing undefined to ignore, here. Dunno whether that will make a difference, but it might be worth a try.

Actually, try it the other way around:

(if (featurep 'xemacs)
    (define-key map [button2] #'flyspell-correct-word)
  (define-key map [mouse-2] #'flyspell-correct-word) ; REVERSED the bindings
  (define-key map [down-mouse-2] 'ignore))

That is usually what I do. For example, in isearch+.el I do this:

(define-key isearch-mode-map [mouse-2]      'isearch-mouse-2)
(define-key isearch-mode-map [down-mouse-2] 'ignore)
Drew
  • 75,699
  • 9
  • 109
  • 225
  • Setting `mouse-2` to `ignore` didn't help but reversing the bindings did. Thank you very much. This bug was annoying me for way too long. – tmalsburg Oct 02 '14 at 00:03
  • Glad it helped. You might consider contacting the flyspell maintainers (which I guess is Emacs Dev, so `M-x report-emacs-bug`, which is not only for bugs). They might want to change something, or they might have some useful advice for users in this regard. – Drew Oct 02 '14 at 00:10