From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] master 3431e82: Ignore directory symlinks in directory-files-recursively Date: Sun, 14 Dec 2014 10:33:39 +0100 Message-ID: References: <20141212105304.4186.22515@vcs.savannah.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1418549660 16910 80.91.229.3 (14 Dec 2014 09:34:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Dec 2014 09:34:20 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 14 10:34:14 2014 Return-path: Envelope-to: ged-emacs-devel@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 1Y05Z8-0000yg-5j for ged-emacs-devel@m.gmane.org; Sun, 14 Dec 2014 10:34:14 +0100 Original-Received: from localhost ([::1]:35453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y05Z7-00074t-Nk for ged-emacs-devel@m.gmane.org; Sun, 14 Dec 2014 04:34:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y05Yy-00073u-Ve for emacs-devel@gnu.org; Sun, 14 Dec 2014 04:34:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y05Yt-0007xz-G6 for emacs-devel@gnu.org; Sun, 14 Dec 2014 04:34:04 -0500 Original-Received: from hermes.netfonds.no ([80.91.224.195]:54446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y05Yt-0007xf-5G for emacs-devel@gnu.org; Sun, 14 Dec 2014 04:33:59 -0500 Original-Received: from cm-84.215.51.58.getinternet.no ([84.215.51.58] helo=stories.gnus.org) by hermes.netfonds.no with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Y05YZ-0004dw-VC; Sun, 14 Dec 2014 10:33:40 +0100 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEUsBgoGAQLw0YrDXCsu CgsZAwZCERCCIxoS5R0JAAACVklEQVQ4jW2US2/bMBCEGTRurhVgyneqaO/a1Lw6qCRfI0BrX1OY Iq9B6HD/fofyI3JaAgLs/TSzOyRtVRTF81j8uxQevfgfWD4ti/SnLFM5L9/fqVUyZKraVIa+X+va j2plruvHDLwo7Vrm378GblvXf4BG9ck7533As7lOpx2rwQffheRDStpfJb1WrP2uLRu3G7ti+XSu M8adXtL9tTB9bU8BZxX/1Td4qb+Ccz0I1kt/2ZLbusj4GZzrkvpbsJMLGG/AMghVNWXS3DQPUlNN xkry/m4Gyki1ofqt+gweIlXZChK3mVlpIcqS3OXIs+arSJYMTowqmxYzEGIWGAMvklmP7BQzqKq6 Inm9glIqWE0SNMrZz2APgJVPHrfCTkCftq9CujOA16JXBWNolpOiPl0XNGEoel18E4GBnCQmf2zR gwm9Y03WxzOA2gKsCL1jXVnXfZhlsLd6KwIwcrQXTQZbm880GoAHobPXpFh/sRKi+Sl+M4h5Q3qy r5NVRFZ4IdhLR7GSdUo8AcqAsIFWNiGZR8ucQUAymwLlKaUdfD167nPALmXQYXOxFy13XTtwwYr7 AcFsaqTOe7GASzudID50B4AWXsi1aVCAoFeaO9QoNRgYXsk3+IUNwSl+9qNcgEF71/pxG0UNXePR 3EJWZ0k8urDeSwYukJDl3XTmltbuYMvHTukOGxVwl3ifu/t4bHeCyVSx3Cc3yHHkgepKGnlnFm7e kbzErd81iflAUTqPeMzbI4DOeYajLLZ0IHffDph3G6d/n3x/krzucLVG5AbYy1916/bpmPelkAAA AABJRU5ErkJggg== X-Now-Playing: Various's _LateNightTales - Franz Ferdinand_: "Justus =?iso-8859-1?Q?K=F6hncke?= - Old Man" X-Hashcash: 1:23:141214:emacs-devel@gnu.org::ovmQKk7EFfKQzCKl:000000000000000000000000000000000000000000E/ZZ X-Hashcash: 1:23:141214:monnier@iro.umontreal.ca::5Dy8MBRqL5lQOTjA:0000000000000000000000000000000000000hkza In-Reply-To: (Stefan Monnier's message of "Sat, 13 Dec 2014 23:59:57 -0500") User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-MailScanner-ID: 1Y05YZ-0004dw-VC MailScanner-NULL-Check: 1419154420.04063@tQxD2swW8Pay5O7AeF/9ZA X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.224.195 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:180061 Archived-At: Stefan Monnier writes: >> As you pointed out, `file-tree-walk' has the nice property that it can >> stop recursing based on a predicate, so implementing it on >> `directory-files-recursively' would not be optimal. > > Right, what is needed is to extend directory-files-recursively such that > it can also use a predicate to decide whether to recurse or not. file-tree-walk uses the same function for the predicate and for the ... processing function. So that would be something like the patch included below. The interface isn't the same, though. I think we should perhaps ignore the non-lexical case and get rid of the ARGS argument. Supplying a lexical lambda predicate just makes more sense. And I don't like passing in the DIR and LEAF separately. To check whether the argument is a directory, the predicate can just use `directory-name-p' . diff --git a/lisp/files.el b/lisp/files.el index d55ef1a..14be6c2 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -766,11 +766,17 @@ prevented. Directory entries are sorted with string-lessp." (and (> (length name) 0) (char-equal (aref name (1- (length name))) ?/))) -(defun directory-files-recursively (dir match &optional include-directories) +(defun directory-files-recursively (dir match &optional + include-directories predicate) "Return all files under DIR that have file names matching MATCH (a regexp). This function works recursively. Files are returned in \"depth first\" and alphabetical order. -If INCLUDE-DIRECTORIES, also include directories that have matching names." +If INCLUDE-DIRECTORIES, also include directories that have matching names. + +If PREDICATE, this should be a function that will be called on +each matching file and on all directories. When called on a +directory, the predicate should return non-nil if the directory +should be descended into." (let ((result nil) (files nil)) (dolist (file (sort (file-name-all-completions "" dir) @@ -780,13 +786,17 @@ If INCLUDE-DIRECTORIES, also include directories that have matching names." (let* ((leaf (substring file 0 (1- (length file)))) (path (expand-file-name leaf dir))) ;; Don't follow symlinks to other directories. - (unless (file-symlink-p path) + (when (and (not (file-symlink-p path)) + (or (null predicate) + (funcall predicate path))) (setq result (nconc result (directory-files-recursively path match include-directories)))) (when (and include-directories (string-match match leaf)) (setq result (nconc result (list path))))) (when (string-match match file) + (when predicate + (funcall predicate (expand-file-name file dir))) (push (expand-file-name file dir) files))))) (nconc result (nreverse files)))) -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no