When I run M-x helm-buffers-list it shows list of buffers in the order of their last visit.

enter image description here

Since I open quite a few dired buffers, when helm-buffers-list is invoked, dired buffers are occupying lots of visible space.

How can i move all dired buffers to bottom and have other files at top?

  • 1
    I guess you can advice helm-buffers-sort-transformer. BTW, you can use *!dired to filter out all Dired buffers. – xuchunyang Oct 6 '15 at 15:03

helm-buffers-sort-transformer is used to sort buffers.

(defun sort-dired-buffers (buffers)
  "Sort BUFFERS by moving all Dired buffers to the end."
  (let (dired-buffers other-buffers)
    (dolist (buf buffers)
      (if (with-current-buffer buf
            (eq major-mode 'dired-mode))
          (push buf dired-buffers)
        (push buf other-buffers)))
    (nreverse (append dired-buffers other-buffers))))

(defun helm-buffers-sort-dired-buffers (orig-fun &rest args)
  (sort-dired-buffers (apply orig-fun args)))

(advice-add 'helm-buffers-sort-transformer :around #'helm-buffers-sort-dired-buffers)

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.