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.
This commit is contained in:
Kyle Meyer 2021-05-08 09:11:12 -03:00 committed by David Bremner
parent a663783343
commit 319dcfb50e
3 changed files with 18 additions and 4 deletions

View file

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

View file

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

View file

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