changeset 11340:5c97fabe0ab9

(write-file): Default is ask for confirmation only interactively.
author Richard M. Stallman <rms@gnu.org>
date Mon, 10 Apr 1995 04:49:13 +0000
parents ca0aead90c7b
children e0f3fa4e7bf3
files lisp/files.el
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Mon Apr 10 01:15:50 1995 +0000
+++ b/lisp/files.el	Mon Apr 10 04:49:13 1995 +0000
@@ -1331,12 +1331,14 @@
   (if buffer-file-name
       (set-buffer-modified-p t)))
 
-(defun write-file (filename)
+(defun write-file (filename &optional confirm)
   "Write current buffer into file FILENAME.
 Makes buffer visit that file, and marks it not modified.
 If the buffer is already visiting a file, you can specify
 a directory name as FILENAME, to write a file of the same
-old name in that directory."
+old name in that directory.
+If optional second arg CONFIRM is non-nil,
+ask for confirmation for overwriting an existing file."
 ;;  (interactive "FWrite file: ")
   (interactive
    (list (if buffer-file-name
@@ -1345,7 +1347,8 @@
 	   (read-file-name "Write file: "
 			       (cdr (assq 'default-directory
 					  (buffer-local-variables)))
-			       nil nil (buffer-name)))))
+			       nil nil (buffer-name)))
+	 t))
   (or (null filename) (string-equal filename "")
       (progn
 	;; If arg is just a directory,
@@ -1353,9 +1356,10 @@
 	(if (and (file-directory-p filename) buffer-file-name)
 	    (setq filename (concat (file-name-as-directory filename)
 				   (file-name-nondirectory buffer-file-name))))
-	(if (file-exists-p filename)
-	    (or (y-or-n-p (format "File `%s' exists; overwrite? " filename))
-		(error "Canceled")))
+	(and confirm
+	     (file-exists-p filename)
+	     (or (y-or-n-p (format "File `%s' exists; overwrite? " filename))
+		 (error "Canceled")))
 	(set-visited-file-name filename)))
   (set-buffer-modified-p t)
   (save-buffer))