all messages for Emacs-related lists mirrored at yhetil.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
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ 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] 8+ messages in thread

end of thread, other threads:[~2022-03-29  6:03 UTC | newest]

Thread overview: 8+ 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:35 ` Kevin Vigouroux via Users list for the GNU Emacs text editor
2022-03-25 22:25   ` Samuel Wales
2022-03-29  6:03     ` Kevin Vigouroux via Users list for the GNU Emacs text editor
2022-02-01 14:48 ` Kevin Vigouroux via Emacs development discussions.

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.