Function: casual-lib-duplicate-file
casual-lib-duplicate-file is an interactive and natively compiled
function defined in casual-lib.el.
Signature
(casual-lib-duplicate-file &optional ARG)
Documentation
Duplicate the current file with prefix option ARG.
This command will duplicate and open the current file in the buffer to a filename of the form “<filename> copy.<extension>”. If the current buffer is modified, a prompt will be raised to save it before making the duplicate copy.
By default this command will immediate open the duplicate file into a new buffer. This can be avoided if a prefix ARG is provided.
Key Bindings
This command is not in any keymaps.
Source Code
;; Defined in /nix/store/wimz22qbgb2rpqyjz09vm30wj4fkmiw4-emacs-packages-deps/share/emacs/site-lisp/elpa/casual-20260831.2129/casual-lib.el
(defun casual-lib-duplicate-file (&optional arg)
"Duplicate the current file with prefix option ARG.
This command will duplicate and open the current file in the buffer to a
filename of the form “<filename> copy.<extension>”. If the current
buffer is modified, a prompt will be raised to save it before making the
duplicate copy.
By default this command will immediate open the duplicate file into a
new buffer. This can be avoided if a prefix ARG is provided."
(interactive "P")
(if (and (buffer-modified-p) (y-or-n-p "Save buffer? "))
(save-buffer))
(let ((filename (buffer-file-name)))
(unless filename
(error "This command only works on a file"))
(let* ((extension (file-name-extension filename t))
(target (format "%s copy%s"
(file-name-sans-extension filename)
extension)))
(copy-file filename target)
(if (not arg)
(find-file target)))))