From: Juri Linkov Date: Fri, 27 Aug 2021 06:24:07 +0000 (+0300) Subject: Replace flyspell-use-mouse-3-for-menu with context-menu-mode (bug#50067) X-Git-Tag: emacs-28.0.90~1292 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a573d6bd88afe9a60728f0b63a45f44a6ff98ce2;p=emacs.git Replace flyspell-use-mouse-3-for-menu with context-menu-mode (bug#50067) * doc/emacs/fixit.texi (Spelling): Replace mentions of flyspell-use-mouse-3-for-menu with context-menu-mode. * lisp/mouse.el (context-menu-map): Use the function from the text property context-menu-function at mouse click event. * lisp/textmodes/flyspell.el (flyspell--set-use-mouse-3-for-menu): Remove function. (flyspell-use-mouse-3-for-menu): Remove defcustom added recently in 28.1. (flyspell-context-menu): New function. (flyspell-mode): Don't call flyspell--set-use-mouse-3-for-menu. (flyspell-mode-on): Replace flyspell-use-mouse-3-for-menu with context-menu-mode. (make-flyspell-overlay): When context-menu-mode is non-nil, put overlay context-menu-function with flyspell-context-menu instead of using keymap flyspell-mouse-map. --- diff --git a/doc/emacs/fixit.texi b/doc/emacs/fixit.texi index b558ebc3fdc..85cdbff5fa5 100644 --- a/doc/emacs/fixit.texi +++ b/doc/emacs/fixit.texi @@ -462,10 +462,9 @@ use @code{flyspell-region} or @code{flyspell-buffer} for that. 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. diff --git a/etc/NEWS b/etc/NEWS index 78aca8cd549..246c89759f8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2875,8 +2875,7 @@ like 'flymake-mode-line-error-counter', 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 'down-mouse-3' (usually the right mouse button) -instead of 'mouse-2' (the default) by customizing the new user option -'flyspell-use-mouse-3-for-menu'. +instead of 'mouse-2' (the default) by enabling 'context-menu-mode'. --- *** The current dictionary is now displayed in the minor mode lighter. diff --git a/lisp/mouse.el b/lisp/mouse.el index 8b209638423..7d3ed9a0e40 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -307,10 +307,15 @@ the same menu with changes such as added new menu items." (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)) diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 836d889a1cf..975f540936a 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -442,22 +442,6 @@ like \"Some." 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.") @@ -486,6 +470,13 @@ See also `flyspell-duplicate-distance'." (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 ... */ ;;*---------------------------------------------------------------------*/ @@ -537,10 +528,7 @@ in your init file. :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))) @@ -656,8 +644,7 @@ are both non-nil." 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 @@ -1820,13 +1807,15 @@ for the overlay." (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