From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Stefan Monnier via "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#66394: 29.1; Make register-read-with-preview more useful
Date: Sun, 17 Dec 2023 18:20:56 -0500
Message-ID: <jwv34w0e807.fsf-monnier+emacs@gnu.org>
References: <87il7ib6cu.fsf@posteo.net> <87a5qhxf05.fsf@posteo.net>
 <83jzpkvs4z.fsf@gnu.org> <87v8947ulo.fsf@posteo.net>
 <871qbsk5le.fsf@posteo.net>
 <f7f749d1-3a2d-0ea0-a106-6c586f4faca7@gutov.dev>
 <87v894hr2e.fsf@posteo.net> <87cyvbepi0.fsf@posteo.net>
 <87bkavk9nv.fsf@posteo.net>
 <8eebbb30-9366-e869-a39a-8100638cb99a@gutov.dev>
 <87o7etgxeb.fsf@posteo.net> <83v891qlcn.fsf@gnu.org>
 <jwvfs04hjm9.fsf-monnier+emacs@gnu.org>
 <CADwFkmm3H9+-nrYi0JQM9YT0_ZYU3SYvcqfmEnEpJWWaZzHTGQ@mail.gmail.com>
 <87r0jn4j8i.fsf@posteo.net> <jwv8r5vfqo6.fsf-monnier+emacs@gnu.org>
 <87jzpf48k5.fsf@posteo.net> <jwvplz73vpg.fsf-monnier+emacs@gnu.org>
 <87plz6xp3m.fsf@posteo.net> <jwvzfya2mk9.fsf-monnier+emacs@gnu.org>
 <87sf41ubjj.fsf@posteo.net>
Reply-To: Stefan Monnier <monnier@iro.umontreal.ca>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="5028"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cc: michael_heerdegen@web.de, dmitry@gutov.dev, Eli Zaretskii <eliz@gnu.org>,
 Stefan Kangas <stefankangas@gmail.com>, 66394@debbugs.gnu.org
To: Thierry Volpiatto <thievol@posteo.net>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 18 00:22:19 2023
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
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 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1rF0Se-00010s-H0
	for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Dec 2023 00:22:16 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1rF0SP-00073Z-Ja; Sun, 17 Dec 2023 18:22:01 -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 <Debian-debbugs@debbugs.gnu.org>)
 id 1rF0SO-00073C-HO
 for bug-gnu-emacs@gnu.org; Sun, 17 Dec 2023 18:22:00 -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 <Debian-debbugs@debbugs.gnu.org>)
 id 1rF0SO-0006N6-9Y
 for bug-gnu-emacs@gnu.org; Sun, 17 Dec 2023 18:22:00 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rF0SP-0003fd-Oq
 for bug-gnu-emacs@gnu.org; Sun, 17 Dec 2023 18:22:01 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Stefan Monnier <monnier@iro.umontreal.ca>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Sun, 17 Dec 2023 23:22:01 +0000
Resent-Message-ID: <handler.66394.B66394.170285526614040@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 66394
X-GNU-PR-Package: emacs
Original-Received: via spool by 66394-submit@debbugs.gnu.org id=B66394.170285526614040
 (code B ref 66394); Sun, 17 Dec 2023 23:22:01 +0000
Original-Received: (at 66394) by debbugs.gnu.org; 17 Dec 2023 23:21:06 +0000
Original-Received: from localhost ([127.0.0.1]:59158 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1rF0RV-0003eO-PI
 for submit@debbugs.gnu.org; Sun, 17 Dec 2023 18:21:06 -0500
Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:21321)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@iro.umontreal.ca>) id 1rF0RT-0003dZ-ED
 for 66394@debbugs.gnu.org; Sun, 17 Dec 2023 18:21:04 -0500
Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 4D2AE444CEC;
 Sun, 17 Dec 2023 18:20:56 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1702855254;
 bh=AkHo6/oRfbvVJpriJpFPhmWf92T0zCD8cIvtlOhLYi8=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=ZsOcHwBkEWJlFj0LonnsktvfX9HtcjnzTwuVhdZYbuxtpDSIhrbrsBnHh7bYeMlO+
 +kHZIox+xKTHBrkLhFxsaz6lpVFkxqNiW7aAJjTWnDUOuAMYrYXKf7pUkuuhm6JXzl
 e4yt1tKnLbsh/MgohgNACXXIeyZqY4/X7rSCnNM7aFJEBLOhZqxGgh1IWffYScPiCF
 nVHUo6mYcxY8PMI7if4OCQGnsLqNbFX1IwLKRX499nOlexhO5CjjbYZ4bLNPx3qdj1
 PDCj8V0prHGX/2FeLXc76+rpjmmn+HIsQimxl2Uz/j66DMVh/xqAsvwHeMv7hOyu0d
 b0U04KnRjfiKw==
Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A52A5444CE5;
 Sun, 17 Dec 2023 18:20:54 -0500 (EST)
Original-Received: from alfajor (65-110-221-238.cpe.pppoe.ca [65.110.221.238])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 66782120E2C;
 Sun, 17 Dec 2023 18:20:54 -0500 (EST)
In-Reply-To: <87sf41ubjj.fsf@posteo.net> (Thierry Volpiatto's message of "Sat, 
 16 Dec 2023 20:39:44 +0000")
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" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=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:276446
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/276446>

> From 6a15a8b7b795b8377ef3537dc7bbd5ba26c0e159 Mon Sep 17 00:00:00 2001
> From: Thierry Volpiatto <thievol@posteo.net>
> Date: Thu, 14 Dec 2023 16:23:26 +0100
> Subject: [PATCH 3/4] Save and restore win confs after register commands
>
> When several windows are open, the register preview may eat other
> windows and break the current window configuration.
>
> * lisp/register.el (register-read-with-preview-fancy): Do it.
> ---
>  lisp/register.el | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lisp/register.el b/lisp/register.el
> index 8f0c6a7105d..1fadbe81056 100644
> --- a/lisp/register.el
> +++ b/lisp/register.el
> @@ -473,6 +473,7 @@ display such a window regardless."
>           (buffer1 "*Register quick preview*")
>           (buf (if register-use-preview buffer buffer1))
>           (pat "")
> +         (winconf (current-window-configuration))
>           (map (let ((m (make-sparse-keymap)))
>                  (set-keymap-parent m minibuffer-local-map)
>                  m))
> @@ -573,6 +574,7 @@ display such a window regardless."
>                        nil "No register specified")
>             (string-to-char result))
>        (when timer (cancel-timer timer))
> +      (set-window-configuration winconf)
>        (let ((w (get-buffer-window buf)))
>          (and (window-live-p w) (delete-window w)))
>        (and (get-buffer buf) (kill-buffer buf)))))

While save&restore of window configuration often works well, it
misbehaves in various cases (such as when the buffer is displayed in
another frame, which case case `set-window-configuration` will do you
no good).

The official way to undo a `display-buffer` is with
`quit-(restore-)window`.  See (info "(elisp)Quitting Windows").


        Stefan