diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-22 10:49:45 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-22 10:49:45 +0100 |
commit | 046f3e38b1441277735bef26e2ea20bfda9544bf (patch) | |
tree | 9030b0f956d19349b68d4ddf0b0216be0a95a3e5 /accounts/gkleen@sif | |
parent | 9fb10610b50aaa2b74b0f6a401aa5867812ff994 (diff) | |
download | nixos-046f3e38b1441277735bef26e2ea20bfda9544bf.tar nixos-046f3e38b1441277735bef26e2ea20bfda9544bf.tar.gz nixos-046f3e38b1441277735bef26e2ea20bfda9544bf.tar.bz2 nixos-046f3e38b1441277735bef26e2ea20bfda9544bf.tar.xz nixos-046f3e38b1441277735bef26e2ea20bfda9544bf.zip |
gkleen@sif: emacs: move-file
Diffstat (limited to 'accounts/gkleen@sif')
-rw-r--r-- | accounts/gkleen@sif/emacs.el | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/emacs.el b/accounts/gkleen@sif/emacs.el index c57118b4..ad04c9ea 100644 --- a/accounts/gkleen@sif/emacs.el +++ b/accounts/gkleen@sif/emacs.el | |||
@@ -188,3 +188,26 @@ necessarily running." | |||
188 | (global-set-key (kbd "C-x k") 'kill-buffer-with-special-emacsclient-handling)) | 188 | (global-set-key (kbd "C-x k") 'kill-buffer-with-special-emacsclient-handling)) |
189 | 189 | ||
190 | (add-hook 'server-switch-hook 'install-emacsclient-wrapped-kill-buffer) | 190 | (add-hook 'server-switch-hook 'install-emacsclient-wrapped-kill-buffer) |
191 | |||
192 | (defun move-file (new-location) | ||
193 | "Write this file to NEW-LOCATION, and delete the old one." | ||
194 | (interactive (list (expand-file-name | ||
195 | (if buffer-file-name | ||
196 | (read-file-name "Move file to: ") | ||
197 | (read-file-name "Move file to: " | ||
198 | default-directory | ||
199 | (expand-file-name (file-name-nondirectory (buffer-name)) | ||
200 | default-directory)))))) | ||
201 | (when (file-exists-p new-location) | ||
202 | (delete-file new-location)) | ||
203 | (let ((old-location (expand-file-name (buffer-file-name)))) | ||
204 | (message "old file is %s and new file is %s" | ||
205 | old-location | ||
206 | new-location) | ||
207 | (write-file new-location t) | ||
208 | (when (and old-location | ||
209 | (file-exists-p new-location) | ||
210 | (not (string-equal old-location new-location))) | ||
211 | (delete-file old-location)))) | ||
212 | |||
213 | (bind-key "C-x C-m" #'move-file) | ||