From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id aNqZBdMbtWGEEgAAsNZ9tg (envelope-from ) for ; Sat, 11 Dec 2021 21:44:51 +0000 Received: from out2.migadu.com ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 4JtQAdMbtWHQKAAAbx9fmQ (envelope-from ) for ; Sat, 11 Dec 2021 21:44:51 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1639259090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ixWu+ODJyaKpHyF5+7Y2WuNAdNfVI/+o17xg+2tc+oA=; b=brtSw+bvckScDT7cuWHbJp4bvj32o/1CDIdTWobqLU33D15dVCbVnKUA3ecPYWOo7Jlbkn SEVUIlvFXnUs6CL0+6b5a2irfsmwylRgfnRFKUrjX7AvjNTj9IiIRel56ax4s/bMZfnP24 j2q1XuRiVrJLcF8qQodUvZwp2bO31sbIh26LnOK+ymH6QsbOJzhPPBCGgFcw6f/uFE/Ua3 bQz7WBhePa1+N/7eAPX/PwXyXK8MCclst6sFGcomWCNHf9+MkpcBefCvajF+UZHueEEKMb 0LfPfpA3zB5EyVGcWpHBOoM30q3dZlErwzBaKUrJiXaOKRRCCn8g1fjIMB9uEA== From: Kyle Meyer To: sourcehut@relevant-information.com Cc: piem@inbox.kyleam.com Subject: Re: [PATCH 1/1] Use notmuch-extract-patch if available In-Reply-To: <20211209204319.168897-2-sourcehut@relevant-information.com> References: <20211209204319.168897-1-sourcehut@relevant-information.com> <20211209204319.168897-2-sourcehut@relevant-information.com> Date: Sat, 11 Dec 2021 16:44:48 -0500 Message-ID: <87mtl66ckv.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: 79wPY5q1CMV5 sourcehut@relevant-information.com writes (in cover letter): > Instead of getting all the messages in the thread like my last patch I thought > using notmuch-extract-patch would be cleaner. The code is adapted from > elpa-mailscripts that is linked from the piem's documentation. It might be a > good alternative to b4. sourcehut@relevant-information.com writes (in commit message): > notmuch-extract-patch is a command line tool from the elpa-mailscripts > package that extracts patches from a thread. It's a useful way to > extract the latest patch series from an email thread and filter out the > replies and reviews. It's been a little while since I've looked over mailscripts, but I think it's got a lot of neat functionality (and in general am excited to see work in this space). I obviously decided to focus piem's patch extraction functionality around b4, but I'm happy to consider some support for notmuch-extract-patch if there are people that 1) want to use notmuch-extract-patch and 2) for whatever reason, prefer to use piem rather than mailscripts.el. > diff --git a/piem-notmuch.el b/piem-notmuch.el > index 8b2a353..05c03ab 100644 > --- a/piem-notmuch.el > +++ b/piem-notmuch.el > @@ -81,7 +81,9 @@ (defun piem-notmuch-am-ready-mbox () > "Return a function that inserts an am-ready mbox. > If the buffer has any MIME parts that look like a patch, use > those parts' contents (in order) as the mbox. Otherwise, use the > -message itself if it looks like a patch." > +message itself if it looks like a patch. If the executable > +notmuch-extract-patch exists on the path, use that to get the > +latest patch series from the notmuch thread." > (when (derived-mode-p 'notmuch-show-mode) > (let* ((handle (piem-notmuch--with-current-message > (mm-dissect-buffer))) > @@ -90,10 +92,25 @@ (defun piem-notmuch-am-ready-mbox () > (if (= n-attachments 0) > (when (string-match-p piem-patch-subject-re > (notmuch-show-get-subject)) > - (let ((id (notmuch-show-get-message-id))) > + (let ((id (notmuch-show-get-message-id)) > + (thread-id notmuch-show-thread-id)) > (lambda () > - (call-process notmuch-command nil t nil > - "show" "--format=mbox" id)))) > + (if-let ((cmd (executable-find "notmuch-extract-patch")) > + (tid > + ;; If `notmuch-show' was called with a notmuch query rather > + ;; than a thread ID, as `org-notmuch-follow-link' in > + ;; org-notmuch.el does, then `notmuch-show-thread-id' might > + ;; be an arbitrary notmuch query instead of a thread ID. We > + ;; need to wrap such a query in thread:{} before passing it > + ;; to notmuch-extract-patch(1), or we might not get a whole > + ;; thread extracted (e.g. if the query is just id:foo) > + (if (string= (substring thread-id 0 7) "thread:") > + thread-id > + (concat "thread:{" thread-id "}")))) I believe this comment and (if ...) is coming straight from mailscripts.el. You note in the cover letter that some of this is copied from mailscripts.el, but I think there should be a code comment as well. However, I don't really understand why the condition is necessary. Wouldn't always using thread:{notmuch-show-get-message-id return value} work? > + (call-process cmd nil t nil > + tid) > + (call-process notmuch-command nil t nil > + "show" "--format=mbox" id))))) Rather than add this functionality to piem-notmuch-am-ready-mbox, I'd prefer to add a dedicated function for notmuch-extract-patch. Then this function can be added instead of (or even just ahead of) piem-notmuch-am-ready-mbox in piem-am-ready-mbox-functions. Whether that function is added to piem-am-ready-mbox-functions could be controlled by a user option.