changeset 16976:c7683cba14c7

(file-relative-name): Protect the match-data.
author Erik Naggum <erik@naggum.no>
date Wed, 05 Feb 1997 01:32:44 +0000
parents 188c4da9bf5d
children e97bdda07a30
files lisp/files.el
diffstat 1 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Tue Feb 04 18:21:29 1997 +0000
+++ b/lisp/files.el	Wed Feb 05 01:32:44 1997 +0000
@@ -1830,14 +1830,15 @@
 
 (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))))
-  (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)))))
+  (save-match-data
+   (setq filename (expand-file-name filename)
+	 directory (file-name-as-directory
+		    (expand-file-name (or directory default-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.