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 +AKHN/mGKWA9YQAA0tVLHw (envelope-from ) for ; Sun, 14 Feb 2021 20:24:25 +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 UBxMM/mGKWBndwAA1q6Kng (envelope-from ) for ; Sun, 14 Feb 2021 20:24:25 +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 AC46715612 for ; Sun, 14 Feb 2021 21:24:24 +0100 (CET) Received: from localhost ([::1]:49066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBNwN-00064O-Ps for larch@yhetil.org; Sun, 14 Feb 2021 15:24:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBNvz-00062g-FK for emacs-orgmode@gnu.org; Sun, 14 Feb 2021 15:23:59 -0500 Received: from out0.migadu.com ([94.23.1.103]:28366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBNvw-0007Zc-15 for emacs-orgmode@gnu.org; Sun, 14 Feb 2021 15:23:59 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1613334231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=tN+hh9e2hcl7bn0Dv8z42sZ2AsnrkNbKs2KCMOMEXyg=; b=q4/OJc8HRgtle0254BxnTTBfkBJMPwk74k9TDAuyaYsqLsxeQS9Y4S636PYm8FoNBllWqZ 7JZb5z+cmRC8p+7qehuNrzM+gXbgg9Ek1tf4Wq5oi2mRs8DdV373Suv3G1dEoIscUFzaWL IOV8K3vXvlPflExdQCevN4PzUzmS2OPbc+P8Ft6z7WcFfJfTFGFexjMIjb9buU/5KxgKFk S8UklpRHHCFfyAZkgcMK2clphniyt9XKcFxsdgBkVZpnAwyxpFcUBxk79y5mGmp1+5u0xg Kuec90aR1RtjZKV402wbFC2E0exdHnh+pJgSZLfidXDbF6hUks785zRgbBm1gQ== From: Kyle Meyer To: Kevin Foley Subject: Re: [PATCH] Org Agenda Support Argument Collection for Custom Bulk Functions (was: Custom Bulk Functions With Prompt) In-Reply-To: Date: Sun, 14 Feb 2021 15:23:49 -0500 Message-ID: <877dnamm96.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Auth-User: kyle@kyleam.com Received-SPF: pass client-ip=94.23.1.103; envelope-from=kyle@kyleam.com; helo=out0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: -1.36 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=kyleam.com header.s=key1 header.b="q4/OJc8H"; 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: AC46715612 X-Spam-Score: -1.36 X-Migadu-Scanner: scn0.migadu.com X-TUID: LoZuc+rJAgiz Kevin Foley writes: > Kyle Meyer 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: ) 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