From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH RFC] subtree archive hook? Date: Mon, 13 Oct 2014 18:13:20 +0200 Message-ID: <87r3ycne1r.fsf@nicolasgoaziou.fr> References: <87vbnp2wix.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdiEm-0003pZ-6b for emacs-orgmode@gnu.org; Mon, 13 Oct 2014 12:12:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XdiEe-0008If-8J for emacs-orgmode@gnu.org; Mon, 13 Oct 2014 12:12:44 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:53622) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdiEd-0008IZ-Vn for emacs-orgmode@gnu.org; Mon, 13 Oct 2014 12:12:36 -0400 In-Reply-To: <87vbnp2wix.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sun, 12 Oct 2014 22:27:34 +0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Abrahamsen Cc: emacs-orgmode@gnu.org Hello, Eric Abrahamsen writes: > I think it would be useful to have a hook that runs before archiving a > subtree. I'm attaching two patches: one that includes a hook in the > archive process, and another (by way of an example) that adds a function > to that hook for the org-attach library. You can set the option > `org-attach-archive-delete' to a non-nil value to have org-attach delete > a subtree's attachments when you archive it. > > Let me know what you think! Thanks for the patch. I think it could be useful. Some comments follow. > +(defvar org-archive-hook nil > + "Hook run after successfully archiving a subtree. > + > +Hook functions are called with point on the subtree in the > +original file. At this stage, the subtree has been added to the You need two spaces after full stop. > * 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, Two spaces are needed. > 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? Non-nil means attachments are deleted upon archiving a subtree. > +Set to nil to never delete attachments, t to always delete > +attachments, and the symbol query to ask." I think you only need to document the `query' symbol, e.g., When set to `query', ask the user instead. > + :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))) You need :package-version and :version is "25.1". > ;;;###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 Two spaces. > +`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)))) (defun org-attach-archive-delete-maybe () (when (if (eq org-attach-archive-delete 'query) (yes-or-no-p "Delete all attachments? ") org-attach-archive-delete) (org-attach-delete-all t))) Regards, -- Nicolas Goaziou