>From c3edec5eff41927f4e3ac2f0691228cb2df32514 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Tue, 14 Oct 2014 09:51:01 +0800 Subject: [PATCH 7/7] 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-archive-hook. Checks the value of org-attach-archive-delete, and behaves accordingly. --- lisp/org-attach.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index 5c341a5..f50d244 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 + "Non-nil means attachments are deleted upon archiving a subtree. + +When set to `query', ask the user instead." + :group 'org-attach + :version "25.1" + :package-version '(Org . "8.3") + :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,18 @@ 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." + (when (if (eq org-attach-archive-delete 'query) + (yes-or-no-p "Delete all attachments? ") + org-attach-archive-delete) + (org-attach-delete-all t))) + +(add-hook 'org-archive-hook 'org-attach-archive-delete-maybe) + (provide 'org-attach) ;; Local variables: -- 2.1.2