1

By default speedbar displays buffers as they are in the buffer list. Is there a way to sort them by their name alphabetically, either automatically or by triggering the sorting?

1
(require 'speedbar)

(defun speedbar-buffer-buttons-engine (temp)
  "Create speedbar buffer buttons.
If TEMP is non-nil, then clicking on a buffer restores the previous display."
  (speedbar-insert-separator "Active Buffers:")
  (let* ((bl (buffer-list))
         (abl ;; alphabetized buffer-list
           (sort
              bl
              #'(lambda (e1 e2)
                  (string-lessp (buffer-name e1) (buffer-name e2)))))
          (case-fold-search t))
    (while abl
      (if (string-match "^[ *]" (buffer-name (car abl)))
    nil
  (let* ((known (string-match speedbar-file-regexp
            (buffer-name (car abl))))
         (expchar (if known ?+ ??))
         (fn (if known 'speedbar-tag-file nil))
         (fname (with-current-buffer (car abl)
                        (buffer-file-name))))
    (speedbar-make-tag-line 'bracket expchar fn
          (if fname (file-name-nondirectory fname))
          (buffer-name (car abl))
          'speedbar-buffer-click temp
          'speedbar-file-face 0)
    (speedbar-buffers-tail-notes (car abl))))
      (setq abl (cdr abl)))
    (setq bl (buffer-list)
          abl ;; alphabetized buffer-list
           (sort
              bl
              #'(lambda (e1 e2)
                  (string-lessp (buffer-name e1) (buffer-name e2)))))
    (speedbar-insert-separator "Scratch Buffers:")
    (while abl
      (if (not (string-match "^\\*" (buffer-name (car abl))))
    nil
  (if (eq (car abl) speedbar-buffer)
      nil
    (speedbar-make-tag-line 'bracket ?? nil nil
          (buffer-name (car abl))
          'speedbar-buffer-click temp
          'speedbar-file-face 0)
    (speedbar-buffers-tail-notes (car abl))))
      (setq abl (cdr abl)))
    ;; Need to research why this last line is needed (if at all)?
    (setq bl (buffer-list))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.