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.
(unless (fboundp 'message--fold-long-headers)
(add-hook 'message-header-hook '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
(provide 'notmuch-compat)
;;; notmuch-compat.el ends here
(unless query
(error "Nothing to tag!"))
(when 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)))
(if (<= (length query) notmuch-tag-argument-limit)
(apply 'notmuch-call-notmuch-process "tag"
(append tag-changes (list "--" query)))
(let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ")
" -- " query)))
(notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch")))
(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.
(defun notmuch-tag-change-list (tags &optional reverse)
"Convert TAGS into a list of tag changes.
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_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")
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")
("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))'
test_begin_subtest "notmuch-show: after-tag-hook is run, variables are defined"
("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")
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")