]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix rename-visited-file when renaming to a directory name
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 30 Sep 2022 13:07:31 +0000 (15:07 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 30 Sep 2022 13:07:31 +0000 (15:07 +0200)
* lisp/files.el (rename-visited-file): Allow renaming to a
directory file name (bug#58182).

lisp/files.el

index 5463f3b5eceb0145f5197f978654a9f62f406209..10b156fb3061124cd005725d86b05c074ee6f3aa 100644 (file)
@@ -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))