From 96c188b08ca4329bec2d6538a7c868cc943f1914 Mon Sep 17 00:00:00 2001 From: Erik Naggum Date: Wed, 5 Feb 1997 01:32:44 +0000 Subject: [PATCH] (file-relative-name): Protect the match-data. --- lisp/files.el | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 251177e64fb..ad5fa847813 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1830,14 +1830,15 @@ If the value is nil, don't make a backup." (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. -- 2.39.2