From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: iterating over a list while removing elements Date: 19 Mar 2014 18:28:35 GMT Message-ID: References: <87ioral4ck.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1395253810 31048 80.91.229.3 (19 Mar 2014 18:30:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Mar 2014 18:30:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 19 19:30:19 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WQLFq-0005G2-Aq for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Mar 2014 19:30:18 +0100 Original-Received: from localhost ([::1]:43174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQLFp-0003hO-Tv for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Mar 2014 14:30:17 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 43 Original-X-Trace: individual.net D+LQWrcPUqVqQJTgdlGFfwL/U7XvmcTxCYJ0M8GWHqG33jQ3Hs Cancel-Lock: sha1:K4h0fYsyRlZyhPHvzVCGvG/3258= Mail-Copies-To: nobody X-Editor: Emacs of course! User-Agent: slrn/pre1.0.0-18 (Linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:204364 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96635 Archived-At: 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)