Function: tab-line-tabs-fixed-window-buffers
tab-line-tabs-fixed-window-buffers is a byte-compiled function defined
in tab-line.el.gz.
Signature
(tab-line-tabs-fixed-window-buffers)
Documentation
Like tab-line-tabs-window-buffers but keep stable sorting order.
This means that switching to a buffer previously shown in the same window will keep the same order of tabs that was before switching. And newly displayed buffers are added to the end of the tab line.
Probably introduced at or before Emacs version 30.1.
Source Code
;; Defined in /usr/src/emacs/lisp/tab-line.el.gz
(defun tab-line-tabs-fixed-window-buffers ()
"Like `tab-line-tabs-window-buffers' but keep stable sorting order.
This means that switching to a buffer previously shown in the same
window will keep the same order of tabs that was before switching.
And newly displayed buffers are added to the end of the tab line."
(let* ((old-buffers (window-parameter nil 'tab-line-buffers))
(buffer-positions (let ((index-table (make-hash-table
:size (length old-buffers)
:test #'eq)))
(seq-do-indexed
(lambda (buf idx) (puthash buf idx index-table))
old-buffers)
index-table))
(new-buffers (sort (tab-line-tabs-window-buffers)
:in-place t
:key (lambda (buffer)
(gethash buffer buffer-positions
most-positive-fixnum)))))
(set-window-parameter nil 'tab-line-buffers new-buffers)
new-buffers))