Discussion:
Change to allow xrefs to be shown in the current window
(too old to reply)
Per Weijnitz
2018-05-10 23:49:32 UTC
Permalink
Hi! I added another possible value for xref-show-xrefs-function in
xref.el. In master, it can be set to value xref--show-xref-buffer,
which shows the result list from xref-find-references in another
window. The proposed, new value xref--show-xref-same-window shows the
result list in the current window. I added it because I prefer that
presentation over the other.

Would this patch be of interest to you?


Proposed Changelog entry:
* lisp/progmodes/xref.el: changed xref--show-xref-buffer and added
xref--show-xref and xref--show-xref-same-window.


I made the following diff from master, updated May 11 2018:

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 9a437b6..28bbc5b 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -762,25 +762,36 @@ xref--analyze
#'equal))

(defun xref--show-xref-buffer (xrefs alist)
+ "Show xref results in another window.
+Use with xref-show-xrefs-function."
+ (xref--show-xref xrefs alist nil))
+
+(defun xref--show-xref-current-window (xrefs alist)
+ "Show xref results in the current window.
+Use with xref-show-xrefs-function."
+ (xref--show-xref xrefs alist 'current-window))
+
+(defun xref--show-xref (xrefs alist mode)
(let ((xref-alist (xref--analyze xrefs)))
(with-current-buffer (get-buffer-create xref-buffer-name)
(setq buffer-undo-list nil)
(let ((inhibit-read-only t)
(buffer-undo-list t))
(erase-buffer)
(xref--insert-xrefs xref-alist)
(xref--xref-buffer-mode)
- (pop-to-buffer (current-buffer))
+ (cond ((eq mode 'current-window) (switch-to-buffer (current-buffer)))
+ (t (pop-to-buffer (current-buffer))))
(goto-char (point-min))
(setq xref--original-window (assoc-default 'window alist)
xref--original-window-intent (assoc-default
'display-action alist))
(current-buffer)))))

^L
;; 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.


Best regards /Per

Loading...