Sorry, forgot to actually attach the patch, here it is.
>From 95cdfa8c3ec81b3a0763b68044611c10a4dadc29 Mon Sep 17 00:00:00 2001
From: Jay Kamat <[email protected]>
Date: Sat, 2 Sep 2017 15:57:36 -0400
Subject: [PATCH] org-archive.el: Update statistic cookies when archiving
* lisp/org-archive.el (org-archive-subtree): Update todo statistics
when calling `org-archive-subtree'.
(org-archive-to-archive-sibling): Update cookie statistics when
calling `org-archive-to-archive-sibling'.
This can be disabled by setting `org-provide-todo-statistics' to nil.
---
lisp/org-archive.el | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lisp/org-archive.el b/lisp/org-archive.el
index adb922e75..9c24d356c 100644
--- a/lisp/org-archive.el
+++ b/lisp/org-archive.el
@@ -393,6 +393,12 @@ direct children of this heading."
(when (featurep 'org-inlinetask)
(org-inlinetask-remove-END-maybe))
(setq org-markers-to-move nil)
+ (when org-provide-todo-statistics
+ (save-excursion
+ ;; Go to parent, even if no children exist
+ (org-up-heading-safe)
+ ;; Update cookie of parent
+ (org-update-statistics-cookies nil)))
(message "Subtree archived %s"
(if (eq this-buffer buffer)
(concat "under heading: " heading)
@@ -470,6 +476,9 @@ Archiving time is retained in the ARCHIVE_TIME node property."
(outline-hide-subtree)
(org-cycle-show-empty-lines 'folded)
(goto-char pos)))
+ (when org-provide-todo-statistics
+ ;; update todo statistics of parent
+ (org-update-parent-todo-statistics))
(org-reveal)
(if (looking-at "^[ \t]*$")
(outline-next-visible-heading 1))))
--
2.11.0
Jay Kamat <[email protected]> writes:
> Hi,
>
> Currently, statistic cookies do not update when archiving headings. For
> example, when archiving the 'Two' header in the below example:
>
> * Top [50%]
> ** TODO One
> ** DONE Two
>
> The status cookie on 'Top' does not get set to [100%].
>
> I have attached a draft patch to add support for this. However, I think
> it needs a little bit more work.
>
> There are 3 archive methods, org-archive-subtree,
> org-archive-to-archive-sibling, and org-archive-set-tag.
>
> For org-archive-set-tag, setting the :ARCHIVE: tag does not seem to
> affect the status cookie, so I did not touch that.
>
> For org-archive-to-archive-sibling, I used the
> (org-update-parent-todo-statistics) function, which seems to work as
> expected.
>
> For org-archive-subtree, the solution I came up with is a little more
> complicated, to handle the edge case of archiving the last child
> header. In this case, 'parent' refers to the wrong (or non-existent)
> header, so I use a small function to call (org-up-heading-safe) on one
> header above point, which seems to work even for this edge case. I'm not
> entirely sure if it's the proper solution though.
>
> Let me know if you have any feedback!
>
> -Jay