changeset 1229:d4324e885a41

(file-relative-name): New function.
author Roland McGrath <roland@gnu.org>
date Sun, 27 Sep 1992 02:25:31 +0000
parents 8abf83cc14b1
children f882f7a19c60
files lisp/files.el
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Sun Sep 27 01:55:21 1992 +0000
+++ b/lisp/files.el	Sun Sep 27 02:25:31 1992 +0000
@@ -936,6 +936,15 @@
 (defun file-nlinks (filename)
   "Return number of names file FILENAME has."
   (car (cdr (file-attributes filename))))
+
+(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 (or (expand-file-name directory)
+					      default-directory)))
+  (while (not (string-match (concat "^" (regexp-quote directory)) filename))
+    (setq directory (file-name-directory (substring directory 0 -1))))
+  (substring filename (match-end 0)))
 
 (defun save-buffer (&optional args)
   "Save current buffer in visited file if modified.  Versions described below.