From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#50067: Context menus Date: Thu, 26 Aug 2021 09:13:10 +0300 Message-ID: <87a6l47mxr.fsf@linkov.net> References: <87wnociu41.fsf@mail.linkov.net> <20210824.191259.1858282353329289005.tkk@misasa.okayama-u.ac.jp> <877dgalpsr.fsf@mail.linkov.net> <20210825.084329.2103284747365062473.tkk@misasa.okayama-u.ac.jp> <87v93ts9jd.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36255"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: 50067@debbugs.gnu.org To: Tak Kunihiro Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 26 08:19:19 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJ8jN-0009Fq-Ps for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Aug 2021 08:19:17 +0200 Original-Received: from localhost ([::1]:37510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJ8jM-0005SO-KV for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Aug 2021 02:19:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJ8j8-0005R1-73 for bug-gnu-emacs@gnu.org; Thu, 26 Aug 2021 02:19:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJ8j7-000613-Qq for bug-gnu-emacs@gnu.org; Thu, 26 Aug 2021 02:19:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mJ8j7-0008K1-NI for bug-gnu-emacs@gnu.org; Thu, 26 Aug 2021 02:19:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Aug 2021 06:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50067 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 50067-submit@debbugs.gnu.org id=B50067.162995871631955 (code B ref 50067); Thu, 26 Aug 2021 06:19:01 +0000 Original-Received: (at 50067) by debbugs.gnu.org; 26 Aug 2021 06:18:36 +0000 Original-Received: from localhost ([127.0.0.1]:48187 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJ8ih-0008JL-Te for submit@debbugs.gnu.org; Thu, 26 Aug 2021 02:18:36 -0400 Original-Received: from relay10.mail.gandi.net ([217.70.178.230]:58509) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJ8if-0008J6-IB for 50067@debbugs.gnu.org; Thu, 26 Aug 2021 02:18:34 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 4C08224000A; Thu, 26 Aug 2021 06:18:20 +0000 (UTC) In-Reply-To: <87v93ts9jd.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 25 Aug 2021 20:45:20 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:212684 Archived-At: --=-=-= Content-Type: text/plain >> * flyspell menu >> >> It is handy to show 'flyspell-correct-word when click on typo word. >> However, menu is embedded inside of pre existing >> 'flyspell-correct-word and it is hard to collect menu. Since >> popup-menu interface can accept both menu and function with `e', it's >> good to utilize 'flyspell-correct-word. >> >> How about something like below to interrupt evaluation of >> context-menu-functions in the middle when one of >> context-menu-functions returns symbol instead of menu? > > Thanks, adapting flyspell to use the context menu is our next priority. > But it seems interrupting evaluation is too hackish solution, and it still > uses x-popup-menu. Would it be possible for flyspell to put its context > function to the end of context-menu-functions, and then replace all > previously added menus with own menu that contains word corrections? Here is the first step that adds support for overlay-local context-menu, and removes the recently added 'flyspell-use-mouse-3-for-menu'. But 'flyspell-context-menu' still returns 'flyspell-correct-word'. I invite you or anyone else to refactor 'flyspell-correct-word' and related functions to return a keymap menu where every menu item is bound to a function that calls flyspell-do-correct with an argument that is a correct word. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=flyspell-context-menu.patch diff --git a/doc/emacs/fixit.texi b/doc/emacs/fixit.texi index b558ebc3fd..85cdbff5fa 100644 --- a/doc/emacs/fixit.texi +++ b/doc/emacs/fixit.texi @@ -462,10 +462,9 @@ Spelling 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 04e482364a..a6d9b3a8b8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2889,8 +2893,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 d137419e02..f52fb3f6ba 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -307,10 +307,15 @@ context-menu-filter-function (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 836d889a1c..c05be9655f 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -442,22 +442,6 @@ flyspell-mode-map 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,10 @@ flyspell-duplicate (defvar flyspell-overlay nil) +(defun flyspell-context-menu (_menu) + "Context menu for `context-menu-mode'." + 'flyspell-correct-word) + ;;*---------------------------------------------------------------------*/ ;;* flyspell-mode ... */ ;;*---------------------------------------------------------------------*/ @@ -537,10 +525,7 @@ 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))) @@ -656,8 +641,7 @@ flyspell-mode-on 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 +1804,15 @@ make-flyspell-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 --=-=-=--