From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcin Borkowski Subject: Re: How to do for all clocks in the region or subtree? Date: Sun, 20 Mar 2016 15:02:27 +0100 Message-ID: <87k2kxdz7w.fsf@mbork.pl> References: <871t76g2te.fsf@mbork.pl> <87twk1jvww.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahdwG-0000sl-Sp for emacs-orgmode@gnu.org; Sun, 20 Mar 2016 10:02:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahdwD-0002Bm-Ni for emacs-orgmode@gnu.org; Sun, 20 Mar 2016 10:02:40 -0400 Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:53300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahdwD-0002Bi-GL for emacs-orgmode@gnu.org; Sun, 20 Mar 2016 10:02:37 -0400 In-reply-to: <87twk1jvww.fsf@nicolasgoaziou.fr> 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: Nicolas Goaziou Cc: Org-Mode mailing list On 2016-03-20, at 11:17, Nicolas Goaziou wrote: > 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. Thanks, I didn't know that. >> (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. You're obviously right -- I'll use `when'. > Regards, Thanks a lot and best regards, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University