summaryrefslogtreecommitdiff
path: root/lisp/files.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1993-03-03 05:12:05 +0000
committerRichard M. Stallman <rms@gnu.org>1993-03-03 05:12:05 +0000
commit41f48cb1bd82bfd78d5d61dbfe173906ed298149 (patch)
tree13cf806cb8c95746cd8c30d7510d85094edc7c5b /lisp/files.el
parentc751ebb6a3632b879cd7efbffdfeafa364c3a6cc (diff)
downloademacs-41f48cb1bd82bfd78d5d61dbfe173906ed298149.tar.gz
(write-file): Handle directory name as arg.
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el13
1 files changed, 11 insertions, 2 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 49d452b92e2..60329f162b2 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -935,7 +935,10 @@ if you wish to pass an empty string as the argument."
(defun write-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
+a directory name as FILENAME, to write a file of the same
+old name in that directory."
;; (interactive "FWrite file: ")
(interactive
(list (if buffer-file-name
@@ -946,7 +949,13 @@ Makes buffer visit that file, and marks it not modified."
(buffer-local-variables)))
nil nil (buffer-name)))))
(or (null filename) (string-equal filename "")
- (set-visited-file-name 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)
+ (setq filename (concat (file-name-as-directory filename)
+ (file-name-nondirectory buffer-file-name))))
+ (set-visited-file-name filename)))
(set-buffer-modified-p t)
(save-buffer))