[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] How to do <something> for all clocks in the region or subtree?
From: |
Marcin Borkowski |
Subject: |
Re: [O] How to do <something> for all clocks in the region or subtree? |
Date: |
Sun, 20 Mar 2016 15:02:27 +0100 |
User-agent: |
mu4e 0.9.13; emacs 25.1.50.7 |
On 2016-03-20, at 11:17, Nicolas Goaziou <address@hidden> wrote:
> Hello,
>
> Marcin Borkowski <address@hidden> writes:
>
>> I have a function which does <something> 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 <something> 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