emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-25 eca277f: Fix documentation and implementation of


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-25 eca277f: Fix documentation and implementation of 'directory-name-p'
Date: Thu, 03 Dec 2015 15:00:58 +0000

branch: emacs-25
commit eca277f937f4c51b83fa0f156b8081e88ea3f121
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix documentation and implementation of 'directory-name-p'
    
    * lisp/files.el (directory-name-p): Modify to recognize
    backslashes on MS-Windows and MS-DOS.  Adjust the doc string
    accordingly.  Use '=', not char-equal, for comparison, as
    letter-case cannot possibly be an issue here.
    
    * doc/lispref/files.texi (Directory Names): Move the documentation
    of directory-name-p here from "Relative File Names".  Update the
    description per the changes in implementation.
    
    * etc/NEWS: Move the entry for 'directory-name-p' to its proper
    place and mark it documented.
---
 doc/lispref/files.texi |   12 +++++++-----
 etc/NEWS               |   12 +++++++-----
 lisp/files.el          |   11 ++++++++---
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index e8ed7cc..918bf5b 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -2030,11 +2030,6 @@ form.
 @end example
 @end defun
 
address@hidden directory-name-p filename
-This function returns address@hidden if @var{filename} ends with a
-forward slash (@samp{/}) character.
address@hidden defun
-
 @node Directory Names
 @subsection Directory Names
 @cindex directory name
@@ -2076,6 +2071,13 @@ string (if it does not already end in one).
 @end example
 @end defun
 
address@hidden directory-name-p filename
+This function returns address@hidden if @var{filename} ends with a
+directory separator character.  This is the forward slash @samp{/} on
+Unix and GNU systems; MS-Windows and MS-DOS recognize both the forward
+slash and the backslash @samp{\} as directory separators.
address@hidden defun
+
 @defun directory-file-name dirname
 This function returns a string representing @var{dirname} in a form
 that the operating system will interpret as the name of a file (a
diff --git a/etc/NEWS b/etc/NEWS
index bd7435b..fa43a7f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -181,11 +181,6 @@ for use in Emacs bug reports.
 hiding character but the default `.' can be used by let-binding the
 variable `read-hide-char'.
 
-** The new function `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.
-
 ** The function `font-info' now returns more details about a font.
 In particular, it now returns the average width of the font's
 characters, which can be used for geometry-related calculations.
@@ -1302,6 +1297,13 @@ integers.
 ** New function `set-binary-mode' allows to switch a standard stream
 of the Emacs process to binary I/O mode.
 
++++
+** The new function `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 directory separator character (forward slash on GNU and
+Unix systems, forward- or backslash on MS-Windows and MS-DOS).
+
 ** ASCII approximations to curved quotes are put in standard-display-table
 if the terminal cannot display curved quotes.
 
diff --git a/lisp/files.el b/lisp/files.el
index f37c23b..d20bb14 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -740,9 +740,14 @@ The path separator is colon in GNU and GNU-like systems."
        (error "No such directory found via CDPATH environment variable"))))
 
 (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))) ?/)))
+  "Return non-nil if NAME ends with a directory separator character."
+  (let ((len (length name))
+        (lastc ?.))
+    (if (> len 0)
+        (setq lastc (aref name (1- len))))
+    (or (= lastc ?/)
+        (and (memq system-type '(windows-nt ms-dos))
+             (= lastc ?\\)))))
 
 (defun directory-files-recursively (dir regexp &optional include-directories)
   "Return list of all files under DIR that have file names matching REGEXP.



reply via email to

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