How to get the list of buffers currently displayed in tabs?

Josip Gracin gracin at tel.fer.hr
Thu Mar 22 10:25:56 EDT 2007


Stephen J. Turnbull wrote:
> Josip Gracin writes:
> 
>  > Is there a way to obtain list of buffers from the tab?  I mean, to get 
>  > what is really displayed, and not what will be displayed next time that 
>  > buffer tabs get refreshed?  Or perhaps, is there a way to force a 
>  > refresh of buffer tabs in order to synchronize it with what 
>  > (buffers-tab-items) returns?
> 
> No, no, and no.  The only hack I know of is the one suggested by Dave
> P.  On X11, at least, that may not be 100% reliable, as the actual
> list of buffers and the one used by the buffers tab are separate, and
> the buffers tab updates its own list in a way that is basically
> independent of the buffers list.

In case anyone is interested, here's what I did.  It's not exactly the 
solution to the original problem, and it's not efficient, but it's 
working well enough for me.

================================================================
(defun enumerated-format-buffers-tab-line (buffer)
   "To be used as a value for buffers-tab-format-buffer-line-function.
The text returned is buffer name prefixed with a number indicating
buffers position in the list of currently displayed buffer tabs."
   (format "(%d) %s"
       (position buffer (my-buffers-tab-items))
       (buffer-name buffer)))

(setq buffers-tab-format-buffer-line-function
       'enumerated-format-buffers-tab-line)

(defun switch-to-nth-buffer-tab (n)
   (switch-to-buffer (nth n (my-buffers-tab-items))))
================================================================


And now I bind those switches starting from 1, because 0 will always be 
the buffer which is currently displayed, so there's no need to bind it 
(which is nice, considering its position on the keyboard).

(global-set-key [(super ?1)] (lambda () (interactive) 		
       (switch-to-nth-buffer-tab 1)))
(global-set-key [(super ?2)] (lambda () (interactive)
       (switch-to-nth-buffer-tab 2)))
...


Note that I use function my-buffers-tab-items.  This function is a 
copy&paste of buffers-tab-items from gutter-items.el, with only 
difference that it returns a list of buffers instead of calling
(build-buffers-tab-internal buffers) and returning that.  When I get the 
time, maybe I'll take a shot at refactoring buffers-tab-items a bit to 
avoid this copy/paste.



More information about the XEmacs-Beta mailing list