Code: Select all
find-coding-systems-region: Wrong type argument: integer-or-marker-p, nil
Code: Select all
(defun save-a-copy-as (file-or-directory)
"Saves a copy of the current buffer in the given directory or file, leaving
the original file in the buffer, and asking for confirmation before
overwriting an existing file."
(interactive "FSave a copy as file: ")
(save-excursion
(save-a-copy-as-confirming file-or-directory t)))
(defun save-a-copy-as-confirming (target-file-or-directory confirming)
"Saves a copy of the current buffer in the given target directory or file,
leaving the original file in the buffer.
If argument confirming is nil, will overwrite any existing file with the same
name; if confirming is anything else, will prompt the user first."
(let ((target-file
(concat target-file-or-directory
(when (string-match "/$" target-file-or-directory)
(buffer-name)))))
(write-region nil nil target-file nil nil nil confirming)))