emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* automatically mark DONE when all sub checkboxes are checked
@ 2012-02-10 21:06 Peter Salazar
  2012-02-10 21:13 ` John Hendy
  2012-02-11 18:17 ` Nick Dokos
  0 siblings, 2 replies; 8+ messages in thread
From: Peter Salazar @ 2012-02-10 21:06 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1378 bytes --]

Hello everyone! Org-mode is amazing. I've totally fallen in love with it.
Glad to be joining the community.

I'm trying to get org-mode to automatically mark DONE when all sub
checkboxes are checked. On http://orgmode.org/worg/org-faq.html, I found a
function that purports to do this.

I pasted the function into my .emacs file, but now I'm getting an error
message when I launch: "Symbol's value as variable is void:
org-checkbox-statistics-hook."

Any thoughts? Thanks in advance!


;; see http://thread.gmane.org/gmane.emacs.orgmode/42715
(add-to-list 'org-checkbox-statistics-hook (function
ndk/checkbox-list-complete))

(defun ndk/checkbox-list-complete ()
  (save-excursion
    (org-back-to-heading t)
    (let ((beg (point)) end)
      (end-of-line)
      (setq end (point))
      (goto-char beg)
      (if (re-search-forward
"\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t)
            (if (match-end 1)
                (if (equal (match-string 1) "100%")
                    ;; all done - do the state change
                    (org-todo 'done)
                  (org-todo 'todo))
              (if (and (> (match-end 2) (match-beginning 2))
                       (equal (match-string 2) (match-string 3)))
                  (org-todo 'done)
                (org-todo 'todo))))))))



P.S. Not sure if it's relevant, but I'm on OSX using Aquamacs 2.4.

[-- Attachment #2: Type: text/html, Size: 1966 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automatically mark DONE when all sub checkboxes are checked
  2012-02-10 21:06 automatically mark DONE when all sub checkboxes are checked Peter Salazar
@ 2012-02-10 21:13 ` John Hendy
  2012-02-10 22:31   ` Angel de Vicente
  2012-02-11 18:17 ` Nick Dokos
  1 sibling, 1 reply; 8+ messages in thread
From: John Hendy @ 2012-02-10 21:13 UTC (permalink / raw)
  To: Peter Salazar; +Cc: emacs-orgmode

On Fri, Feb 10, 2012 at 3:06 PM, Peter Salazar <cycleofsong@gmail.com> wrote:
> Hello everyone! Org-mode is amazing. I've totally fallen in love with it.
> Glad to be joining the community.
>
> I'm trying to get org-mode to automatically mark DONE when all sub
> checkboxes are checked. On http://orgmode.org/worg/org-faq.html, I found a
> function that purports to do this.
>
> I pasted the function into my .emacs file, but now I'm getting an error
> message when I launch: "Symbol's value as variable is void:
> org-checkbox-statistics-hook."
>

I don't get any error, but it doesn't work. Also, the example in worg
had an extra parenthesis at the end of it... not sure if that's
goofing it up. I don't know lisp, so I just deleted one of the last
parentheses and loading my .emacs stopped complaining. Not sure if
that last trailing one was the offender or not. In any case, this is
not working for me on an up to date org install (pulled yesterday).


John

> Any thoughts? Thanks in advance!
>
>
> ;; see http://thread.gmane.org/gmane.emacs.orgmode/42715
> (add-to-list 'org-checkbox-statistics-hook (function
> ndk/checkbox-list-complete))
>
> (defun ndk/checkbox-list-complete ()
>   (save-excursion
>     (org-back-to-heading t)
>     (let ((beg (point)) end)
>       (end-of-line)
>       (setq end (point))
>       (goto-char beg)
>       (if (re-search-forward
> "\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t)
>             (if (match-end 1)
>                 (if (equal (match-string 1) "100%")
>                     ;; all done - do the state change
>                     (org-todo 'done)
>                   (org-todo 'todo))
>               (if (and (> (match-end 2) (match-beginning 2))
>                        (equal (match-string 2) (match-string 3)))
>                   (org-todo 'done)
>                 (org-todo 'todo))))))))
>
>
>
> P.S. Not sure if it's relevant, but I'm on OSX using Aquamacs 2.4.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automatically mark DONE when all sub checkboxes are checked
  2012-02-10 21:13 ` John Hendy
@ 2012-02-10 22:31   ` Angel de Vicente
  2012-02-10 22:47     ` John Hendy
  0 siblings, 1 reply; 8+ messages in thread
From: Angel de Vicente @ 2012-02-10 22:31 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

John Hendy <jw.hendy@gmail.com> writes:
> I don't get any error, but it doesn't work. Also, the example in worg
> had an extra parenthesis at the end of it... not sure if that's
> goofing it up. I don't know lisp, so I just deleted one of the last
> parentheses and loading my .emacs stopped complaining. Not sure if
> that last trailing one was the offender or not. In any case, this is
> not working for me on an up to date org install (pulled yesterday).

Perhaps you are trying a TODO heading that doesn't have one of the
progress indicators? 

I have just tried it, and with TODOs headings as follows works OK. If
you don't put the progress indicators then it doesn't work, since the
function is looking for the 100% text or for n/n (which indicates that
you have completed all the tasks).

* TODO try [%]

* TODO try [/]

Actually, I wonder why this is not the default behaviour. It looks
natural that if a task is made of checkboxes and you complete all of
them the task should be DONE.

Cheers,
-- 
Ángel de Vicente
http://angel-de-vicente.blogspot.com/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automatically mark DONE when all sub checkboxes are checked
  2012-02-10 22:31   ` Angel de Vicente
@ 2012-02-10 22:47     ` John Hendy
  2012-02-11  0:41       ` Nick Dokos
  0 siblings, 1 reply; 8+ messages in thread
From: John Hendy @ 2012-02-10 22:47 UTC (permalink / raw)
  To: Angel de Vicente; +Cc: emacs-orgmode

On Fri, Feb 10, 2012 at 4:31 PM, Angel de Vicente <angelv@iac.es> wrote:
> Hi,
>
> John Hendy <jw.hendy@gmail.com> writes:
>> I don't get any error, but it doesn't work. Also, the example in worg
>> had an extra parenthesis at the end of it... not sure if that's
>> goofing it up. I don't know lisp, so I just deleted one of the last
>> parentheses and loading my .emacs stopped complaining. Not sure if
>> that last trailing one was the offender or not. In any case, this is
>> not working for me on an up to date org install (pulled yesterday).
>
> Perhaps you are trying a TODO heading that doesn't have one of the
> progress indicators?
>
> I have just tried it, and with TODOs headings as follows works OK. If
> you don't put the progress indicators then it doesn't work, since the
> function is looking for the 100% text or for n/n (which indicates that
> you have completed all the tasks).
>
> * TODO try [%]
>
> * TODO try [/]

Yup -- that was the ticket. Though the function just seems to cycle
the state to the first done one in the list. My states are:
-- todo next | waiting cancelled done

Thus, when I complete all checkboxes, it actually moves it from todo -> waiting.

In any case, it seems that with the right setup (probably just
changing the order of my items after the =|=) it does work. As a
general  note, I think the manual would be improved with concrete
examples of what this means:

,---
| Note that the code requires that a checkbox statistics
| cookie be present in order for it to work.
`---

I had no idea what that meant and thought it was just reiterating that
you actually need checkboxes for this to work. Now it makes sense.
Even inserting "(a statistics cookie is [/] or [%] in the parent todo
headline)" would make it crystal clear.


Thanks,
John

>
> Actually, I wonder why this is not the default behaviour. It looks
> natural that if a task is made of checkboxes and you complete all of
> them the task should be DONE.
>
> Cheers,
> --
> Ángel de Vicente
> http://angel-de-vicente.blogspot.com/
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automatically mark DONE when all sub checkboxes are checked
  2012-02-10 22:47     ` John Hendy
@ 2012-02-11  0:41       ` Nick Dokos
  2012-02-11  2:20         ` John Hendy
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2012-02-11  0:41 UTC (permalink / raw)
  To: John Hendy; +Cc: Angel de Vicente, nicholas.dokos, emacs-orgmode

John Hendy <jw.hendy@gmail.com> wrote:

> ,---
> | Note that the code requires that a checkbox statistics
> | cookie be present in order for it to work.
> `---
> 
> I had no idea what that meant and thought it was just reiterating that
> you actually need checkboxes for this to work. Now it makes sense.
> Even inserting "(a statistics cookie is [/] or [%] in the parent todo
> headline)" would make it crystal clear.
> 

The manual refers to them as "cookies": searching the index for either
"statistics" or "cookie" takes you to section 5.6 where they are
described.

But you should feel free to add the appropriate words: Worg (as you
know) is editable, and if you found it confusing, somebody else will too
(nudge, nudge). But I beat you to it in this case: thanks for the
suggestion and also for noticing the extra paren as well. OTOH, if you
don't like my verbiage, feel free to change it!

BTW, I don't agree that this should be default behavior (as Angel, I
believe, suggested): whether an item is done may be a matter of checking
boxes in some cases, but not always - for myself, I would like to
maintain the ultimate authority of declaring something done and not to
relegate it to mere code (is that provocative enough? :-) )

In addition, the function slows things down (every time you
check a box, the function runs), it makes a few assumptions about the
environment (todo states, statistics cookies), and I certainly would not
trust it to DTRT all the time: it would need hardening.

Nick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automatically mark DONE when all sub checkboxes are checked
  2012-02-11  0:41       ` Nick Dokos
@ 2012-02-11  2:20         ` John Hendy
  0 siblings, 0 replies; 8+ messages in thread
From: John Hendy @ 2012-02-11  2:20 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Angel de Vicente, emacs-orgmode

On Fri, Feb 10, 2012 at 6:41 PM, Nick Dokos <nicholas.dokos@hp.com> wrote:
> John Hendy <jw.hendy@gmail.com> wrote:
>
>> ,---
>> | Note that the code requires that a checkbox statistics
>> | cookie be present in order for it to work.
>> `---
>>
>> I had no idea what that meant and thought it was just reiterating that
>> you actually need checkboxes for this to work. Now it makes sense.
>> Even inserting "(a statistics cookie is [/] or [%] in the parent todo
>> headline)" would make it crystal clear.
>>
>
> The manual refers to them as "cookies": searching the index for either
> "statistics" or "cookie" takes you to section 5.6 where they are
> described.

Alright, alright... I should have rt[f]m :)

>
> But you should feel free to add the appropriate words: Worg (as you
> know) is editable, and if you found it confusing, somebody else will too
> (nudge, nudge). But I beat you to it in this case: thanks for the
> suggestion and also for noticing the extra paren as well. OTOH, if you
> don't like my verbiage, feel free to change it!
>

I will do this :)

> BTW, I don't agree that this should be default behavior (as Angel, I
> believe, suggested): whether an item is done may be a matter of checking
> boxes in some cases, but not always - for myself, I would like to
> maintain the ultimate authority of declaring something done and not to
> relegate it to mere code (is that provocative enough? :-) )
>
> In addition, the function slows things down (every time you
> check a box, the function runs), it makes a few assumptions about the
> environment (todo states, statistics cookies), and I certainly would not
> trust it to DTRT all the time: it would need hardening.
>

I don't use it, so I don't really care, but I get what you're saying.
I think it should be opt-in. A todo might have *some* things that
you'd like to keep track of with checkboxes, but the task as a whole
might have some other requirement and thus shouldn't really be done
until the user decides.

I'll add a link in the FAQ pointed at the manual section about those
this weekend.


Thanks,
John

> Nick
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automatically mark DONE when all sub checkboxes are checked
  2012-02-10 21:06 automatically mark DONE when all sub checkboxes are checked Peter Salazar
  2012-02-10 21:13 ` John Hendy
@ 2012-02-11 18:17 ` Nick Dokos
  2012-02-13  8:08   ` Peter Salazar
  1 sibling, 1 reply; 8+ messages in thread
From: Nick Dokos @ 2012-02-11 18:17 UTC (permalink / raw)
  To: Peter Salazar; +Cc: nicholas.dokos, emacs-orgmode

Peter Salazar <cycleofsong@gmail.com> wrote:

> Hello everyone! Org-mode is amazing. I've totally fallen in love with it. Glad to be joining the
> community. 
> 
> I'm trying to get org-mode to automatically mark DONE when all sub checkboxes are checked. On http:/
> /orgmode.org/worg/org-faq.html, I found a function that purports to do this.
> 
> I pasted the function into my .emacs file, but now I'm getting an error message when I launch:
> "Symbol's value as variable is void: org-checkbox-statistics-hook." 
> 
> Any thoughts? Thanks in advance! 
> 

You need to do the add-to-list *after* the variable is defined. The
variable is defined in org-list.el, so one way to do it is

	 (require 'org-list)
	 (add-to-list 'org-checkbox-statistics-hook (function ndk/checkbox-list-complete))

This is the sledge hammer approach - and depending on exactly when it's
done, it might cause other problems (e.g. it should probably be done
after the rest of org is loaded). There are various other ways to do it
more gently - e.g.

(eval-after-load 'org-list
     '(add-to-list 'org-checkbox-statistics-hook (function ndk/checkbox-list-complete)))

I'll probably modify the faq to say this (actually, I think the whole kit-n-caboodle
should be moved over to org-hacks and a link should be planted in org-faq pointing to
the org-hacks entry.)

Nick

> ;; see http://thread.gmane.org/gmane.emacs.orgmode/42715
> (add-to-list 'org-checkbox-statistics-hook (function ndk/checkbox-list-complete))
> 
> (defun ndk/checkbox-list-complete ()
>   (save-excursion
>     (org-back-to-heading t)
>     (let ((beg (point)) end)
>       (end-of-line)
>       (setq end (point))
>       (goto-char beg)
>       (if (re-search-forward "\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t)
>             (if (match-end 1)
>                 (if (equal (match-string 1) "100%")
>                     ;; all done - do the state change
>                     (org-todo 'done)
>                   (org-todo 'todo))
>               (if (and (> (match-end 2) (match-beginning 2))
>                        (equal (match-string 2) (match-string 3)))
>                   (org-todo 'done)
>                 (org-todo 'todo))))))))
> 
> P.S. Not sure if it's relevant, but I'm on OSX using Aquamacs 2.4.
> 
> 
> ----------------------------------------------------
> Alternatives:
> 
> ----------------------------------------------------

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: automatically mark DONE when all sub checkboxes are checked
  2012-02-11 18:17 ` Nick Dokos
@ 2012-02-13  8:08   ` Peter Salazar
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Salazar @ 2012-02-13  8:08 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2678 bytes --]

Nick, thank you so much. That worked like a charm!


On Sat, Feb 11, 2012 at 1:17 PM, Nick Dokos <nicholas.dokos@hp.com> wrote:

> Peter Salazar <cycleofsong@gmail.com> wrote:
>
> > Hello everyone! Org-mode is amazing. I've totally fallen in love with
> it. Glad to be joining the
> > community.
> >
> > I'm trying to get org-mode to automatically mark DONE when all sub
> checkboxes are checked. On http:/
> > /orgmode.org/worg/org-faq.html, I found a function that purports to do
> this.
> >
> > I pasted the function into my .emacs file, but now I'm getting an error
> message when I launch:
> > "Symbol's value as variable is void: org-checkbox-statistics-hook."
> >
> > Any thoughts? Thanks in advance!
> >
>
> You need to do the add-to-list *after* the variable is defined. The
> variable is defined in org-list.el, so one way to do it is
>
>         (require 'org-list)
>         (add-to-list 'org-checkbox-statistics-hook (function
> ndk/checkbox-list-complete))
>
> This is the sledge hammer approach - and depending on exactly when it's
> done, it might cause other problems (e.g. it should probably be done
> after the rest of org is loaded). There are various other ways to do it
> more gently - e.g.
>
> (eval-after-load 'org-list
>     '(add-to-list 'org-checkbox-statistics-hook (function
> ndk/checkbox-list-complete)))
>
> I'll probably modify the faq to say this (actually, I think the whole
> kit-n-caboodle
> should be moved over to org-hacks and a link should be planted in org-faq
> pointing to
> the org-hacks entry.)
>
> Nick
>
> > ;; see http://thread.gmane.org/gmane.emacs.orgmode/42715
> > (add-to-list 'org-checkbox-statistics-hook (function
> ndk/checkbox-list-complete))
> >
> > (defun ndk/checkbox-list-complete ()
> >   (save-excursion
> >     (org-back-to-heading t)
> >     (let ((beg (point)) end)
> >       (end-of-line)
> >       (setq end (point))
> >       (goto-char beg)
> >       (if (re-search-forward
> "\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t)
> >             (if (match-end 1)
> >                 (if (equal (match-string 1) "100%")
> >                     ;; all done - do the state change
> >                     (org-todo 'done)
> >                   (org-todo 'todo))
> >               (if (and (> (match-end 2) (match-beginning 2))
> >                        (equal (match-string 2) (match-string 3)))
> >                   (org-todo 'done)
> >                 (org-todo 'todo))))))))
> >
> > P.S. Not sure if it's relevant, but I'm on OSX using Aquamacs 2.4.
> >
> >
> > ----------------------------------------------------
> > Alternatives:
> >
> > ----------------------------------------------------
>

[-- Attachment #2: Type: text/html, Size: 3562 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-02-13  8:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-10 21:06 automatically mark DONE when all sub checkboxes are checked Peter Salazar
2012-02-10 21:13 ` John Hendy
2012-02-10 22:31   ` Angel de Vicente
2012-02-10 22:47     ` John Hendy
2012-02-11  0:41       ` Nick Dokos
2012-02-11  2:20         ` John Hendy
2012-02-11 18:17 ` Nick Dokos
2012-02-13  8:08   ` Peter Salazar

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).