[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#50256: thing-at-mouse
From: |
Juri Linkov |
Subject: |
bug#50256: thing-at-mouse |
Date: |
Mon, 30 Aug 2021 10:20:05 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) |
> I'm not quite sure I understand how such a function would look like.
> `thing-at-point' has the signature
>
> (thing-at-point THING)
>
> Would the proposed new function have a signature
>
> (thing-at-mouse EVENT THING)
>
> ?
This looks like the right signature. Then the implementation
and an example of usage could look like this:
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index ab17748df5..536eef5406 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -151,6 +151,15 @@ bounds-of-thing-at-point
(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 reacts to the event
+where the mouse button is clicked."
+ (save-excursion
+ (mouse-set-point last-input-event)
+ (thing-at-point thing no-properties)))
+
;;;###autoload
(defun thing-at-point (thing &optional no-properties)
"Return the THING at point.
diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index f33cbaf112..c9b2bdeaf1 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -1368,5 +1367,14 @@ global-dictionary-tooltip-mode
(if on #'dictionary-tooltip-track-mouse #'ignore))
on))
+(defun context-menu-dictionary (menu)
+ "Dictionary context menu."
+ (when (thing-at-mouse last-input-event '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)
+
(provide 'dictionary)
;;; dictionary.el ends here