From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Maus Subject: Re: New feature: loop over siblings for some commands Date: Wed, 27 Jul 2011 20:47:23 +0200 Message-ID: <87wrf3lfwk.wl%dmaus@ictsoc.de> References: <87aacchtv8.fsf@gnu.org> <87zkkayvld.wl%dmaus@ictsoc.de> <87pql4g2fg.wl%dmaus@ictsoc.de> <87pqkvu4ij.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/signed; boundary="pgp-sign-Multipart_Wed_Jul_27_20:47:21_2011-1"; micalg=pgp-sha256; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:50097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qm98j-0000LD-EX for emacs-orgmode@gnu.org; Wed, 27 Jul 2011 14:47:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qm98h-00048X-T6 for emacs-orgmode@gnu.org; Wed, 27 Jul 2011 14:47:29 -0400 Received: from app1b.xlhost.de ([213.202.242.162]:48793) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qm98h-00045A-K9 for emacs-orgmode@gnu.org; Wed, 27 Jul 2011 14:47:27 -0400 In-Reply-To: <87pqkvu4ij.fsf@gnu.org> 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: Bastien Cc: David Maus , emacs-orgmode@gnu.org --pgp-sign-Multipart_Wed_Jul_27_20:47:21_2011-1 Content-Type: text/plain; charset=US-ASCII Hi Bastien, At Wed, 27 Jul 2011 17:28:36 +0200, Bastien wrote: > > Hi David, > > David Maus 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 --pgp-sign-Multipart_Wed_Jul_27_20:47:21_2011-1 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iF4EABEIAAYFAk4wXTkACgkQma24O1pEeOaowAD9FqkOzJaeqrkcAgWrV6XMx8dj YfWJAWkWKiNFB0zHH0MA/1IdoM62SZ3gZQwbdhHGB/R/0ReGENDkSixPocv0oflM =bgTY -----END PGP SIGNATURE----- --pgp-sign-Multipart_Wed_Jul_27_20:47:21_2011-1--