[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] emacs-26 e950f32 3/3: New xref-quit-and-goto-xref command
From: |
João Távora |
Subject: |
[Emacs-diffs] emacs-26 e950f32 3/3: New xref-quit-and-goto-xref command bound to TAB (bug#28814) |
Date: |
Fri, 3 Nov 2017 12:14:19 -0400 (EDT) |
branch: emacs-26
commit e950f329c0cfbe9bf3ba2c2e8ee788d6cdf4cebb
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
New xref-quit-and-goto-xref command bound to TAB (bug#28814)
This is like xref-goto-xref, but quits the *xref* window just before
the user jump to ref.
* lisp/progmodes/xref.el (xref--show-location): Handle 'quit
value for SELECT.
(xref-goto-xref): Take optional QUIT arg.
(xref-quit-and-goto-xref): New command.
(xref--xref-buffer-mode-map): Bind "Q" and "TAB" to
xref-quit-and-goto-xref.
* doc/emacs/maintaining.texi (Xref Commands): Describe new bindings in
*xref*.
* etc/NEWS (Xref): Describe new binding.
---
doc/emacs/maintaining.texi | 7 +++++--
etc/NEWS | 10 ++++++++++
lisp/progmodes/xref.el | 24 +++++++++++++++++++-----
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index dc0a715..112f1f4 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -1887,8 +1887,7 @@ the special XREF mode:
@table @kbd
@item @key{RET}
@itemx mouse-2
-Display the reference on the current line and bury the @file{*xref*}
-buffer.
+Display the reference on the current line.
@item n
@itemx .
@findex xref-next-line
@@ -1903,6 +1902,10 @@ Move to the previous reference and display it in the
other window
@findex xref-show-location-at-point
Display the reference on the current line in the other window
(@code{xref-show-location-at-point}).
address@hidden TAB
address@hidden xref-quit-and-goto-xref
+Display the reference on the current line and bury the @file{*xref*}
+buffer (@code{xref-quit-and-goto-xref}).
@findex xref-query-replace-in-results
@item r @var{pattern} @key{RET} @var{replacement} @key{RET}
Perform interactive query-replace on references that match
diff --git a/etc/NEWS b/etc/NEWS
index 286d274..10e9a7f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1213,6 +1213,16 @@ New user options `term-char-mode-buffer-read-only' and
are non-nil by default. Customize these options to nil if you want
the previous behavior.
+** Xref
+
++++
+*** When an *xref* buffer is needed, 'TAB' quits and jumps to an xref.
+
+A new command 'xref-quit-and-goto-xref', bound to 'TAB' in *xref*
+buffers, quits the window before jumping to the destination. In many
+situations, the intended window configuration is restored, just as if
+the *xref* buffer hadn't been necessary in the first place.
+
* New Modes and Packages in Emacs 26.1
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index ee23bc7..db025d4 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -492,11 +492,17 @@ and finally return the window."
(selected-window))))
(defun xref--show-location (location &optional select)
+ "Help `xref-show-xref' and `xref-goto-xref' do their job.
+Go to LOCATION and if SELECT is non-nil select its window. If
+SELECT is `quit', also quit the *xref* window."
(condition-case err
(let* ((marker (xref-location-marker location))
- (buf (marker-buffer marker)))
+ (buf (marker-buffer marker))
+ (xref-buffer (current-buffer)))
(cond (select
- (select-window (xref--show-pos-in-buf marker buf)))
+ (if (eq select 'quit) (quit-window nil nil))
+ (with-current-buffer xref-buffer
+ (select-window (xref--show-pos-in-buf marker buf))))
(t
(save-selected-window
(xref--with-dedicated-window
@@ -528,12 +534,19 @@ and finally return the window."
(back-to-indentation)
(get-text-property (point) 'xref-item)))
-(defun xref-goto-xref ()
- "Jump to the xref on the current line and select its window."
+(defun xref-goto-xref (&optional quit)
+ "Jump to the xref on the current line and select its window.
+Non-interactively, non-nil QUIT means to first quit the *xref*
+buffer."
(interactive)
(let ((xref (or (xref--item-at-point)
(user-error "No reference at point"))))
- (xref--show-location (xref-item-location xref) t)))
+ (xref--show-location (xref-item-location xref) (if quit 'quit t))))
+
+(defun xref-quit-and-goto-xref ()
+ "Quit *xref* buffer, then jump to xref on current line."
+ (interactive)
+ (xref-goto-xref t))
(defun xref-query-replace-in-results (from to)
"Perform interactive replacement of FROM with TO in all displayed xrefs.
@@ -657,6 +670,7 @@ references displayed in the current *xref* buffer."
(define-key map (kbd "p") #'xref-prev-line)
(define-key map (kbd "r") #'xref-query-replace-in-results)
(define-key map (kbd "RET") #'xref-goto-xref)
+ (define-key map (kbd "TAB") #'xref-quit-and-goto-xref)
(define-key map (kbd "C-o") #'xref-show-location-at-point)
;; suggested by Johan Claesson "to further reduce finger movement":
(define-key map (kbd ".") #'xref-next-line)