IIUC, you want a function that will return the value of my/tab-order
in a given buffer. Then you can use that function the same way (well, almost) that you use buffer-name
to sort the buffers by name.
Since you are applying the function only to a list of buffers where my/tab-order
is defined, we'll dispense with checking whether the value exists and what to do if it does not: we'll assume it's there.
The function is simple:
(defun my/buffer-tab-order (buffer)
(with-buffer buffer
(list my/tab-order (buffer-name buffer))))
The function returns a two-element list consisting of the tab order of the buffer and its name (since ultimately, the buffer name is what you want).
We need a comparison function that can compare two such lists and tell us which one is smaller. It just needs to compare the tab order of each such list which is the first element:
(defun my/buffer-tab-order< (l1 l2)
(< (nth 0 l1) (nth 0 l2)))
Then we map it across the list of buffers of interest and sort the results, using our comparison function for the two-element list structure:
(defun my/sorted-buffer-list ()
(sort (mapcar #'my/buffer-tab-order (my-unsorted-buffer-list)) #'my/buffer-tab-order<))
This produces the sorted list of (tab-order buffer-name)
two-element lists. If you just want the buffer names only, just map a cadr
on the list:
(defun my/sorted-buffer-list ()
(mapcar #'cadr
(sort (mapcar #'my/buffer-tab-order (my-unsorted-buffer-list)) #'my/buffer-tab-order<)))
Untested. It should work modulo typos: let me know if you run into problems.
The idea of attaching a sort key to an object, sort by the key value and then strip the sort keys out, is a common (almost ubiquitous) one. Here's an example from "The AWK Programming Language" from 1988, but it certainly goes back much further.