From 182891ef3dc1ae345ad73cad80abbbd6e7098f4b Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 19 Aug 1995 17:01:27 +0000 Subject: [PATCH] (basic-save-buffer): Confirm for overwriting old file when a file name is specified. --- lisp/files.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 4f36427a2e2..930c343430e 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1716,8 +1716,14 @@ the last real save, but optional arg FORCE non-nil means delete anyway." (rename-buffer buffer-new-name))) ;; If buffer has no file name, ask user for one. (or buffer-file-name - (set-visited-file-name - (expand-file-name (read-file-name "File to save in: ") nil))) + (let ((filename + (expand-file-name + (read-file-name "File to save in: ") nil))) + (and (file-exists-p filename) + (or (y-or-n-p (format "File `%s' exists; overwrite? " + filename)) + (error "Canceled"))) + (set-visited-file-name filename))) (or (verify-visited-file-modtime (current-buffer)) (not (file-exists-p buffer-file-name)) (yes-or-no-p -- 2.39.2