unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Switch buffers without modifying the buffer list ordering?
@ 2022-01-30 21:26 Augusto Stoffel
  2022-01-31  8:42 ` martin rudalics
  2022-02-01 14:48 ` Kevin Vigouroux via Emacs development discussions.
  0 siblings, 2 replies; 5+ messages in thread
From: Augusto Stoffel @ 2022-01-30 21:26 UTC (permalink / raw)
  To: emacs-devel; +Cc: Daniel Mendler, Omar Antolín Camarena

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 #<buffer A>.

Now, here's a catch: if next I type `M-x (car (buffer-list))', I get
#<buffer B> instead of #<buffer A>.  Why does that happen, and is there
a way to switch to buffer B and *really* not modify the buffer list
ordering?

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
        <do the completing-read with live preview>
      (save-window-excursion
        ;; Restore the original buffer list ordering
        (dolist (buffer buffers)
          (when (buffer-live-p buffer)
            (bury-buffer-internal buffer))))))
```



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-02 11:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-30 21:26 Switch buffers without modifying the buffer list ordering? Augusto Stoffel
2022-01-31  8:42 ` martin rudalics
2022-02-01 18:46   ` Augusto Stoffel
2022-02-02 11:24   ` Kevin Vigouroux via Emacs development discussions.
2022-02-01 14:48 ` Kevin Vigouroux via Emacs development discussions.

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).