]> git.eshelyaron.com Git - emacs.git/commitdiff
Add "Find References" to context menu (bug#50067)
authorMattias Engdegård <mattiase@acm.org>
Fri, 20 Aug 2021 16:19:43 +0000 (18:19 +0200)
committerMattias Engdegård <mattiase@acm.org>
Sat, 21 Aug 2021 10:41:54 +0000 (12:41 +0200)
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
lisp/progmodes/xref.el

index 4f000d6613af42c29a4f7aafab32846bf48b07f1..3babbdc6b42166ae77b2f3842d99db01e9c46a13 100644 (file)
                            (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
index 32fe6b612b3971480ed198951566eeb6e3d3e8f6..a8bab47ea250d01ad18416d8d1c5b578f9e039c7 100644 (file)
@@ -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