emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master bd91708: * lisp/thingatpt.el (thing-at-mouse): New function (bug#


From: Juri Linkov
Subject: master bd91708: * lisp/thingatpt.el (thing-at-mouse): New function (bug#50256).
Date: Sun, 12 Sep 2021 13:32:26 -0400 (EDT)

branch: master
commit bd917088e69e71e77c15069f0751096141ca3f1a
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/thingatpt.el (thing-at-mouse): New function (bug#50256).
    
    * 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                   |  2 ++
 lisp/net/dictionary.el     | 22 +++++++++++++++++++++-
 lisp/textmodes/flyspell.el |  2 +-
 lisp/thingatpt.el          |  9 +++++++++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ca269aa..8385128 100644
--- 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
 
 ---
diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index 0f42af0..5a6f3b5 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -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
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 975f540..423f377 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -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
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index ab17748..8782c9e 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -152,6 +152,15 @@ positions of the thing found."
                    (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.
 THING should be a symbol specifying a type of syntactic entity.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]