From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jay Kamat Subject: Re: [PATCH] Update statistic cookies when archiving Date: Sat, 02 Sep 2017 16:11:16 -0400 Message-ID: <87mv6cyi6z.fsf@gmail.com> References: <87r2voyi9z.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1doElH-0003og-Pc for emacs-orgmode@gnu.org; Sat, 02 Sep 2017 16:11:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1doElD-0005Vb-2F for emacs-orgmode@gnu.org; Sat, 02 Sep 2017 16:11:23 -0400 Received: from mail-yw0-x232.google.com ([2607:f8b0:4002:c05::232]:35860) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1doElC-0005VM-S7 for emacs-orgmode@gnu.org; Sat, 02 Sep 2017 16:11:18 -0400 Received: by mail-yw0-x232.google.com with SMTP id h127so12756636ywf.3 for ; Sat, 02 Sep 2017 13:11:18 -0700 (PDT) Received: from laythe (res380d-128-61-81-32.res.gatech.edu. [128.61.81.32]) by smtp.gmail.com with ESMTPSA id s3sm1176812ywj.74.2017.09.02.13.11.16 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 02 Sep 2017 13:11:17 -0700 (PDT) In-Reply-To: <87r2voyi9z.fsf@gmail.com> (Jay Kamat's message of "Sat, 02 Sep 2017 16:09:28 -0400") 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" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Sorry, forgot to actually attach the patch, here it is. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-archive.el-Update-statistic-cookies-when-archivi.patch >From 95cdfa8c3ec81b3a0763b68044611c10a4dadc29 Mon Sep 17 00:00:00 2001 From: Jay Kamat 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 --=-=-= Content-Type: text/plain Jay Kamat 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 --=-=-=--