:version "28.1"
:package-version '(xref . "1.0.4"))
+(defcustom xref-auto-jump-to-first-definition nil
+ "If t, `xref-find-definitions' always jumps to the first result.
+`show' means to show the first result's location, but keep the
+focus on the Xref buffer's window.
+`move' means to only move point to the first result."
+ :type '(choice (const t :tag "Jump")
+ (const show :tag "Show")
+ (const move :tag "Move point only"))
+ :version "28.1"
+ :package-version '(xref . "1.2.0"))
+
+(defcustom xref-auto-jump-to-first-xref nil
+ "If t, xref commands always jump to the first result.
+`show' means to show the first result's location, but keep the
+focus on the Xref buffer's window.
+`move' means to only move point to the first result."
+ :type '(choice (const t :tag "Jump")
+ (const show :tag "Show")
+ (const move :tag "Move point only"))
+ :version "28.1"
+ :package-version '(xref . "1.2.0"))
+
(defvar xref--marker-ring (make-ring xref-marker-ring-length)
"Ring of markers to implement the marker stack.")
(error-message-string err)
'face 'error)))))))
+(defun xref--auto-jump-first (buf value)
+ (when value
+ (select-window (get-buffer-window buf))
+ (goto-char (point-min)))
+ (cond
+ ((eq value t)
+ (xref-next-line-no-show)
+ (xref-goto-xref))
+ ((eq value 'show)
+ (xref-next-line))
+ ((eq value 'move)
+ (forward-line 1))))
+
(defun xref-show-definitions-buffer (fetcher alist)
"Show the definitions list in a regular window.
When only one definition found, jump to it right away instead."
- (let ((xrefs (funcall fetcher)))
+ (let ((xrefs (funcall fetcher))
+ buf)
(cond
((not (cdr xrefs))
(xref-pop-to-location (car xrefs)
(assoc-default 'display-action alist)))
(t
- (xref--show-xref-buffer fetcher
- (cons (cons 'fetched-xrefs xrefs)
- alist))))))
+ (setq buf
+ (xref--show-xref-buffer fetcher
+ (cons (cons 'fetched-xrefs xrefs)
+ alist)))
+ (xref--auto-jump-first buf (assoc-default 'auto-jump alist))
+ buf))))
(define-obsolete-function-alias
'xref--show-defs-buffer #'xref-show-definitions-buffer "28.1")
;; XXX: Make percentage customizable maybe?
(max-height (/ (window-height) 2))
(size-fun (lambda (window)
- (fit-window-to-buffer window max-height))))
+ (fit-window-to-buffer window max-height)))
+ buf)
(cond
((not (cdr xrefs))
(xref-pop-to-location (car xrefs)
(pop-to-buffer (current-buffer)
`(display-buffer-in-direction . ((direction . below)
(window-height . ,size-fun))))
- (current-buffer))))))
+ (setq buf (current-buffer)))
+ (xref--auto-jump-first buf (assoc-default 'auto-jump alist))
+ buf))))
(define-obsolete-function-alias 'xref--show-defs-buffer-at-bottom
#'xref-show-definitions-buffer-at-bottom "28.1")
(setq xrefs 'called-already)))))))
(funcall xref-show-xrefs-function fetcher
`((window . ,(selected-window))
- (display-action . ,display-action))))
+ (display-action . ,display-action)
+ (auto-jump . ,xref-auto-jump-to-first-xref))))
(defun xref--show-defs (xrefs display-action)
(xref--push-markers)
(funcall xref-show-definitions-function xrefs
`((window . ,(selected-window))
- (display-action . ,display-action))))
+ (display-action . ,display-action)
+ (auto-jump . ,xref-auto-jump-to-first-definition))))
(defun xref--push-markers ()
(unless (region-active-p) (push-mark nil t))