From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 2A4nBv0MKGA6IQAA0tVLHw (envelope-from ) for ; Sat, 13 Feb 2021 17:31:41 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GDf/Af0MKGCxcAAA1q6Kng (envelope-from ) for ; Sat, 13 Feb 2021 17:31:41 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 37D092F001 for ; Sat, 13 Feb 2021 18:31:40 +0100 (CET) Received: from localhost ([::1]:42542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAyle-00053W-BC for larch@yhetil.org; Sat, 13 Feb 2021 12:31:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAykB-00053B-VM for emacs-orgmode@gnu.org; Sat, 13 Feb 2021 12:30:08 -0500 Received: from mout-p-103.mailbox.org ([80.241.56.161]:11642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1lAyk8-0006ui-Cy for emacs-orgmode@gnu.org; Sat, 13 Feb 2021 12:30:07 -0500 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4DdHS74vVqzQlLR; Sat, 13 Feb 2021 18:29:59 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id ylvsm3EYmJej; Sat, 13 Feb 2021 18:29:56 +0100 (CET) From: Kevin Foley To: Kyle Meyer Subject: Re: [PATCH] Org Agenda Support Argument Collection for Custom Bulk Functions (was: Custom Bulk Functions With Prompt) In-Reply-To: <8735yij25b.fsf@kyleam.com> References: <871rekxgpf.fsf@localhost> <87lfcrvvro.fsf@localhost> <878s8qwrvb.fsf@localhost> <87v9bsumpb.fsf@localhost> <87zh11sfnu.fsf@kyleam.com> <8735yij25b.fsf@kyleam.com> Date: Sat, 13 Feb 2021 12:29:52 -0500 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-MBO-SPAM-Probability: X-Rspamd-Score: -6.54 / 15.00 / 15.00 X-Rspamd-Queue-Id: 8A6C1185F X-Rspamd-UID: 1fb46f Received-SPF: pass client-ip=80.241.56.161; envelope-from=kevin@kevinjfoley.me; helo=mout-p-103.mailbox.org X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org, Ihor Radchenko Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.36 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 37D092F001 X-Spam-Score: -2.36 X-Migadu-Scanner: scn1.migadu.com X-TUID: FmUPTs/QHRf0 --=-=-= Content-Type: text/plain Kyle Meyer writes: > Please fill this line (fill-column in .dir-locals.el is set to 70) > and... >> [...] > ... drop this unrelated space change. Done and done. > Reading this docstring in full, I felt it was a bit odd to repeat the > bulk-cut entry from the initial example again, as it stays the same and > isn't relevant. So perhaps something like this would be clearer: > > ... and returns them as a list. For example, the first > entry in the above example could be extended as > > (?R (set-category get-category)) > > Now, `B R' will ... > > Or perhaps not. I'm okay with it either way and will leave that up to > you. I agree, I've removed it. > Please drop the new line before the closing quote. Done. > convention nit: It'd be good to reflow the type to not go beyond ~80 > columns. Fixed. >> + :type '(alist :key-type character >> + :value-type (list (function :tag "Bulk Custom Function") >> + (choice (const :tag "No Bulk Custom Argument Function" nil) >> + (function :tag "Bulk Custom Argument Function")))) > This type looks like it's specifying a format that isn't supported by > org-agenda-bulk-action: > [...] > I think it'd probably end up a bit cleaner if you go with (key fn > [arg-fn]) I ended up moving to this structure and changing the pcase to a pcase-let which I think makes things a bit cleaner, let me know your thoughts. > (setq org-agenda-bulk-custom-functions > '((?D my/bulk-action) > (?E (my/bulk-action)) > (?F (my/bulk-action my/args)))) > However, customize doesn't render the above value properly I believe I have the type correct for the new layout. For example the following renders correctly: (setq org-agenda-bulk-custom-functions '((?a ignore) (?b ignore nil) (?c ignore ignore))) Side note I'm not sure your example would render properly regardless since `my/bulk-action' and `my/args' aren't functions. Cheers, Kevin Foley --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-agenda.el-Support-argument-collection-for-custom.patch >From 3d5dc61c1565695e797936af1f2eb50cd5460c95 Mon Sep 17 00:00:00 2001 From: "Kevin J. Foley" Date: Sat, 13 Feb 2021 12:04:38 -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 argument collection for custom bulk functions. (org-agenda-bulk-action): Support function to collect arguments for custom bulk functions. * etc/ORG-NEWS (Option ~org-agenda-bulk-custom-functions~ now supports collecting bulk arguments): Add entry to NEWS. --- etc/ORG-NEWS | 7 +++++++ lisp/org-agenda.el | 34 +++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 5e5f1954d..d7de97e2c 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -81,6 +81,13 @@ block. ~org-babel-latex-preamble~, ~org-babel-latex-begin-env~ and the user to specify the preamble and code that preceedes and proceeds the contents of the source block. +*** Option ~org-agenda-bulk-custom-functions~ now supports collecting bulk arguments + +When specifying a custom agenda bulk option, you can now also specify +a function which collects the arguments to be used with each call to +the custom function. + + ** New features *** =ob-python= improvements to =:return= header argument diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index dedf7e5bb..42d127232 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -2080,9 +2080,25 @@ (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." - :type '(alist :key-type character :value-type (group function)) - :version "24.1" +Note that functions in this alist don't need to be quoted. + +You can also specify a function which collects arguments to be +used for each call to your bulk custom function. The argument +collecting function will be run once and should return a list of +arguments to pass to the bulk function. For example: + + \\='((?R set-category get-category)) + +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 :tag "Bulk Custom Function") + (choice (function :tag "Bulk Custom Argument Function") + (const :tag "No Bulk Custom Argument Function" nil)))) + :package-version '(Org . "9.5") :group 'org-agenda) (defmacro org-agenda-with-point-at-orig-entry (string &rest body) @@ -10486,10 +10502,14 @@ (defun org-agenda-bulk-action (&optional arg) (completing-read "Function: " obarray #'fboundp t nil nil)))) (action - (pcase (assoc action org-agenda-bulk-custom-functions) - (`(,_ ,f) (setq cmd f) (setq redo-at-end t)) - (_ (user-error "Invalid bulk action: %c" action))))) - + (pcase-let (`(,_ ,fn ,arg-fn) + (assoc action org-agenda-bulk-custom-functions)) + (if (not fn) + (user-error "Invalid bulk action: %c" action) + (when (functionp arg-fn) + (setq fn (apply #'apply-partially fn (funcall arg-fn)))) + (setq cmd fn) + (setq redo-at-end t))))) ;; Sort the markers, to make sure that parents are handled ;; before children. (setq entries (sort entries -- 2.28.0 --=-=-=--