From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Automatic tagging based on # of todo items as children Date: Tue, 16 Feb 2010 05:53:23 +0100 Message-ID: <9F69ED3D-EF2E-4166-91D4-A2A102479268@gmail.com> References: <20100215120548.6ef57e56@hsdev.com> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NhFRB-0001PA-1b for emacs-orgmode@gnu.org; Mon, 15 Feb 2010 23:53:29 -0500 Received: from [140.186.70.92] (port=60174 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NhFR9-0001O5-9Y for emacs-orgmode@gnu.org; Mon, 15 Feb 2010 23:53:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NhFR8-0004bW-DA for emacs-orgmode@gnu.org; Mon, 15 Feb 2010 23:53:27 -0500 Received: from mail-ew0-f228.google.com ([209.85.219.228]:34087) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NhFR8-0004bM-7b for emacs-orgmode@gnu.org; Mon, 15 Feb 2010 23:53:26 -0500 Received: by ewy28 with SMTP id 28so988715ewy.8 for ; Mon, 15 Feb 2010 20:53:25 -0800 (PST) In-Reply-To: <20100215120548.6ef57e56@hsdev.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: mrb@hsdev.com Cc: emacs-orgmode@gnu.org Hi Marcel, there is not simple other way, because only when making TODO statistics are the TODO children counted. You can hook into `org- after-todo-state-change-hook' with a function that moves back up to the parent and then counts children with TODO keyword. THis is untested: (defun my-define-prj () (save-excursion (when (org-up-heading-safe) (let ((beg (point)) (end (org-end-of-subtree t t)) two-not-done) (goto-char beg) (goto-char (point-at-eol)) (setq two-not-done (and (re-search-forward org-not-done-heading-regexp end t) (re-search-forward org-not-done-heading-regexp end t))) (goto-char beg) (org-toggle-tag "prj" (if two-not-done 'on 'off)))))) (add-hook 'org-after-todo-state-change-hook 'my-define-prj) - Carsten On Feb 15, 2010, at 12:05 PM, mrb@hsdev.com wrote: > Hi, > > I would like to have org-mode assist me in tagging headlines with a > 'prj' tag if that headline contains more than one todo item. It does > not matter if the items are completed or not, if it has more than one > task as its children, I would like to have it tagged with 'prj' > > I came up with this: > > #+begin_src elisp > (defun ensure-prj-tag() > "Ensure a header gets a prj tag" > (interactive) > (org-toggle-tag "prj" > (if (> (length (org-map-entries t "/+TODO|DONE|CANCELLED" 'tree))1) > 'on 'off)) ) > #+end_src > > which sort-of works if the cursor is on the heading. > > I need some help with the following: > - I would like it to be automatic and the org-todo-statistics hook > seem candidates to attach a function to, but I also want it for > heading which do not have a [1/N] or [%] counter. How to proceed? > - Can I do this automatically on a whole file? > > marcel > > -- > Marcel van der Boom -- http://hsdev.com/mvdb.vcf > HS-Development BV -- http://www.hsdev.com > So! web applications -- http://make-it-so.info > Cobra build -- http://cobra.mrblog.nl > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten