From: Juri Linkov <juri@linkov.net>
To: martin rudalics <rudalics@gmx.at>
Cc: 70949@debbugs.gnu.org
Subject: bug#70949: display-buffer-choose-some-window
Date: Fri, 31 May 2024 09:18:49 +0300 [thread overview]
Message-ID: <86frty34km.fsf@mail.linkov.net> (raw)
In-Reply-To: <becd5819-6b15-422a-ba4f-106c03a04bbd@gmx.at> (martin rudalics's message of "Thu, 30 May 2024 10:54:35 +0200")
> And it will set up the '...-previous-window' variable
Not a variable, but a window parameter. A buffer-local variable
can't be used because for example 'vc-diff-internal' uses such
call sequence:
(set-buffer buffer)
(pop-to-buffer (current-buffer))
so 'display-buffer' is called from 'pop-to-buffer' in the wrong buffer.
Therefore, when using a window parameter, the solution is very simple
like in the following patch that allows a short customization:
(setq display-buffer-base-action
'(nil (set-previous-window . t)))
Then users can use anything such as 'C-x 4 1' or 'C-x 4 4',
and after this the subsequent navigation will reuse
the same window.
Even 'next-error-no-select' ('n' and 'p' keys in the grep buffer)
that hard-codes 'inhibit-same-window', still uses the mru window,
because it's 'second-best-window'.
diff --git a/lisp/window.el b/lisp/window.el
index b014be6a7cf..ff12a2225b5 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7883,7 +7888,8 @@ display-buffer
specified by the ACTION argument."
(interactive (list (read-buffer "Display buffer: " (other-buffer))
(if current-prefix-arg t)))
- (let ((buffer (if (bufferp buffer-or-name)
+ (let ((old-selected-window (selected-window))
+ (buffer (if (bufferp buffer-or-name)
buffer-or-name
(get-buffer buffer-or-name)))
(buf-name (if (bufferp buffer-or-name)
@@ -7933,6 +7938,8 @@ display-buffer
(select-window old-selected-window)))
(remove-hook 'post-command-hook postfun))))
(add-hook 'post-command-hook postfun)))
+ (when (cdr (assq 'set-previous-window alist))
+ (set-window-parameter old-selected-window 'previous-window window))
(and (windowp window) window))))
(defun display-buffer-other-frame (buffer)
@@ -8638,6 +8645,7 @@ display-buffer-in-previous-window
(display-buffer-reuse-frames 0)
(t (last-nonminibuffer-frame))))
(previous-window (cdr (assq 'previous-window alist)))
+ (set-previous-window (cdr (assq 'set-previous-window alist)))
best-window second-best-window window)
;; Scan windows whether they have shown the buffer recently.
(catch 'best
@@ -8654,6 +8662,9 @@ display-buffer-in-previous-window
(when (and previous-window (symbolp previous-window)
(boundp previous-window))
(setq previous-window (symbol-value previous-window)))
+ (when-let ((set-previous-window)
+ (prev (window-parameter (selected-window) 'previous-window)))
+ (setq previous-window prev))
(when (and (setq window previous-window)
(window-live-p window)
(or (eq buffer (window-buffer window))
next prev parent reply other threads:[~2024-05-31 6:18 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-14 16:56 bug#70949: display-buffer-choose-some-window Juri Linkov
2024-05-15 8:06 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-15 16:49 ` Juri Linkov
2024-05-16 8:20 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-17 6:40 ` Juri Linkov
2024-05-18 9:21 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-20 6:15 ` Juri Linkov
2024-05-20 8:01 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-20 16:54 ` Juri Linkov
2024-05-21 8:21 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-21 17:18 ` Juri Linkov
2024-05-22 7:39 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-23 6:16 ` Juri Linkov
2024-05-23 7:22 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-23 17:27 ` Juri Linkov
2024-05-24 9:32 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-24 17:38 ` Juri Linkov
2024-05-26 8:54 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-27 17:52 ` Juri Linkov
2024-05-28 8:05 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-28 16:19 ` Juri Linkov
2024-05-29 8:49 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-30 6:34 ` Juri Linkov
2024-05-30 8:54 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-31 6:18 ` Juri Linkov [this message]
2024-05-31 9:45 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02 6:39 ` Juri Linkov
2024-06-04 8:20 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-04 16:43 ` Juri Linkov
2024-06-05 8:46 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-05 16:48 ` Juri Linkov
2024-06-06 9:19 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-07 6:37 ` Juri Linkov
2024-06-07 8:23 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-07 16:45 ` Juri Linkov
2024-06-08 9:12 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-09 17:04 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86frty34km.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=70949@debbugs.gnu.org \
--cc=rudalics@gmx.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.