* Checkboxes and state toggling
@ 2011-06-10 15:56 Klaus Thoben
2011-06-10 17:16 ` Nick Dokos
0 siblings, 1 reply; 3+ messages in thread
From: Klaus Thoben @ 2011-06-10 15:56 UTC (permalink / raw)
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Checkboxes and state toggling
2011-06-10 15:56 Checkboxes and state toggling Klaus Thoben
@ 2011-06-10 17:16 ` Nick Dokos
2011-06-14 20:22 ` Klaus Thoben
0 siblings, 1 reply; 3+ messages in thread
From: Nick Dokos @ 2011-06-10 17:16 UTC (permalink / raw)
To: Klaus Thoben; +Cc: nicholas.dokos, emacs-orgmode
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Checkboxes and state toggling
2011-06-10 17:16 ` Nick Dokos
@ 2011-06-14 20:22 ` Klaus Thoben
0 siblings, 0 replies; 3+ messages in thread
From: Klaus Thoben @ 2011-06-14 20:22 UTC (permalink / raw)
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-06-14 20:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-10 15:56 Checkboxes and state toggling Klaus Thoben
2011-06-10 17:16 ` Nick Dokos
2011-06-14 20:22 ` Klaus Thoben
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).