unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] Add hook inside notmuch-mua-reply
@ 2023-12-10 22:40 Sandra Snan
  2023-12-11 12:03 ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: Sandra Snan @ 2023-12-10 22:40 UTC (permalink / raw)
  To: notmuch; +Cc: Sandra Snan

This hook is run after `notmuch reply` has been successfully called
with the headers from the original message.
---
Can we please get a hook inside notmuch-mua-reply in the Emacs
frontend to notmuch? But not a hook for thunks but a hook that has
access to the message-id for the message we are replying to.

A little bit of `run-hook-with-args`.♥

I know that I can solve the problem with add-advice and I'm gonna do
that for now, but a hook here would save one call to the notmuch
binary when the user hits `r` on a thread with multiple mails.

What I am trying to implement specifically is a plugin for Emacs
autocrypt package. It needs headers from the message you're replying
to, headers beyond what notmuch-reply returns in its sexp.

 emacs/notmuch-mua.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index e4b7e9d1..c40e60af 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -44,6 +44,11 @@
 (defvar notmuch-show-max-text-part-size)
 (defvar notmuch-show-insert-text/plain-hook)
 
+(defvar in-notmuch-mua-reply-functions nil
+  "Functions to run after `notmuch-reply' was called successfully
+without erroring. The functions get the message-id as a string
+argument.")
+
 ;;; Options
 
 (defcustom notmuch-mua-send-hook nil
@@ -256,6 +261,8 @@ Typically this is added to `notmuch-mua-send-hook'."
     ;; Extract the headers of both the reply and the original message.
     (let* ((original-headers (plist-get original :headers))
 	   (reply-headers (plist-get reply :reply-headers)))
+      ;; Run hook here with the original message-id
+      (run-hook-with-args 'in-notmuch-mua-reply-functions (plist-get original :id))
       ;; If sender is non-nil, set the From: header to its value.
       (when sender
 	(plist-put reply-headers :From sender))
-- 
2.39.2
\r

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

* Re: [PATCH] Add hook inside notmuch-mua-reply
  2023-12-10 22:40 [PATCH] Add hook inside notmuch-mua-reply Sandra Snan
@ 2023-12-11 12:03 ` David Bremner
  2023-12-11 12:14   ` Tomi Ollila
  0 siblings, 1 reply; 5+ messages in thread
From: David Bremner @ 2023-12-11 12:03 UTC (permalink / raw)
  To: Sandra Snan, notmuch; +Cc: Sandra Snan

Sandra Snan <sandra.snan@idiomdrottning.org> writes:


> +(defvar in-notmuch-mua-reply-functions nil
> +  "Functions to run after `notmuch-reply' was called successfully
> +without erroring. The functions get the message-id as a string
> +argument.")
> +

Overall this looks reasonable to me, but I'm not sure about the
name. Since emacs doesn't have any namespace facility, I think that any
globals we define should probably start with 'notmuch-'

d

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

* Re: [PATCH] Add hook inside notmuch-mua-reply
  2023-12-11 12:03 ` David Bremner
@ 2023-12-11 12:14   ` Tomi Ollila
  2023-12-11 12:47     ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: Tomi Ollila @ 2023-12-11 12:14 UTC (permalink / raw)
  To: David Bremner, Sandra Snan, notmuch

On Mon, Dec 11 2023, David Bremner wrote:

> Sandra Snan <sandra.snan@idiomdrottning.org> writes:
>
>
>> +(defvar in-notmuch-mua-reply-functions nil
>> +  "Functions to run after `notmuch-reply' was called successfully
>> +without erroring. The functions get the message-id as a string
>> +argument.")
>> +
>
> Overall this looks reasonable to me, but I'm not sure about the
> name. Since emacs doesn't have any namespace facility, I think that any
> globals we define should probably start with 'notmuch-'

I'd also mention that name starting with in-* -- my first thought would
have been inconsistency, but that "namespace" naming is (even) more
important.

another thing what should be the parameters passed, and why. this change
adds (just) message-id but no reasoning (nor documentation) there...

other than these notes, the change looks reasonable to me, too :D

>
> d

Tomi

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

* Re: [PATCH] Add hook inside notmuch-mua-reply
  2023-12-11 12:14   ` Tomi Ollila
@ 2023-12-11 12:47     ` David Bremner
  2023-12-11 22:26       ` Sandra Snan
  0 siblings, 1 reply; 5+ messages in thread
From: David Bremner @ 2023-12-11 12:47 UTC (permalink / raw)
  To: Tomi Ollila, Sandra Snan, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:
>
> another thing what should be the parameters passed, and why. this change
> adds (just) message-id but no reasoning (nor documentation) there...
>

I wonder if we should pass the whole (parsed) original message, for
maximum flexibility?

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

* Re: [PATCH] Add hook inside notmuch-mua-reply
  2023-12-11 12:47     ` David Bremner
@ 2023-12-11 22:26       ` Sandra Snan
  0 siblings, 0 replies; 5+ messages in thread
From: Sandra Snan @ 2023-12-11 22:26 UTC (permalink / raw)
  To: David Bremner, Tomi Ollila, notmuch

I missed the other notes. I'll do a v3 renaming to 
notmuch-mua-reply-functions.

The reason I need message-id is because I need to call notmuch 
again to get other headers beyond what's included in the sexp, 
including autocrypt.

But the suggestion to jam the entire sexp is good. I did that for 
v2.  It's not more expensive for Emacs to do that since it's all 
cons cells anyway. I can just as easily grab it from the plist in 
the hooked function as I could in notmuch-mua-reply itself.

David Bremner <david@tethera.net> writes:

> Tomi Ollila <tomi.ollila@iki.fi> writes:
>>
>> another thing what should be the parameters passed, and why. this change
>> adds (just) message-id but no reasoning (nor documentation) there...
>>
>
> I wonder if we should pass the whole (parsed) original message, for
> maximum flexibility?

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

end of thread, other threads:[~2023-12-11 22:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-10 22:40 [PATCH] Add hook inside notmuch-mua-reply Sandra Snan
2023-12-11 12:03 ` David Bremner
2023-12-11 12:14   ` Tomi Ollila
2023-12-11 12:47     ` David Bremner
2023-12-11 22:26       ` Sandra Snan

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