emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: Klaus Thoben <o22mailinglisten@imap.cc>
Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org
Subject: Re: Checkboxes and state toggling
Date: Fri, 10 Jun 2011 13:16:49 -0400	[thread overview]
Message-ID: <6667.1307726209@alphaville.americas.hpqcorp.net> (raw)
In-Reply-To: Message from Klaus Thoben <o22mailinglisten@imap.cc> of "Fri, 10 Jun 2011 17:56:28 +0200." <87r5718ytv.fsf@sputnik.localhost>

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

  reply	other threads:[~2011-06-10 17:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-10 15:56 Checkboxes and state toggling Klaus Thoben
2011-06-10 17:16 ` Nick Dokos [this message]
2011-06-14 20:22   ` Klaus Thoben

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=6667.1307726209@alphaville.americas.hpqcorp.net \
    --to=nicholas.dokos@hp.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=o22mailinglisten@imap.cc \
    /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).