summaryrefslogtreecommitdiff
path: root/lisp/files.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el14
1 files changed, 11 insertions, 3 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 0a0052a01ae..db50e86dccb 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -943,9 +943,17 @@ Value is a list whose car is the name for the backup file
directory (file-name-as-directory (if directory
(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)))
+ (let ((strip (lambda (directory)
+ (cond ((string= directory "/")
+ filename)
+ ((string-match (concat "^" (regexp-quote directory))
+ filename)
+ (substring filename (match-end 0)))
+ (t
+ (funcall strip
+ (file-name-directory (substring directory
+ 0 -1))))))))
+ (funcall strip directory)))
(defun save-buffer (&optional args)
"Save current buffer in visited file if modified. Versions described below.