[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iterating over a list while removing elements

From: lee
Subject: Re: iterating over a list while removing elements
Date: Thu, 20 Mar 2014 17:10:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Michael Albinus <address@hidden> writes:

> lee <address@hidden> writes:
>> (defsubst multisearch-directory-ref-p (dots)
>>   "Return t when the string DOTS ends in a directory reference."
>>   (or
>>    (string-match "\\.$" dots)
>>    (string-match "\\.\\.$" dots)))
>> (defun multisearch-make-files-list (directory)
>>   "Return a list of files in DIRECTORY, with directory references
>> and directories removed."
>>   (let ((files-list (directory-files directory t)))
>>     (dolist (entry files-list files-list)
>>       (unless (and
>>             (not (multisearch-directory-ref-p entry))
>>             (file-directory-p entry)
>>             (file-readable-p entry))
>>      (setq files-list (delete entry files-list))))))
> Side remark: You don't need `multisearch-directory-ref-p' when applying
>   (let ((files-list (directory-files directory t 
> directory-files-no-dot-files-regexp)))

True --- and (not (file-directory-p entry) returns nil for directory
refs.  I`ve come to use the MATCH argument of `directory-files', though,
and `multisearch-directory-ref-p' is easier because then I don`t need to
figure out a regexp that matches MATCH but not "." or "..".  And a
string match is less expensive than a file look-up ...

Which reminds me that I should put something in to save all file look-ups
for files which already are in buffers because they are not needed then

Knowledge is volatile and fluid.  Software is power.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]