emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kevin Foley <kevin@kevinjfoley.me>
To: Kyle Meyer <kyle@kyleam.com>
Cc: emacs-orgmode@gnu.org, Ihor Radchenko <yantar92@gmail.com>
Subject: Re: [PATCH] Org Agenda Support Argument Collection for Custom Bulk Functions (was: Custom Bulk Functions With Prompt)
Date: Wed, 27 Jan 2021 18:13:01 -0500	[thread overview]
Message-ID: <m2zh0uvurm.fsf@Kevins-MBP.home.lan> (raw)
In-Reply-To: <87zh11sfnu.fsf@kyleam.com>

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

Kyle Meyer <kyle@kyleam.com> writes:

Thanks for the review Kyle.

> nit: No ":" after "lisp/org-agenda.el".

Fixed.

> Drop either "about" or "for"?

Fixed.

> In addition to the NEWS entry that Ihor mentioned, it looks like an
> update to the manual is missing.

NEWS entry added.  With regard to the manual, the custom bulk function
option is only mentioned as a footnote.  I'm happy to add a more in
depth explanation, however I'm not sure where it should go, any
recommendations?

> s/it's/its/

Fixed.

> Should this :type be updated?

Updated.  I went with list with and optional second element for the
argument collection function (I also updated my patch to handle a nil
second argument).

I think it makes sense to encourage use of the list even when not using
an argument collection function but let me know if you think a choice
between function and list would be better.

> Please update this version, or rather drop :version and add
>   :package-version '(Org . "9.5")

Updated.


Thanks,
Kevin


[-- 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: 3630 bytes --]

From 1d09a90abcb4136a3cf7562870f7eda831f163d3 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
 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 | 29 +++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 5e5f1954d..4958d2b2e 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -81,8 +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 
+*** =ob-python= improvements to =:return= header argument
 
 The =:return= header argument in =ob-python= now works for session
 blocks as well as non-session blocks.  Also, it now works with the
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index dedf7e5bb..c5c1b54ba 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.
+
+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
+its 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 (list (function :tag "Bulk Custom Function")
+                                  (choice (const :tag "No Bulk Custom Argument Function" nil)
+                                          (function :tag "Bulk Custom Argument Function"))))
+  :package-version '(Org . "9.5")
   :group 'org-agenda)
 
 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
@@ -10487,7 +10503,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 (when (nth 1 f) (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


  reply	other threads:[~2021-01-27 23:13 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               ` [PATCH] Org Agenda Support Argument Collection for Custom Bulk Functions (was: Custom Bulk Functions With Prompt) Kevin Foley
2021-01-22  5:14                 ` Ihor Radchenko
2021-01-22  5:29                 ` Kyle Meyer
2021-01-27 23:13                   ` Kevin Foley [this message]
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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=m2zh0uvurm.fsf@Kevins-MBP.home.lan \
    --to=kevin@kevinjfoley.me \
    --cc=emacs-orgmode@gnu.org \
    --cc=kyle@kyleam.com \
    --cc=yantar92@gmail.com \
    --subject='Re: [PATCH] Org Agenda Support Argument Collection for Custom Bulk Functions (was: Custom Bulk Functions With Prompt)' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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