]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: restore tag-changes and query bindings for tag hooks
authorKyle Meyer <kyle@kyleam.com>
Sat, 8 May 2021 12:11:12 +0000 (09:11 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 15 May 2021 11:34:28 +0000 (08:34 -0300)
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
emacs/notmuch-tag.el
test/T310-emacs.sh

index ad134dfee99c273f7ffb5895730364902abe40af..179bf59ca86116e79b64393ff76c41d65db53be9 100644 (file)
 (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
index f348d4ae2dc82c1b0c57570269cf4015a54d939b..ebccb5a089bf59394b6e17026d68bc8ca89c4147 100644 (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.
index 5ebc8e66853a9a2448534e624054b043cc224f6e..e648924675f6551a33414d8d70b04e30b4ea1257 100755 (executable)
@@ -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")