1

I alphabetize my tabs when using the tabbar.el library https://marmalade-repo.org/packages/tabbar. As you may already know, sorting is costly. I have a feeling that this sorting is even more costly when I have several frames open and buffers displayed in each frame. I would like to optimize this using a tried and true concept where a previous value is stored to a variable and recalculation using sort is only done when something has changed; e.g., a buffer added/deleted from the buffer-list. However, I'm not sure how to implement that familiar tried and true concept in this particular context -- especially since figuring out whether a buffer has been added or deleted could also be costly. How can this optimization be achieved?

;; redefine tabbar-add-tab so that it alphabetizes / sorts the tabs
(defun tabbar-add-tab (tabset object &optional append)
  "Add to TABSET a tab with value OBJECT if there isn't one there yet.
If the tab is added, it is added at the beginning of the tab list,
unless the optional argument APPEND is non-nil, in which case it is
added at the end."
  (let ((tabs (tabbar-tabs tabset)))
    (if (tabbar-get-tab object tabset)
        tabs
      (let* (
          (tab (tabbar-make-tab object tabset))
          (tentative-new-tabset
            (if append
              (append tabs (list tab))
              (cons tab tabs)))
          (new-tabset
            (sort
               tentative-new-tabset
               #'(lambda (e1 e2)
                  (string-lessp
                    (format "%s" (car e1)) (format "%s" (car e2)))))))
        (tabbar-set-template tabset nil)
        (set tabset new-tabset)))))

In the event that it makes a difference to the above question, I am organizing and adding/removing tabs dynamically using a concept implemented by Alp Aker in the frame-bufs library -- i.e., the frame-local value for associated buffers are stored in the frame-parameters of each frame. The code that I use to achieve this frame-local buffer association with the tabbar.el library is contained in the following linked answer: https://emacs.stackexchange.com/a/10112/2287

lawlist
  • 18,826
  • 5
  • 37
  • 118

0 Answers0