emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kevin Foley <kevin@kevinjfoley.me>
To: Ihor Radchenko <yantar92@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Org Agenda Support Argument Collection for Custom Bulk Functions (was: Custom Bulk Functions With Prompt)
Date: Thu, 21 Jan 2021 09:01:35 -0500	[thread overview]
Message-ID: <m2bldijsn4.fsf@Kevins-MBP.home.lan> (raw)
In-Reply-To: <87v9bsumpb.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 201 bytes --]

Attached patch should allow user to specify a function to collect
arguments when calling a custom bulk function such that those arguments
are only collected once and used for each entry.

Kevin Foley

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda.el-Support-argument-collection-for-custom.patch --]
[-- Type: text/x-patch, Size: 2223 bytes --]

From dfab64f738f227691d84a2fdec5bba2cf4f1e3b0 Mon Sep 17 00:00:00 2001
From: "Kevin J. Foley" <kevin@kevinjfoley.me>
Date: Thu, 21 Jan 2021 08:48:52 -0500
Subject: [PATCH] org-agenda.el: Support argument collection for custom bulk

* 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)
 	 (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

  reply	other threads:[~2021-01-21 14:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-17  2:31 Custom Bulk Functions With Prompt Kevin Foley
2021-01-17  5:42 ` Ihor Radchenko
2021-01-17 18:06   ` Kevin Foley
2021-01-18  2:11     ` Ihor Radchenko
2021-01-18  2:14       ` Kevin Foley
2021-01-18  8:50         ` Ihor Radchenko
2021-01-19 18:36           ` Kevin Foley
2021-01-20  6:49             ` Ihor Radchenko
2021-01-21 14:01               ` Kevin Foley [this message]
2021-01-22  5:14                 ` [PATCH] Org Agenda Support Argument Collection for Custom Bulk Functions (was: Custom Bulk Functions With Prompt) Ihor Radchenko
2021-01-22  5:29                 ` Kyle Meyer
2021-01-27 23:13                   ` Kevin Foley
2021-01-30  7:48                     ` Kyle Meyer
2021-02-13 17:29                       ` Kevin Foley
2021-02-14 20:23                         ` Kyle Meyer
2021-02-15  2:30                           ` Kevin Foley
2021-02-15  3:01                             ` Kyle Meyer
2021-02-15 14:04                               ` Kevin Foley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2bldijsn4.fsf@Kevins-MBP.home.lan \
    --to=kevin@kevinjfoley.me \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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).