[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 16:30:18 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Matt Price <address@hidden> 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
Re: [O] org-map-entries but with arguments?, John Kitchin, 2019/09/18