diff options
| author | Dmitry Gutov | 2019-05-25 00:11:41 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2019-05-25 00:43:44 +0300 |
| commit | e309818ecee190727d85c6f3f878c99445d06cfe (patch) | |
| tree | b2625500ab11f51f12d6c1781a8678f06c60412f | |
| parent | 35f305652c9eacb2e75fa6bcd784247d4de939fb (diff) | |
| download | emacs-e309818ecee190727d85c6f3f878c99445d06cfe.tar.gz emacs-e309818ecee190727d85c6f3f878c99445d06cfe.zip | |
Support reverting in xref-find-definitions results as well
* lisp/progmodes/xref.el (xref--show-xref-buffer): Expect the
first argument to always be a function (bug#35702). Handle a
FETCHED-XREFS entry in ALIST.
(xref--show-defs-buffer): Update accordingly.
(xref--create-fetcher): Extract from xref--find-xrefs.
(xref--find-definitions): Use it.
| -rw-r--r-- | lisp/progmodes/xref.el | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 6a4906a2325..45d2fc2fe24 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -782,7 +782,11 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 782 | #'equal)) | 782 | #'equal)) |
| 783 | 783 | ||
| 784 | (defun xref--show-xref-buffer (fetcher alist) | 784 | (defun xref--show-xref-buffer (fetcher alist) |
| 785 | (let* ((xrefs (if (functionp fetcher) (funcall fetcher) fetcher)) | 785 | (cl-assert (functionp fetcher)) |
| 786 | (let* ((xrefs | ||
| 787 | (or | ||
| 788 | (assoc-default 'fetched-xrefs alist) | ||
| 789 | (funcall fetcher))) | ||
| 786 | (xref-alist (xref--analyze xrefs))) | 790 | (xref-alist (xref--analyze xrefs))) |
| 787 | (with-current-buffer (get-buffer-create xref-buffer-name) | 791 | (with-current-buffer (get-buffer-create xref-buffer-name) |
| 788 | (setq buffer-undo-list nil) | 792 | (setq buffer-undo-list nil) |
| @@ -795,8 +799,7 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 795 | (goto-char (point-min)) | 799 | (goto-char (point-min)) |
| 796 | (setq xref--original-window (assoc-default 'window alist) | 800 | (setq xref--original-window (assoc-default 'window alist) |
| 797 | xref--original-window-intent (assoc-default 'display-action alist)) | 801 | xref--original-window-intent (assoc-default 'display-action alist)) |
| 798 | (when (functionp fetcher) | 802 | (setq xref--fetcher fetcher) |
| 799 | (setq xref--fetcher fetcher)) | ||
| 800 | (current-buffer))))) | 803 | (current-buffer))))) |
| 801 | 804 | ||
| 802 | (defun xref--revert-xref-buffer () | 805 | (defun xref--revert-xref-buffer () |
| @@ -817,13 +820,16 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 817 | 'face 'error)))) | 820 | 'face 'error)))) |
| 818 | (goto-char (point-min))))) | 821 | (goto-char (point-min))))) |
| 819 | 822 | ||
| 820 | (defun xref--show-defs-buffer (xrefs alist) | 823 | (defun xref--show-defs-buffer (fetcher alist) |
| 821 | (cond | 824 | (let ((xrefs (funcall fetcher))) |
| 822 | ((not (cdr xrefs)) | 825 | (cond |
| 823 | (xref--pop-to-location (car xrefs) | 826 | ((not (cdr xrefs)) |
| 824 | (assoc-default 'display-action alist))) | 827 | (xref--pop-to-location (car xrefs) |
| 825 | (t | 828 | (assoc-default 'display-action alist))) |
| 826 | (xref--show-xref-buffer xrefs alist)))) | 829 | (t |
| 830 | (xref--show-xref-buffer fetcher | ||
| 831 | (cons (cons 'fetched-xrefs xrefs) | ||
| 832 | alist)))))) | ||
| 827 | 833 | ||
| 828 | 834 | ||
| 829 | (defvar xref-show-xrefs-function 'xref--show-xref-buffer | 835 | (defvar xref-show-xrefs-function 'xref--show-xref-buffer |
| @@ -885,28 +891,29 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." | |||
| 885 | ;;; Commands | 891 | ;;; Commands |
| 886 | 892 | ||
| 887 | (defun xref--find-xrefs (input kind arg display-action) | 893 | (defun xref--find-xrefs (input kind arg display-action) |
| 894 | (xref--show-xrefs | ||
| 895 | (xref--create-fetcher input kind arg) | ||
| 896 | display-action)) | ||
| 897 | |||
| 898 | (defun xref--find-definitions (id display-action) | ||
| 899 | (xref--show-defs | ||
| 900 | (xref--create-fetcher id 'definitions id) | ||
| 901 | display-action)) | ||
| 902 | |||
| 903 | (defun xref--create-fetcher (input kind arg) | ||
| 888 | (let* ((orig-buffer (current-buffer)) | 904 | (let* ((orig-buffer (current-buffer)) |
| 889 | (orig-position (point)) | 905 | (orig-position (point)) |
| 890 | (backend (xref-find-backend)) | 906 | (backend (xref-find-backend)) |
| 891 | (method (intern (format "xref-backend-%s" kind))) | 907 | (method (intern (format "xref-backend-%s" kind)))) |
| 892 | (fetcher (lambda () | 908 | (lambda () |
| 893 | (save-excursion | 909 | (save-excursion |
| 894 | (when (buffer-live-p orig-buffer) | 910 | (when (buffer-live-p orig-buffer) |
| 895 | (set-buffer orig-buffer) | 911 | (set-buffer orig-buffer) |
| 896 | (ignore-errors (goto-char orig-position))) | 912 | (ignore-errors (goto-char orig-position))) |
| 897 | (let ((xrefs (funcall method backend arg))) | 913 | (let ((xrefs (funcall method backend arg))) |
| 898 | (unless xrefs | 914 | (unless xrefs |
| 899 | (xref--not-found-error kind input)) | 915 | (xref--not-found-error kind input)) |
| 900 | xrefs))))) | 916 | xrefs))))) |
| 901 | (xref--show-xrefs fetcher display-action))) | ||
| 902 | |||
| 903 | (defun xref--find-definitions (id display-action) | ||
| 904 | (let ((xrefs (funcall #'xref-backend-definitions | ||
| 905 | (xref-find-backend) | ||
| 906 | id))) | ||
| 907 | (unless xrefs | ||
| 908 | (xref--not-found-error 'definitions id)) | ||
| 909 | (xref--show-defs xrefs display-action))) | ||
| 910 | 917 | ||
| 911 | (defun xref--not-found-error (kind input) | 918 | (defun xref--not-found-error (kind input) |
| 912 | (user-error "No %s found for: %s" (symbol-name kind) input)) | 919 | (user-error "No %s found for: %s" (symbol-name kind) input)) |