How to set a custom sort order for helm-find-files?

189 views
Skip to first unread message

George T. Halifax

unread,
Mar 9, 2015, 9:06:46 PM3/9/15
to emacs...@googlegroups.com
In a basic LaTeX project, typically the only file the user will open themselves is the file ending with the extension .tex . However there are many files generated after compilation with the same name, but different extensions (such as .pdf, .log, .aux). As many of these files appear alphabetically before .tex, it requires you to begin typing the file extension before the desired file is selected. There does seem to be a list (helm-boring-file-regexp-list), one application of which is to ignore files/directories with particular extensions. However occasionally I might want to open the pdf file, or view the log, and so permanently hiding these files is not a good solution.

In the similar project ido, there is something called ido-file-extensions-order, which allows one to set precedence for certain file extensions. I was wondering if there was anything available already in helm which can achieve this, and if not, if it could be added as a feature?

Eric Abrahamsen

unread,
Mar 9, 2015, 9:30:00 PM3/9/15
to emacs...@googlegroups.com
"George T. Halifax"
You could just type "tex" at the file-name prompt, that ought to go
straight to the file you want, doesn't it?

George T. Halifax

unread,
Mar 9, 2015, 11:53:02 PM3/9/15
to emacs...@googlegroups.com, er...@ericabrahamsen.net
Yes that is true, however it just adds to the total number of keystrokes required, and feels very inefficient when opening many different .tex files (hence the post). There should be a way for me to let helm know in advance that the vast majority of the time I will prefer .tex files over files with the same name but a different extension.

Eric Abrahamsen

unread,
Mar 10, 2015, 12:20:05 AM3/10/15
to emacs...@googlegroups.com
"George T. Halifax"
<georget...@gmail.com> writes:

> Yes that is true, however it just adds to the total number of
> keystrokes required, and feels very inefficient when opening many
> different .tex files (hence the post). There should be a way for me to
> let helm know in advance that the vast majority of the time I will
> prefer .tex files over files with the same name but a different
> extension.

I may still be misunderstanding you...

If there's only one tex file in a directory, you _only_ have to type
"tex", not the filename at all. If there are multiple tex files in a
directory, you can type "tex" first, to narrow down to those files, then
a space, then a few letters from the filename. Ie, the strings don't
have to be in the "right order." That ends up being very little typing!

Unless I'm still not getting it...

George T. Halifax

unread,
Mar 10, 2015, 12:43:15 AM3/10/15
to emacs...@googlegroups.com, er...@ericabrahamsen.net
No you've got it. I'm basically griping over having to type the extra 3 characters.

But the reason why I'm griping is that I don't feel as though I should ever have to type them, because the vast majority of the time the tex file is what I will be opening, and rarely do I ever touch the other files with different extensions. If I can comminicate this to helm somehow, then I can save typing those characters every time I open a tex file (which happens quite a lot -- those characters do add up, not to mention that it requires that slightly greater amount of conscious thought which can be enough to derail trains of thought). When I think about opening the file, I shouldn't have to consciously decide to open the tex file, I should only need to make the conscious decision if I decide to open one of the other files.

Besides, I think it highlights an greater issue: namely that certain people may not find the alphabetic sorting to be the most efficient for them, most of the time. Ideally, there would be some mechanism by which users could write and customize their own "sort function" which sorts the files optimally for their needs.

Thierry Volpiatto

unread,
Mar 10, 2015, 2:14:14 AM3/10/15
to emacs...@googlegroups.com, er...@ericabrahamsen.net

George T. Halifax <georget...@gmail.com> writes:

> No you've got it. I'm basically griping over having to type the extra 3 characters.
>
> But the reason why I'm griping is that I don't feel as though I should ever have to type them, because the vast majority of the time the tex file is what I will be
> opening, and rarely do I ever touch the other files with different extensions. If I can comminicate this to helm somehow, then I can save typing those characters
> every time I open a tex file (which happens quite a lot -- those characters do add up, not to mention that it requires that slightly greater amount of conscious
> thought which can be enough to derail trains of thought). When I think about opening the file, I shouldn't have to consciously decide to open the tex file, I should
> only need to make the conscious decision if I decide to open one of the other files.
>
> Besides, I think it highlights an greater issue: namely that certain
> people may not find the alphabetic sorting to be the most efficient
> for them, most of the time.

It is not and helm-find-files is not sorting alphabetically.

> Ideally, there would be some mechanism by which users could write and
> customize their own "sort function" which sorts the files optimally
> for their needs.

(defmethod helm-setup-user-source ((source helm-source-ffiles))
(oset source :filtered-candidate-transformer 'my-own-sort-function))

Be sure to load helm-files or use some eval-after-load with this.
You will have to write a sort function with two args "S1" and "S2" and
`my-own-sort-function' will take two args "CANDIDATES" and "_SOURCE".
Sorting will happen on "CANDIDATES", "_SOURCE" will stay unused.

--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
Reply all
Reply to author
Forward
0 new messages