diff options
| author | João Távora | 2017-10-13 16:37:47 +0100 |
|---|---|---|
| committer | João Távora | 2017-11-03 16:13:39 +0000 |
| commit | e950f329c0cfbe9bf3ba2c2e8ee788d6cdf4cebb (patch) | |
| tree | 3878b76f97508cbd1d5830b3cbbf1c03140f89d2 /lisp | |
| parent | 5d34e1b2881caa5743816030c2e9cdcda58e9719 (diff) | |
| download | emacs-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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/xref.el | 24 |
1 files changed, 19 insertions, 5 deletions
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. | ||
| 496 | Go to LOCATION and if SELECT is non-nil select its window. If | ||
| 497 | SELECT 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. |
| 539 | Non-interactively, non-nil QUIT means to first quit the *xref* | ||
| 540 | buffer." | ||
| 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) |