-
Notifications
You must be signed in to change notification settings - Fork 70
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
[Help]: Faster way to search for directories recursively #117
Comments
A simple way to write what you are looking for would be the following (seq-uniq (mapcar #'f-parent
(f-files "~/org"
(lambda (f) (f-ext-p f "org"))
t))) To explain it simply, On average, it runs in 40ms in my Note also that this code currently returns absolute paths. If you wish to have relative paths, you can wrap this code in this (mapcar (lambda (f) (f-relative f "[root_dir]"))
;; The rest of your code
) I wanted to try to see if faster times could be achieved with Apparently you also ignore hidden files and directories. I will soon publish an update to (seq-uniq (mapcar #'f-parent
(f-files "~/org"
(lambda (f) (and (f-ext-p f "org")
(not (f-hidden-p f))))
t))) |
Hey, congratulations on the release, I saw your post on Reddit and decided to take a look at the project. I find this issue quite interesting, and while investigating things I've found that Another (or complementary) idea is to use something like generators or transducers.el to make things lazy. |
I've found that `f--collect-entries` doesn't use
`directory-files-recursive` but `directory-files`, and since the
former supports predicates, regexes, etc., in my experience it works
much faster (like a few seconds for my 170G $HOME).
This sounds interesting, is `directory-files' available on all Emacs
versions since Emacs 25? If not, we could still use it, but not
without checking the Emacs version at runtime. We should also check
with some benchmarks to see whether it is indeed faster before
implementing it in the main branch.
Another (or complementary) idea is to use something like generators
or transdusers.el to make things lazy.
I’m not sure I follow, can you share an example for what you mean?
…--
Lucien “Phundrak” Cartier-Tilet
<https://phundrak.com> (Français)
<https://phundrak.com/en> (English)
Sent from GNU/Emacs
|
Contact Details
@jingxlim
New feature
Hi, I wanted to preface this by saying that this is neither a feature request nor a bug report, and more like a cry for help.
I wanted my little script to help me find directories that contain
.org
files. I also wanted these directories to not be at any point, hidden. To this end, I am glad that I foundf.el
, which did all the heavy-lifting.Here are the few lines of code I wrote. Bear in mind that the following are literally the first few lines of Emacs Lisp I have written, ever, which is why I'm hoping to get some feedback. I also never took a course or went through a beginners tutorial on Emacs Lisp; and instead just decided to dive right into it just by looking particular things up. It's probably not the most Lisp-y (if there's even such a thing) and very verbose, but please bear with me!
So for the
root_directory
that I specified, this piece of code took somewhere from 1-2 minutes to run. Because I also hope to run this at the startup of Emacs, this speed won't do.On the other hand, something like the Linux tool
find
achieved the same thing in less than 5 seconds.Of course, I am not claiming that I wrote them the same way, so differences in performance is expected.
However, I do want to do this in Emacs, so I'm wondering if there are any ways I could improve on it, using
f.el
or otherwise (e.g. piping in the results fromfind
). In the case off-directories
, I understand that every directory is visited recursively, even if it is many layers deep into a hidden directory (e.g..git
). Perhaps one way is to write the program in a way that prevents this from happening.Any help is greatly appreciated! Thanks!
Why this new feature
f.el
is great! I just need help using it!Implementation ideas and additional thoughts
It could be implemented doing foo, bar, and baz
The text was updated successfully, but these errors were encountered: