Skip to content

Commit 1cadab7

Browse files
committed
Make xref-find-definitions more customizable
* lisp/progmodes/xref.el (xref--show-defs-buffer): New function. Move a bit of logic from xref--show-defs to make it more customizable. (xref--push-markers): New function, extracted from xref--show-xrefs. (xref-show-definitions-function): Set to the new function.
1 parent 49a363c commit 1cadab7

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lisp/progmodes/xref.el

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -792,34 +792,40 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
792792
xref--original-window-intent (assoc-default 'display-action alist))
793793
(current-buffer)))))
794794

795+
(defun xref--show-defs-buffer (xrefs alist)
796+
(cond
797+
((not (cdr xrefs))
798+
(xref--pop-to-location (car xrefs)
799+
(assoc-default 'display-action alist)))
800+
(t
801+
(xref--show-xref-buffer xrefs alist))))
802+
795803

796804
(defvar xref-show-xrefs-function 'xref--show-xref-buffer
797805
"Function to display a list of search results.")
798806

799-
(defvar xref-show-definitions-function 'xref--show-xref-buffer
807+
(defvar xref-show-definitions-function 'xref--show-defs-buffer
800808
"Function to display a list of definitions.")
801809

802810
(defvar xref--read-identifier-history nil)
803811

804812
(defvar xref--read-pattern-history nil)
805813

806814
(defun xref--show-xrefs (xrefs display-action)
807-
(unless (region-active-p) (push-mark nil t))
808-
(xref-push-marker-stack)
815+
(xref--push-markers)
809816
(funcall xref-show-xrefs-function xrefs
810817
`((window . ,(selected-window))
811818
(display-action . ,display-action))))
812819

813820
(defun xref--show-defs (xrefs display-action)
821+
(xref--push-markers)
822+
(funcall xref-show-definitions-function xrefs
823+
`((window . ,(selected-window))
824+
(display-action . ,display-action))))
825+
826+
(defun xref--push-markers ()
814827
(unless (region-active-p) (push-mark nil t))
815-
(xref-push-marker-stack)
816-
(cond
817-
((not (cdr xrefs))
818-
(xref--pop-to-location (car xrefs) display-action))
819-
(t
820-
(funcall xref-show-definitions-function xrefs
821-
`((window . ,(selected-window))
822-
(display-action . ,display-action))))))
828+
(xref-push-marker-stack))
823829

824830
(defun xref--prompt-p (command)
825831
(or (eq xref-prompt-for-identifier t)

0 commit comments

Comments
 (0)