Helm: Can I define sorting order when narrowing down buffers list?

Created on 3 May 2016  路  3Comments  路  Source: emacs-helm/helm

I 'd like to get LRU order results even when narrowing down the buffer lists.

Most helpful comment

So glad I found this! The default behavior is very confusing for me: When I see a sorted list in front of me, and I start typing to narrow it down, the order changes. Very often I want the first result that matches a pattern, so I start typing that pattern and expect to be able to hit enter on the first result. But that doesn't happen, because the results are re-sorted.

Is there a reason one would want the sort order to be different before and after they start entering a query?

I would think a lot of users would want the behavior from your provided example by default, and it would be nice if that behavior were explicitly supported or documented.

All 3 comments

The current sorting is done in

(defun helm-buffers-sort-transformer (candidates _source)
  (if (string= helm-pattern "")
      candidates
    (sort candidates
          (lambda (s1 s2)
              (< (string-width s1) (string-width s2))))))

so you can advice this function to do your own sorting. Something like

(defun helm-buffers-sort-transformer@donot-sort (_ candidates _)
  candidates)

(advice-add 'helm-buffers-sort-transformer :around 'helm-buffers-sort-transformer@donot-sort)

then helm will preserve the initial sorting order made by helm-buffer-list, if you don't like the initial order, advice helm-buffer-list as you like.

wow, perfect, wonder why it's not a default behavior.

So glad I found this! The default behavior is very confusing for me: When I see a sorted list in front of me, and I start typing to narrow it down, the order changes. Very often I want the first result that matches a pattern, so I start typing that pattern and expect to be able to hit enter on the first result. But that doesn't happen, because the results are re-sorted.

Is there a reason one would want the sort order to be different before and after they start entering a query?

I would think a lot of users would want the behavior from your provided example by default, and it would be nice if that behavior were explicitly supported or documented.

Was this page helpful?
0 / 5 - 0 ratings