]> code.delx.au - gnu-emacs/commitdiff
Fix documentation and implementation of 'directory-name-p'
authorEli Zaretskii <eliz@gnu.org>
Thu, 3 Dec 2015 14:59:42 +0000 (16:59 +0200)
committerEli Zaretskii <eliz@gnu.org>
Thu, 3 Dec 2015 14:59:42 +0000 (16:59 +0200)
* 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
etc/NEWS
lisp/files.el

index e8ed7ccd9f7fcf1726e08ee30c38dfc0a18aff6c..918bf5becbd81b6fff29d8a9a13501da0baf0b74 100644 (file)
@@ -2030,11 +2030,6 @@ 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
@@ -2076,6 +2071,13 @@ string (if it does not already end in one).
 @end example
 @end defun
 
+@defun directory-name-p filename
+This function returns non-@code{nil} 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.
+@end 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
index bd7435b1760e095c50846fbb2151f754db0be166..fa43a7f9f6a09d8465502215ee565d9d68ea19d0 100644 (file)
--- 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.
 
index f37c23b7bdd5f0665e0b7228840cc40ac2f46b7d..d20bb1401fab4e801f1938f0750947a458684269 100644 (file)
@@ -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.