From 0332142e8e78b49b4f98438be21d2868e738986b Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 30 Sep 2022 15:07:31 +0200 Subject: [PATCH] Fix rename-visited-file when renaming to a directory name * lisp/files.el (rename-visited-file): Allow renaming to a directory file name (bug#58182). --- lisp/files.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lisp/files.el b/lisp/files.el index 5463f3b5ece..10b156fb306 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4866,6 +4866,14 @@ Interactively, this prompts for NEW-LOCATION." (expand-file-name (file-name-nondirectory (buffer-name)) default-directory))))) + ;; If the user has given a directory name, the file should be moved + ;; there (under the same file name). + (when (file-directory-p new-location) + (unless buffer-file-name + (user-error "Can't rename buffer to a directory file name")) + (setq new-location (expand-file-name + (file-name-nondirectory buffer-file-name) + new-location))) (when (and buffer-file-name (file-exists-p buffer-file-name)) (rename-file buffer-file-name new-location)) -- 2.39.2