Dear List, I wonder if following functionality is already implemented. Could it be achieved that, if I have a checkbox list with a TODO state in the headline and I toggle all of the checkboxes, that the TODO state switches automatically to DONE? I hope the following example makes my question even more clear. * TODO Organize party [1/4] - [ ] call people - [X] order food - [ ] think about what music to play - [ ] talk to the neighbors becomes * DONE Organize party [4/4] - [X] call people - [X] order food - [X] think about what music to play - [X] talk to the neighbors Cheers, Klaus
Klaus Thoben <o22mailinglisten@imap.cc> wrote:
> I wonder if following functionality is already implemented.
>
> Could it be achieved that, if I have a checkbox list with a TODO state
> in the headline and I toggle all of the checkboxes, that the TODO state
> switches automatically to DONE?
>
> I hope the following example makes my question even more clear.
>
> * TODO Organize party [1/4]
> - [ ] call people
> - [X] order food
> - [ ] think about what music to play
> - [ ] talk to the neighbors
>
> becomes
>
> * DONE Organize party [4/4]
> - [X] call people
> - [X] order food
> - [X] think about what music to play
> - [X] talk to the neighbors
>
Here is one way to do that - cobbled together with various bits and
pieces that I found in org.el and org-list.el. In particular, I stole
the regexp from org.el where it is used to check how to fontify the
cookie. I used the org-get-checkbox-statistics-face function as a model
for the ``(if (match-end 1) ...'' structure afterwards (all I had to
do is the (org-todo 'done) calls instead of returning a face).
The initial part limiting the region is pretty standard org code: you'll
find variations of it all over the place.
#+begin_src emacs-lisp
(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)
;; check for the cookie: [100%] or [N/N]
(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))
(if (and (> (match-end 2) (match-beginning 2))
(equal (match-string 2) (match-string 3)))
;; all done - do the state change
(org-todo 'done))))))))
#+end_src
Nick
Nick Dokos <nicholas.dokos@hp.com> writes:
>
> #+begin_src emacs-lisp
> (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)
> ;; check for the cookie: [100%] or [N/N]
> (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))
> (if (and (> (match-end 2) (match-beginning 2))
> (equal (match-string 2) (match-string 3)))
> ;; all done - do the state change
> (org-todo 'done))))))))
> #+end_src
>
> Nick
Thanks, works like charm.
Klaus