From: Adam Porter <adam@alphapapa.net>
To: emacs-orgmode@gnu.org
Subject: Re: org-map-entries but with arguments?
Date: Wed, 18 Sep 2019 20:34:25 -0500 [thread overview]
Message-ID: <87impp6pcu.fsf@alphapapa.net> (raw)
In-Reply-To: CAN_Dec-zmNYQww5o6XW-kEWaVfQ=ofWfof-TFiGVVeVrc7wNgA@mail.gmail.com
Matt Price <moptop99@gmail.com> writes:
> OK, this is pretty cool, thank you. I took John's excellent
> suggestion of using a headline property to store the appropriate
> actions, but it makes sense to switch to org-ql if I can master the
> syntax (which seems awfully powerful). One questions: does
> org-ql-select respect buffer narrowing? That would be important for
> me.
Yes, just pass the argument ":narrow t". Take a look at the examples
and documentation, you can do a bunch of things. :)
> Another question. In place of a function or sexp, the :action key
> accepts the keyword "element" as a value, and will return a parsed
> headline. Is it possible to then pass that value on to a function that
> will be evaluated? I'm asking because I have a bunch of functions with
> very long `let` sections in which information is extracted from a
> headline with (org-entry-get).
There are a few ways to do something like that:
1. Just call functions like org-entry-get from the action function
(which is called with point at each match). For simple things, this is
the simplest way.
2. In a custom action function, do what the "element" action does, i.e.
(org-element-headline-parser (line-end-position)), then do whatever you
need with the resulting element.
3. Collect the elements into a list (i.e. use ":action 'element") and
map across it. Since that requires more consing, it will probably be
slower, but likely not a performance problem in most cases.
> It would be nice to use John's plist trick (from the other thread
> we're on) to, essentially, let-plist all the properties of the
> headline. It would declutter my code significantly.
You'll probably want to use -let from dash.el, with its &plist or &keys
destructuring. &plist was added to -let since John wrote that article,
and it also gives you all the other powerful features of -let. It works
well and is fast. You could also use pcase-let*'s destructuring, which
is built-in to Emacs, but its syntax is a bit more complex.
next prev parent reply other threads:[~2019-09-19 1:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-18 18:51 org-map-entries but with arguments? Matt Price
2019-09-18 21:30 ` Adam Porter
[not found] ` <CAN_Dec8gBJ9+A+tvhDzGVwcMV7NmMRj=UMfLQyrDr51NtAabgA@mail.gmail.com>
2019-09-19 1:10 ` Matt Price
2019-09-19 1:34 ` Adam Porter [this message]
2019-09-19 1:42 ` John Kitchin
2019-09-19 13:31 ` Matt Price
2019-09-18 23:28 ` John Kitchin
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=87impp6pcu.fsf@alphapapa.net \
--to=adam@alphapapa.net \
--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 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).