Commit c2fb8488 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(write-file): Default is ask for confirmation only interactively.

parent 80ccb2b3
...@@ -1331,12 +1331,14 @@ if you wish to pass an empty string as the argument." ...@@ -1331,12 +1331,14 @@ if you wish to pass an empty string as the argument."
(if buffer-file-name (if buffer-file-name
(set-buffer-modified-p t))) (set-buffer-modified-p t)))
(defun write-file (filename) (defun write-file (filename &optional confirm)
"Write current buffer into file FILENAME. "Write current buffer into file FILENAME.
Makes buffer visit that file, and marks it not modified. Makes buffer visit that file, and marks it not modified.
If the buffer is already visiting a file, you can specify If the buffer is already visiting a file, you can specify
a directory name as FILENAME, to write a file of the same 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 "FWrite file: ")
(interactive (interactive
(list (if buffer-file-name (list (if buffer-file-name
...@@ -1345,7 +1347,8 @@ old name in that directory." ...@@ -1345,7 +1347,8 @@ old name in that directory."
(read-file-name "Write file: " (read-file-name "Write file: "
(cdr (assq 'default-directory (cdr (assq 'default-directory
(buffer-local-variables))) (buffer-local-variables)))
nil nil (buffer-name))))) nil nil (buffer-name)))
t))
(or (null filename) (string-equal filename "") (or (null filename) (string-equal filename "")
(progn (progn
;; If arg is just a directory, ;; If arg is just a directory,
...@@ -1353,9 +1356,10 @@ old name in that directory." ...@@ -1353,9 +1356,10 @@ old name in that directory."
(if (and (file-directory-p filename) buffer-file-name) (if (and (file-directory-p filename) buffer-file-name)
(setq filename (concat (file-name-as-directory filename) (setq filename (concat (file-name-as-directory filename)
(file-name-nondirectory buffer-file-name)))) (file-name-nondirectory buffer-file-name))))
(if (file-exists-p filename) (and confirm
(or (y-or-n-p (format "File `%s' exists; overwrite? " filename)) (file-exists-p filename)
(error "Canceled"))) (or (y-or-n-p (format "File `%s' exists; overwrite? " filename))
(error "Canceled")))
(set-visited-file-name filename))) (set-visited-file-name filename)))
(set-buffer-modified-p t) (set-buffer-modified-p t)
(save-buffer)) (save-buffer))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment