From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: org-map-entries but with arguments? Date: Thu, 19 Sep 2019 09:31:57 -0400 Message-ID: References: <87zhj170np.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000000254cc0592e7fb78" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:47749) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAwXd-0001gN-Jv for emacs-orgmode@gnu.org; Thu, 19 Sep 2019 09:32:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAwXb-0004DN-7v for emacs-orgmode@gnu.org; Thu, 19 Sep 2019 09:32:13 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:38021) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iAwXa-0004Ce-VP for emacs-orgmode@gnu.org; Thu, 19 Sep 2019 09:32:11 -0400 Received: by mail-pl1-x62f.google.com with SMTP id w10so1643734plq.5 for ; Thu, 19 Sep 2019 06:32:10 -0700 (PDT) In-Reply-To: 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: John Kitchin Cc: Adam Porter , Org Mode --0000000000000254cc0592e7fb78 Content-Type: text/plain; charset="UTF-8" On Wed., Sep. 18, 2019, 9:42 p.m. John Kitchin, wrote: > You can get an alist of all the properties in an entry with > org-entry-properties, and then you can let-alist these, or do something > else. Here is an example that might be related. > > * test > :PROPERTIES: > :some-random-property: True > :END: > > #+BEGIN_SRC emacs-lisp :results code > (org-entry-properties) > #+END_SRC > > #+RESULTS: > #+begin_src emacs-lisp > (("CATEGORY" . "2019-09-18 21:33") > ("SOME-RANDOM-PROPERTY" . "True") > ("BLOCKED" . "") > ("FILE" . "/Users/jkitchin/Box > Sync/kitchingroup/jkitchin/journal/2019/09/18 21:33/2019-09-18 21:33.org") > ("PRIORITY" . "B") > ("ITEM" . "test")) > #+end_src > > #+BEGIN_SRC emacs-lisp > (let-alist (cl-loop for (key . value) in (org-entry-properties) > collect (cons (intern key) value)) > .SOME-RANDOM-PROPERTY) > #+END_SRC > > #+RESULTS: > : True > > John > Jeez, thanks John. For some reason when I first tried org-entry-properties I thought it was only reporting back the standard properties, like ITEM. And in any case I had forgotten how to convert strings to symbols. This is enormously helpful. > > ----------------------------------- > Professor John Kitchin > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > > > > On Wed, Sep 18, 2019 at 9:11 PM Matt Price wrote: > >> >> Sorry, replied to Adam directly by accident. >> >> On Wed, Sep 18, 2019 at 8:32 PM Matt Price wrote: >> >>> >>> >>> On Wed, Sep 18, 2019 at 5:31 PM Adam Porter wrote: >>> >>>> Matt Price writes: >>>> >>>> > Is there a lisp trick for adding arguments to the function called by >>>> > `org-map-entries`? >>>> > >>>> > I have the following function: >>>> > >>>> > (cl-defun org-lms-return-all-assignments (&optional (send-all nil) >>>> (also-mail nil) (post-to-lms t) ) >>>> > "By default mail all subtrees 'READY' to student recipients, unless >>>> SEND-ALL is non-nil. >>>> > In that case, send all marked 'READY' or 'TODO'." >>>> > (interactive) >>>> > (message "Mailing all READY subtrees to students") >>>> > (let ((send-condition >>>> > (if send-all >>>> > `(or (string= (org-element-property :todo-keyword item) >>>> "READY") >>>> > (string= (org-element-property :todo-keyword item) >>>> "TODO") ) >>>> > `(string= (org-element-property :todo-keyword item) >>>> "READY") >>>> > ))) >>>> > (org-map-entries >>>> > #'ol-send-just-one)) >>>> > (org-cycle-hide-drawers 'all)) >>>> > >>>> > I'd like to relay some of hte functions arguments to the one called >>>> > internally to do the work. ~(ol-send-just-one~ takes an ~also-mail~ >>>> > and a ~post-to-lms~ parameter,just like >>>> > ~org-lms-return-all-assignments~, but I'm not sure how to trick >>>> > org-map-entries into passing those arguments on. Any hints? Thank >>>> > you! >>>> >>>> Hi Matt, >>>> >>>> If I may, I think org-ql can help you here. It should also work much >>>> faster than org-map-entries, because it can skip to entries with the >>>> desired to-do keywords (although you could also use the MATCH argument >>>> to org-map-entries to improve its speed). Try this function (untested): >>>> >>>> #+BEGIN_SRC elisp >>>> (cl-defun org-lms-return-all-assignments-ql (&optional (send-all nil) >>>> (also-mail nil) (post-to-lms t)) >>>> "By default mail all subtrees 'READY' to student recipients, unless >>>> SEND-ALL is non-nil. >>>> In that case, send all marked 'READY' or 'TODO'." >>>> (interactive) >>>> (message "Mailing all READY subtrees to students") >>>> (let ((todo-keywords (if send-all >>>> '("READY" "TODO") >>>> '("READY")))) >>>> (org-ql-select (current-buffer) >>>> `(todo ,@todo-keywords) >>>> :action `(ol-send-just-one ,also-mail ,post-to-lms)))) >>>> #+END_SRC >>>> >>>> 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. >>> >>> Man, hard to hold all this stuff in my head. ANd very hard to navigate >>> my own code now that I see how ugly it is. >>> >> >> 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). 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. >> > --0000000000000254cc0592e7fb78 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed., Sep. 18, 2019, 9:42 p.m. John Kitchin, <jkitchin@andrew.cmu.edu> wr= ote:
You can get an alist of all the properties in an entry with org-en= try-properties, and then you can let-alist these, or do something else. Her= e is an example that might be related.

* test
=C2=A0= :PROPERTIES:
=C2=A0 :some-random-property: True
=C2=A0 :END:

= #+BEGIN_SRC emacs-lisp :results code
(org-entry-properties)
#+END_SRC=

#+RESULTS:
#+begin_src emacs-lisp
(("CATEGORY" . &q= uot;2019-09-18 21:33")
=C2=A0("SOME-RANDOM-PROPERTY" . &q= uot;True")
=C2=A0("BLOCKED" . "")
=C2=A0(&qu= ot;FILE" . "/Users/jkitchin/Box Sync/kitchingroup/jkitchin/journa= l/2019/09/18 21:33/2019-09-18 21:33.org")
=C2=A0("PRIORITY" . &qu= ot;B")
=C2=A0("ITEM" . "test"))
#+end_src
#+BEGIN_SRC emacs-lisp
(let-alist (cl-loop for (key . value) in (or= g-entry-properties)
=C2=A0 =C2=A0collect (cons (intern key) value))<= br>=C2=A0.SOME-RANDOM-PROPERTY)
#+END_SRC

#+RESULTS:
: True

<= /div>
John

Jeez, t= hanks John. For some reason when I first tried org-entry-properties I thoug= ht it was only reporting back the standard properties, like ITEM.=C2=A0 And= in any case I had forgotten how to convert strings to symbols. This is eno= rmously helpful.=C2=A0

--------------= ---------------------
Professor John Kitchin=C2=A0
Doherty Hall A207F=
Department of Chemical Engineering
Carnegie Mellon University
Pit= tsburgh, PA 15213
412-268-7803
<= /div>

On Wed, Sep 18, 2019 at 9:11 PM Matt Price <moptop99@gmail.com<= /a>> wrote:
<= div dir=3D"ltr">

Sorry, replied to Adam dire= ctly by accident.



On Wed, Sep 18, 2019 at 5= :31 PM Adam Porter <adam@alphapapa.net> wrote:
Matt Price <moptop99@gmail.com<= /a>> writes:

> Is there a lisp trick for adding arguments to the function called by > `org-map-entries`?
>
> I have the following function:
>
> (cl-defun org-lms-return-all-assignments (&optional (send-all nil)= (also-mail nil) (post-to-lms t) )
>=C2=A0 =C2=A0"By default mail all subtrees 'READY' to stud= ent recipients, unless SEND-ALL is non-nil.
> In that case, send all marked 'READY' or 'TODO'."=
>=C2=A0 =C2=A0(interactive)
>=C2=A0 =C2=A0(message "Mailing all READY subtrees to students"= ;)
>=C2=A0 =C2=A0(let ((send-condition
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if send-all
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 `(or (string=3D (org-e= lement-property :todo-keyword item) "READY")
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(s= tring=3D (org-element-property :todo-keyword item) "TODO") )
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 `(string=3D (org-element-prop= erty :todo-keyword item) "READY")
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )))
>=C2=A0 =C2=A0 =C2=A0(org-map-entries
>=C2=A0 =C2=A0 =C2=A0 #'ol-send-just-one))
>=C2=A0 =C2=A0(org-cycle-hide-drawers 'all))
>
> I'd like to relay some of hte functions arguments to the one calle= d
> internally to do the work.=C2=A0 ~(ol-send-just-one~ takes an ~also-ma= il~
> and a ~post-to-lms~ parameter,just like
> ~org-lms-return-all-assignments~, but I'm not sure how to trick > org-map-entries into passing those arguments on. Any hints?=C2=A0 Than= k
> you!

Hi Matt,

If I may, I think org-ql can help you here.=C2=A0 It should also work much<= br> faster than org-map-entries, because it can skip to entries with the
desired to-do keywords (although you could also use the MATCH argument
to org-map-entries to improve its speed).=C2=A0 Try this function (untested= ):

#+BEGIN_SRC elisp
(cl-defun org-lms-return-all-assignments-ql (&optional (send-all nil) (= also-mail nil) (post-to-lms t))
=C2=A0 "By default mail all subtrees 'READY' to student recipi= ents, unless SEND-ALL is non-nil.
In that case, send all marked 'READY' or 'TODO'."
=C2=A0 (interactive)
=C2=A0 (message "Mailing all READY subtrees to students")
=C2=A0 (let ((todo-keywords (if send-all
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0'("READY" "TODO")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0'("READY"))))
=C2=A0 =C2=A0 (org-ql-select (current-buffer)
=C2=A0 =C2=A0 =C2=A0 `(todo ,@todo-keywords)
=C2=A0 =C2=A0 =C2=A0 :action `(ol-send-just-one ,also-mail ,post-to-lms))))=
#+END_SRC



--0000000000000254cc0592e7fb78--