changeset 5733:04260338bfca

Fix file-relative-name to allow for ancestors as well as descendants.
author Karl Heuer <kwzh@gnu.org>
date Wed, 02 Feb 1994 04:39:22 +0000
parents d97df1629181
children 3c8ae6c720d8
files lisp/files.el
diffstat 1 files changed, 5 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Wed Feb 02 03:27:26 1994 +0000
+++ b/lisp/files.el	Wed Feb 02 04:39:22 1994 +0000
@@ -1382,22 +1382,16 @@
   "Return number of names file FILENAME has."
   (car (cdr (file-attributes filename))))
 
-(defun file-relative-name-1 (directory)
-  (cond ((string= directory "/")
-	 filename)
-	((string-match (concat "^" (regexp-quote directory))
-		       filename)
-	 (substring filename (match-end 0)))
-	(t
-	 (file-relative-name-1
-	  (file-name-directory (substring directory 0 -1))))))
-
 (defun file-relative-name (filename &optional directory)
   "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
   (setq filename (expand-file-name filename)
 	directory (file-name-as-directory (expand-file-name
 					   (or directory default-directory))))
-  (file-relative-name-1 directory))
+  (let ((ancestor ""))
+    (while (not (string-match (concat "^" (regexp-quote directory)) filename))
+      (setq directory (file-name-directory (substring directory 0 -1))
+	    ancestor (concat "../" ancestor)))
+    (concat ancestor (substring filename (match-end 0)))))
 
 (defun save-buffer (&optional args)
   "Save current buffer in visited file if modified.  Versions described below.