[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: empty-directory predicate, native implementation
From: |
Arthur Miller |
Subject: |
Re: empty-directory predicate, native implementation |
Date: |
Sat, 17 Oct 2020 22:27:28 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Drew Adams <drew.adams@oracle.com> writes:
> Sorry I'm coming to this late. It's a long thread,
> and I've only checked your patch, not the messages.
>
> I don't understand why we would do this. Is the
> real aim to be able to have an empty-directory
> predicate, i.e., to be able to see if there are
> no files in a directory?
Yes.
> If so, then why not do just that, witout
> bothering (changing the signature of)
> `directory-files'?
Because it is not possible to that efficiently with current elisp; how
would you do that directly? OS does not have such call, one have to
iterate through directories. At least I am not aware of such call. If
you know, please tell me, I would be happy to use it, at least for myself.
Fastest I am aware of is to get a buffered list with SYS_getdents and then
check for first non-dot file. That changes complexity from linear in
number of files in directory to constant (3 files at max). It works only
on Linux kernel, and I don't know if there is nt version of such call,
or what there is on macs.
I suggested such predicate, but to not re-iterate entire discussion, pls
check my first mail and followed 2 or 3 I think.
> Is there really some use case for getting only
> the first N files in a directory? I can
> understand wanting to test whether a dir is
> empty. I can't see why someone would want the
> first N files (however "first" might be defined).
Probably not; it is just a result of having count parameter.
> The doc string itself seems to suggest that the
> (only?) use case is to test for emptiness:
>
> You can use this function to short circuit evaluation
> in case you are just interested to find if a directory
> is empty or not (request one file and tell it to
> ignore dot-files).
It does not say only, but it suggests it can be usd in that way. But
yes, that was the driver behind.
Check the attachment; maybe something you would like to have in Dired+?
I don't know if it could become a part of Dired itself, I believe it is
probably too niche and subjective.
> That need is clear enough. But what else is
> COUNT useful for? How about having the doc
> string also tell us what we can use a COUNT
> value > 1 for? That's the case that really
> needs pointing out, not the empty-dir-p case.
>
> And what is the order that defines which file
> is first, second, etc.? Without knowing that,
> what use is getting the "first" N?
OS.
There is no hard guarantee by OS:s that you will get files in
particular order. I had that sentence in docs, but it was a bit too
verse. I am not very literal of me, if you can phrase it better and more
concise, please go ahead, I would appreciate. Check all docs if you have
time and feel for it, I always need help with the language.
> If this has already been raised, discussed,
> and dismissed, fine - apologies for the noise.
> If not, what's the raison d'etre for adding
> optional parameter COUNT?
I hope you don't mind me snitching your regex for nodots. I was trying
to get one fast myself, and gave up after half hour, would never thought
it was so picky to get that one right.
> Why not just add a predicate `directory-empty-p'?
:-) Check my first mail. I implemented one with that name.
Best regards
/a
dired-mark-empty-dirs.el
Description: Text document
- Re: empty-directory predicate, native implementation, (continued)
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/15
- Re: empty-directory predicate, native implementation, Michael Albinus, 2020/10/15
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/15
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/15
- Re: empty-directory predicate, native implementation, Michael Albinus, 2020/10/15
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/15
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/16
- Re: empty-directory predicate, native implementation, Michael Albinus, 2020/10/17
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/17
- RE: empty-directory predicate, native implementation, Drew Adams, 2020/10/17
- Re: empty-directory predicate, native implementation,
Arthur Miller <=
- RE: empty-directory predicate, native implementation, Drew Adams, 2020/10/17
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/17
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/17
- RE: empty-directory predicate, native implementation, Drew Adams, 2020/10/17
- Re: empty-directory predicate, native implementation, Arthur Miller, 2020/10/17
- Re: empty-directory predicate, native implementation, Michael Albinus, 2020/10/18
- Re: empty-directory predicate, native implementation, Eli Zaretskii, 2020/10/17
- RE: empty-directory predicate, native implementation, Drew Adams, 2020/10/18
- Re: empty-directory predicate, native implementation, Michael Albinus, 2020/10/18
- RE: empty-directory predicate, native implementation, Drew Adams, 2020/10/18