From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: Re: org-map-entries but with arguments? Date: Wed, 18 Sep 2019 20:34:25 -0500 Message-ID: <87impp6pcu.fsf@alphapapa.net> References: <87zhj170np.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:45992) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAlLD-00040D-8S for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 21:34:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAlL8-0001eM-E7 for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 21:34:39 -0400 Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:59074 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAlL8-0001dQ-7v for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 21:34:34 -0400 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1iAlL5-000DRn-Pb for emacs-orgmode@gnu.org; Thu, 19 Sep 2019 03:34:31 +0200 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" To: emacs-orgmode@gnu.org Matt Price 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.