diff options
| author | Dmitry Gutov | 2024-11-27 03:43:22 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2024-11-27 03:43:22 +0200 |
| commit | 0624fe6f8497a677ae354da0a604dbf82e69400a (patch) | |
| tree | 48ccdb6bfad8062a56172828226cb30c594da92c | |
| parent | 298bbf3cd76ffaf0c88a6a9ec56aa33c4103b8e6 (diff) | |
| download | emacs-0624fe6f8497a677ae354da0a604dbf82e69400a.tar.gz emacs-0624fe6f8497a677ae354da0a604dbf82e69400a.zip | |
Make Xref commands follow 'display-buffer' customizations
* lisp/progmodes/xref.el (xref--show-pos-in-buf): Append
'(category . xref-jump)' to display-buffer action argument, when
the target window or frame is not made explicit by the command.
(xref--switch-to-buffer): New function (bug#74361).
Do the switch through 'pop-to-buffer' and use the new category.
(xref-go-back, xref-go-forward, xref-pop-to-location): Use it.
* etc/NEWS: Describe the change.
| -rw-r--r-- | etc/NEWS | 11 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 18 |
2 files changed, 23 insertions, 6 deletions
| @@ -781,6 +781,17 @@ removing packages. | |||
| 781 | When invoked with a prefix argument, 'package-install-selected-packages' | 781 | When invoked with a prefix argument, 'package-install-selected-packages' |
| 782 | will not prompt the user for confirmation before installing packages. | 782 | will not prompt the user for confirmation before installing packages. |
| 783 | 783 | ||
| 784 | ** Xref | ||
| 785 | |||
| 786 | The commands that jump to some location use 'display-buffer' and specify | ||
| 787 | the category 'xref-jump'. As a result you can customize how the | ||
| 788 | destination window is chosen using 'display-buffer-alist'. Example: | ||
| 789 | |||
| 790 | (setq display-buffer-alist '(((category . xref) | ||
| 791 | (display-buffer-reuse-window | ||
| 792 | display-buffer-use-some-window) | ||
| 793 | (some-window . mru)))) | ||
| 794 | |||
| 784 | 795 | ||
| 785 | * New Modes and Packages in Emacs 31.1 | 796 | * New Modes and Packages in Emacs 31.1 |
| 786 | 797 | ||
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index cf061a18ee0..e6f029f3fa8 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -513,6 +513,9 @@ Erase the stack slots following this one." | |||
| 513 | ;;;###autoload | 513 | ;;;###autoload |
| 514 | (define-obsolete-function-alias 'xref-pop-marker-stack #'xref-go-back "29.1") | 514 | (define-obsolete-function-alias 'xref-pop-marker-stack #'xref-go-back "29.1") |
| 515 | 515 | ||
| 516 | (defun xref--switch-to-buffer (buf) | ||
| 517 | (pop-to-buffer buf '((display-buffer-same-window) (category . xref-jump)))) | ||
| 518 | |||
| 516 | ;;;###autoload | 519 | ;;;###autoload |
| 517 | (defun xref-go-back () | 520 | (defun xref-go-back () |
| 518 | "Go back to the previous position in xref history. | 521 | "Go back to the previous position in xref history. |
| @@ -523,8 +526,8 @@ To undo, use \\[xref-go-forward]." | |||
| 523 | (user-error "At start of xref history") | 526 | (user-error "At start of xref history") |
| 524 | (let ((marker (pop (car history)))) | 527 | (let ((marker (pop (car history)))) |
| 525 | (xref--push-forward (point-marker)) | 528 | (xref--push-forward (point-marker)) |
| 526 | (switch-to-buffer (or (marker-buffer marker) | 529 | (xref--switch-to-buffer (or (marker-buffer marker) |
| 527 | (user-error "The marked buffer has been deleted"))) | 530 | (user-error "The marked buffer has been deleted"))) |
| 528 | (goto-char (marker-position marker)) | 531 | (goto-char (marker-position marker)) |
| 529 | (set-marker marker nil nil) | 532 | (set-marker marker nil nil) |
| 530 | (run-hooks 'xref-after-return-hook))))) | 533 | (run-hooks 'xref-after-return-hook))))) |
| @@ -538,8 +541,8 @@ To undo, use \\[xref-go-forward]." | |||
| 538 | (user-error "At end of xref history") | 541 | (user-error "At end of xref history") |
| 539 | (let ((marker (pop (cdr history)))) | 542 | (let ((marker (pop (cdr history)))) |
| 540 | (xref--push-backward (point-marker)) | 543 | (xref--push-backward (point-marker)) |
| 541 | (switch-to-buffer (or (marker-buffer marker) | 544 | (xref--switch-to-buffer (or (marker-buffer marker) |
| 542 | (user-error "The marked buffer has been deleted"))) | 545 | (user-error "The marked buffer has been deleted"))) |
| 543 | (goto-char (marker-position marker)) | 546 | (goto-char (marker-position marker)) |
| 544 | (set-marker marker nil nil) | 547 | (set-marker marker nil nil) |
| 545 | (run-hooks 'xref-after-return-hook))))) | 548 | (run-hooks 'xref-after-return-hook))))) |
| @@ -612,7 +615,7 @@ If SELECT is non-nil, select the target window." | |||
| 612 | (xref-location-marker (xref-item-location item)))) | 615 | (xref-location-marker (xref-item-location item)))) |
| 613 | (buf (marker-buffer marker))) | 616 | (buf (marker-buffer marker))) |
| 614 | (cl-ecase action | 617 | (cl-ecase action |
| 615 | ((nil) (switch-to-buffer buf)) | 618 | ((nil) (xref--switch-to-buffer buf)) |
| 616 | (window (pop-to-buffer buf t)) | 619 | (window (pop-to-buffer buf t)) |
| 617 | (frame (let ((pop-up-frames t)) (pop-to-buffer buf t)))) | 620 | (frame (let ((pop-up-frames t)) (pop-to-buffer buf t)))) |
| 618 | (xref--goto-char marker)) | 621 | (xref--goto-char marker)) |
| @@ -688,7 +691,10 @@ and finally return the window." | |||
| 688 | (or (not (window-dedicated-p xref--original-window)) | 691 | (or (not (window-dedicated-p xref--original-window)) |
| 689 | (eq (window-buffer xref--original-window) buf))) | 692 | (eq (window-buffer xref--original-window) buf))) |
| 690 | `((xref--display-buffer-in-window) | 693 | `((xref--display-buffer-in-window) |
| 691 | (window . ,xref--original-window)))))) | 694 | (category . xref-jump) |
| 695 | (window . ,xref--original-window))) | ||
| 696 | (t | ||
| 697 | '(nil (category . xref-jump)))))) | ||
| 692 | (with-selected-window (display-buffer buf action) | 698 | (with-selected-window (display-buffer buf action) |
| 693 | (xref--goto-char pos) | 699 | (xref--goto-char pos) |
| 694 | (run-hooks 'xref-after-jump-hook) | 700 | (run-hooks 'xref-after-jump-hook) |