annotate .elisp/settings/99.move-file.el @ 482:0731ceeb27dd

emacs: run hg tests under python3 by default now
author Augie Fackler <raf@durin42.com>
date Tue, 07 Jan 2020 16:49:47 -0500
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))))