diff options
| author | Luc Teirlinck | 2004-04-05 00:52:10 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2004-04-05 00:52:10 +0000 |
| commit | 8c5fe07fa2dbf6c520728fe39a83f3a5516d786b (patch) | |
| tree | f54969f09b57210cb506a638e7f4604f0a7b9f1a | |
| parent | 361535c2a95c76e96ef861a48a4d7a2bd000e6b7 (diff) | |
| download | emacs-8c5fe07fa2dbf6c520728fe39a83f3a5516d786b.tar.gz emacs-8c5fe07fa2dbf6c520728fe39a83f3a5516d786b.zip | |
(format-write-file): Add optional argument CONFIRM and make it behave
like the analogous argument to `write-file'.
| -rw-r--r-- | lisp/format.el | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lisp/format.el b/lisp/format.el index 09d3e5fa715..525588eeca4 100644 --- a/lisp/format.el +++ b/lisp/format.el | |||
| @@ -366,11 +366,15 @@ one of the formats defined in `format-alist', or a list of such symbols." | |||
| 366 | (funcall to-fn beg end (current-buffer))))) | 366 | (funcall to-fn beg end (current-buffer))))) |
| 367 | (setq format (cdr format))))))) | 367 | (setq format (cdr format))))))) |
| 368 | 368 | ||
| 369 | (defun format-write-file (filename format) | 369 | (defun format-write-file (filename format &optional confirm) |
| 370 | "Write current buffer into file FILENAME using some FORMAT. | 370 | "Write current buffer into file FILENAME using some FORMAT. |
| 371 | Makes buffer visit that file and sets the format as the default for future | 371 | Make buffer visit that file and set the format as the default for future |
| 372 | saves. If the buffer is already visiting a file, you can specify a directory | 372 | saves. If the buffer is already visiting a file, you can specify a directory |
| 373 | name as FILENAME, to write a file of the same old name in that directory." | 373 | name as FILENAME, to write a file of the same old name in that directory. |
| 374 | |||
| 375 | If optional third arg CONFIRM is non-nil, this function asks for | ||
| 376 | confirmation before overwriting an existing file. Interactively, | ||
| 377 | confirmation is required unless you supply a prefix argument." | ||
| 374 | (interactive | 378 | (interactive |
| 375 | ;; Same interactive spec as write-file, plus format question. | 379 | ;; Same interactive spec as write-file, plus format question. |
| 376 | (let* ((file (if buffer-file-name | 380 | (let* ((file (if buffer-file-name |
| @@ -382,7 +386,7 @@ name as FILENAME, to write a file of the same old name in that directory." | |||
| 382 | nil nil (buffer-name)))) | 386 | nil nil (buffer-name)))) |
| 383 | (fmt (format-read (format "Write file `%s' in format: " | 387 | (fmt (format-read (format "Write file `%s' in format: " |
| 384 | (file-name-nondirectory file))))) | 388 | (file-name-nondirectory file))))) |
| 385 | (list file fmt))) | 389 | (list file fmt (not current-prefix-arg)))) |
| 386 | (let ((old-formats buffer-file-format) | 390 | (let ((old-formats buffer-file-format) |
| 387 | preserve-formats) | 391 | preserve-formats) |
| 388 | (dolist (fmt old-formats) | 392 | (dolist (fmt old-formats) |
| @@ -393,7 +397,7 @@ name as FILENAME, to write a file of the same old name in that directory." | |||
| 393 | (dolist (fmt preserve-formats) | 397 | (dolist (fmt preserve-formats) |
| 394 | (unless (memq fmt buffer-file-format) | 398 | (unless (memq fmt buffer-file-format) |
| 395 | (setq buffer-file-format (append buffer-file-format (list fmt)))))) | 399 | (setq buffer-file-format (append buffer-file-format (list fmt)))))) |
| 396 | (write-file filename)) | 400 | (write-file filename confirm)) |
| 397 | 401 | ||
| 398 | (defun format-find-file (filename format) | 402 | (defun format-find-file (filename format) |
| 399 | "Find the file FILENAME using data format FORMAT. | 403 | "Find the file FILENAME using data format FORMAT. |