From: Lars Ingebrigtsen Date: Fri, 30 Sep 2022 13:07:31 +0000 (+0200) Subject: Fix rename-visited-file when renaming to a directory name X-Git-Tag: emacs-29.0.90~1856^2~127 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0332142e8e78b49b4f98438be21d2868e738986b;p=emacs.git 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). --- 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))