0

Ispell/Flyspell in Emacs uses the mouse middle button to activate the context menu for a misspelled word. The problem is that my laptop doesn't have a middle button. So is there any way to tell Ispell or emacs to use a different key/button (say Ctrl+Right click) for this purpose? (I use Auctex if that matters.)

  • 1
    This looks like a good question for emacs.stackexchange.com – Thérèse Nov 6 '14 at 14:49
  • @Thérèse Yes, but sites in beta are not targets for migration, so it would have to be re-asked. – Joseph Wright Nov 6 '14 at 15:16
  • What about this one: tex.stackexchange.com/questions/117204/… – Reza Nov 6 '14 at 15:43
  • Are you on GNU/Linux or another operating system? On GNU/Linux, middle button is equal to pressing right and left button together. – giordano Nov 6 '14 at 23:12
  • I just use M-$… I had no idea you could do this with a mouse :P – Sean Allred Nov 7 '14 at 0:13
3

The library flyspell.el is normally installed in the folder .../lisp/textmodes/flyspell.el. Within the flyspell.el library, there is a variable called flyspell-mouse-map. By default, it is written as follows:

(defvar flyspell-mouse-map
  (let ((map (make-sparse-keymap)))
    (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))
    map)
  "Keymap for Flyspell to put on erroneous words.")

The original poster seeks to implement flyspell-correct-word for a right mouse click with the control key depressed. So as not to generate an error message if the library flyspell.el has not yet been loaded, we use an eval-after-load statement. The alternative would be to use (require 'flyspell) before attempting to assign anything new to the variable flyspell-mouse-map. In other words, the variable must be in existence before we can start using it. The following code does not remove the prior key assignments, but merely adds two new ones to meet the requirements of the original poster:

(eval-after-load "flyspell" '(progn
  (define-key flyspell-mouse-map (kbd "<C-down-mouse-3>") #'flyspell-correct-word)
  (define-key flyspell-mouse-map (kbd "<C-mouse-3>") 'undefined) ))

There are a few variations that can be used to write the actual keyboard shortcut, but that is beyond the scope of this answer.

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.