emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Org-Mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: How to do <something> for all clocks in the region or subtree?
Date: Sun, 20 Mar 2016 11:17:19 +0100	[thread overview]
Message-ID: <87twk1jvww.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <871t76g2te.fsf@mbork.pl> (Marcin Borkowski's message of "Sat, 19 Mar 2016 11:49:33 +0100")

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

  reply	other threads:[~2016-03-20 10:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2016-03-20 14:02   ` Marcin Borkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87twk1jvww.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=mbork@mbork.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).