From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: [PATCH RFC] subtree archive hook? Date: Mon, 13 Oct 2014 00:10:18 +0800 Message-ID: <87r3yd2rrp.fsf@ericabrahamsen.net> References: <87vbnp2wix.fsf@ericabrahamsen.net> <87oathia7m.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdLfG-0002Rd-UY for emacs-orgmode@gnu.org; Sun, 12 Oct 2014 12:06:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XdLfA-00020v-PL for emacs-orgmode@gnu.org; Sun, 12 Oct 2014 12:06:34 -0400 Received: from plane.gmane.org ([80.91.229.3]:49593) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdLfA-00020p-EL for emacs-orgmode@gnu.org; Sun, 12 Oct 2014 12:06:28 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XdLf8-00019U-TH for emacs-orgmode@gnu.org; Sun, 12 Oct 2014 18:06:26 +0200 Received: from 114.248.11.237 ([114.248.11.237]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 12 Oct 2014 18:06:26 +0200 Received: from eric by 114.248.11.237 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 12 Oct 2014 18:06:26 +0200 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Disposition: inline Aaron Ecay writes: > Hi Eric, > > Looks like a sensible feature. One comment: > > 2014ko urriak 12an, Eric Abrahamsen-ek idatzi zuen: >> >> 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! >> >> Eric >> >> From 1bfc84570f29dd884c2759dfe19116f09228ed4e Mon Sep 17 00:00:00 2001 >> From: Eric Abrahamsen >> Date: Sun, 12 Oct 2014 22:01:29 +0800 >> Subject: [PATCH 2/3] Provide a hook during the archive process >> >> * lisp/org-archive.el (org-archive-hook): New hook. >> (org-archive-subtree): Run hook. >> --- >> lisp/org-archive.el | 13 +++++++++++-- >> 1 file changed, 11 insertions(+), 2 deletions(-) >> >> diff --git a/lisp/org-archive.el b/lisp/org-archive.el >> index 700e59b..c7f02b9 100644 >> --- a/lisp/org-archive.el >> +++ b/lisp/org-archive.el >> @@ -119,6 +119,13 @@ information." >> (const :tag "Outline path" olpath) >> (const :tag "Local tags" ltags))) >> >> +(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 >> +archive location, but not yet deleted from the original file.") >> + >> (defun org-get-local-archive-location () >> "Get the archive location applicable at point." >> (let ((re "^[ \t]*#\\+ARCHIVE:[ \t]+\\(\\S-.*\\S-\\)[ \t]*$") >> @@ -366,8 +373,10 @@ this heading." >> ;; Save and kill the buffer, if it is not the same buffer. >> (when (not (eq this-buffer buffer)) >> (save-buffer)))) >> - ;; Here we are back in the original buffer. Everything seems to have >> - ;; worked. So now cut the tree and finish up. >> + ;; Here we are back in the original buffer. Everything seems >> + ;; to have worked. So now run hooks, cut the tree and finish >> + ;; up. >> + (run-hooks 'org-archive-hook) >> (let (this-command) (org-cut-subtree)) >> (when (featurep 'org-inlinetask) >> (org-inlinetask-remove-END-maybe)) > > Can the above inlinetask thing also be moved into the hook? That > seems cleaner, and gives another demonstration of the usefulness of > the feature. Here's a patch that does it, though I'm a little more cautious about this since I only did a minimal test. Two things that worry me: 1) why is it called "remove-END-maybe" when it appears to remove the whole inlinetask, and 2) it its original habitat in org-attach, it came after the call to org-cut-subtree, meaning that it couldn't have operated on the subtree to be archived at all! Or am I misunderstanding something? I tried it on a test subtree, and the org-cut-subtree took out the included inlinetask as well. Anyway, it's a little mysterious, and I'm less confident about this bit. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0004-Move-deletion-of-inlinetasks-to-archive-hook.patch >From 3236ba94c92c021311f7ffb128686f9c2751d4e1 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sun, 12 Oct 2014 23:48:49 +0800 Subject: [PATCH 4/4] Move deletion of inlinetasks to archive hook * lisp/org-archive.el (org-archive-subtree): Remove org-inlinetask specific code. * lisp/org-inlinetask.el: Add org-inlinetask-remove-END-maybe to the org-archive-hook. --- lisp/org-archive.el | 2 -- lisp/org-inlinetask.el | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/org-archive.el b/lisp/org-archive.el index c7f02b9..6d07f5a 100644 --- a/lisp/org-archive.el +++ b/lisp/org-archive.el @@ -378,8 +378,6 @@ this heading." ;; up. (run-hooks 'org-archive-hook) (let (this-command) (org-cut-subtree)) - (when (featurep 'org-inlinetask) - (org-inlinetask-remove-END-maybe)) (setq org-markers-to-move nil) (message "Subtree archived %s" (if (eq this-buffer buffer) diff --git a/lisp/org-inlinetask.el b/lisp/org-inlinetask.el index 9e0aadb..206ddf3 100644 --- a/lisp/org-inlinetask.el +++ b/lisp/org-inlinetask.el @@ -325,6 +325,8 @@ If the task has an end part, also demote it." org-inlinetask-min-level)) (replace-match ""))) +(add-hook 'org-archive-hook 'org-inlinetask-remove-END-maybe) + (eval-after-load "org" '(add-hook 'org-font-lock-hook 'org-inlinetask-fontify)) -- 2.1.2 --=-=-=--