Mercurial > dotfiles
annotate .elisp/settings/99.move-file.el @ 494:ef22f075b638
hgrc: also ignore NoBackup dir where I hide stuff from time machine
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 01 Jul 2020 18:46:56 -0400 |
parents | 2f24474b1f84 |
children |
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)))) |