From 987d2f9421bc854893673c234c02479583476785 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Sat, 13 Dec 2014 16:10:04 +0100 Subject: [PATCH] Implement a new function `directory-name-p' * doc/lispref/files.texi (Relative File Names): Mention `directory-name-p'. * etc/NEWS: Mention directory-name-p. (directory-name-p): New function. (directory-files-recursively): Use it. --- doc/lispref/ChangeLog | 4 ++++ doc/lispref/files.texi | 5 +++++ etc/ChangeLog | 4 ++++ etc/NEWS | 5 +++++ lisp/ChangeLog | 2 ++ lisp/files.el | 7 ++++++- 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 8f06881adc4..0d8458fabd1 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,7 @@ +2014-12-13 Lars Magne Ingebrigtsen + + * files.texi (Relative File Names): Mention `directory-name-p'. + 2014-12-13 Eli Zaretskii * text.texi (Comparing Text): Prevent a text string from being diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 92bb718e46a..b79d5df67c8 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -2020,6 +2020,11 @@ form. @end example @end defun +@defun directory-name-p filename +This function returns non-@code{nil} if @var{filename} ends with a +forward slash (@samp{/}) character. +@end defun + @node Directory Names @subsection Directory Names @cindex directory name diff --git a/etc/ChangeLog b/etc/ChangeLog index f56fb4ea683..5e02fced672 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog @@ -1,3 +1,7 @@ +2014-12-13 Lars Magne Ingebrigtsen + + * NEWS: Mention directory-name-p. + 2014-12-09 Lars Magne Ingebrigtsen * NEWS: Mention directory-files-recursively. diff --git a/etc/NEWS b/etc/NEWS index 58a5836a1c0..58e4b0e2cf1 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -140,6 +140,11 @@ library function `ftw'. ** A new function `directory-files-recursively' returns all matching files (recursively) under a directory. +** The new `directory-name-p' can be used to check whether a file +name (as returned from, for instance, `file-name-all-completions' is +a directory file name. It returns non-nil if the last character in +the name is a forward slash. + * Editing Changes in Emacs 25.1 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bc757189f60..6955c3c6cca 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -2,6 +2,8 @@ * files.el (directory-files-recursively): Really check whether files are symlinks. + (directory-name-p): New function. + (directory-files-recursively): Use it. 2014-12-13 Artur Malabarba diff --git a/lisp/files.el b/lisp/files.el index 2ab740d4a7f..d55ef1ad538 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -761,6 +761,11 @@ prevented. Directory entries are sorted with string-lessp." (file-name-nondirectory dir) args)))) +(defsubst directory-name-p (name) + "Return non-nil if NAME ends with a slash character." + (and (> (length name) 0) + (char-equal (aref name (1- (length name))) ?/))) + (defun directory-files-recursively (dir match &optional include-directories) "Return all files under DIR that have file names matching MATCH (a regexp). This function works recursively. Files are returned in \"depth first\" @@ -771,7 +776,7 @@ If INCLUDE-DIRECTORIES, also include directories that have matching names." (dolist (file (sort (file-name-all-completions "" dir) 'string<)) (unless (member file '("./" "../")) - (if (= (aref file (1- (length file))) ?/) + (if (directory-name-p file) (let* ((leaf (substring file 0 (1- (length file)))) (path (expand-file-name leaf dir))) ;; Don't follow symlinks to other directories. -- 2.39.2