* How to do <something> for all clocks in the region or subtree?
@ 2016-03-19 10:49 Marcin Borkowski
2016-03-20 10:17 ` Nicolas Goaziou
0 siblings, 1 reply; 3+ messages in thread
From: Marcin Borkowski @ 2016-03-19 10:49 UTC (permalink / raw)
To: Org-Mode mailing list
Hi list,
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:
--8<---------------cut here---------------start------------->8---
(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)
(if (eq (org-element-type (org-element-at-point))
'clock)
(do-something-with-clock-at-point))))))
--8<---------------cut here---------------end--------------->8---
Is it ok or is there some fancy way of iterating across all clock
entries in the region? (I don't want any dependencies - only vanilla
Org!)
TIA,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to do <something> for all clocks in the region or subtree?
2016-03-19 10:49 How to do <something> for all clocks in the region or subtree? Marcin Borkowski
@ 2016-03-20 10:17 ` Nicolas Goaziou
2016-03-20 14:02 ` Marcin Borkowski
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2016-03-20 10:17 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: Org-Mode mailing list
Hello,
Marcin Borkowski <mbork@mbork.pl> 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.
> (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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to do <something> for all clocks in the region or subtree?
2016-03-20 10:17 ` Nicolas Goaziou
@ 2016-03-20 14:02 ` Marcin Borkowski
0 siblings, 0 replies; 3+ messages in thread
From: Marcin Borkowski @ 2016-03-20 14:02 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org-Mode mailing list
On 2016-03-20, at 11:17, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Hello,
>
> Marcin Borkowski <mbork@mbork.pl> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-03-20 14:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-19 10:49 How to do <something> for all clocks in the region or subtree? Marcin Borkowski
2016-03-20 10:17 ` Nicolas Goaziou
2016-03-20 14:02 ` Marcin Borkowski
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).