unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Updated fix for notmuch-{before,after}-tag-hook
@ 2021-05-08 12:11 David Bremner
  2021-05-08 12:11 ` [PATCH 1/3] test: add known broken tests for notuch-{before,after}-tag-hook David Bremner
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Bremner @ 2021-05-08 12:11 UTC (permalink / raw)
  To: notmuch; +Cc: jonas

The gist is the same, I just added some tests and a minimal NEWS item,

Jonas, I somehow failed at my last attempt to ask you about Kyle's
patch, so here it is again.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] test: add known broken tests for notuch-{before,after}-tag-hook
  2021-05-08 12:11 Updated fix for notmuch-{before,after}-tag-hook David Bremner
@ 2021-05-08 12:11 ` David Bremner
  2021-05-08 12:11 ` [PATCH 2/3] emacs: restore tag-changes and query bindings for tag hooks David Bremner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2021-05-08 12:11 UTC (permalink / raw)
  To: notmuch; +Cc: jonas, David Bremner

These tests illustrate the bug reported in id:87v97ytd2s.fsf@fastmail.fm
---
 test/T310-emacs.sh | 24 ++++++++++++++++++++++++
 test/test-lib.el   |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index 78ac19a8..5ebc8e66 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -161,6 +161,30 @@ test_emacs "(notmuch-show \"$os_x_darwin_thread\")
 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")
+	       (execute-kbd-macro "+activate-hook\n")
+	       (execute-kbd-macro "-activate-hook\n")
+	       notmuch-test-tag-hook-output)')
+test_expect_equal "$output" \
+'(("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "-activate-hook")
+ ("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")
+	       (execute-kbd-macro "+activate-hook\n")
+	       (execute-kbd-macro "-activate-hook\n")
+	       notmuch-test-tag-hook-output)')
+test_expect_equal "$output" \
+'(("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "-activate-hook")
+ ("id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com" "+activate-hook"))'
+
 test_begin_subtest "Message with .. in Message-Id:"
 add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'
 test_emacs '(notmuch-search "id:\"123..456@example\"")
diff --git a/test/test-lib.el b/test/test-lib.el
index 4de5b292..32d53736 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -99,6 +99,9 @@ running, quit if it terminated."
 (add-hook 'notmuch-hello-refresh-hook
 	  (lambda () (cl-incf notmuch-hello-refresh-hook-counter)))
 
+(defvar notmuch-test-tag-hook-output nil)
+(defun notmuch-test-tag-hook () (push (cons query tag-changes) notmuch-test-tag-hook-output))
+
 (defun notmuch-test-mark-links ()
   "Enclose links in the current buffer with << and >>."
   ;; Links are often created by jit-lock functions
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] emacs: restore tag-changes and query bindings for tag hooks
  2021-05-08 12:11 Updated fix for notmuch-{before,after}-tag-hook David Bremner
  2021-05-08 12:11 ` [PATCH 1/3] test: add known broken tests for notuch-{before,after}-tag-hook David Bremner
@ 2021-05-08 12:11 ` David Bremner
  2021-05-08 12:11 ` [PATCH 3/3] NEWS: add NEWS for notmuch-{before,after}-tag-hook fixes David Bremner
  2021-05-15 12:12 ` Updated fix for notmuch-{before,after}-tag-hook David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2021-05-08 12:11 UTC (permalink / raw)
  To: notmuch; +Cc: jonas, Kyle Meyer

From: Kyle Meyer <kyle@kyleam.com>

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] NEWS: add NEWS for notmuch-{before,after}-tag-hook fixes
  2021-05-08 12:11 Updated fix for notmuch-{before,after}-tag-hook David Bremner
  2021-05-08 12:11 ` [PATCH 1/3] test: add known broken tests for notuch-{before,after}-tag-hook David Bremner
  2021-05-08 12:11 ` [PATCH 2/3] emacs: restore tag-changes and query bindings for tag hooks David Bremner
@ 2021-05-08 12:11 ` David Bremner
  2021-05-15 12:12 ` Updated fix for notmuch-{before,after}-tag-hook David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2021-05-08 12:11 UTC (permalink / raw)
  To: notmuch; +Cc: jonas, David Bremner

---
 NEWS | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/NEWS b/NEWS
index 44a18951..a3e59da4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,19 @@
 Notmuch 0.32.1 (UNRELEASED)
 ===========================
 
+General
+-------
+
 Restore handling of relative values for `database.path` that was
 broken by 0.32. Extend this handling to `database.mail_root`,
 `database.backup_dir`, and `database.hook_dir`.
 
+Emacs
+-----
+
+Restore the dynamically bound variables `tag-changes` and `query` in
+in `notmuch-before-tag-hook` and `notmuch-after-tag-hook`.
+
 Notmuch 0.32 (2021-05-02)
 =========================
 
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Updated fix for notmuch-{before,after}-tag-hook
  2021-05-08 12:11 Updated fix for notmuch-{before,after}-tag-hook David Bremner
                   ` (2 preceding siblings ...)
  2021-05-08 12:11 ` [PATCH 3/3] NEWS: add NEWS for notmuch-{before,after}-tag-hook fixes David Bremner
@ 2021-05-15 12:12 ` David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2021-05-15 12:12 UTC (permalink / raw)
  To: notmuch; +Cc: jonas

David Bremner <david@tethera.net> writes:

> The gist is the same, I just added some tests and a minimal NEWS item,
>
> Jonas, I somehow failed at my last attempt to ask you about Kyle's
> patch, so here it is again.

I have applied this series to master and release

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-15 12:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-08 12:11 Updated fix for notmuch-{before,after}-tag-hook David Bremner
2021-05-08 12:11 ` [PATCH 1/3] test: add known broken tests for notuch-{before,after}-tag-hook David Bremner
2021-05-08 12:11 ` [PATCH 2/3] emacs: restore tag-changes and query bindings for tag hooks David Bremner
2021-05-08 12:11 ` [PATCH 3/3] NEWS: add NEWS for notmuch-{before,after}-tag-hook fixes David Bremner
2021-05-15 12:12 ` Updated fix for notmuch-{before,after}-tag-hook David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).