]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/thingatpt.el (thing-at-mouse): New function (bug#50256).
authorJuri Linkov <juri@linkov.net>
Sun, 12 Sep 2021 17:32:02 +0000 (20:32 +0300)
committerJuri Linkov <juri@linkov.net>
Sun, 12 Sep 2021 17:32:02 +0000 (20:32 +0300)
* lisp/net/dictionary.el: Add 'context-menu-dictionary' to
'context-menu-functions'.
(dictionary-search-word-at-mouse): New function.
(context-menu-dictionary): New function that uses 'thing-at-mouse'.
(dictionary-mouse-popup-matching-words): Remove stray 'selected-window'.

* lisp/textmodes/flyspell.el (flyspell-context-menu): Add '_click' arg.

etc/NEWS
lisp/net/dictionary.el
lisp/textmodes/flyspell.el
lisp/thingatpt.el

index ca269aabaa466d34f805f1c3706a39fd79180489..8385128f698476a6ea2b0d0b65c4450d3e4dbfd4 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2503,6 +2503,8 @@ This allows mode-specific alterations to how 'thing-at-point' works.
 'symbol-at-point') will narrow to the current field (if any) before
 trying to identify the thing at point.
 
+*** New function 'thing-at-mouse'.
+
 ** image-dired
 
 ---
index 0f42af0911b158f8057f24ee682074d0eb0fbd79..5a6f3b555d232d78818c828ce2e41dccf88580e7 100644 (file)
@@ -1211,7 +1211,6 @@ allows editing it."
                (save-excursion
                  (mouse-set-point event)
                  (current-word)))))
-    (selected-window)
     (dictionary-popup-matching-words word)))
 
 ;;;###autoload
@@ -1368,5 +1367,26 @@ any buffer where (dictionary-tooltip-mode 1) has been called."
                     (if on #'dictionary-tooltip-track-mouse #'ignore))
     on))
 
+;;; Context menu support
+
+(defun dictionary-search-word-at-mouse (event)
+  (interactive "e")
+  (let ((word (save-window-excursion
+               (save-excursion
+                 (mouse-set-point event)
+                 (current-word)))))
+    (dictionary-search word)))
+
+(defun context-menu-dictionary (menu click)
+  "Dictionary context menu."
+  (when (thing-at-mouse click '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
index 975f540936a429c9a10c1ddc9b34dc102bc6d482..423f37762cf807f73caf3c8760ae1ee924448219 100644 (file)
@@ -470,7 +470,7 @@ See also `flyspell-duplicate-distance'."
 
 (defvar flyspell-overlay nil)
 
-(defun flyspell-context-menu (_menu)
+(defun flyspell-context-menu (_menu _click)
   "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
index ab17748df5b96d3b0e5652a1f4687885f486e384..8782c9eeb565be7c9b1a5b86ed4cb54d69df0664 100644 (file)
@@ -151,6 +151,15 @@ positions of the thing found."
                (if (and (<= real-beg orig) (<= orig end) (< real-beg end))
                    (cons real-beg end))))))))))
 
+;;;###autoload
+(defun thing-at-mouse (event thing &optional no-properties)
+  "Return the THING at mouse click.
+Like `thing-at-point', but tries to use the event
+where the mouse button is clicked to find a thing nearby."
+  (save-excursion
+    (mouse-set-point event)
+    (thing-at-point thing no-properties)))
+
 ;;;###autoload
 (defun thing-at-point (thing &optional no-properties)
   "Return the THING at point.