unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#74361: [PATCH] New option xref-navigation-display-window-action
@ 2024-11-14 22:29 Dmitry Gutov
  2024-11-15  0:50 ` Dmitry Gutov
                   ` (2 more replies)
  0 siblings, 3 replies; 64+ messages in thread
From: Dmitry Gutov @ 2024-11-14 22:29 UTC (permalink / raw)
  To: 74361; +Cc: juri linkov

[-- Attachment #1: Type: text/plain, Size: 868 bytes --]

X-Debbugs-Cc: Juri Linkov <juri@linkov.net>

This adds a capability to customize the destination window selection 
logic for navigation (xref-find-definitions, xref-go-back, 
xref-go-forward) by allowing a user-supplied display window function.

Inspired by the Merlin package and its user option 
merlin-locate-in-new-window 
(https://github.com/ocaml/merlin/blob/a36f42a5b181d0c9cc84174e8eb241b11eeabc0f/emacs/merlin.el#L177C12-L177C39) 
- where the value 'diff' uses a different window if the destination is 
in an file different from the current one.

With the attached patch the customization looks a bit noisier though:

   (setq xref-navigation-display-window-action
         '(display-buffer-reuse-window))

^ This makes it try to reuse an existing window and fall back to 
pop-to-window, but the effect is similar to what's described above.

Comments welcome.

[-- Attachment #2: xref-navigation-display-window-action.diff --]
[-- Type: text/x-patch, Size: 3980 bytes --]

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index cc06e06ef78..670e80ea40b 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -431,6 +431,21 @@ xref-auto-jump-to-first-xref
   :version "28.1"
   :package-version '(xref . "1.2.0"))
 
+(defcustom xref-navigation-display-window-action nil
+  "When non-nil, the display action to use for navigation commands.
+
+The value should be nil or a buffer display action like described in
+docstring for `display-buffer'.
+
+This does not affect commands that specify the action explicitly,
+such as `xref-find-definitions-other-window'."
+  :type '(choice (const :tag "Use selected window" nil)
+                 (const :tag "Reuse window showing destination or use another"
+                        (display-buffer-reuse-window))
+                 display-buffer--action-custom-type)
+  :version "31.1"
+  :package-version '(xref . "1.8.0"))
+
 (defcustom xref-history-storage #'xref-global-history
   "Function that returns xref history.
 
@@ -513,6 +528,11 @@ xref-push-marker-stack
 ;;;###autoload
 (define-obsolete-function-alias 'xref-pop-marker-stack #'xref-go-back "29.1")
 
+(defun xref--switch-to-buffer (buf)
+  (if xref-navigation-display-window-action
+      (pop-to-buffer buf xref-navigation-display-window-action)
+    (switch-to-buffer buf)))
+
 ;;;###autoload
 (defun xref-go-back ()
   "Go back to the previous position in xref history.
@@ -523,8 +543,8 @@ xref-go-back
         (user-error "At start of xref history")
       (let ((marker (pop (car history))))
         (xref--push-forward (point-marker))
-        (switch-to-buffer (or (marker-buffer marker)
-                              (user-error "The marked buffer has been deleted")))
+        (xref--switch-to-buffer (or (marker-buffer marker)
+                                    (user-error "The marked buffer has been deleted")))
         (goto-char (marker-position marker))
         (set-marker marker nil nil)
         (run-hooks 'xref-after-return-hook)))))
@@ -538,8 +558,8 @@ xref-go-forward
         (user-error "At end of xref history")
       (let ((marker (pop (cdr history))))
         (xref--push-backward (point-marker))
-        (switch-to-buffer (or (marker-buffer marker)
-                              (user-error "The marked buffer has been deleted")))
+        (xref--switch-to-buffer (or (marker-buffer marker)
+                                    (user-error "The marked buffer has been deleted")))
         (goto-char (marker-position marker))
         (set-marker marker nil nil)
         (run-hooks 'xref-after-return-hook)))))
@@ -612,7 +632,7 @@ xref-pop-to-location
                    (xref-location-marker (xref-item-location item))))
          (buf (marker-buffer marker)))
     (cl-ecase action
-      ((nil)  (switch-to-buffer buf))
+      ((nil)  (xref--switch-to-buffer buf))
       (window (pop-to-buffer buf t))
       (frame  (let ((pop-up-frames t)) (pop-to-buffer buf t))))
     (xref--goto-char marker))
@@ -683,6 +703,9 @@ xref--show-pos-in-buf
                 ((eq xref--original-window-intent 'window)
                  `((xref--display-buffer-in-other-window)
                    (window . ,xref--original-window)))
+                (xref-navigation-display-window-action
+                 `(,xref-navigation-display-window-action
+                   (window . ,xref--original-window)))
                 ((and
                   (window-live-p xref--original-window)
                   (or (not (window-dedicated-p xref--original-window))
@@ -1628,6 +1651,9 @@ xref-find-definitions
 Otherwise, display the list of the possible definitions in a
 buffer where the user can select from the list.
 
+See also `xref-navigation-display-window-action' which can change
+the destination window.
+
 Use \\[xref-go-back] to return back to where you invoked this command."
   (interactive (list (xref--read-identifier "Find definitions of: ")))
   (xref--find-definitions identifier nil))

^ permalink raw reply related	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2024-11-28 20:27 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-14 22:29 bug#74361: [PATCH] New option xref-navigation-display-window-action Dmitry Gutov
2024-11-15  0:50 ` Dmitry Gutov
2024-11-15  7:49 ` Juri Linkov
2024-11-15 19:05   ` Dmitry Gutov
2024-11-16 19:12     ` Juri Linkov
2024-11-18  1:28       ` Dmitry Gutov
2024-11-19 18:33         ` Juri Linkov
2024-11-19 19:43           ` Dmitry Gutov
2024-11-20  7:11             ` Juri Linkov
2024-11-20 19:12               ` Dmitry Gutov
2024-11-21  7:34                 ` Juri Linkov
2024-11-25  1:58                   ` Dmitry Gutov
2024-11-27  1:45                     ` Dmitry Gutov
2024-11-20  8:37             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-20 17:31               ` Juri Linkov
2024-11-20 19:10                 ` Dmitry Gutov
2024-11-21  7:29                   ` Juri Linkov
2024-11-20 19:08               ` Dmitry Gutov
2024-11-22  9:22                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-23  9:35                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-23 18:45                     ` Juri Linkov
2024-11-23 19:16                       ` Juri Linkov
2024-11-24  8:59                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-24 17:40                         ` Juri Linkov
2024-11-25  9:18                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-25 17:49                             ` Juri Linkov
2024-11-26  9:15                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-27  1:52                                 ` Dmitry Gutov
2024-11-27  8:58                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-27 13:07                                     ` Dmitry Gutov
2024-11-28  9:27                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-28 17:15                                         ` Dmitry Gutov
2024-11-28 18:32                                         ` Juri Linkov
2024-11-28 20:27                                           ` Dmitry Gutov
2024-11-27  7:30                                 ` Juri Linkov
2024-11-27  9:00                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-20  8:36           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-15 12:13 ` Eli Zaretskii
2024-11-15 17:20   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-15 19:10   ` Dmitry Gutov
2024-11-16  8:43     ` Eli Zaretskii
2024-11-18  1:42       ` Dmitry Gutov
2024-11-18 12:25         ` Eli Zaretskii
2024-11-18 16:10           ` Dmitry Gutov
2024-11-18 17:03             ` Eli Zaretskii
2024-11-19  1:21               ` Dmitry Gutov
2024-11-19 15:33                 ` Eli Zaretskii
2024-11-19 19:51                   ` Dmitry Gutov
2024-11-20 12:54                     ` Eli Zaretskii
2024-11-21 10:37                   ` Eli Zaretskii
2024-11-21 18:01                     ` Juri Linkov
2024-11-21 19:16                       ` Eli Zaretskii
2024-11-21 19:39                         ` Juri Linkov
2024-11-21 19:56                           ` Eli Zaretskii
2024-11-22  7:29                             ` Juri Linkov
2024-11-22  8:20                               ` Eli Zaretskii
2024-11-23 18:25                                 ` Juri Linkov
2024-11-23 18:53                                   ` Eli Zaretskii
2024-11-23 19:14                                     ` Juri Linkov
2024-11-23 19:36                                       ` Eli Zaretskii
2024-11-24  7:34                                         ` Juri Linkov
2024-11-24  9:42                                           ` Eli Zaretskii
2024-11-25  7:28                                             ` Juri Linkov
2024-11-19 18:36         ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).