From: Jay Kamat <jaygkamat@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Update statistic cookies when archiving
Date: Sat, 02 Sep 2017 16:11:16 -0400 [thread overview]
Message-ID: <87mv6cyi6z.fsf@gmail.com> (raw)
In-Reply-To: <87r2voyi9z.fsf@gmail.com> (Jay Kamat's message of "Sat, 02 Sep 2017 16:09:28 -0400")
[-- Attachment #1: Type: text/plain, Size: 58 bytes --]
Sorry, forgot to actually attach the patch, here it is.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-archive.el-Update-statistic-cookies-when-archivi.patch --]
[-- Type: text/x-diff, Size: 1591 bytes --]
From 95cdfa8c3ec81b3a0763b68044611c10a4dadc29 Mon Sep 17 00:00:00 2001
From: Jay Kamat <jaygkamat@gmail.com>
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
[-- Attachment #3: Type: text/plain, Size: 1239 bytes --]
Jay Kamat <jaygkamat@gmail.com> 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
next prev parent reply other threads:[~2017-09-02 20:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-02 20:09 [PATCH] Update statistic cookies when archiving Jay Kamat
2017-09-02 20:11 ` Jay Kamat [this message]
2017-09-03 8:02 ` Nicolas Goaziou
2017-09-03 16:28 ` Jay Kamat
2017-09-06 12:32 ` Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mv6cyi6z.fsf@gmail.com \
--to=jaygkamat@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).