Make window choice in xref commands configurable

Previously, it wasn't easy to tell xref.el commands like
xref-find-definitions or xref-find-definitions-other-window how to
choose a window for the *xref* buffer or how to find windows for
displaying the results after choosing a candidate.  This patch makes
that task easier, but keeps the current behaviour intact.

Co-authored-by: João Távora <joaotavora@gmail.com>

* lisp/progmodes/xref.el (xref--show-pos-in-buf): Simplify.
This commit is contained in:
Juri Linkov 2019-02-04 22:52:25 +00:00 committed by João Távora
parent 6ed9d0057d
commit 94b320849e

View file

@ -474,27 +474,17 @@ and finally return the window."
(or (eq xref--original-window-intent 'frame)
pop-up-frames))
(action
(cond ((memq
xref--original-window-intent
'(window frame))
(cond ((eq xref--original-window-intent 'frame)
t)
((eq xref--original-window-intent 'window)
'(display-buffer-same-window))
((and
(window-live-p xref--original-window)
(or (not (window-dedicated-p xref--original-window))
(eq (window-buffer xref--original-window) buf)))
`(,(lambda (buf _alist)
(set-window-buffer xref--original-window buf)
xref--original-window))))))
(with-selected-window
(with-selected-window
;; Just before `display-buffer', place ourselves in the
;; original window to suggest preserving it. Of course, if
;; user has deleted the original window, all bets are off,
;; just use the selected one.
(or (and (window-live-p xref--original-window)
xref--original-window)
(selected-window))
(display-buffer buf action))
`((display-buffer-in-previous-window)
(previous-window . ,xref--original-window))))))
(with-selected-window (display-buffer buf action)
(xref--goto-char pos)
(run-hooks 'xref-after-jump-hook)
(let ((buf (current-buffer)))