Add new command `rename-visited-file'

* doc/emacs/files.texi (Save Commands): Document it.

* lisp/files.el (rename-visited-file): New command (bug#56229).
This commit is contained in:
Zachary Kanfer 2022-06-28 14:13:58 +02:00 committed by Lars Ingebrigtsen
parent 0b62ad2f3a
commit 772b189143
3 changed files with 27 additions and 0 deletions

View file

@ -4824,6 +4824,26 @@ Interactively, confirmation is required unless you supply a prefix argument."
;; It's likely that the VC status at the new location is different from
;; the one at the old location.
(vc-refresh-state)))
(defun rename-visited-file (new-location)
"Rename the file visited by the current buffer to NEW-LOCATION.
This command also sets the visited file name. If the buffer
isn't visiting any file, that's all it does.
Interactively, this prompts for NEW-LOCATION."
(interactive
(list (if buffer-file-name
(read-file-name "Rename visited file to: ")
(read-file-name "Set visited file name: "
default-directory
(expand-file-name
(file-name-nondirectory (buffer-name))
default-directory)))))
(when (and buffer-file-name
(file-exists-p buffer-file-name))
(rename-file buffer-file-name new-location))
(set-visited-file-name new-location nil t))
(defun file-extended-attributes (filename)
"Return an alist of extended attributes of file FILENAME.