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 16:30:18 -0500 Message-ID: <87zhj170np.fsf@alphapapa.net> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:50901) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAhWu-0001de-IN for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 17:30:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAhWt-00085C-Jp for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 17:30:28 -0400 Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:57096 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAhWt-00084j-DZ for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 17:30:27 -0400 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1iAhWq-000crK-Hf for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 23:30:24 +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: > 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