Function: format-write-file
format-write-file is an interactive and byte-compiled function defined
in format.el.gz.
Signature
(format-write-file FILENAME FORMAT &optional CONFIRM)
Documentation
Write current buffer into FILENAME, using a format based on FORMAT.
Constructs the actual format starting from FORMAT, then appending
any elements from the value of buffer-file-format with a non-nil
preserve flag (see the documentation of format-alist), if they
are not already present in FORMAT. It then updates buffer-file-format
with this format, making it the default for future saves.
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.
If optional third arg CONFIRM is non-nil, asks for confirmation before overwriting an existing file. Interactively, requires confirmation unless you supply a prefix argument.
Probably introduced at or before Emacs version 19.29.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/format.el.gz
(defun format-write-file (filename format &optional confirm)
"Write current buffer into FILENAME, using a format based on FORMAT.
Constructs the actual format starting from FORMAT, then appending
any elements from the value of `buffer-file-format' with a non-nil
`preserve' flag (see the documentation of `format-alist'), if they
are not already present in FORMAT. It then updates `buffer-file-format'
with this format, making it the default for future saves.
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.
If optional third arg CONFIRM is non-nil, asks for confirmation before
overwriting an existing file. Interactively, requires confirmation
unless you supply a prefix argument."
(interactive
;; Same interactive spec as write-file, plus format question.
(let* ((file (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 (buffer-name))))
(fmt (format-read (format-message "Write file `%s' in format: "
(file-name-nondirectory file)))))
(list file fmt (not current-prefix-arg))))
(let ((old-formats buffer-file-format)
preserve-formats)
(dolist (fmt old-formats)
(let ((aelt (assq fmt format-alist)))
(if (nth 7 aelt)
(push fmt preserve-formats))))
(setq buffer-file-format format)
(dolist (fmt preserve-formats)
(unless (memq fmt buffer-file-format)
(setq buffer-file-format (append buffer-file-format (list fmt))))))
(write-file filename confirm))