From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id OFjOAHTXsGFDdAAAsNZ9tg (envelope-from ) for ; Wed, 08 Dec 2021 16:04:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id gDZSOHPXsGH4QQAA1q6Kng (envelope-from ) for ; Wed, 08 Dec 2021 16:04:03 +0000 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 88D9D274C for ; Wed, 8 Dec 2021 17:04:00 +0100 (CET) Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:105:465:1:3:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4J8MRM0PYBzQk2f; Wed, 8 Dec 2021 17:03:59 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de From: sourcehut@relevant-information.com To: piem@inbox.kyleam.com Cc: sourcehut@relevant-information.com Subject: [PATCH 1/1] piem-notmuch-am-ready-mbox: Add option to edit patches before applying them Date: Wed, 8 Dec 2021 17:01:43 +0100 Message-Id: <20211208160142.84085-2-sourcehut@relevant-information.com> In-Reply-To: <20211208160142.84085-1-sourcehut@relevant-information.com> References: <20211208160142.84085-1-sourcehut@relevant-information.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1638979443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t69Otw/CozZuTncO1rfTkQed0mOhyfk249HLddmCsYg=; b=DgEuj51V9/EZazqk5Sq8nKLhUK+1EdSPajj9zUjPv863az4F41Ovrm6uKb6CAZUYHmrEZR lMzwwL3ua7U9/pBENDpNqE7oNKxysg7LAJ8m4mn02f56X3VMvMMxwn1CuQEPXWZiV9W2SI OxuYOgK9ZZuXWrNP/a+/49KWlHeOw510jbdiaI0RCoO6Hg6eyZmwyLEqxWHUMnPVTv/cwW 2nQyp8ZNpTjA0CkKtNqji4efRC9shT3h/G1P6ZOlpeNQGzcb58/Z1JZuBaALFDb3cQpyJ+ nVBFgV4a33UnnCp+wgATJ9KWu6dAy50S+dA7ZqHvqSv9r40pOMq79yrt4Jh03A== ARC-Seal: i=1; s=key1; d=kyleam.com; t=1638979443; a=rsa-sha256; cv=none; b=PB0kVA1T+w1xRLjaRLti4Hi9EnR8+eamvN7p87S2VmUBB76Q6FO1hJfisYa2saAfm4vMfP l2FNlixw/PyJ8vbJUeXwzZ29YOaVJtN1RoqEOZuUASk0tI+pOpiGlVamgzh4rep43Il/Wv RXaTpZquCZ8Oz6Qr2LZhLFKcOntqPKdV+IWPsGyL5MrwLIsRPM9oPaIaOD9PKnANW/Uh15 q0Ntetm5hGDbgYyEymtbVDMe94AS6MaOIXx0bggMjj1ptQm7W7xsvYqGs7AeOgmm1hAKg+ X21NMuEUt1ghR7k5d6kGPvfWC/d+BX2q0GXJyaem9Lvm2iAlZDAdJ6IOR/ZtSw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of sourcehut@relevant-information.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=sourcehut@relevant-information.com X-Migadu-Spam-Score: -0.29 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of sourcehut@relevant-information.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=sourcehut@relevant-information.com X-Migadu-Queue-Id: 88D9D274C X-Spam-Score: -0.29 X-Migadu-Scanner: scn1.migadu.com X-TUID: jkKc2WoqMG8I From: --- piem-notmuch.el | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/piem-notmuch.el b/piem-notmuch.el index 8b2a353..2ad4ace 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -77,11 +77,35 @@ (defun piem-notmuch-mid-to-thread (mid) "show" "--format=mbox" "--entire-thread=true" (concat "id:" mid))))) +(defun piem-notmuch-show-view-mbox-message (arg) + "View the mbox formatted version of the current message. + +Used for editing patches before applying them. + +With one universal prefix argument, view the entire thread instead. " + (interactive "P") + (let* ((id (notmuch-show-get-message-id)) + (buf (get-buffer-create (concat "*notmuch-mbox-" id "*"))) + (inhibit-read-only t)) + (pop-to-buffer-same-window buf) + (erase-buffer) + (let ((coding-system-for-read 'no-conversion)) + (if (equal '(4) arg) + (call-process notmuch-command nil t nil "show" "--entire-thread=true" "--format=mbox" id) + (call-process notmuch-command nil t nil "show" "--format=mbox" id))) + (goto-char (point-min)) + (set-buffer-modified-p nil) + (setq buffer-read-only nil) + (view-buffer buf 'kill-buffer-if-not-modified))) + + (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 a corresponding +*notmuch-mbox- buffer exists, use that instead of fetching from +the notmuch database." (when (derived-mode-p 'notmuch-show-mode) (let* ((handle (piem-notmuch--with-current-message (mm-dissect-buffer))) @@ -90,10 +114,16 @@ (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))) - (lambda () - (call-process notmuch-command nil t nil - "show" "--format=mbox" id)))) + (if-let ((buf (get-buffer (concat "*notmuch-mbox-" (notmuch-show-get-message-id) "*")))) + (let ((str (with-current-buffer buf + (buffer-substring-no-properties (point-min) + (point-max))))) + (lambda () + (insert str))) + (let ((id (notmuch-show-get-message-id))) + (lambda () + (call-process notmuch-command nil t nil + "show" "--format=mbox" id))))) (notmuch-foreach-mime-part (lambda (p) (when-let ((patch (piem-am-extract-attached-patch p))) -- 2.31.0