diff options
| author | Chong Yidong | 2012-02-26 17:08:19 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-02-26 17:08:19 +0800 |
| commit | 9a4888c093e829c13f3dd27efd85331aeeb44696 (patch) | |
| tree | 6038ddfe8a945682cf84bd1e40c35430f41782b0 /lisp | |
| parent | f0e751b92f2bdf4815607a5d4a2c4ab593315c9d (diff) | |
| download | emacs-9a4888c093e829c13f3dd27efd85331aeeb44696.tar.gz emacs-9a4888c093e829c13f3dd27efd85331aeeb44696.zip | |
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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/files.el | 35 |
2 files changed, 25 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f585be4ec34..418be2539b6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-02-26 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * files.el (files-equal-p): Doc fix. | ||
| 4 | (file-subdir-of-p): Doc fix. Convert loop macro to plain Lisp, | ||
| 5 | and quit the loop once a mismatch is found. | ||
| 6 | |||
| 1 | 2012-02-25 Juanma Barranquero <lekktu@gmail.com> | 7 | 2012-02-25 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 8 | ||
| 3 | * bs.el (bs--show-with-configuration): Don't throw an error | 9 | * bs.el (bs--show-with-configuration): Don't throw an error |
diff --git a/lisp/files.el b/lisp/files.el index 3523fbdc012..acd04de34ec 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -4986,7 +4986,9 @@ given. With a prefix argument, TRASH is nil." | |||
| 4986 | (delete-directory-internal directory))))) | 4986 | (delete-directory-internal directory))))) |
| 4987 | 4987 | ||
| 4988 | (defun files-equal-p (file1 file2) | 4988 | (defun files-equal-p (file1 file2) |
| 4989 | "Return non-nil if FILE1 and FILE2 name the same file." | 4989 | "Return non-nil if FILE1 and FILE2 name the same file. |
| 4990 | Ordinary files are considered to be the same if `file-attributes' | ||
| 4991 | returns `equal' values for them." | ||
| 4990 | (let ((handler (or (find-file-name-handler file1 'files-equal-p) | 4992 | (let ((handler (or (find-file-name-handler file1 'files-equal-p) |
| 4991 | (find-file-name-handler file2 'files-equal-p)))) | 4993 | (find-file-name-handler file2 'files-equal-p)))) |
| 4992 | (if handler | 4994 | (if handler |
| @@ -4996,27 +4998,28 @@ given. With a prefix argument, TRASH is nil." | |||
| 4996 | 4998 | ||
| 4997 | (defun file-subdir-of-p (dir1 dir2) | 4999 | (defun file-subdir-of-p (dir1 dir2) |
| 4998 | "Return non-nil if DIR1 is a subdirectory of DIR2. | 5000 | "Return non-nil if DIR1 is a subdirectory of DIR2. |
| 4999 | Note that a directory is treated by this function as a subdirectory of itself. | 5001 | A directory is considered to be a subdirectory of itself. |
| 5000 | This function only works when its two arguments already exist, | 5002 | Return nil if DIR1 or DIR2 are not existing directories." |
| 5001 | when they don't, it returns nil." | ||
| 5002 | (let ((handler (or (find-file-name-handler dir1 'file-subdir-of-p) | 5003 | (let ((handler (or (find-file-name-handler dir1 'file-subdir-of-p) |
| 5003 | (find-file-name-handler dir2 'file-subdir-of-p)))) | 5004 | (find-file-name-handler dir2 'file-subdir-of-p)))) |
| 5004 | (if handler | 5005 | (if handler |
| 5005 | (funcall handler 'file-subdir-of-p dir1 dir2) | 5006 | (funcall handler 'file-subdir-of-p dir1 dir2) |
| 5006 | (when (and (file-directory-p dir1) | 5007 | (when (and (file-directory-p dir1) |
| 5007 | (file-directory-p dir2)) | 5008 | (file-directory-p dir2)) |
| 5008 | (loop with f1 = (file-truename dir1) | 5009 | (setq dir1 (file-truename dir1) |
| 5009 | with f2 = (file-truename dir2) | 5010 | dir2 (file-truename dir2)) |
| 5010 | with ls1 = (or (split-string f1 "/" t) (list "/")) | 5011 | (let ((ls1 (or (split-string dir1 "/" t) '("/"))) |
| 5011 | with ls2 = (or (split-string f2 "/" t) (list "/")) | 5012 | (ls2 (or (split-string dir2 "/" t) '("/"))) |
| 5012 | for p = (string-match "^/" f1) | 5013 | (root (if (string-match "\\`/" dir1) "/" "")) |
| 5013 | for i in ls1 | 5014 | (mismatch nil)) |
| 5014 | for j in ls2 | 5015 | (while (and ls1 ls2 (not mismatch)) |
| 5015 | when (string= i j) | 5016 | (if (string-equal (car ls1) (car ls2)) |
| 5016 | concat (if p (concat "/" i) (concat i "/")) | 5017 | (setq root (concat root (car ls1) "/")) |
| 5017 | into root | 5018 | (setq mismatch t)) |
| 5018 | finally return | 5019 | (setq ls1 (cdr ls1) |
| 5019 | (files-equal-p (file-truename root) f2)))))) | 5020 | ls2 (cdr ls2))) |
| 5021 | (unless mismatch | ||
| 5022 | (files-equal-p (file-truename root) dir2))))))) | ||
| 5020 | 5023 | ||
| 5021 | (defun copy-directory (directory newname &optional keep-time parents copy-contents) | 5024 | (defun copy-directory (directory newname &optional keep-time parents copy-contents) |
| 5022 | "Copy DIRECTORY to NEWNAME. Both args must be strings. | 5025 | "Copy DIRECTORY to NEWNAME. Both args must be strings. |