From dfab64f738f227691d84a2fdec5bba2cf4f1e3b0 Mon Sep 17 00:00:00 2001 From: "Kevin J. Foley" Date: Thu, 21 Jan 2021 08:48:52 -0500 Subject: [PATCH] org-agenda.el: Support argument collection for custom bulk functions * lisp/org-agenda.el: (org-agenda-bulk-custom-functions): Add documentation about for collection arguments for custom bulk functions. (org-agenda-bulk-action): Support function to collect arguments for custom bulk functions. --- lisp/org-agenda.el | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index dedf7e5bb..deadacc1e 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -2080,7 +2080,20 @@ (defcustom org-agenda-bulk-custom-functions nil With selected entries in an agenda buffer, `B R' will call the custom function `set-category' on the selected entries. -Note that functions in this alist don't need to be quoted." +Note that functions in this alist don't need to be quoted. + +If the custom function accepts arguments which you'd like to +collect once from the user to be used for each call, you can pass +a list with the bulk function, and the function which collects +it's arguments and returns them as a list. For example: + + \\='((?R (set-category get-category)) + (?C bulk-cut)) + +Now, `B R' will call the custom `get-category' which would prompt +the user once for a category. That category is then passed as an +argument to `set-category' for each entry it's called against. +" :type '(alist :key-type character :value-type (group function)) :version "24.1" :group 'org-agenda) @@ -10487,7 +10500,12 @@ (defun org-agenda-bulk-action (&optional arg) (action (pcase (assoc action org-agenda-bulk-custom-functions) - (`(,_ ,f) (setq cmd f) (setq redo-at-end t)) + (`(,_ ,f) + (when (listp f) + (let ((args (funcall (nth 1 f))) + (func (nth 0 f))) + (setq f (apply #'apply-partially func args)))) + (setq cmd f) (setq redo-at-end t)) (_ (user-error "Invalid bulk action: %c" action))))) ;; Sort the markers, to make sure that parents are handled -- 2.28.0