[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 49a363c 1/4: Separate xref-find-definitions' behavi
From: |
Dmitry Gutov |
Subject: |
[Emacs-diffs] master 49a363c 1/4: Separate xref-find-definitions' behavior from other commands |
Date: |
Thu, 23 May 2019 21:54:29 -0400 (EDT) |
branch: master
commit 49a363c875c66f3d937a7d33e1a1451227a1887d
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
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.
---
lisp/dired-aux.el | 2 +-
lisp/progmodes/xref.el | 41 +++++++++++++++++++++++++----------------
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index aae5212..f699b79 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 bf999ae..3951b9f 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)