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

Port ido-file-extension-order #453

Closed
ThibautVerron opened this issue Mar 30, 2016 · 7 comments
Closed

Port ido-file-extension-order #453

ThibautVerron opened this issue Mar 30, 2016 · 7 comments

Comments

@ThibautVerron
Copy link
Contributor

It would be nice to have a feature similar to ido-file-extension-order: it allows to specify a set of extensions which should be shown first in the file list. It is the same idea as "boring files", except that the unwanted extensions are still shown if needed, just further down the list.

The following seems to do the job on a system where ido is available:

(defun ivy-sort-file-function-using-ido-extensions (a b)
  (if (and (boundp 'ido-file-extensions-order)
           ido-file-extensions-order)
      (ido-file-extension-lessp a b)
    (ivy-sort-file-function-default a b)))

(setq ivy-sort-functions-alist
      (cons (cons 'read-file-name-internal 'ivy-sort-file-function-using-ido-extensions)
            (cdr ivy-sort-functions-alist)))

It is quite unefficient because it will test for ido-file-extensions-order at each comparison... so merely a proof of concept.

By the way, is there a good reason for functions in ivy-sort-functions-alist to be restricted to 3 values?

@abo-abo
Copy link
Owner

abo-abo commented Mar 30, 2016

It is quite unefficient because it will test for ido-file-extensions-order at each comparison... so merely a proof of concept.

Could be good enough. The sorting is performed only once per collection, i.e. just after you enter a directory.

By the way, is there a good reason for functions in ivy-sort-functions-alist to be restricted to 3 values?

I don't understand what you mean here.

@ThibautVerron
Copy link
Contributor Author

Oh, my bad, I forgot the end of the sentence. I meant the configuration interface for the variable:

    :value-type (choice
                 (const :tag "Plain sort" string-lessp)
                 (const :tag "File sort" ivy-sort-file-function-default)
                 (const :tag "No sort" nil)))

@abo-abo
Copy link
Owner

abo-abo commented Mar 30, 2016

Feel free to PR with a new sorting option.

@ThibautVerron
Copy link
Contributor Author

The question was rather "why isn't it a free-form field"? For example if a user wants to implement his own comparison function, he has to modify the variable in elisp, he can't use customize.

As for the ido-sort thing, I'll try to submit a PR this week-end.

@abo-abo
Copy link
Owner

abo-abo commented Mar 31, 2016

why isn't it a free-form field

Should have just said so:)

@abo-abo
Copy link
Owner

abo-abo commented May 3, 2016

It is quite unefficient because it will test for ido-file-extensions-order at each comparison... so merely a proof of concept.

Why exactly should this be inefficient? The sorting in ivy-sort-functions-alist is performed only once per current directory change. Just test the code as-is and open a PR. The sorting doesn't have to be on by default.

@ThibautVerron
Copy link
Contributor Author

ThibautVerron commented May 3, 2016 via email

ThibautVerron added a commit to ThibautVerron/swiper that referenced this issue May 3, 2016
This is just the sorting function, as suggested in issue abo-abo#453.

I'm not sure of how this option is best presented to the user.
Also, in the long term, it would probably be a good idea to create a "purely ivy" variable replacing `ido-file-extensions-order`, in which case the new function could completely replace the default function.
@abo-abo abo-abo closed this as completed in 23d7c74 May 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants