From 319dcfb50e5bc929719167afa353e19632ea55f3 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 8 May 2021 09:11:12 -0300 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 ++++++-- test/T310-emacs.sh | 2 -- 3 files changed, 18 insertions(+), 4 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 @@ (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 @@ notmuch-after-tag-hook will be run." (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 @@ notmuch-after-tag-hook will be run." (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. diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh index 5ebc8e66..e6489246 100755 --- a/test/T310-emacs.sh +++ b/test/T310-emacs.sh @@ -162,7 +162,6 @@ output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)" test_begin_subtest "notmuch-show: before-tag-hook is run, variables are defined" -test_subtest_known_broken output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil) (notmuch-before-tag-hook (function notmuch-test-tag-hook))) (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com") @@ -174,7 +173,6 @@ test_expect_equal "$output" \ ("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))' test_begin_subtest "notmuch-show: after-tag-hook is run, variables are defined" -test_subtest_known_broken output=$(test_emacs '(let ((notmuch-test-tag-hook-output nil) (notmuch-after-tag-hook (function notmuch-test-tag-hook))) (notmuch-show "id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com") -- 2.43.0