Save the current buffer with a specified file name (@code{write-file}).
@item M-x set-visited-file-name
Change the file name under which the current buffer will be saved.
+@item M-x rename-visited-file
+The same as @kbd{M-x set-visited-file-name}, but also rename the file
+the buffer if visiting (if any).
@end table
@kindex C-x C-s
** Menus
+** New command 'rename-visited-file'.
+This command renames the file visited by the current buffer by moving
+it to a new location, and also makes the buffer visit this new file.
+
---
*** The entries following the buffers in the "Buffers" menu can now be altered.
Change the 'menu-bar-buffers-menu-command-entries' variable to alter
;; 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))
+
\f
(defun file-extended-attributes (filename)
"Return an alist of extended attributes of file FILENAME.