From: David Maus <dmaus@ictsoc.de>
To: Bastien <bzg@altern.org>
Cc: David Maus <dmaus@ictsoc.de>, emacs-orgmode@gnu.org
Subject: Re: New feature: loop over siblings for some commands
Date: Wed, 27 Jul 2011 20:47:23 +0200 [thread overview]
Message-ID: <87wrf3lfwk.wl%dmaus@ictsoc.de> (raw)
In-Reply-To: <87pqkvu4ij.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 3457 bytes --]
Hi Bastien,
At Wed, 27 Jul 2011 17:28:36 +0200,
Bastien wrote:
>
> Hi David,
>
> David Maus <dmaus@ictsoc.de> writes:
>
> > I highly recommend to not use this macro but to build the intended
> > functionality with separate building blocks: Factor out the flesh of
> > the respective functions (e.g. org-schedule) and use org-map-entries
> > to map. As far as I can see, the latter provides all we need:
>
> I took this road.
>
>
> The first patch manually reverts the commit you are commenting.
>
> The third patch implements the "loop" functionality by just using
> `org-map-entries', not a macro.
>
> I'm sure we could have an `org-loop' macro factoring out the duplicate
> code in the new `org-schedule' and `org-deadline'. If you have time to
> look at this, that will greatly help.
My vacation starts saturday so I do have time and really like to get
my hands dirty with some Lisp hacking.
Now for the macro (2 iterations later): It might not be necessary to
factor out the functions if the function that invokes the looping
can be called recursively.
E.g.
#+begin_src emacs-lisp
(defmacro org-with-headline-siblings (function)
"Apply function to siblings of current headline."
`(org-map-entries ,function 'siblings))
(defun org-schedule ()
(...)
(if (or (not (org-region-active-p))
(not org-loop-over-siblings))
(let ((org-loop-over-siblings nil))
(org-with-headline-siblings 'org-schedule))))
#+end_src
If the function takes arguments, we need to wrap the function call at
the end in a lambda.
And if this works out, we are almost there:
#+begin_src emacs-lisp
(defmacro org-with-headline-siblings-maybe (predicate &rest body)
"Execute body on current headline's siblings if PREDICATE."
`(progn
,@body
(if ,predicate
(org-map-entries '(lambda () (progn ,@body)) 'siblings))))
#+end_src
>
> > Another abstraction: Instead
> > 'org-loop-over-siblings-with-active-region' something like:
> > 'org-loop-over-headlines-with-active-region' that can be set to a
> > symbol or a list of symbols indicating which headings to loop over
> > (e.g. 'siblings, 'children, ...).
>
> The variable is now called `org-loop-over-headlines-in-active-region'
> and understand these kind of values:
>
> - nil: don't loop
> - t: loop over all headlines
> - "MATCH": a tag/property/todo match to loop over matching headlines
>
Nice. These values can fit into org-map-entries MATCH argument, can't
they?
We would have:
org-loop-over-headlines-in-active-region
/
(org-map-entries FUNC &optional MATCH SCOPE &rest SKIP)
/ \
our function region is active
I'm not quite sure, but
a/ we move the check for an active region to org-map-entries: If
SCOPE is 'region but no region is active, org-map-entries simply
returns.
b/ we modify org-map-entries, so that a MATCH of nil means: No
match.
This way we can express the predicate as a condition of map.
#+begin_src emacs-lisp
(defmacro org-loop-over-headlines (&rest body)
`(progn
,@body
(org-map-entries '(lambda () (progn ,@body)) org-loop-over-headlines-in-active-region 'region)))
#+end_src
> If you can test these patches and send some feedback, that'd be nice!
Scheduled for Sunday.
Best,
-- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de
[-- Attachment #2: Type: application/pgp-signature, Size: 230 bytes --]
next prev parent reply other threads:[~2011-07-27 18:47 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-18 8:32 New feature: loop over siblings for some commands Bastien
2011-07-19 18:27 ` David Maus
2011-07-20 19:46 ` David Maus
2011-07-27 15:28 ` Bastien
2011-07-27 18:47 ` David Maus [this message]
2011-07-28 8:54 ` Bastien
2011-08-10 8:34 ` David Maus
2011-08-12 7:58 ` David Maus
2011-08-16 16:36 ` Bastien
2011-08-25 4:25 ` [PATCH 0/5] loop over headlines in active region David Maus
2011-08-25 6:13 ` Carsten Dominik
2011-08-28 13:58 ` David Maus
2011-08-29 9:29 ` Carsten Dominik
2011-08-30 4:36 ` David Maus
2011-08-25 10:08 ` Štěpán Němec
2011-08-28 13:57 ` David Maus
2011-09-07 19:34 ` Štěpán Němec
2011-09-09 4:06 ` David Maus
2011-09-09 10:26 ` Štěpán Němec
2011-09-09 10:41 ` Bastien
2011-09-09 10:46 ` Štěpán Němec
2011-09-09 15:10 ` David Maus
2011-09-09 15:26 ` Štěpán Němec
2011-09-09 15:52 ` David Maus
2011-10-06 8:35 ` Carsten Dominik
2011-10-08 18:59 ` David Maus
2011-10-08 20:11 ` Carsten Dominik
2011-10-08 20:55 ` David Maus
2011-08-25 4:25 ` [PATCH 1/5] Extend scope 'region to include body of last headline " David Maus
2011-08-25 5:40 ` Carsten Dominik
2011-08-30 4:33 ` David Maus
2011-08-25 4:25 ` [PATCH 2/5] Immediately return if scope is region but no region is active David Maus
2011-08-25 5:43 ` Carsten Dominik
2011-08-28 14:00 ` David Maus
2011-08-29 9:31 ` Carsten Dominik
2011-08-30 4:40 ` David Maus
2011-08-25 4:25 ` [PATCH 3/5] New customization variable: Loop over headlines in active region David Maus
2011-08-25 4:25 ` [PATCH 4/5] Skip invisible headlines when mapping " David Maus
2011-08-25 4:25 ` [PATCH 5/5] Avoid conflict between bulk command and loop-over-headlines David Maus
2011-10-22 14:23 ` Bastien
2011-07-27 15:23 ` New feature: loop over siblings for some commands Bastien
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wrf3lfwk.wl%dmaus@ictsoc.de \
--to=dmaus@ictsoc.de \
--cc=bzg@altern.org \
--cc=emacs-orgmode@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.