From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: How to do for all clocks in the region or subtree? Date: Sun, 20 Mar 2016 11:17:19 +0100 Message-ID: <87twk1jvww.fsf@nicolasgoaziou.fr> References: <871t76g2te.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahaOC-0007WN-C1 for emacs-orgmode@gnu.org; Sun, 20 Mar 2016 06:15:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahaO9-0003YW-5a for emacs-orgmode@gnu.org; Sun, 20 Mar 2016 06:15:16 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:34134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahaO8-0003Y3-Vb for emacs-orgmode@gnu.org; Sun, 20 Mar 2016 06:15:13 -0400 In-Reply-To: <871t76g2te.fsf@mbork.pl> (Marcin Borkowski's message of "Sat, 19 Mar 2016 11:49:33 +0100") 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: Marcin Borkowski Cc: Org-Mode mailing list Hello, Marcin Borkowski writes: > I have a function which does on a clock the point is on. > I want to call it for every clock in the region if it is active, and if > not, then for every clock in the current subtree. Here's what I have: > > (defun do-something-for-all-clocks (begin end) > "Do for all clocks in the region. > In interactive use, use region if active and current subtree > otherwise. Use with caution!" > (interactive (if (use-region-p) > (list (region-beginning) > (region-end)) > (list nil nil))) > (save-excursion > (save-restriction > (narrow-to-region > (or begin (progn (org-back-to-heading t) > (point))) > (or end (progn (org-end-of-subtree t t) > (when (and (org-at-heading-p) ; see org-narrow-to-subtree > (not (eobp))) > (backward-char 1)) > (point)))) > (goto-char (point-min)) > (while (re-search-forward "^CLOCK: " nil t) The regexp above is not correct. Valid clocks are not required to start at column 0. > (if (eq (org-element-type (org-element-at-point)) > 'clock) > (do-something-with-clock-at-point)))))) `when', or `and' if return value matters, is clearer IMO. Regards, -- Nicolas Goaziou