Mercurial > emacs
changeset 24832:b772f629b45b
(write-file): When buffer is not already visiting a file,
don't put buffer name in the minibuffer, just make it the default.
Also handle just directory as arg usefully in that case.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Sat, 12 Jun 1999 03:57:37 +0000 |
parents | e16164c4f6a9 |
children | 7b18c1a51e98 |
files | lisp/files.el |
diffstat | 1 files changed, 19 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/files.el Sat Jun 12 03:56:14 1999 +0000 +++ b/lisp/files.el Sat Jun 12 03:57:37 1999 +0000 @@ -1914,31 +1914,37 @@ (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. +This makes the buffer visit that file, and marks it as not modified. + +If you specify just a directory name as FILENAME, that means to use +the default file name but in that directory. You can also yank +the default file name into the minibuffer to edit it, using M-n. -If optional second arg CONFIRM is non-nil, -ask for confirmation for overwriting an existing file. +If the buffer is not already visiting a file, the default file name +for the output file is the buffer name. + +If optional second arg CONFIRM is non-nil, this function +asks for confirmation before overwriting an existing file. Interactively, confirmation is required unless you supply a prefix argument." ;; (interactive "FWrite file: ") (interactive (list (if buffer-file-name (read-file-name "Write file: " nil nil nil nil) - (read-file-name "Write file: " - (cdr (assq 'default-directory - (buffer-local-variables))) - nil nil (file-name-nondirectory (buffer-name)))) + (read-file-name "Write file: " default-directory + (expand-file-name + (file-name-nondirectory (buffer-name)) + default-directory) + nil nil)) (not current-prefix-arg))) (or (null filename) (string-equal filename "") (progn ;; If arg is just a directory, - ;; use same file name, but in that directory. - (if (and (file-directory-p filename) buffer-file-name) + ;; use the default file name, but in that directory. + (if (file-directory-p filename) (setq filename (concat (file-name-as-directory filename) - (file-name-nondirectory buffer-file-name)))) + (file-name-nondirectory + (or buffer-file-name (buffer-name)))))) (and confirm (file-exists-p filename) (or (y-or-n-p (format "File `%s' exists; overwrite? " filename))