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

ivy-sort-functions-alist default does not have an effect? #1561

Closed
raxod502 opened this issue May 11, 2018 · 6 comments

Comments

@raxod502
Copy link
Contributor

commented May 11, 2018

The documentation of ivy-sort-functions-alist claims that the function associated with t is used for fall-through cases:

(defcustom ivy-sort-functions-alist
  '((read-file-name-internal . ivy-sort-file-function-default)
    (internal-complete-buffer . nil)
    (counsel-git-grep-function . nil)
    (Man-goto-section . nil)
    (org-refile . nil)
    (t . string-lessp))
  "An alist of sorting functions for each collection function.
Interactive functions that call completion fit in here as well.

Nil means no sorting, which is useful to turn off the sorting for
functions that have candidates in the natural buffer order, like
`org-refile' or `Man-goto-section'.

A list can be used to associate multiple sorting functions with a
collection.  The car of the list is the current sort
function.  This list can be rotated with `ivy-rotate-sort'.

The entry associated with t is used for all fall-through cases.

See also `ivy-sort-max-size'.")

This does not seem to be the case. For example, with no specific customizations, the following code:

(ivy-read "Select a letter: " '("b" "c" "a") :sort t)

presents a menu with candidates in the order:

b
c
a

when ivy-sort-functions-alist says that the candidates should be sorted using string-lessp, which would result in:

a
b
c

Is this expected behavior?

@raxod502

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2018

Further testing reveals that the following code does not produce sorting either:

(ivy-read "Select a letter: " '("b" "c" "a") :sort #'string-lessp)
@raxod502

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2018

And apparently declaring the list as a "dynamic collection" makes the sorting work. What's going on?

(ivy-read "Select a letter: " (lambda (_) (list "b" "c" "a"))
          :sort t
          :dynamic-collection t)
@raxod502

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2018

Suggested fix: #1562

@basil-conto

This comment has been minimized.

Copy link
Collaborator

commented May 11, 2018

Further testing reveals that the following code does not produce sorting either:

I'm not sure how ivy--sort-maybe (which is touched in #1562) comes into the picture, but ivy--reset-state unconditionally interprets the :sort keyword as a boolean, not a function.

raxod502 added a commit to raxod502/swiper that referenced this issue May 11, 2018
@raxod502

This comment has been minimized.

Copy link
Contributor Author

commented May 11, 2018

Yes, I noticed that whether :sort is a boolean or a function seems to depend on which part of the codebase you look at. It's only documented to act as a boolean, but it does act as a function for dynamic collections at least. Perhaps that's another point for improvement.

@abo-abo

This comment has been minimized.

Copy link
Owner

commented May 12, 2018

unconditionally interprets the :sort keyword as a boolean, not a function.

This was the intention by design at the time: :sort is a bool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.