annotate .elisp/settings/99.move-file.el @ 498:ab38b9bf226d

bootstrap: always install exec-path-from-shell-initialize Required fixing the melpa URL, which has been broken ~forever.
author Augie Fackler <raf@durin42.com>
date Sat, 03 Oct 2020 11:14:06 -0400
parents 2f24474b1f84
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
454
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
1 ;; emacs move-file function from http://zck.me/emacs-move-file
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
2
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 (defun move-file (new-location)
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 "Write this file to NEW-LOCATION, and delete the old one."
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 (interactive (list (if buffer-file-name
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6 (read-file-name "Move file to: ")
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 (read-file-name "Move file to: "
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8 default-directory
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 (expand-file-name (file-name-nondirectory (buffer-name))
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 default-directory)))))
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 (when (file-exists-p new-location)
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 (delete-file new-location))
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 (let ((old-location (buffer-file-name)))
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 (write-file new-location t)
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15 (when (and old-location
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 (file-exists-p new-location))
2f24474b1f84 move-file: new function for emacs to move a file and fix up the buffer
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 (delete-file old-location))))