Function: dired-rename-file
dired-rename-file is an autoloaded and byte-compiled function defined
in dired-aux.el.gz.
Signature
(dired-rename-file FILE NEWNAME OK-IF-ALREADY-EXISTS)
Documentation
Rename FILE to NEWNAME.
Signal a file-already-exists error if a file NEWNAME already exists
unless OK-IF-ALREADY-EXISTS is non-nil.
Probably introduced at or before Emacs version 27.1.
Source Code
;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
;;;###autoload
(defun dired-rename-file (file newname ok-if-already-exists)
"Rename FILE to NEWNAME.
Signal a `file-already-exists' error if a file NEWNAME already exists
unless OK-IF-ALREADY-EXISTS is non-nil."
(let ((file-is-dir-p (file-directory-p file)))
(dired-handle-overwrite newname)
(dired-maybe-create-dirs (file-name-directory newname))
(if (and dired-vc-rename-file
(vc-backend file)
(ignore-errors (vc-responsible-backend newname)))
(vc-rename-file file newname)
;; error is caught in -create-files
(rename-file file newname ok-if-already-exists))
;; Silently rename the visited file of any buffer visiting this file.
(and (get-file-buffer file)
(with-current-buffer (get-file-buffer file)
(set-visited-file-name newname nil t)))
(dired-remove-file file)
;; See if it's an inserted subdir, and rename that, too.
(when file-is-dir-p
(dired-rename-subdir file newname))))