From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#74246: [PATCH] Reuse display windows in image-dired Date: Sat, 07 Dec 2024 19:13:14 +0200 Organization: LINKOV.NET Message-ID: <87ed2jwhm5.fsf@mail.linkov.net> References: <868qtsmydz.fsf@gnu.org> <86a5dqm9gl.fsf@gnu.org> <06f264c8-b1a1-4a7f-8fe9-1ca58b2343ff@gmx.at> <87jzcn1af7.fsf@mail.linkov.net> <08f46ed1-e489-4859-8a25-ba7dc4262b95@gmx.at> <87y1108u9k.fsf@mail.linkov.net> <87ldwyil8q.fsf@mail.linkov.net> <3a5afa37-0ea1-4183-a563-ecc3067818c2@gmx.at> <871pypb43g.fsf@mail.linkov.net> <8cd0088f-1beb-4871-a06c-17f8cfb23e29@gmx.at> <87plm8addt.fsf@mail.linkov.net> <90c5f5d6-37f3-41a6-be7c-903e6d0359ac@gmx.at> <87ikrzjrj1.fsf@mail.linkov.net> <87cyi6f2gb.fsf@mail.linkov.net> <6689d418-d028-40b8-b3d2-4ff12fe4283a@gmx.at> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25802"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: Morgan Smith , Eli Zaretskii , 74246@debbugs.gnu.org, stefankangas@gmail.com To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 07 18:20:13 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 1tJyTV-0006We-ED for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 07 Dec 2024 18:20:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJyTN-0003fU-6N; Sat, 07 Dec 2024 12:20:05 -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 1tJyTK-0003e0-Cp for bug-gnu-emacs@gnu.org; Sat, 07 Dec 2024 12:20:02 -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 1tJyTK-0004Ml-3L for bug-gnu-emacs@gnu.org; Sat, 07 Dec 2024 12:20: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:Date:References:In-Reply-To:From:To:Subject; bh=st+ozrRgHulEdqYHhBhma9aqNtaAmb4UUSyR7ouKpIg=; b=D+j0S+0xEUfVIRgmMd2I+uze0xgN9lh5i4w8hO4omqOucOjM94I8IWLfn3/XkKZsH/jI+hRJORReRWF+KINGRANpJib7MFGKIpk4yI13MYnqSo0sTv5xmd1s+tK/JSA/aPrBtZrlUlavRvnc2rMpmu8bTz4ops3Iq6OyVaeqOdzgYbxDrufsH/pChwgfZrpLOC6L2b2u7MPlbHd8SbBTYS1uGm4+Mq+gLsARzNwdkDpoPcGQZw4pyoH4oBO6a4olrwVttDamcDJ6h5KSc96a9dFCdsfeOZY906RzbJZFcaXHlWdZv3yfZSly4juYOBBcqi/f6knhMKv61zG703ElnA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tJyTJ-0000Ct-UI for bug-gnu-emacs@gnu.org; Sat, 07 Dec 2024 12:20:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 Dec 2024 17:20:01 +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.1733591968710 (code B ref 74246); Sat, 07 Dec 2024 17:20:01 +0000 Original-Received: (at 74246) by debbugs.gnu.org; 7 Dec 2024 17:19:28 +0000 Original-Received: from localhost ([127.0.0.1]:48361 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJySl-0000BO-PS for submit@debbugs.gnu.org; Sat, 07 Dec 2024 12:19:28 -0500 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:56679) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tJySj-0000B8-Fl for 74246@debbugs.gnu.org; Sat, 07 Dec 2024 12:19:26 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 27CBEFF804; Sat, 7 Dec 2024 17:18:56 +0000 (UTC) In-Reply-To: <6689d418-d028-40b8-b3d2-4ff12fe4283a@gmx.at> (martin rudalics's message of "Fri, 6 Dec 2024 09:33:33 +0100") X-GND-Sasl: juri@linkov.net 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:296585 Archived-At: >>> The second specification has the drawback that _any_ 'display-buffer' >>> call that relies on 'display-buffer-use-some-window' may use that >>> window. Just think of an error occurring during that call: The >>> *backtrace* buffer will pop up in the window specified by that variable >>> although it is by no means related to it. >> >> Indeed, this is not good. So only a category can ensure that >> the same display-buffer call is used? > > You mean that is uses the same window? I meant that only the same command (and therefore the same display-buffer call) should reuse the same window. This is why I checked for 'this-command' in the posted snippet. But instead of associating with a command name an alternative approach would be to use a category. The *backtrace* buffer is not a problem because it uses own display-buffer alist that overrides display-buffer-use-some-window. > There cannot be such a guarantee. > That window might have been (de-)selected, (temporarily) > deleted, made dedicated and for any such reason may have become > unsuitable for 'display-buffer'. In the course of years people have > added more and more conditions why 'display-buffer' should avoid certain > windows. Think of 'display-buffer-avoid-small-windows' - a global > option that completely sidesteps the internal alist concept. display-buffer-use-some-window could recheck if the window is still suitable for every use of the same command and display-buffer call. >> It's fine to set a buffer-local variable in the buffer where the user >> types a key that displays the target buffer from another source buffer. >> As long as the same buffer is used to get the value of this variable. > > I have no idea of a secure way to retrieve that buffer. It's always the current buffer, even if another buffer is used as the source buffer. >> There are two goals: >> >> 1. replace the current lru with another default that reuses a previous window. >> But not complicating all exiting display-buffer calls by requiring >> each of them to set a buffer-local variable. When a standard variable >> will be set, then it can be shared by different calls. > > Whatever we do: The buffer-local variable would have to be an option to > fix the existing misbehavior of lru. And it should be used only in > cases where 'display-buffer-reuse-window' can't find a suitable windows. > > 'image-dired' could safely use 'display-buffer-reuse-window' because it > eventually displays its images always in the same buffer. It cannot do > that right away in its present version because that one does ... What if the user wants to display an image buffer in another window? Then 'display-buffer-reuse-window' can't be used. > (let ((buf (get-buffer image-dired-display-image-buffer)) > (cur-win (selected-window))) > (when buf > (kill-buffer buf)) > (when-let ((buf (find-file-noselect file nil t))) > (pop-to-buffer buf) > > ... first pop up a buffer showing 'file' which means that > 'display-buffer-reuse-window' usually won't find such a window ... > > (rename-buffer image-dired-display-image-buffer) > > ... and then renames that buffer to 'image-dired-display-image-buffer' - > a buffer that 'display-buffer-reuse-window' would have found if it has > been displayed at least once. Note that the present lru mischief > doesn't happen for the first image displayed. It happens for successive > image displays only, where 'image-dired-display-image-buffer' has been > already displayed at least once. > > And note the 'kill-buffer' killing 'image-dired-display-image-buffer'. > That one defies any attempt to set a buffer-local variable in that > buffer. A buffer-local variable should be set in the source buffer only, not in the image buffer. >> 2. make user customization easy by using a special symbol like >> '(some-window . reuse). But directly using the variable >> is also fine, e.g. `(some-window . ,last-window) > > I would have to understand the semantics of 'reuse' first. What > 'display-buffer' cannot handle currently is something like the > 'image-dired' scenario above where the buffer would not be renamed. In > that case it would be nice if the caller could set a 'category' or a > 'some-window' alist entry and 'display-buffer' could use that to find a > window with the same 'category' or 'some-window' value and display the > buffer there. I have absolutely no problems with existing code in 'image-dired-display-image' because of using: (setq display-buffer-base-action '(nil . ((some-window . (lambda (_buffer alist) (let ((last-window (buffer-local-value 'display-buffer-last-window (window-buffer)))) (or (and (eq this-command (car last-window)) (window-live-p (cdr last-window)) (cdr last-window)) (get-mru-window nil nil t))))))))