* org-map-entries but with arguments? @ 2019-09-18 18:51 Matt Price 2019-09-18 21:30 ` Adam Porter 2019-09-18 23:28 ` John Kitchin 0 siblings, 2 replies; 7+ messages in thread From: Matt Price @ 2019-09-18 18:51 UTC (permalink / raw) To: Org Mode [-- Attachment #1: Type: text/plain, Size: 1116 bytes --] 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! [-- Attachment #2: Type: text/html, Size: 1420 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: org-map-entries but with arguments? 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-18 23:28 ` John Kitchin 1 sibling, 1 reply; 7+ messages in thread From: Adam Porter @ 2019-09-18 21:30 UTC (permalink / raw) To: emacs-orgmode Matt Price <moptop99@gmail.com> 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAN_Dec8gBJ9+A+tvhDzGVwcMV7NmMRj=UMfLQyrDr51NtAabgA@mail.gmail.com>]
* Re: org-map-entries but with arguments? [not found] ` <CAN_Dec8gBJ9+A+tvhDzGVwcMV7NmMRj=UMfLQyrDr51NtAabgA@mail.gmail.com> @ 2019-09-19 1:10 ` Matt Price 2019-09-19 1:34 ` Adam Porter 2019-09-19 1:42 ` John Kitchin 0 siblings, 2 replies; 7+ messages in thread From: Matt Price @ 2019-09-19 1:10 UTC (permalink / raw) To: Adam Porter, Org Mode [-- Attachment #1: Type: text/plain, Size: 3467 bytes --] Sorry, replied to Adam directly by accident. On Wed, Sep 18, 2019 at 8:32 PM Matt Price <moptop99@gmail.com> wrote: > > > On Wed, Sep 18, 2019 at 5:31 PM Adam Porter <adam@alphapapa.net> wrote: > >> Matt Price <moptop99@gmail.com> 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. [-- Attachment #2: Type: text/html, Size: 4687 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: org-map-entries but with arguments? 2019-09-19 1:10 ` Matt Price @ 2019-09-19 1:34 ` Adam Porter 2019-09-19 1:42 ` John Kitchin 1 sibling, 0 replies; 7+ messages in thread From: Adam Porter @ 2019-09-19 1:34 UTC (permalink / raw) To: emacs-orgmode 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. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: org-map-entries but with arguments? 2019-09-19 1:10 ` Matt Price 2019-09-19 1:34 ` Adam Porter @ 2019-09-19 1:42 ` John Kitchin 2019-09-19 13:31 ` Matt Price 1 sibling, 1 reply; 7+ messages in thread From: John Kitchin @ 2019-09-19 1:42 UTC (permalink / raw) To: Matt Price; +Cc: Adam Porter, Org Mode [-- Attachment #1: Type: text/plain, Size: 4637 bytes --] 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 ----------------------------------- 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 <moptop99@gmail.com> wrote: > > Sorry, replied to Adam directly by accident. > > On Wed, Sep 18, 2019 at 8:32 PM Matt Price <moptop99@gmail.com> wrote: > >> >> >> On Wed, Sep 18, 2019 at 5:31 PM Adam Porter <adam@alphapapa.net> wrote: >> >>> Matt Price <moptop99@gmail.com> 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. > [-- Attachment #2: Type: text/html, Size: 6633 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: org-map-entries but with arguments? 2019-09-19 1:42 ` John Kitchin @ 2019-09-19 13:31 ` Matt Price 0 siblings, 0 replies; 7+ messages in thread From: Matt Price @ 2019-09-19 13:31 UTC (permalink / raw) To: John Kitchin; +Cc: Adam Porter, Org Mode [-- Attachment #1: Type: text/plain, Size: 5144 bytes --] On Wed., Sep. 18, 2019, 9:42 p.m. John Kitchin, <jkitchin@andrew.cmu.edu> 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 <moptop99@gmail.com> wrote: > >> >> Sorry, replied to Adam directly by accident. >> >> On Wed, Sep 18, 2019 at 8:32 PM Matt Price <moptop99@gmail.com> wrote: >> >>> >>> >>> On Wed, Sep 18, 2019 at 5:31 PM Adam Porter <adam@alphapapa.net> wrote: >>> >>>> Matt Price <moptop99@gmail.com> 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. >> > [-- Attachment #2: Type: text/html, Size: 7821 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: org-map-entries but with arguments? 2019-09-18 18:51 org-map-entries but with arguments? Matt Price 2019-09-18 21:30 ` Adam Porter @ 2019-09-18 23:28 ` John Kitchin 1 sibling, 0 replies; 7+ messages in thread From: John Kitchin @ 2019-09-18 23:28 UTC (permalink / raw) To: Matt Price; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 1791 bytes --] I guess this information should be accessible in the entry where the function is called, e.g. by a property (that may be inherited or set in the file). then in your function just get the property values and do what you want. Alternatively, you can probably do this with global (or maybe lexically let) variables. John ----------------------------------- 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 2:52 PM Matt Price <moptop99@gmail.com> wrote: > 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! > > [-- Attachment #2: Type: text/html, Size: 2604 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-09-19 13:32 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2019-09-19 1:42 ` John Kitchin 2019-09-19 13:31 ` Matt Price 2019-09-18 23:28 ` John Kitchin
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).