Mercurial > dotfiles
comparison .elisp/settings/99.move-file.el @ 454:2f24474b1f84
move-file: new function for emacs to move a file and fix up the buffer
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Sat, 10 Dec 2016 18:43:17 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
453:6f3342c9e53d | 454:2f24474b1f84 |
---|---|
1 ;; emacs move-file function from http://zck.me/emacs-move-file | |
2 | |
3 (defun move-file (new-location) | |
4 "Write this file to NEW-LOCATION, and delete the old one." | |
5 (interactive (list (if buffer-file-name | |
6 (read-file-name "Move file to: ") | |
7 (read-file-name "Move file to: " | |
8 default-directory | |
9 (expand-file-name (file-name-nondirectory (buffer-name)) | |
10 default-directory))))) | |
11 (when (file-exists-p new-location) | |
12 (delete-file new-location)) | |
13 (let ((old-location (buffer-file-name))) | |
14 (write-file new-location t) | |
15 (when (and old-location | |
16 (file-exists-p new-location)) | |
17 (delete-file old-location)))) |