Fix {copy,move}-this-file commands when file doesn't exist yet

This commit is contained in:
Henrik Lissner 2018-05-20 15:17:59 +02:00
parent f058505306
commit f3f8172579
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -56,9 +56,10 @@
(not force-p) (not force-p)
(not (y-or-n-p (format "File already exists at %s, overwrite?" short-new-name)))) (not (y-or-n-p (format "File already exists at %s, overwrite?" short-new-name))))
(throw 'status 'aborted)) (throw 'status 'aborted))
(t ((file-exists-p old-path)
(copy-file old-path new-path t) (copy-file old-path new-path t)
short-new-name)))) short-new-name)
(short-new-name))))
;;;###autoload ;;;###autoload
(defun doom/delete-this-file (&optional path force-p) (defun doom/delete-this-file (&optional path force-p)
@ -107,7 +108,8 @@ file if it exists, without confirmation."
(let ((old-path (buffer-file-name)) (let ((old-path (buffer-file-name))
(new-path (expand-file-name new-path))) (new-path (expand-file-name new-path)))
(when-let* ((dest (doom--copy-file old-path new-path force-p))) (when-let* ((dest (doom--copy-file old-path new-path force-p)))
(delete-file old-path) (when (file-exists-p old-path)
(delete-file old-path))
(kill-this-buffer) (kill-this-buffer)
(find-file new-path) (find-file new-path)
(doom--forget-file old-path new-path) (doom--forget-file old-path new-path)