Skip to content

Commit 49a363c

Browse files
committed
Separate xref-find-definitions' behavior from other commands
* lisp/progmodes/xref.el (xref-show-definitions-function): New variable. (xref--show-defs): Split off from xref--show-xrefs. (xref--find-definitions): Use it. (xref--not-found-error): New function. (xref--show-xrefs): Simplify. Show the list buffer even when there is just one item in the list. Remove the last argument. * lisp/dired-aux.el (dired-do-find-regexp): Update accordingly.
1 parent 6135654 commit 49a363c

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

lisp/dired-aux.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@ REGEXP should use constructs supported by your local `grep' command."
29142914
files)))
29152915
(unless xrefs
29162916
(user-error "No matches for: %s" regexp))
2917-
(xref--show-xrefs xrefs nil t)))
2917+
(xref--show-xrefs xrefs nil)))
29182918

29192919
;;;###autoload
29202920
(defun dired-do-find-regexp-and-replace (from to)

lisp/progmodes/xref.el

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -793,30 +793,31 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
793793
(current-buffer)))))
794794

795795

796-
;; This part of the UI seems fairly uncontroversial: it reads the
797-
;; identifier and deals with the single definition case.
798-
;; (FIXME: do we really want this case to be handled like that in
799-
;; "find references" and "find regexp searches"?)
800-
;;
801-
;; The controversial multiple definitions case is handed off to
802-
;; xref-show-xrefs-function.
803-
804796
(defvar xref-show-xrefs-function 'xref--show-xref-buffer
805-
"Function to display a list of xrefs.")
797+
"Function to display a list of search results.")
798+
799+
(defvar xref-show-definitions-function 'xref--show-xref-buffer
800+
"Function to display a list of definitions.")
806801

807802
(defvar xref--read-identifier-history nil)
808803

809804
(defvar xref--read-pattern-history nil)
810805

811-
(defun xref--show-xrefs (xrefs display-action &optional always-show-list)
806+
(defun xref--show-xrefs (xrefs display-action)
807+
(unless (region-active-p) (push-mark nil t))
808+
(xref-push-marker-stack)
809+
(funcall xref-show-xrefs-function xrefs
810+
`((window . ,(selected-window))
811+
(display-action . ,display-action))))
812+
813+
(defun xref--show-defs (xrefs display-action)
812814
(unless (region-active-p) (push-mark nil t))
815+
(xref-push-marker-stack)
813816
(cond
814-
((and (not (cdr xrefs)) (not always-show-list))
815-
(xref-push-marker-stack)
817+
((not (cdr xrefs))
816818
(xref--pop-to-location (car xrefs) display-action))
817819
(t
818-
(xref-push-marker-stack)
819-
(funcall xref-show-xrefs-function xrefs
820+
(funcall xref-show-definitions-function xrefs
820821
`((window . ,(selected-window))
821822
(display-action . ,display-action))))))
822823

@@ -857,11 +858,19 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
857858
(xref-find-backend)
858859
arg)))
859860
(unless xrefs
860-
(user-error "No %s found for: %s" (symbol-name kind) input))
861+
(xref--not-found-error kind input))
861862
(xref--show-xrefs xrefs display-action)))
862863

863864
(defun xref--find-definitions (id display-action)
864-
(xref--find-xrefs id 'definitions id display-action))
865+
(let ((xrefs (funcall #'xref-backend-definitions
866+
(xref-find-backend)
867+
id)))
868+
(unless xrefs
869+
(xref--not-found-error 'definitions id))
870+
(xref--show-defs xrefs display-action)))
871+
872+
(defun xref--not-found-error (kind input)
873+
(user-error "No %s found for: %s" (symbol-name kind) input))
865874

866875
;;;###autoload
867876
(defun xref-find-definitions (identifier)

0 commit comments

Comments
 (0)