From 9303ad228d085c5c5a36b7ec0d62e0a6af0fb6b5 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 11 Mar 2016 19:30:58 -0500 Subject: [PATCH] org: take attachments into account on file move/delete --- core/defuns/defuns-file.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/defuns/defuns-file.el b/core/defuns/defuns-file.el index b32496f0e..aecd2f289 100644 --- a/core/defuns/defuns-file.el +++ b/core/defuns/defuns-file.el @@ -9,6 +9,12 @@ (if (not (file-exists-p filename)) (error "File doesn't exist: %s" filename) (when (or bang (and (not bang) (y-or-n-p (format "Delete %s?" (f-base filename))))) + ;; Delete attachments if in org-mode + (when (eq major-mode 'org-mode) + (mapc (lambda (file) + (when (file-exists-p file) + (delete-file file t))) + (narf/org-attachments))) (delete-file filename) (kill-this-buffer) (unless (narf/real-buffer-p) @@ -49,6 +55,12 @@ provided." (f-full path)) (t (user-error "Not a valid destination: %s" path)))) (project-root (narf/project-root))) + ;; Move all attachments if in org-mode + (when (eq major-mode 'org-mode) + (mapc (lambda (file) + (when (file-exists-p file) + (rename-file file (f-expand (f-filename old-path) (f-dirname new-path)) t))) + (narf/org-attachments))) (rename-file old-path new-path 1) (rename-buffer (f-filename new-path)) (set-visited-file-name new-path)