Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I define sorting order when narrowing down buffers list? #1492

Closed
pcompassion opened this issue May 3, 2016 · 3 comments
Closed

Can I define sorting order when narrowing down buffers list? #1492

pcompassion opened this issue May 3, 2016 · 3 comments

Comments

@pcompassion
Copy link

@pcompassion pcompassion commented May 3, 2016

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

@xuchunyang
Copy link
Member

@xuchunyang xuchunyang commented May 3, 2016

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.

@pcompassion
Copy link
Author

@pcompassion pcompassion commented May 3, 2016

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

@pheaver
Copy link

@pheaver pheaver commented May 2, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants