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. If you want this menu on
-@kbd{mouse-3} instead, customize the variable
-@code{flyspell-use-mouse-3-for-menu}. 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
+@kbd{mouse-3} instead, enable @code{context-menu-mode}. 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.
(defun context-menu-map ()
"Return composite menu map."
(let ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t))))
- (run-hook-wrapped 'context-menu-functions
- (lambda (fun)
- (setq menu (funcall fun menu))
- nil))
+ (let ((fun (mouse-posn-property (event-start last-input-event)
+ 'context-menu-function)))
+ (if (functionp fun)
+ (setq menu (funcall fun menu))
+ (run-hook-wrapped 'context-menu-functions
+ (lambda (fun)
+ (setq menu (funcall fun menu))
+ nil))))
+ ;; TODO: remove double separators
(when (functionp context-menu-filter-function)
(setq menu (funcall context-menu-filter-function menu)))
menu))
map)
"Minor mode keymap for Flyspell mode--for the whole buffer.")
-;; correct on mouse 3
-(defun flyspell--set-use-mouse-3-for-menu (var value)
- (set-default var value)
- (if value
- (progn (define-key flyspell-mouse-map [mouse-2] nil)
- (define-key flyspell-mouse-map [down-mouse-3] 'flyspell-correct-word))
- (define-key flyspell-mouse-map [mouse-2] 'flyspell-correct-word)
- (define-key flyspell-mouse-map [down-mouse-3] nil)))
-
-(defcustom flyspell-use-mouse-3-for-menu 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-use-mouse-3-for-menu
- :version "28.1")
-
;; dash character machinery
(defvar-local flyspell-consider-dash-as-word-delimiter-flag nil
"Non-nil means that the `-' char is considered as a word delimiter.")
(defvar flyspell-overlay nil)
+(defun flyspell-context-menu (_menu)
+ "Context menu for `context-menu-mode'."
+ ;; TODO: refactor `flyspell-correct-word' and related functions to return
+ ;; a keymap menu where every menu item is bound to a lambda that calls
+ ;; `flyspell-do-correct' with an argument that is a correct word.
+ 'flyspell-correct-word)
+
;;*---------------------------------------------------------------------*/
;;* flyspell-mode ... */
;;*---------------------------------------------------------------------*/
:group 'flyspell
(if flyspell-mode
(condition-case err
- (progn
- (when flyspell-use-mouse-3-for-menu
- (flyspell--set-use-mouse-3-for-menu 'flyspell-use-mouse-3-for-menu t))
- (flyspell-mode-on (called-interactively-p 'interactive)))
+ (flyspell-mode-on (called-interactively-p 'interactive))
(error (message "Error enabling Flyspell mode:\n%s" (cdr err))
(flyspell-mode -1)))
(flyspell-mode-off)))
show-msg)
(let* ((binding (where-is-internal 'flyspell-auto-correct-word
nil 'non-ascii))
- (mouse-button (if flyspell-use-mouse-3-for-menu
- "Mouse-3" "Mouse-2")))
+ (mouse-button (if context-menu-mode "Mouse-3" "Mouse-2")))
(message (format-message
"Welcome to Flyspell. Use %s to correct words."
(if binding
(overlay-put overlay 'mouse-face mouse-face)
(overlay-put overlay 'flyspell-overlay t)
(overlay-put overlay 'evaporate t)
- (overlay-put overlay 'help-echo (concat (if flyspell-use-mouse-3-for-menu
- "mouse-3"
- "mouse-2") ": correct word at point"))
- ;; If misspelled text has a 'keymap' property, let that remain in
- ;; effect for the bindings that flyspell-mouse-map doesn't override.
- (set-keymap-parent flyspell-mouse-map (get-char-property beg 'keymap))
- (overlay-put overlay 'keymap flyspell-mouse-map)
+ (overlay-put overlay 'help-echo
+ (concat (if context-menu-mode "mouse-3" "mouse-2")
+ ": correct word at point"))
+ (if context-menu-mode
+ (overlay-put overlay 'context-menu-function 'flyspell-context-menu)
+ ;; If misspelled text has a 'keymap' property, let that remain in
+ ;; effect for the bindings that flyspell-mouse-map doesn't override.
+ (set-keymap-parent flyspell-mouse-map (get-char-property beg 'keymap))
+ (overlay-put overlay 'keymap flyspell-mouse-map))
(when (eq face 'flyspell-incorrect)
(and (stringp flyspell-before-incorrect-word-string)
(overlay-put overlay 'before-string