From: martin rudalics via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>,
Morgan Smith <Morgan.J.Smith@outlook.com>,
Stefan Kangas <stefankangas@gmail.com>
Cc: 74246@debbugs.gnu.org
Subject: bug#74246: [PATCH] Reuse display windows in image-dired
Date: Sat, 9 Nov 2024 18:36:12 +0100 [thread overview]
Message-ID: <a4e687f5-487b-4cb1-8dee-7559f5f0796a@gmx.at> (raw)
In-Reply-To: <868qtsmydz.fsf@gnu.org>
>> When using image-dired, one can use SPC (image-dired-display-next)
>> repeatedly to display successive images in a dedicated buffer. However,
>> it seems to choose a different window each time I press SPC.
>>
>> I can reproduce this in "emacs -Q" when I have 4 windows.
>>
>> The following patch works on my system.
>
> Thanks.
>
> Martin and Stefan, any comments or suggestions?
It's a problem we've seen in other contexts before: For historical
reasons 'display-buffer' by default tries to use the least recently used
window which changes whenever we display an image in it. Juri invented
the 'some-window' buffer display option and I quote the corresponding
entry from the Elisp manual here:
The above describes the behavior when the ‘some-window’ ALIST entry
is ‘lru’ or ‘nil’ which is the default. Another possible value is
‘mru’. If, for example, ‘display-buffer-base-action’ is customized
to ‘(nil . ((some-window . mru)))’, then this function will prefer
the most recently used window. This will try to display several
buffers from consecutive calls of ‘display-buffer’ in the same
window. Consider a configuration of three or more windows where a
user wants to consult, in a non-selected window, one after the
other, the results of a query spread among several buffers. With
the ‘lru’ strategy, Emacs may continuously choose another window
because the least recently used window changes with every call of
‘display-buffer-use-some-window’. With the ‘mru’ strategy, the
window chosen would always remain the same, resulting in a
predictable user experience.
So I think that Morgan should try to use this approach first. But if
the image is always displayed in 'image-dired-image-display' mode then
the appropriate action function 'image-dired' should use is
'display-buffer-reuse-mode-window'.
+ (let* ((buf (get-buffer image-dired-display-image-buffer))
+ (windows (and buf
+ (get-buffer-window-list buf t t)))
+ (cur-win (selected-window)))
(when buf
(kill-buffer buf))
(when-let ((buf (find-file-noselect file nil t)))
+ (dolist (window windows)
+ (set-window-buffer window buf))
Is this supposed to show the same image in all windows that previously
displayed 'image-dired-display-image-buffer'?
FWIW, I would rewrite 'image-dired-display-image' as the (largely
untested)
(defun image-dired-display-image (file &optional _ignored)
"Display image FILE in the image buffer window.
If FILE is an image, the window will use `image-dired-image-mode'
which is based on `image-mode'."
(declare (advertised-calling-convention (file) "29.1"))
(setq file (expand-file-name file))
(when (not (file-exists-p file))
(error "No such file: %s" file))
(let* ((buffer (get-buffer-create image-dired-display-image-buffer))
(window (get-buffer-window buffer)))
(find-file-noselect-1 buffer file nil t nil nil)
(with-current-buffer buffer
(if (string-match (image-file-name-regexp) file)
(image-dired-image-mode)
;; Support visiting PDF files.
(normal-mode)))
(unless window
(display-buffer buffer))))
instead of doing all that 'kill-buffer' (which could delete the selected
window as a side-effect so the final 'select-window' will throw an
error) 'rename-buffer' rigmarole.
martin
prev parent reply other threads:[~2024-11-09 17:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 20:19 bug#74246: [PATCH] Reuse display windows in image-dired Morgan Smith
2024-11-09 11:37 ` Eli Zaretskii
2024-11-09 17:36 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a4e687f5-487b-4cb1-8dee-7559f5f0796a@gmx.at \
--to=bug-gnu-emacs@gnu.org \
--cc=74246@debbugs.gnu.org \
--cc=Morgan.J.Smith@outlook.com \
--cc=eliz@gnu.org \
--cc=rudalics@gmx.at \
--cc=stefankangas@gmail.com \
/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 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).