Subject: bug#50067: Context menus

From: Juri Linkov <[email-masked]>
Date: Sat, 28 Aug 2021 21:50:15 +0300

> Hi.  I'm one of the users of Emacs-jp.  Tak introduced us to this
> thread and it got me interested, I'm sending this Email.  This
> mail thread is huge and I haven't read all of it, so I'm sorry if
> I misread the context.
>
> I've created a context menu for ispell (referencing `context-menu-ffap`).
> You may find some inspiration from this.
>
>     (defun context-menu-ispell (menu)
>       "Ispell at point menu."
>       (when t ;; (ffap-guess-file-name-at-point)
>         (define-key menu [ispell-separator] menu-bar-separator)
>         (define-key menu [ispell-at-mouse]
>           '(menu-item "Check spelling of word" ispell-word
>                       :help "Check spelling of word under or before the cursor.")))
>       menu)

Thanks for the suggestion.  I think such menus should be added to their
respective packages.  context-menu-ispell could be added to ispell.el
(when flyspell is unavailable).

Then dictionary.el could provide own context menu too:

diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index f33cbaf112..7a84f9978f 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -1368,5 +1368,27 @@ global-dictionary-tooltip-mode
                     (if on #'dictionary-tooltip-track-mouse #'ignore))
     on))
 
+(defun dictionary-search-word-at-mouse (event)
+  (interactive "e")
+  (let ((word (save-window-excursion
+		(save-excursion
+		  (mouse-set-point event)
+		  (current-word)))))
+    (selected-window)
+    (dictionary-search word)))
+
+(defun context-menu-dictionary (menu)
+  "Dictionary word at point menu."
+  (save-excursion
+    (mouse-set-point last-input-event)
+    (when (thing-at-point 'word)
+      (define-key menu [dictionary-separator] menu-bar-separator)
+      (define-key menu [dictionary-search-word-at-mouse]
+        '(menu-item "Dictionary Search" dictionary-search-word-at-mouse
+                    :help "Search the word at mouse click in dictionary"))))
+  menu)
+
+(add-hook 'context-menu-functions 'context-menu-dictionary 15)
+
 (provide 'dictionary)
 ;;; dictionary.el ends here