From 3c1ceeff2c8c80914c590f461c6b876c3c5882af Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 15 Aug 2020 02:53:35 +0200 Subject: [PATCH] Add new option flyspell-correct-on-mouse-3 * lisp/textmodes/flyspell.el (flyspell-correct-on-mouse-3): New option to bind 'flyspell-correct-word' to 'mouse-3'. (flyspell--set-correct-on-mouse-3): New function to update option. (flyspell-mode): Update 'flyspell-mouse-map' if above option is set. * doc/emacs/fixit.texi (Spelling): Mention the new option. * etc/NEWS: Announce the new option. --- doc/emacs/fixit.texi | 9 +++++---- etc/NEWS | 9 +++++++++ lisp/textmodes/flyspell.el | 20 +++++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/doc/emacs/fixit.texi b/doc/emacs/fixit.texi index 5046146dda..b6f65848d1 100644 --- a/doc/emacs/fixit.texi +++ b/doc/emacs/fixit.texi @@ -445,12 +445,13 @@ Spelling @findex flyspell-correct-word-before-point When Flyspell mode highlights a word as misspelled, you can click on it with @kbd{mouse-2} (@code{flyspell-correct-word}) to display a menu -of possible corrections and actions. In addition, @kbd{C-.} or +of possible corrections and actions. If you want this menu on +@kbd{mouse-3} instead, customize the variable +@code{flyspell-correct-on-mouse-3}. In addition, @kbd{C-.} or @kbd{@key{ESC}-@key{TAB}} (@code{flyspell-auto-correct-word}) will propose various successive corrections for the word at point, and -@w{@kbd{C-c $}} (@code{flyspell-correct-word-before-point}) will pop up a -menu of possible corrections. Of course, you can always correct the -misspelled word by editing it manually in any way you like. +@w{@kbd{C-c $}} (@code{flyspell-correct-word-before-point}) will pop +up a misspelled word by editing it manually in any way you like. @findex flyspell-prog-mode Flyspell Prog mode works just like ordinary Flyspell mode, except diff --git a/etc/NEWS b/etc/NEWS index 8cd845a7b9..e6c1c6224a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -839,6 +839,15 @@ height of lines or width of chars. *** New user option 'xwidget-webkit-bookmark-jump-new-session'. When non-nil, use a new xwidget webkit session after bookmark jump. Otherwise, it will use 'xwidget-webkit-last-session'. +** Flyspell mode + ++++ +*** Corrections and actions menu optionally bound to mouse-3. +When Flyspell mode highlights a word as misspelled, you can click on +it to display a menu of possible corrections and actions. You can now +easily bind this menu to mouse-2 (usually the right mouse button) +instead of mouse-3 (the default) by customizing the new option +'flyspell-correct-on-mouse-3'. * New Modes and Packages in Emacs 28.1 diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index b6ebb9f098..c594e02e98 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -445,6 +445,21 @@ flyspell-mode-map map) "Minor mode keymap for Flyspell mode--for the whole buffer.") +;; correct on mouse 3 +(defun flyspell--set-correct-on-mouse-3 (var value) + (set-default var value) + (if value + (progn (define-key flyspell-mouse-map [mouse-2] nil) + (define-key flyspell-mouse-map [mouse-3] 'flyspell-correct-word)) + (define-key flyspell-mouse-map [mouse-2] 'flyspell-correct-word) + (define-key flyspell-mouse-map [mouse-3] nil))) + +(defcustom flyspell-correct-on-mouse-3 nil + "Non-nil means to bind `mouse-3' to `flyspell-correct-word'. +If this is set, also unbind `mouse-2'." + :type 'boolean + :set 'flyspell--set-correct-on-mouse-3) + ;; dash character machinery (defvar flyspell-consider-dash-as-word-delimiter-flag nil "Non-nil means that the `-' char is considered as a word delimiter.") @@ -514,7 +529,10 @@ flyspell-mode :group 'flyspell (if flyspell-mode (condition-case err - (flyspell-mode-on) + (progn + (when flyspell-correct-on-mouse-3 + (flyspell--set-correct-on-mouse-3 'flyspell-correct-on-mouse-3 t)) + (flyspell-mode-on)) (error (message "Error enabling Flyspell mode:\n%s" (cdr err)) (flyspell-mode -1))) (flyspell-mode-off))) -- 2.28.0