summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Abrahamsen <eric@ericabrahamsen.net>2014-10-14 09:51:01 +0800
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2014-10-16 18:57:39 +0200
commit1feafbfa99b27d093db18b5423aba8e604e2a0c9 (patch)
tree8fe7f6a6c209c5523a34bacbcdc3747c381ec328
parenta7c72e0de593e77863d68d10e05d392c40b61cda (diff)
downloadorg-mode-1feafbfa99b27d093db18b5423aba8e604e2a0c9.tar.gz
org-attach: 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.
-rw-r--r--lisp/org-attach.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 5c341a5..1737ec1 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -120,6 +120,17 @@ 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 +486,17 @@ 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: