>From f6b9bc0e2cef23b87ec77ddb9003c0791f992a2f Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sun, 12 Oct 2014 22:02:38 +0800 Subject: [PATCH 3/3] Maybe delete heading attachments when archiving * lisp/org-attach.el (org-attach-archive-delete): New option controlling what to do with attachments when archiving. (org-attach-archive-delete-maybe): New function that runs as a hook on org-attach-hook. Checks the value of org-attach-archive-delete, and behaves accordingly. --- lisp/org-attach.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index 5c341a5..cc077c4 100644 --- a/lisp/org-attach.el +++ b/lisp/org-attach.el @@ -120,6 +120,18 @@ lns create a symbol link. Note that this is not supported (const :tag "Link to origin location" t) (const :tag "Link to the attach-dir location" attached))) +(defcustom org-attach-archive-delete nil + "If a subtree is archived, should its attachments be deleted? + +Set to nil to never delete attachments, t to always delete +attachments, and the symbol query to ask." + :group 'org-attach + :version "24.1" + :type '(choice + (const :tag "Never delete attachments" nil) + (const :tag "Always delete attachments" t) + (const :tag "Query the user" query))) + ;;;###autoload (defun org-attach () "The dispatcher for attachment commands. @@ -475,6 +487,26 @@ Basically, this adds the path to the attachment directory, and a \"file:\" prefix." (concat "file:" (org-attach-expand file))) +(defun org-attach-archive-delete-maybe () + "Maybe delete subtree attachments when archiving. + +This function is called by `org-archive-hook'. The option +`org-attach-archive-delete' controls its behavior." + (let (delete-p) + (setq delete-p + (cond + ((eq org-attach-archive-delete 'query) + (y-or-n-p "Delete all attachments?")) + ((null org-attach-archive-delete) + nil) + (org-attach-archive-delete + t) + (t nil))) + (when delete-p + (org-attach-delete-all t)))) + +(add-hook 'org-archive-hook 'org-attach-archive-delete-maybe) + (provide 'org-attach) ;; Local variables: -- 2.1.2