From: Dmitry Gutov Date: Wed, 22 May 2019 22:16:41 +0000 (+0300) Subject: Separate xref-find-definitions' behavior from other commands X-Git-Tag: emacs-27.0.90~2808 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=49a363c875c66f3d937a7d33e1a1451227a1887d;p=emacs.git 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. --- diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index aae521287e3..f699b79432b 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -2914,7 +2914,7 @@ REGEXP should use constructs supported by your local `grep' command." files))) (unless xrefs (user-error "No matches for: %s" regexp)) - (xref--show-xrefs xrefs nil t))) + (xref--show-xrefs xrefs nil))) ;;;###autoload (defun dired-do-find-regexp-and-replace (from to) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index bf999aeb0d1..3951b9f1dd2 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -793,30 +793,31 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." (current-buffer))))) -;; This part of the UI seems fairly uncontroversial: it reads the -;; identifier and deals with the single definition case. -;; (FIXME: do we really want this case to be handled like that in -;; "find references" and "find regexp searches"?) -;; -;; The controversial multiple definitions case is handed off to -;; xref-show-xrefs-function. - (defvar xref-show-xrefs-function 'xref--show-xref-buffer - "Function to display a list of xrefs.") + "Function to display a list of search results.") + +(defvar xref-show-definitions-function 'xref--show-xref-buffer + "Function to display a list of definitions.") (defvar xref--read-identifier-history nil) (defvar xref--read-pattern-history nil) -(defun xref--show-xrefs (xrefs display-action &optional always-show-list) +(defun xref--show-xrefs (xrefs display-action) + (unless (region-active-p) (push-mark nil t)) + (xref-push-marker-stack) + (funcall xref-show-xrefs-function xrefs + `((window . ,(selected-window)) + (display-action . ,display-action)))) + +(defun xref--show-defs (xrefs display-action) (unless (region-active-p) (push-mark nil t)) + (xref-push-marker-stack) (cond - ((and (not (cdr xrefs)) (not always-show-list)) - (xref-push-marker-stack) + ((not (cdr xrefs)) (xref--pop-to-location (car xrefs) display-action)) (t - (xref-push-marker-stack) - (funcall xref-show-xrefs-function xrefs + (funcall xref-show-definitions-function xrefs `((window . ,(selected-window)) (display-action . ,display-action)))))) @@ -857,11 +858,19 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." (xref-find-backend) arg))) (unless xrefs - (user-error "No %s found for: %s" (symbol-name kind) input)) + (xref--not-found-error kind input)) (xref--show-xrefs xrefs display-action))) (defun xref--find-definitions (id display-action) - (xref--find-xrefs id 'definitions id display-action)) + (let ((xrefs (funcall #'xref-backend-definitions + (xref-find-backend) + id))) + (unless xrefs + (xref--not-found-error 'definitions id)) + (xref--show-defs xrefs display-action))) + +(defun xref--not-found-error (kind input) + (user-error "No %s found for: %s" (symbol-name kind) input)) ;;;###autoload (defun xref-find-definitions (identifier)