From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Checkboxes and state toggling Date: Fri, 10 Jun 2011 13:16:49 -0400 Message-ID: <6667.1307726209@alphaville.americas.hpqcorp.net> References: <87r5718ytv.fsf@sputnik.localhost> Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([140.186.70.92]:51947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QV5KH-0003O7-Oh for emacs-orgmode@gnu.org; Fri, 10 Jun 2011 13:16:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QV5KF-0003tR-MH for emacs-orgmode@gnu.org; Fri, 10 Jun 2011 13:16:53 -0400 Received: from g1t0029.austin.hp.com ([15.216.28.36]:32275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QV5KF-0003sz-BP for emacs-orgmode@gnu.org; Fri, 10 Jun 2011 13:16:51 -0400 In-Reply-To: Message from Klaus Thoben of "Fri, 10 Jun 2011 17:56:28 +0200." <87r5718ytv.fsf@sputnik.localhost> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Klaus Thoben Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org Klaus Thoben 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