From mboxrd@z Thu Jan 1 00:00:00 1970 From: James Harkins Subject: Re: after-todo-statistics hook for checkboxes Date: Wed, 15 Oct 2014 21:38:43 +0800 Message-ID: <20141015213843.6003d235@hjh-e431> References: <87a94xk2ts.wl-jamshark70@qq.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/j0uMu6tlN62ILu/uM/iv099" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeOnF-0006Li-Sy for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 09:39:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeOn7-0003RO-P5 for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 09:39:09 -0400 Received: from smtpbg63.qq.com ([103.7.29.150]:40843) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeOn6-0003OM-NQ for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 09:39:01 -0400 Received: from hjh-e431 (unknown [113.109.22.122]) by esmtp4.qq.com (ESMTP) with SMTP id 0 for ; Wed, 15 Oct 2014 21:38:53 +0800 (CST) In-Reply-To: <87a94xk2ts.wl-jamshark70@qq.com> 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: orgmode --MP_/j0uMu6tlN62ILu/uM/iv099 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wed, 15 Oct 2014 19:08:31 +0800 James Harkins wrote: > org-after-todo-statistics-hook allows you to do something to a node after its statistics cookie got updated. Unfortunately, it does this only for TODO subheadings and it doesn't work with checkboxes. > (snip) > Actually... after a little more poking around, the problem seems to be that org-update-checkbox-count refers to no hooks whatsoever. Should it go toward the end, here? (Untested.) > > (mapc (lambda (cookie) > (let* ((beg (car cookie)) > (end (nth 1 cookie)) > (percentp (nth 2 cookie)) > (checked (car (nth 3 cookie))) > (total (cdr (nth 3 cookie))) > (new (if percentp > (format "[%d%%]" (/ (* 100 checked) > (max 1 total))) > (format "[%d/%d]" checked total)))) > (goto-char beg) > (insert new) > (delete-region (point) (+ (point) (- end beg))) > (run-hook-with-args 'org-after-todo-statistics-hook > checked (- total checked)) > (when org-auto-align-tags (org-fix-tags-on-the-fly)))) > cookies-list)))) After dinner, I tested the change that I had speculated about, and... it works exactly correctly. * TODO Test A [0/2] ** TODO Test B [0/2] - [ ] 1 - [ ] 2 ** TODO Test C C-c C-c on "1" (with my hook function[1]): * TODO Test A [0/2] ** INPROG Test B [1/2] - [X] 1 - [ ] 2 ** TODO Test C C-c C-c on "2": * INPROG Test A [1/2] ** DONE Test B [2/2] - [X] 1 - [X] 2 ** TODO Test C So I'm submitting this as a TINYCHANGE patch. Do with it as you will, although I will keep using it locally until something better comes along. hjh [1] (defun hjh-org-summary-todo (n-done n-not-done) "Switch entry to DONE when all subentries are done, to TODO otherwise." (let (org-log-done org-log-states) ; turn off logging (org-todo (if (= n-not-done 0) "DONE" (if (= n-done 0) "TODO" "INPROG"))))) (add-hook 'org-after-todo-statistics-hook 'hjh-org-summary-todo) --MP_/j0uMu6tlN62ILu/uM/iv099 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-Run-org-after-todo-statistics-hook-when-toggling-a-c.patch >From cbb4c589b1ed65152485ea2b687eb54ff7e2e478 Mon Sep 17 00:00:00 2001 From: James Harkins Date: Wed, 15 Oct 2014 21:32:28 +0800 Subject: [PATCH] Run org-after-todo-statistics-hook when toggling a checkbox * org-list.el (org-update-checkbox-count): Run org-after-todo-statistics-hook for each affected cookie. TINYCHANGE --- lisp/org-list.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/org-list.el b/lisp/org-list.el index b1d47c9..2fdda6b 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -2553,6 +2553,8 @@ With optional prefix argument ALL, do this for the whole buffer." (goto-char beg) (insert new) (delete-region (point) (+ (point) (- end beg))) + (run-hook-with-args 'org-after-todo-statistics-hook + checked (- total checked)) (when org-auto-align-tags (org-fix-tags-on-the-fly)))) cookies-list)))) -- 1.7.9.5 --MP_/j0uMu6tlN62ILu/uM/iv099--