emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: James Harkins <jamshark70@qq.com>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: after-todo-statistics hook for checkboxes
Date: Wed, 15 Oct 2014 15:45:14 +0200	[thread overview]
Message-ID: <877g014fbp.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <20141015213843.6003d235@hjh-e431> (James Harkins's message of "Wed, 15 Oct 2014 21:38:43 +0800")

Hello,

James Harkins <jamshark70@qq.com> writes:

> On Wed, 15 Oct 2014 19:08:31 +0800
> James Harkins <jamshark70@qq.com> 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)

See also "org-checklist.el" in contrib/.


Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2014-10-15 13:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15 11:08 after-todo-statistics hook for checkboxes James Harkins
2014-10-15 13:38 ` James Harkins
2014-10-15 13:45   ` Nicolas Goaziou [this message]
     [not found]     ` <1491661ce88.27cd.0bb60a3c7e492ea180363c67eb170725@qq.com>
2014-10-16  1:01       ` James Harkins
2014-10-16 16:39         ` Nicolas Goaziou
2014-10-16 23:23           ` James Harkins
2014-10-17 20:22             ` Nicolas Goaziou
2014-10-18  2:21               ` James Harkins
2014-10-18  7:31                 ` Nicolas Goaziou
2014-10-20 12:46                   ` Bastien

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=877g014fbp.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=jamshark70@qq.com \
    /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).