Is it possible to place the current buffer at the end of the buffer list without switching buffers in the window? I would like to write a wrapper function for ibuffer
that modifies the buffer list so that the IBuffer buffer is at the end of the list after calling it. The motivation is for the case when working on say src1.code
and then I call ibuffer
and use it to select src2.code
, then the buffer list looks like (most recent at the top)
src2.code
*Ibuffer*
src1.code
.
.
.
but I would like it to look like
src2.code
src1.code
.
.
.
*Ibuffer*
In the Emacs manual at https://www.gnu.org/software/emacs/manual/html_node/elisp/Buffer-List.html, it says that there is a function bury-buffer
that places a buffer at the end of the buffer list. So I was hoping to write a function such as follows to achieve the desired result:
(defun ibuffer-bury-buffer ()
"Calls `ibuffer` and moves the buffer to the end of the buffer
list. Doesn't work!"
(interactive)
(ibuffer)
(bury-buffer))
But it seems that when you call bury-buffer
using the current buffer in the window that it also changes the buffer to the next buffer in the buffer list. Is there anything that can be done to prevent that?
*Ibuffer*
, there are likely customizable sort options. To the extent you wish to see how the functionbury-buffer-internal
works, typeM-x describe-function
orC-h f
. Here is something you can use to test:(progn (message "\nbuffer-list (BEFORE): %s" (buffer-list)) (bury-buffer-internal (current-buffer)) (message "\nbuffer-list (AFTER): %s" (buffer-list)) nil)
. You can place that in a*scratch*
buffer and move to the end of the code and typeC-x C-e
and then switch to*Messages*
buffer.buffer-list
, that is a Pandora's Box that I do not wish to open. Stefan was the lead of the Emacs development team for years, so he is definitely the expert here. Most of the code that I have seen or written/modified over the years calls the function(buffer-list)
and then does something with the copied list and does not modify the actual internalbuffer-list
that Emacs relies upon. Here is a simple first/last of thebuffer-list
which does not modify the internalbuffer-list
:(let ((lst (buffer-list))) (cons (first lst) (last lst)))