Procházet zdrojové kódy

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.
Eric Abrahamsen před 10 roky
rodič
revize
1feafbfa99
1 změnil soubory, kde provedl 22 přidání a 0 odebrání
  1. 22 0
      lisp/org-attach.el

+ 22 - 0
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: