emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-map-entries but with arguments?


From: Adam Porter
Subject: Re: [O] org-map-entries but with arguments?
Date: Wed, 18 Sep 2019 20:34:25 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Matt Price <address@hidden> 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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]