From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.devel Subject: Re: Switch buffers without modifying the buffer list ordering? Date: Tue, 01 Feb 2022 19:46:05 +0100 Message-ID: <8735l2a0ia.fsf@gmail.com> References: <874k5kncd8.fsf@gmail.com> <1c2b4184-0f2a-95a7-16bd-d17f4bf6af53@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="34329"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux) Cc: Daniel Mendler , Omar =?utf-8?Q?Antol=C3=ADn?= Camarena , emacs-devel@gnu.org To: martin rudalics Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Feb 02 00:25:14 2022 Return-path: Envelope-to: ged-emacs-devel@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 1nF2WP-0008ki-Ti for ged-emacs-devel@m.gmane-mx.org; Wed, 02 Feb 2022 00:25:13 +0100 Original-Received: from localhost ([::1]:40556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nF2WO-00026J-7a for ged-emacs-devel@m.gmane-mx.org; Tue, 01 Feb 2022 18:25:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEyCI-0002rc-8W for emacs-devel@gnu.org; Tue, 01 Feb 2022 13:48:11 -0500 Original-Received: from [2a00:1450:4864:20::62b] (port=37828 helo=mail-ej1-x62b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEyC6-0004SW-MI for emacs-devel@gnu.org; Tue, 01 Feb 2022 13:48:02 -0500 Original-Received: by mail-ej1-x62b.google.com with SMTP id ah7so56811950ejc.4 for ; Tue, 01 Feb 2022 10:46:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=3cUC2/SZV2+IkVbNYE/yfyFZqac3yKeayng7fmK3Bhs=; b=oEp9H4KeGvxIKGXLAjhgpIguX+o5M8y0jXLj0mLpNqQ/hMbDxRUCT5bf6aMULFCwV/ Uu/pMggzJHtn2edHcYazIJxxUHhlOCqFxlqXV8EpJfy0HBSBiR7KLLyrtw19jVNsz6Tg ONdYglEaRFOxbaRadfcGXK7EQ4Cv6UDX2Sv9GLWHnd3mmJkAJYGcdx1PeNef9cZlTotc 9xJ7APA/HqJ3RjHI1diSyC1xrlxuKT10zwrs4go0NXA4gSJu6HvMsdauXUBQDRfwJ8FZ suxOMVvKOPMkzjT9REtW6M+XhFrKLUkunysJlDXLkFIywR3L92bObg7Zp1XUbwMt17cl L1uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=3cUC2/SZV2+IkVbNYE/yfyFZqac3yKeayng7fmK3Bhs=; b=nzBN37h3DDioYUSTd3CHgfEMtnnZ5pAJwhioHKewMibr4bw/0KY51kkRvz22uXsSw/ Rw1l9xta0Uw3IDePchrhHm68RgiwYKl44jA5f31UQupAebqo1ZHbqHAD/q1V0X5TNI21 W2ctSfh9J6ReLbS9karPeMOrqJM0XVPlsshbNKY3TifwUfl6WebGznT0MIfJ9BazdaMS NlFuT28zxgP9C/QJcxfuF94bqeLDTT7hEbaYvwWB3uHE72KGqTX5g1+34i2RULRtSgFO Q3BK8TAU1bXaNcVZRZLFXz+T34zESoAdwqzW3AeqLkEGHn7DnRHJktZ4VT2ep0ow5Rnd ho4g== X-Gm-Message-State: AOAM532s7kY9f2lo20Rb7xGZaSQU3CpLSk5Zg5vtaNQYggvv34S3Kn4M +cW85yWVrX6a+HeBiYjV4lg= X-Google-Smtp-Source: ABdhPJwA165v3LnA0ADBpS4vpRK4Z6AGgQbk/F9soyLcHGKkK/fEPTuBxComYoQm7u8TplnDIRJ5Mg== X-Received: by 2002:a17:906:4fd2:: with SMTP id i18mr22809192ejw.206.1643741167674; Tue, 01 Feb 2022 10:46:07 -0800 (PST) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::a4e1]) by smtp.gmail.com with ESMTPSA id x6sm1698488edv.109.2022.02.01.10.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 10:46:07 -0800 (PST) In-Reply-To: <1c2b4184-0f2a-95a7-16bd-d17f4bf6af53@gmx.at> (martin rudalics's message of "Mon, 31 Jan 2022 09:42:10 +0100") X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::62b (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=arstoffel@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:285746 Archived-At: Thanks, this essentially clarifies everything. On Mon, 31 Jan 2022 at 09:42, martin rudalics wrote: >> With the following code, I can verify that the NORECORD argument of >> `switch-to-buffer' does what it promises: >> >> ``` >> (progn >> (switch-to-buffer "A") >> (switch-to-buffer "B" 'norecord) >> (car (buffer-list))) >> ``` >> >> Namely, this makes buffer B current, but returns #. >> >> Now, here's a catch: if next I type `M-x (car (buffer-list))', > > ... M-: (car (buffer-list)) I suppose ... > >> I get >> # instead of #. Why does that happen, and is there >> a way to switch to buffer B and *really* not modify the buffer list >> ordering? > > It's restoring the window configuration after reading from the > minibuffer but before evaluating the expression you typed that gets in > the way. Try with emacs -Q and evaluate the forms below step by step > > (display-buffer "*Messages*") > > (defun foo () > (message > "%s - %s" (selected-window) (car (buffer-list)))) > > (add-hook 'buffer-list-update-hook 'foo) > > (progn > (switch-to-buffer "A") > (switch-to-buffer "B" 'norecord) > (car (buffer-list))) > > and now type M-: (car (buffer-list)). This gets me in the *Messages* > buffer > > # - A [3 times] > # > # - A > # - *Minibuf-1* [4 times] > # - B [2 times] > # > > Now try again the same scenario but first evaluate > > (setq read-minibuffer-restore-windows nil) > > which gets me here the > > # - A [3 times] > # > > you probably expected. > >> I'm asking this because of an issue with the live preview feature of the >> Consult package. Very succinctly, the idea here is to temporarily >> change the current buffer during a `completing-read' call, in order to >> display more information about the candidates. When the >> `completing-read' ends, we would like to restore the original order of >> the buffer list. There seems to be no simple way to achieve that, and >> some kludge like the following seems necessary. Any better suggestions? >> >> ``` >> (let ((buffers (buffer-list))) >> (unwind-protect >> >> (save-window-excursion >> ;; Restore the original buffer list ordering >> (dolist (buffer buffers) >> (when (buffer-live-p buffer) >> (bury-buffer-internal buffer)))))) > > That's a different issue. 'buffer-list' is a function that returns a > list from the internal C variable Vbuffer_alist - a variable, Lisp code > is not allowed to modify directly. In order to modify Vbuffer_alist, a > Lisp programmer has to bury buffers in precisely the same way as you do. > > You could try coming up with a macro, say 'with-buffer-list-unmodified' > (where you probably should suspend calling 'buffer-list-update-hook' > while running it). > > martin