From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#74246: [PATCH] Reuse display windows in image-dired Date: Sat, 23 Nov 2024 14:16:26 +0200 Message-ID: <86a5dqm9gl.fsf@gnu.org> References: <868qtsmydz.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19216"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 74246@debbugs.gnu.org, stefankangas@gmail.com To: Morgan.J.Smith@outlook.com, martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 23 13:17:21 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tEp4j-0004sr-P6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 23 Nov 2024 13:17:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tEp4S-0001N6-SB; Sat, 23 Nov 2024 07:17:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tEp4Q-0001Mh-Vg for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2024 07:17:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tEp4Q-0004yo-MW for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2024 07:17:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-version:References:In-Reply-To:From:Date:To:Subject; bh=SWRWBHQ6KiHPxcJp19IRr8BN1NBENBgyMkrMTNKO7Qw=; b=WHdeiqzQdfNZRjNKTk92cfbDWnbihZR9jCO+xDuuG0Ezt/j8glC3pNyLHXl+AdCIfwhO53xxSNXrbSzq0H0+Zynv9Yqjv924nmk8P06+DXFDOITtnhQETMGKOtmorNMWtteYL8vsY4hJxsyyIybd+vR4Lux8vlszDj1jL2BxRPnutRkGAn4as6ZwsuEYLrmISj7OYhrGGrATq9SxEMGdT+Zhra/dqeZUcJB+95F397H1Jhg83BSc/UG6pPA6cBrS8nxd6kOEnK3OaZHP0m8n4DKgDxgsfwvjFmNzNUIrPtTeP2WGW34kZeNkRV2qtdjcGAPr/6R20Wo2e1CVhat/HA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tEp4Q-0003ZL-Gi for bug-gnu-emacs@gnu.org; Sat, 23 Nov 2024 07:17:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Nov 2024 12:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74246 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74246-submit@debbugs.gnu.org id=B74246.173236419913679 (code B ref 74246); Sat, 23 Nov 2024 12:17:02 +0000 Original-Received: (at 74246) by debbugs.gnu.org; 23 Nov 2024 12:16:39 +0000 Original-Received: from localhost ([127.0.0.1]:56962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tEp42-0003YZ-R5 for submit@debbugs.gnu.org; Sat, 23 Nov 2024 07:16:39 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:54072) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tEp40-0003YJ-RS for 74246@debbugs.gnu.org; Sat, 23 Nov 2024 07:16:37 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tEp3v-0004xU-6F; Sat, 23 Nov 2024 07:16:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=SWRWBHQ6KiHPxcJp19IRr8BN1NBENBgyMkrMTNKO7Qw=; b=q9RYxh9u03ER4CmL/TL6 X/F1c+C1whaHc7WU4kvIntqIj/yG8sPpdXfTnVALi2z8HLFcnuODhO5ZATtER50aR+cqo0RNU3Wdh Y8hn5QeIFVBHRKzcYuYdvm0mbMnNLqIFQY1MIRaz98455w+auzn8mU+S3JQgsgOYYQLi6z0VZbFjF 0Yar6+anLxY2X0T2veid0922/63WudUhrpBLppv0tfOByOKO6N4/wzGiRuPNBb3414HUiQE7N6fvi pC3ckAFlpDs/aR2Tzd0sj9q+0m2aElbJxUVZG4vDfz4BL0QJzKGYwy+e9lYZun6ud/Y2uSy7X5xnv Ehnh68qesX3ztw==; In-Reply-To: (message from martin rudalics on Sat, 9 Nov 2024 18:36:12 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295819 Archived-At: Ping! Morgan, could you please try Martin's suggestions and report back? > Date: Sat, 9 Nov 2024 18:36:12 +0100 > Cc: 74246@debbugs.gnu.org > From: martin rudalics > > >> 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