diff options
| author | Karl Heuer | 1999-06-12 03:57:37 +0000 |
|---|---|---|
| committer | Karl Heuer | 1999-06-12 03:57:37 +0000 |
| commit | 7f99999ab4cfb3d7e700ddbd72ded2aa1fd82f45 (patch) | |
| tree | 5ba2aaf3388561668e5be69b854722a4d17c4114 | |
| parent | 170b8e50d7caf8735842b126680189e1d598173d (diff) | |
| download | emacs-7f99999ab4cfb3d7e700ddbd72ded2aa1fd82f45.tar.gz emacs-7f99999ab4cfb3d7e700ddbd72ded2aa1fd82f45.zip | |
(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.
| -rw-r--r-- | lisp/files.el | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lisp/files.el b/lisp/files.el index 24249311836..6ea09721367 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1914,31 +1914,37 @@ the old visited file has been renamed to the new name FILENAME." | |||
| 1914 | 1914 | ||
| 1915 | (defun write-file (filename &optional confirm) | 1915 | (defun write-file (filename &optional confirm) |
| 1916 | "Write current buffer into file FILENAME. | 1916 | "Write current buffer into file FILENAME. |
| 1917 | Makes buffer visit that file, and marks it not modified. | 1917 | This makes the buffer visit that file, and marks it as not modified. |
| 1918 | If the buffer is already visiting a file, you can specify | ||
| 1919 | a directory name as FILENAME, to write a file of the same | ||
| 1920 | old name in that directory. | ||
| 1921 | 1918 | ||
| 1922 | If optional second arg CONFIRM is non-nil, | 1919 | If you specify just a directory name as FILENAME, that means to use |
| 1923 | ask for confirmation for overwriting an existing file. | 1920 | the default file name but in that directory. You can also yank |
| 1921 | the default file name into the minibuffer to edit it, using M-n. | ||
| 1922 | |||
| 1923 | If the buffer is not already visiting a file, the default file name | ||
| 1924 | for the output file is the buffer name. | ||
| 1925 | |||
| 1926 | If optional second arg CONFIRM is non-nil, this function | ||
| 1927 | asks for confirmation before overwriting an existing file. | ||
| 1924 | Interactively, confirmation is required unless you supply a prefix argument." | 1928 | Interactively, confirmation is required unless you supply a prefix argument." |
| 1925 | ;; (interactive "FWrite file: ") | 1929 | ;; (interactive "FWrite file: ") |
| 1926 | (interactive | 1930 | (interactive |
| 1927 | (list (if buffer-file-name | 1931 | (list (if buffer-file-name |
| 1928 | (read-file-name "Write file: " | 1932 | (read-file-name "Write file: " |
| 1929 | nil nil nil nil) | 1933 | nil nil nil nil) |
| 1930 | (read-file-name "Write file: " | 1934 | (read-file-name "Write file: " default-directory |
| 1931 | (cdr (assq 'default-directory | 1935 | (expand-file-name |
| 1932 | (buffer-local-variables))) | 1936 | (file-name-nondirectory (buffer-name)) |
| 1933 | nil nil (file-name-nondirectory (buffer-name)))) | 1937 | default-directory) |
| 1938 | nil nil)) | ||
| 1934 | (not current-prefix-arg))) | 1939 | (not current-prefix-arg))) |
| 1935 | (or (null filename) (string-equal filename "") | 1940 | (or (null filename) (string-equal filename "") |
| 1936 | (progn | 1941 | (progn |
| 1937 | ;; If arg is just a directory, | 1942 | ;; If arg is just a directory, |
| 1938 | ;; use same file name, but in that directory. | 1943 | ;; use the default file name, but in that directory. |
| 1939 | (if (and (file-directory-p filename) buffer-file-name) | 1944 | (if (file-directory-p filename) |
| 1940 | (setq filename (concat (file-name-as-directory filename) | 1945 | (setq filename (concat (file-name-as-directory filename) |
| 1941 | (file-name-nondirectory buffer-file-name)))) | 1946 | (file-name-nondirectory |
| 1947 | (or buffer-file-name (buffer-name)))))) | ||
| 1942 | (and confirm | 1948 | (and confirm |
| 1943 | (file-exists-p filename) | 1949 | (file-exists-p filename) |
| 1944 | (or (y-or-n-p (format "File `%s' exists; overwrite? " filename)) | 1950 | (or (y-or-n-p (format "File `%s' exists; overwrite? " filename)) |