emacs-diffs
[Top][All Lists]
Advanced

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

master 6993d45 4/6: Add "Find References" to context menu (bug#50067)


From: Mattias Engdegård
Subject: master 6993d45 4/6: Add "Find References" to context menu (bug#50067)
Date: Sat, 21 Aug 2021 06:56:44 -0400 (EDT)

branch: master
commit 6993d45e519ad7504adcf5a00842114ce8b25110
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Add "Find References" to context menu (bug#50067)
    
    The new entry appears next to "Find Definition" and like it only
    appears when the context menu was invoked on an identifier.
    
    * lisp/progmodes/prog-mode.el (prog-context-menu): New menu entry.
    * lisp/progmodes/xref.el (xref-find-references-at-mouse): New
    function, analogous to `xref-find-definitions-at-mouse`.
---
 lisp/progmodes/prog-mode.el | 12 ++++++++++--
 lisp/progmodes/xref.el      | 14 ++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 4f000d6..3babbdc 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -52,13 +52,21 @@
                            (mouse-set-point last-input-event)
                            (xref-backend-identifier-at-point
                             (xref-find-backend)))
-                :help "Find definition of function or variable")
+                :help "Find definition of identifier")
     'prog-separator)
+  (define-key-after menu [xref-find-ref]
+    '(menu-item "Find References" xref-find-references-at-mouse
+                :visible (save-excursion
+                           (mouse-set-point last-input-event)
+                           (xref-backend-identifier-at-point
+                            (xref-find-backend)))
+                :help "Find references to identifier")
+    'xref-find-def)
   (define-key-after menu [xref-pop]
     '(menu-item "Back Definition" xref-pop-marker-stack
                 :visible (not (xref-marker-stack-empty-p))
                 :help "Back to the position of the last search")
-    'xref-find-def)
+    'xref-find-ref)
   menu)
 
 (defvar prog-mode-map
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 32fe6b6..a8bab47 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1355,6 +1355,20 @@ This command is intended to be bound to a mouse event."
         (xref-find-definitions identifier)
       (user-error "No identifier here"))))
 
+;;;###autoload
+(defun xref-find-references-at-mouse (event)
+  "Find references to the identifier at or around mouse click.
+This command is intended to be bound to a mouse event."
+  (interactive "e")
+  (let ((identifier
+         (save-excursion
+           (mouse-set-point event)
+           (xref-backend-identifier-at-point (xref-find-backend)))))
+    (if identifier
+        (let ((xref-prompt-for-identifier nil))
+          (xref-find-references identifier))
+      (user-error "No identifier here"))))
+
 (declare-function apropos-parse-pattern "apropos" (pattern))
 
 ;;;###autoload



reply via email to

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