unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
Cc: 50067@debbugs.gnu.org
Subject: bug#50067: Context menus
Date: Thu, 26 Aug 2021 09:13:10 +0300	[thread overview]
Message-ID: <87a6l47mxr.fsf@linkov.net> (raw)
In-Reply-To: <87v93ts9jd.fsf@mail.linkov.net> (Juri Linkov's message of "Wed,  25 Aug 2021 20:45:20 +0300")

[-- Attachment #1: Type: text/plain, Size: 1303 bytes --]

>> * 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: flyspell-context-menu.patch --]
[-- Type: text/x-diff, Size: 6613 bytes --]

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

  reply	other threads:[~2021-08-26  6:13 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <74BC00E9-2509-47DA-9428-1523FF7F3B33@acm.org>
2021-08-18 16:42 ` bug#50067: Context menus Juri Linkov
2021-08-18 17:46   ` Mattias Engdegård
2021-08-18 17:53     ` Eli Zaretskii
2021-08-19 14:22     ` Mattias Engdegård
2021-08-20  7:31       ` Juri Linkov
2021-08-20 17:06         ` Mattias Engdegård
2021-08-20 23:31           ` Dmitry Gutov
2021-08-21  4:43         ` Tak Kunihiro
2021-08-21  6:33           ` Tak Kunihiro
2021-08-22  8:28           ` Juri Linkov
2021-08-23  3:11             ` Tak Kunihiro
2021-08-23  7:24               ` Juri Linkov
2021-08-24 10:12                 ` Tak Kunihiro
2021-08-24 17:23                   ` Juri Linkov
2021-08-24 23:43                     ` Tak Kunihiro
2021-08-25 17:45                       ` Juri Linkov
2021-08-26  6:13                         ` Juri Linkov [this message]
2021-08-27  6:24                           ` Juri Linkov
2021-08-28  5:18                             ` Tak Kunihiro
2021-08-31 17:37                 ` Juri Linkov
2021-08-31 17:43               ` Juri Linkov
2021-08-31 18:58                 ` Eli Zaretskii
2021-09-01  7:12                   ` Juri Linkov
2021-08-18 17:46   ` Eli Zaretskii
2021-08-18 18:01     ` Mattias Engdegård
2021-08-18 18:11       ` Eli Zaretskii
2021-08-18 18:06     ` Juri Linkov
2021-08-18 18:12       ` Eli Zaretskii
2021-08-18 18:39         ` Eli Zaretskii
2021-08-19  1:31           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-19  6:44             ` Eli Zaretskii
2021-08-18 18:40         ` Juri Linkov
2021-08-18 18:59           ` Eli Zaretskii
2021-08-19  7:12             ` Juri Linkov
2021-08-19  7:57               ` Eli Zaretskii
2021-08-20  7:29                 ` Juri Linkov
2021-08-20 10:29                   ` Mattias Engdegård
2021-08-20 10:53                     ` Eli Zaretskii
2021-08-20 11:32                       ` Mattias Engdegård
2021-08-20 16:50                         ` Juri Linkov
2021-08-20 17:11                           ` Mattias Engdegård
2021-08-20 11:32                   ` Eli Zaretskii
2021-08-20 16:36                     ` Juri Linkov
2021-08-20 17:59                       ` Eli Zaretskii
2021-08-20 19:29                         ` Mattias Engdegård
2021-08-21  9:42                           ` Alan Third
2021-08-21 10:57                             ` Mattias Engdegård
2021-08-21 11:17                               ` Eli Zaretskii
2021-08-21 11:45                                 ` Mattias Engdegård
2021-08-21 12:16                                   ` Eli Zaretskii
2021-08-22 19:11                                     ` Dmitry Gutov
2021-08-22 19:22                                       ` Eli Zaretskii
2021-08-22 19:54                                         ` Dmitry Gutov
2021-08-23  2:21                                           ` Eli Zaretskii
2021-08-23 11:18                                             ` Dmitry Gutov
2021-08-23 11:40                                               ` Eli Zaretskii
2021-08-23 16:02                                                 ` Juri Linkov
2021-08-24 17:59                                                   ` Dmitry Gutov
2021-08-25 14:15                                                     ` Dmitry Gutov
2021-08-25 15:59                                                       ` Eli Zaretskii
2021-08-26 13:01                                                     ` Eli Zaretskii
2021-08-26 21:05                                                       ` Dmitry Gutov
2021-08-26 21:07                                                         ` Dmitry Gutov
2021-08-27  6:13                                                           ` Juri Linkov
2021-08-27  6:26                                                         ` Eli Zaretskii
2021-08-30  2:45                                                           ` Dmitry Gutov
2021-08-30 11:57                                                             ` Eli Zaretskii
2021-08-31  7:05                                                               ` Juri Linkov
2021-08-31 12:24                                                                 ` Dmitry Gutov
2021-08-31 16:56                                                                   ` Juri Linkov
2021-08-31 20:23                                                                     ` Dmitry Gutov
2021-09-01  7:08                                                                       ` Juri Linkov
2021-09-01 19:03                                                                         ` Dmitry Gutov
2021-09-05  0:55                                                                         ` Dmitry Gutov
2021-09-05  8:37                                                                           ` Juri Linkov
2021-09-05 19:25                                                                             ` Dmitry Gutov
2021-08-22  8:46                         ` Juri Linkov
2021-08-15  8:48 Juri Linkov
2021-08-15 11:56 ` Lars Ingebrigtsen
2021-08-15 16:12   ` Juri Linkov
2021-08-16 11:31     ` Lars Ingebrigtsen
2021-08-17  8:12       ` Juri Linkov
2021-08-18  4:38         ` Tak Kunihiro
2021-08-18  7:47           ` Juri Linkov
2021-08-28  9:08 ` Naoya Yamashita
2021-08-28 18:50   ` Juri Linkov
2021-09-27 15:30 ` Juri Linkov
2021-09-27 15:50   ` Lars Ingebrigtsen
2021-09-28 18:49     ` Juri Linkov
2021-09-29  7:00       ` Juri Linkov
2021-09-27 18:41   ` Eli Zaretskii
2021-09-28 18:54     ` Juri Linkov
2021-09-28 19:31       ` Eli Zaretskii
2021-09-27 15:33 ` Juri Linkov
2021-10-20 16:59 ` Juri Linkov
2021-11-08 20:05   ` Juri Linkov
2021-11-18 18:38     ` Juri Linkov
2021-11-25  7:50       ` Juri Linkov
2021-11-25  8:38         ` Eli Zaretskii
2021-11-25 19:28           ` Juri Linkov
2021-11-30 18:12             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6l47mxr.fsf@linkov.net \
    --to=juri@linkov.net \
    --cc=50067@debbugs.gnu.org \
    --cc=tkk@misasa.okayama-u.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).