emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r107434: Code and doc fixes for file-


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r107434: Code and doc fixes for file-subdir-of-p and files-equal-p.
Date: Sun, 26 Feb 2012 17:08:19 +0800
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 107434
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sun 2012-02-26 17:08:19 +0800
message:
  Code and doc fixes for file-subdir-of-p and files-equal-p.
  
  * lisp/files.el (files-equal-p): Doc fix.
  (file-subdir-of-p): Doc fix.  Convert loop macro to plain Lisp,
  and quit the loop once a mismatch is found.
  
  * doc/lispref/files.texi (Kinds of Files): Improve documentation of
  files-equal-p and file-subdir-of-p.
modified:
  doc/lispref/ChangeLog
  doc/lispref/files.texi
  doc/lispref/modes.texi
  lisp/ChangeLog
  lisp/files.el
=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog     2012-02-26 02:25:07 +0000
+++ b/doc/lispref/ChangeLog     2012-02-26 09:08:19 +0000
@@ -1,3 +1,8 @@
+2012-02-26  Chong Yidong  <address@hidden>
+
+       * files.texi (Kinds of Files): Improve documentation of
+       files-equal-p and file-subdir-of-p.
+
 2012-02-26  Glenn Morris  <address@hidden>
 
        * intro.texi (Acknowledgements): Small changes.

=== modified file 'doc/lispref/files.texi'
--- a/doc/lispref/files.texi    2012-02-25 15:31:07 +0000
+++ b/doc/lispref/files.texi    2012-02-26 09:08:19 +0000
@@ -1019,20 +1019,19 @@
 @end defun
 
 @defun files-equal-p file1 file2
-This function return @code{t} if the files @var{file1} and @var{file2} name
-the same file.
-Comparison is made with the @code{file-attributes} of both files. 
+This function returns @code{t} if the files @var{file1} and
address@hidden name the same file.  Two ordinary files are considered to
+be the same if the function @code{file-attributes} (@xref{File
+Attributes}) returns @code{equal} values for them.
 @end defun
 
 @defun file-subdir-of-p dir1 dir2
-This function return @code{t} if directory @var{dir1} is a subdirectory
-of @var{dir2} or if @var{dir1} and @var{dir2} are the same directory.
-Arguments @var{dir1} and @var{dir2} must be existing directories,
-otherwise, return nil.
-Check is done by building a directory name based on equality of differents
-components of both directory names, if this resulting directory name
-is equal to @var{dir2}, we assume directory @var{dir1}
-is a subdirectory of @var{dir2}.
+This function returns @code{t} if directory @var{dir1} is a
+subdirectory of @var{dir2}, or if @var{dir1} and @var{dir2} are the
+same directory.  It compares the @code{file-truename} values of the
+two directories (@pxref{Truenames}).  If either @var{dir1} or
address@hidden do not name existing directories, the return value is
address@hidden
 @end defun
 
 @node Truenames

=== modified file 'doc/lispref/modes.texi'
--- a/doc/lispref/modes.texi    2012-02-23 18:51:22 +0000
+++ b/doc/lispref/modes.texi    2012-02-26 09:08:19 +0000
@@ -1596,7 +1596,7 @@
 and @var{set} is a function of one argument (a state) that sets it.
 
 @item :after-hook @var{after-hook}
-This defines a single lisp form which is evaluated after the mode hooks
+This defines a single Lisp form which is evaluated after the mode hooks
 have run.  It should not be quoted.
 @end table
 

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-02-25 23:26:40 +0000
+++ b/lisp/ChangeLog    2012-02-26 09:08:19 +0000
@@ -1,3 +1,9 @@
+2012-02-26  Chong Yidong  <address@hidden>
+
+       * files.el (files-equal-p): Doc fix.
+       (file-subdir-of-p): Doc fix.  Convert loop macro to plain Lisp,
+       and quit the loop once a mismatch is found.
+
 2012-02-25  Juanma Barranquero  <address@hidden>
 
        * bs.el (bs--show-with-configuration): Don't throw an error

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2012-02-24 19:25:38 +0000
+++ b/lisp/files.el     2012-02-26 09:08:19 +0000
@@ -4986,7 +4986,9 @@
       (delete-directory-internal directory)))))
 
 (defun files-equal-p (file1 file2)
-  "Return non-nil if FILE1 and FILE2 name the same file."
+  "Return non-nil if FILE1 and FILE2 name the same file.
+Ordinary files are considered to be the same if `file-attributes'
+returns `equal' values for them."
   (let ((handler (or (find-file-name-handler file1 'files-equal-p)
                      (find-file-name-handler file2 'files-equal-p))))
     (if handler
@@ -4996,27 +4998,28 @@
 
 (defun file-subdir-of-p (dir1 dir2)
   "Return non-nil if DIR1 is a subdirectory of DIR2.
-Note that a directory is treated by this function as a subdirectory of itself.
-This function only works when its two arguments already exist,
-when they don't, it returns nil."
+A directory is considered to be a subdirectory of itself.
+Return nil if DIR1 or DIR2 are not existing directories."
   (let ((handler (or (find-file-name-handler dir1 'file-subdir-of-p)
                      (find-file-name-handler dir2 'file-subdir-of-p))))
     (if handler
         (funcall handler 'file-subdir-of-p dir1 dir2)
       (when (and (file-directory-p dir1)
                  (file-directory-p dir2))
-        (loop with f1 = (file-truename dir1)
-              with f2 = (file-truename dir2)
-              with ls1 = (or (split-string f1 "/" t) (list "/"))
-              with ls2 = (or (split-string f2 "/" t) (list "/"))
-              for p = (string-match "^/" f1)
-              for i in ls1
-              for j in ls2
-              when (string= i j)
-              concat (if p (concat "/" i) (concat i "/"))
-              into root
-              finally return
-              (files-equal-p (file-truename root) f2))))))
+       (setq dir1 (file-truename dir1)
+             dir2 (file-truename dir2))
+       (let ((ls1  (or (split-string dir1 "/" t) '("/")))
+             (ls2  (or (split-string dir2 "/" t) '("/")))
+             (root (if (string-match "\\`/" dir1) "/" ""))
+             (mismatch nil))
+         (while (and ls1 ls2 (not mismatch))
+           (if (string-equal (car ls1) (car ls2))
+               (setq root (concat root (car ls1) "/"))
+             (setq mismatch t))
+           (setq ls1 (cdr ls1)
+                 ls2 (cdr ls2)))
+         (unless mismatch
+           (files-equal-p (file-truename root) dir2)))))))
 
 (defun copy-directory (directory newname &optional keep-time parents 
copy-contents)
   "Copy DIRECTORY to NEWNAME.  Both args must be strings.


reply via email to

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