aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2017-10-13 16:37:47 +0100
committerJoão Távora2017-11-03 16:13:39 +0000
commite950f329c0cfbe9bf3ba2c2e8ee788d6cdf4cebb (patch)
tree3878b76f97508cbd1d5830b3cbbf1c03140f89d2
parent5d34e1b2881caa5743816030c2e9cdcda58e9719 (diff)
downloademacs-e950f329c0cfbe9bf3ba2c2e8ee788d6cdf4cebb.tar.gz
emacs-e950f329c0cfbe9bf3ba2c2e8ee788d6cdf4cebb.zip
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.
-rw-r--r--doc/emacs/maintaining.texi7
-rw-r--r--etc/NEWS10
-rw-r--r--lisp/progmodes/xref.el24
3 files changed, 34 insertions, 7 deletions
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index dc0a71511ff..112f1f4d9ed 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -1887,8 +1887,7 @@ the special XREF mode:
1887@table @kbd 1887@table @kbd
1888@item @key{RET} 1888@item @key{RET}
1889@itemx mouse-2 1889@itemx mouse-2
1890Display the reference on the current line and bury the @file{*xref*} 1890Display the reference on the current line.
1891buffer.
1892@item n 1891@item n
1893@itemx . 1892@itemx .
1894@findex xref-next-line 1893@findex xref-next-line
@@ -1903,6 +1902,10 @@ Move to the previous reference and display it in the other window
1903@findex xref-show-location-at-point 1902@findex xref-show-location-at-point
1904Display the reference on the current line in the other window 1903Display the reference on the current line in the other window
1905(@code{xref-show-location-at-point}). 1904(@code{xref-show-location-at-point}).
1905@item TAB
1906@findex xref-quit-and-goto-xref
1907Display the reference on the current line and bury the @file{*xref*}
1908buffer (@code{xref-quit-and-goto-xref}).
1906@findex xref-query-replace-in-results 1909@findex xref-query-replace-in-results
1907@item r @var{pattern} @key{RET} @var{replacement} @key{RET} 1910@item r @var{pattern} @key{RET} @var{replacement} @key{RET}
1908Perform interactive query-replace on references that match 1911Perform interactive query-replace on references that match
diff --git a/etc/NEWS b/etc/NEWS
index 286d27455fe..10e9a7f00f3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1213,6 +1213,16 @@ New user options `term-char-mode-buffer-read-only' and
1213are non-nil by default. Customize these options to nil if you want 1213are non-nil by default. Customize these options to nil if you want
1214the previous behavior. 1214the previous behavior.
1215 1215
1216** Xref
1217
1218+++
1219*** When an *xref* buffer is needed, 'TAB' quits and jumps to an xref.
1220
1221A new command 'xref-quit-and-goto-xref', bound to 'TAB' in *xref*
1222buffers, quits the window before jumping to the destination. In many
1223situations, the intended window configuration is restored, just as if
1224the *xref* buffer hadn't been necessary in the first place.
1225
1216 1226
1217* New Modes and Packages in Emacs 26.1 1227* New Modes and Packages in Emacs 26.1
1218 1228
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index ee23bc7a64e..db025d40aa3 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -492,11 +492,17 @@ and finally return the window."
492 (selected-window)))) 492 (selected-window))))
493 493
494(defun xref--show-location (location &optional select) 494(defun xref--show-location (location &optional select)
495 "Help `xref-show-xref' and `xref-goto-xref' do their job.
496Go to LOCATION and if SELECT is non-nil select its window. If
497SELECT is `quit', also quit the *xref* window."
495 (condition-case err 498 (condition-case err
496 (let* ((marker (xref-location-marker location)) 499 (let* ((marker (xref-location-marker location))
497 (buf (marker-buffer marker))) 500 (buf (marker-buffer marker))
501 (xref-buffer (current-buffer)))
498 (cond (select 502 (cond (select
499 (select-window (xref--show-pos-in-buf marker buf))) 503 (if (eq select 'quit) (quit-window nil nil))
504 (with-current-buffer xref-buffer
505 (select-window (xref--show-pos-in-buf marker buf))))
500 (t 506 (t
501 (save-selected-window 507 (save-selected-window
502 (xref--with-dedicated-window 508 (xref--with-dedicated-window
@@ -528,12 +534,19 @@ and finally return the window."
528 (back-to-indentation) 534 (back-to-indentation)
529 (get-text-property (point) 'xref-item))) 535 (get-text-property (point) 'xref-item)))
530 536
531(defun xref-goto-xref () 537(defun xref-goto-xref (&optional quit)
532 "Jump to the xref on the current line and select its window." 538 "Jump to the xref on the current line and select its window.
539Non-interactively, non-nil QUIT means to first quit the *xref*
540buffer."
533 (interactive) 541 (interactive)
534 (let ((xref (or (xref--item-at-point) 542 (let ((xref (or (xref--item-at-point)
535 (user-error "No reference at point")))) 543 (user-error "No reference at point"))))
536 (xref--show-location (xref-item-location xref) t))) 544 (xref--show-location (xref-item-location xref) (if quit 'quit t))))
545
546(defun xref-quit-and-goto-xref ()
547 "Quit *xref* buffer, then jump to xref on current line."
548 (interactive)
549 (xref-goto-xref t))
537 550
538(defun xref-query-replace-in-results (from to) 551(defun xref-query-replace-in-results (from to)
539 "Perform interactive replacement of FROM with TO in all displayed xrefs. 552 "Perform interactive replacement of FROM with TO in all displayed xrefs.
@@ -657,6 +670,7 @@ references displayed in the current *xref* buffer."
657 (define-key map (kbd "p") #'xref-prev-line) 670 (define-key map (kbd "p") #'xref-prev-line)
658 (define-key map (kbd "r") #'xref-query-replace-in-results) 671 (define-key map (kbd "r") #'xref-query-replace-in-results)
659 (define-key map (kbd "RET") #'xref-goto-xref) 672 (define-key map (kbd "RET") #'xref-goto-xref)
673 (define-key map (kbd "TAB") #'xref-quit-and-goto-xref)
660 (define-key map (kbd "C-o") #'xref-show-location-at-point) 674 (define-key map (kbd "C-o") #'xref-show-location-at-point)
661 ;; suggested by Johan Claesson "to further reduce finger movement": 675 ;; suggested by Johan Claesson "to further reduce finger movement":
662 (define-key map (kbd ".") #'xref-next-line) 676 (define-key map (kbd ".") #'xref-next-line)