From: Joost Kremers <joost.m.kremers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: iterating over a list while removing elements
Date: 19 Mar 2014 18:28:35 GMT [thread overview]
Message-ID: <slrnlijoej.9nq.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> (raw)
In-Reply-To: 87ioral4ck.fsf@kuiper.lan.informatimago.com
Pascal J. Bourguignon wrote:
> (require 'cl)
>
> (defun multisearch-make-files-list (directory)
> "Return a list of files in DIRECTORY, with directory references
> and directories removed."
> (remove-if (lambda (entry)
> (and (not (multisearch-directory-ref-p entry))
> (file-directory-p entry)
> (file-readable-p entry)))
> (directory-files directory t)))
Or use --remove from the dash library. No need for lambda:
(require 'dash)
(defun multisearch-make-files-list (directory)
"Return a list of files in DIRECTORY, with directory references
and directories removed."
(--remove (or (multisearch-directory-ref-p it) ; or seems to better express the intention of the doc string.
(file-directory-p it)
(not (file-readable-p it)))
(directory-files directory t)))
It's less portable, though, because dash doesn't come with Emacs.
Note, BTW, that file-directory-p returns t for "." and "..". It seems to
me that the only two names that directory-files could return that you
really want to exclude are those two,[1] so there's no need for
multisearch-directory-ref-p, I think. (Or is there?)
Joost
[1] Files can have dots in their names, so what do you want to do with a
file whose name ends in a dot? Or two? Unlikely, for sure, but not
impossible.
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
next prev parent reply other threads:[~2014-03-19 18:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.17526.1395229207.10748.help-gnu-emacs@gnu.org>
2014-03-19 13:12 ` iterating over a list while removing elements Pascal J. Bourguignon
2014-03-19 18:28 ` Joost Kremers [this message]
2014-03-20 17:34 ` lee
2014-03-20 20:16 ` Eli Zaretskii
2014-03-21 5:25 ` lee
2014-03-20 16:33 ` lee
2014-03-19 11:39 lee
2014-03-19 12:39 ` Stefan
2014-03-20 16:02 ` lee
2014-03-19 13:11 ` Michael Albinus
2014-03-20 16:10 ` lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=slrnlijoej.9nq.joost.m.kremers@j.kremers4.news.arnhem.chello.nl \
--to=joost.m.kremers@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.