Skip to content

Commit ccefd5c

Browse files
committed
tweak(core): make use of rename-visited-file when available
1 parent 68736c1 commit ccefd5c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

core/me-lib.el

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -745,23 +745,26 @@ RECURSIVE is non-nil."
745745
(delete-directory file-or-directory recursive trash)
746746
(delete-file file-or-directory trash)))
747747

748-
(defun +move-this-file (new-path &optional force-p)
749-
"Move current buffer's file to NEW-PATH.
748+
(if (fboundp 'rename-visited-file)
749+
(defalias '+move-this-file #'rename-visited-file)
750+
751+
(defun +move-this-file (new-path &optional force-p)
752+
"Move current buffer's file to NEW-PATH.
750753
751754
If FORCE-P, overwrite the destination file if it exists, without confirmation."
752-
(interactive
753-
(list (read-file-name "Move file to: ")
754-
current-prefix-arg))
755-
(unless (and buffer-file-name (file-exists-p buffer-file-name))
756-
(user-error "Buffer is not visiting any file"))
757-
(let ((old-path (buffer-file-name (buffer-base-buffer)))
758-
(new-path (expand-file-name new-path)))
759-
(when (directory-name-p new-path)
760-
(setq new-path (expand-file-name (file-name-nondirectory old-path) new-path)))
761-
(make-directory (file-name-directory new-path) t)
762-
(rename-file old-path new-path (or force-p 1))
763-
(set-visited-file-name new-path t t)
764-
(message "File moved to %S" (abbreviate-file-name new-path))))
755+
(interactive
756+
(list (read-file-name "Move file to: ")
757+
current-prefix-arg))
758+
(unless (and buffer-file-name (file-exists-p buffer-file-name))
759+
(user-error "Buffer is not visiting any file"))
760+
(let ((old-path (buffer-file-name (buffer-base-buffer)))
761+
(new-path (expand-file-name new-path)))
762+
(when (directory-name-p new-path)
763+
(setq new-path (expand-file-name (file-name-nondirectory old-path) new-path)))
764+
(make-directory (file-name-directory new-path) t)
765+
(rename-file old-path new-path (or force-p 1))
766+
(set-visited-file-name new-path t t)
767+
(message "File moved to %S" (abbreviate-file-name new-path)))))
765768

766769
(autoload 'tramp-make-tramp-file-name "tramp")
767770
(defvar tramp-root-id-string)

0 commit comments

Comments
 (0)