emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Kevin Foley <kevin@kevinjfoley.me>
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: Sun, 14 Feb 2021 15:23:49 -0500	[thread overview]
Message-ID: <877dnamm96.fsf@kyleam.com> (raw)
In-Reply-To: <m2lfbrj2pb.fsf@Kevins-MBP.home.lan>

Kevin Foley writes:

> Kyle Meyer <kyle@kyleam.com> writes:
>
>>   (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
[...]
> Side note I'm not sure your example would render properly regardless
> since `my/bulk-action' and `my/args' aren't functions.

I'm confused by this.  They were defined just above the text you quoted:

  (defun my/bulk-action (&rest args)
    args)

  (defun my/args ()
    (list 1 2 3))

  (setq org-agenda-bulk-custom-functions
  [...]

Either way, your latest defcustom type as well as the rest of the
update, aside from the issue I note below, looks good to me.  Thanks.

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

Aren't the pcase-let bindings missing a set of parentheses?

  (pcase-let (`(,_ ,fn ,arg-fn)
              (list 1 2 3))
    (list fn arg-fn))  ; let: Invalid function: (\, _)

  (pcase-let ((`(,_ ,fn ,arg-fn)
               (list 1 2 3)))
    (list fn arg-fn))  ; => (2 3)

However, I don't see using pcase-let here as an improvement.  Admittedly
it's mostly subjective, but I think it's unhelpfully permissive for this
use case:

  (pcase-let ((`(,a ,b) (list 1 2 3 4)))
    (list a b))  ; => (1 2)

Fwiw, here's a relevant emacs.devel thread:
https://lists.gnu.org/archive/html/emacs-devel/2015-07/msg00103.html
(message ID: <jwvegkfoniv.fsf-monnier+emacs@gnu.org>)

My pcase-based suggestion, on top of your patch, is below.  If that
looks okay to you, there's no need to resend; I can squash it in.

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 42d127232..d6499e6b0 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -10502,14 +10502,15 @@ (defun org-agenda-bulk-action (&optional arg)
 		(completing-read "Function: " obarray #'fboundp t nil nil))))
 
 	(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)))))
+         (setq cmd
+               (pcase (assoc action org-agenda-bulk-custom-functions)
+                 (`(,_ ,fn)
+                  fn)
+                 (`(,_ ,fn ,arg-fn)
+                  (apply #'apply-partially fn (funcall arg-fn)))
+                 (_
+                  (user-error "Invalid bulk action: %c" action))))
+         (setq redo-at-end t)))
       ;; Sort the markers, to make sure that parents are handled
       ;; before children.
       (setq entries (sort entries


  reply	other threads:[~2021-02-14 20:24 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
2021-01-30  7:48                     ` Kyle Meyer
2021-02-13 17:29                       ` Kevin Foley
2021-02-14 20:23                         ` Kyle Meyer [this message]
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=877dnamm96.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=kevin@kevinjfoley.me \
    --cc=yantar92@gmail.com \
    /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
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

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