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 ms0.migadu.com with LMTPS id AEaPAs4DkmBZ4AAAgWs5BA (envelope-from ) for ; Wed, 05 May 2021 04:32:46 +0200 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 sNnrOc0DkmDpPwAA1q6Kng (envelope-from ) for ; Wed, 05 May 2021 02:32:45 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5436423432 for ; Wed, 5 May 2021 04:32:45 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6FC03271D6; Tue, 4 May 2021 22:32:19 -0400 (EDT) X-Greylist: delayed 310 seconds by postgrey-1.36 at nmbug; Tue, 04 May 2021 22:32:16 EDT Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by mail.notmuchmail.org (Postfix) with ESMTPS id B074720017 for ; Tue, 4 May 2021 22:32:16 -0400 (EDT) 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=1620181616; 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:references:references; bh=5186+uFOUVVjNH5GRCrqIzKpF//W8TdNlfHPVyq+iwQ=; b=JGKY9NKtNstgbRhLhrGKVvpQbCV2o2uUkrkTJKvKit2DWOKFtHOoFaXOaOzjVIMcGhvhR0 1B8HVWk2XJde4G0FjsV94+6tpoRrRlsNe330siv+x2PCzXrdMpoxmDS2r4Pry7uoDBkN4i nY5XNfuPJnrApUfGsIkEFhdTC5TyzL0BFAcP8+pnI7jUTFaSBbZNlVGTnyFHKU2fIGVGUB 63O2JY61BJtPKauDj73dW8EcfZqXXGXFXKKFZmaT8lFIRhr7ejcR2T3ksHrbS632qVOvcD Soudr9JgDd7EnvCjDLwCKjJ3/d8ebisTgHWKYBnmvUPUYL6iob5F+7YCLkFAsA== From: Kyle Meyer To: Matt Lundin Subject: [PATCH] emacs: restore tag-changes and query bindings for tag hooks In-Reply-To: <87v97ytd2s.fsf@fastmail.fm> References: <87v97ytd2s.fsf@fastmail.fm> Date: Tue, 04 May 2021 22:26:53 -0400 Message-ID: <87sg319aqa.fsf@kyleam.com> MIME-Version: 1.0 X-Migadu-Auth-User: kyle@kyleam.com Message-ID-Hash: DC7E7LUW3K3ZCAOSPKOTPVFDZ772Z7KE X-Message-ID-Hash: DC7E7LUW3K3ZCAOSPKOTPVFDZ772Z7KE X-MailFrom: kyle@kyleam.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: notmuch@notmuchmail.org X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620181965; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=ZXHk14yfXPze/ZV7F2NuCshIfEMmaMIU1qGFZrAITUk=; b=P1X9Be0K9aa80NXm4QH1QxOEMe+Jk57Wk9T/u3HZiIcIxCxgCw1u/kQEw+56nAjoTBQ08L R/xJ0inCYlgVqM5Mulk/vKz7OWTG7QY2F6gHRa7wMLDhLZ+O+aC1UTVtrf14pI4v5k0AmG 7rGKNUrVPcBCTd1qBXVcr4nfWn8memoHChXV/xFu0aabQzrwy+37jvDuV38tA3PK23hvyN eT9BColfObs3ZnD6aLVM6IHyP99wBU85lu9fTAPtnU9/qQXyfKFAQWvTlda8JdLVohJ8VY MtJw4Mfgw2HMNftlv/1ws5y8v6qradIzdMCcyA9W2U2QvQJ4stjrLvX6Pubjjw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620181965; a=rsa-sha256; cv=none; b=StyWTUXBuRtEqWo4HMrFQAVkEqdQ2zHzW2BhP2s0H7wwMzw9Hiph5FnKTdaCyN3WzT+oVQ 0dmKUKZtYyFDm/RgtmPFPAwHz1woSGjzUgBMWINJqR2bUuEOvjeEvG9WWGfqwtdUNDYesz 1cXDkvvR7doLD+7X9YDoqmwPe7NahBgw2q50lNgFPsOsNCKuTq9KmqnC+y7nXjhys6HMTt nSQ+HJHcQaPumMkx1MgMAKG/xEySNCZ4zvAQkPvLTldgDobOVV+eI9WbuZLhVnb3NyRmxR rRaHaaYUbtMCFORJ/kqQcB7ZOmeT8du93eTw8/KW45+YUs6n/p6q8sXv6Xyyrw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=kyleam.com header.s=key1 header.b=JGKY9NKt; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.09 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=kyleam.com header.s=key1 header.b=JGKY9NKt; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 5436423432 X-Spam-Score: -1.09 X-Migadu-Scanner: scn0.migadu.com X-TUID: HgQ4f2vket8f Matt Lundin writes: > With the upgrade to notmuch 0.32, functions added to > 'notmuch-after-tag-hook' or 'notmuch-before-tag-hook' no longer have > access to the 'tag-changes' or 'query' variables advertised in the > docstrings of both hooks. If I try to access either variable in a hook > function, emacs throws an error. I believe this results from the > addition of lexical binding in commit fc4cda07a9af. The approach in the patch below is similar to some changes I've seen Stefan Monnier do for lexical binding conversions. -- >8 -- Subject: [PATCH] emacs: restore tag-changes and query bindings for tag hooks notmuch-before-tag-hook and notmuch-after-tag-hook are supposed to have access to two dynamic variables, tag-changes and query, but these were lost with the switch to lexical binding in fc4cda07 (emacs: use lexical-bindings in all libraries, 2021-01-13). Add a variant of Emacs's dlet (not available until Emacs 28) and use it in notmuch-tag to expose tag-changes and query to the hooks. --- emacs/notmuch-compat.el | 12 ++++++++++++ emacs/notmuch-tag.el | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch-compat.el b/emacs/notmuch-compat.el index ad134dfe..179bf59c 100644 --- a/emacs/notmuch-compat.el +++ b/emacs/notmuch-compat.el @@ -41,6 +41,18 @@ (defun notmuch-message--fold-long-headers () (unless (fboundp 'message--fold-long-headers) (add-hook 'message-header-hook 'notmuch-message--fold-long-headers)) +;; `dlet' isn't available until Emacs 28.1. Below is a copy, with the +;; addition of `with-no-warnings'. +(defmacro notmuch-dlet (binders &rest body) + "Like `let*' but using dynamic scoping." + (declare (indent 1) (debug let)) + `(let (_) + (with-no-warnings ; Quiet "lacks a prefix" warning. + ,@(mapcar (lambda (binder) + `(defvar ,(if (consp binder) (car binder) binder))) + binders)) + (let* ,binders ,@body))) + (provide 'notmuch-compat) ;;; notmuch-compat.el ends here diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el index f348d4ae..ebccb5a0 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -486,7 +486,9 @@ (defun notmuch-tag (query tag-changes) (unless query (error "Nothing to tag!")) (when tag-changes - (run-hooks 'notmuch-before-tag-hook) + (notmuch-dlet ((tag-changes tag-changes) + (query query)) + (run-hooks 'notmuch-before-tag-hook)) (if (<= (length query) notmuch-tag-argument-limit) (apply 'notmuch-call-notmuch-process "tag" (append tag-changes (list "--" query))) @@ -494,7 +496,9 @@ (defun notmuch-tag (query tag-changes) (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ") " -- " query))) (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch"))) - (run-hooks 'notmuch-after-tag-hook))) + (notmuch-dlet ((tag-changes tag-changes) + (query query)) + (run-hooks 'notmuch-after-tag-hook)))) (defun notmuch-tag-change-list (tags &optional reverse) "Convert TAGS into a list of tag changes. base-commit: 63413a5563450bdedee4c077f2f998578e75083a -- 2.31.1