From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id yIJRE5UNMl98QwAAsNZ9tg (envelope-from ) for ; Tue, 11 Aug 2020 03:16:37 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eFEnD5UNMl+mCQAAB5/wlQ (envelope-from ) for ; Tue, 11 Aug 2020 03:16:37 +0000 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4428E9404E2 for ; Tue, 11 Aug 2020 03:16:36 +0000 (UTC) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id D60D67EC93 for ; Mon, 10 Aug 2020 23:16:33 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:in-reply-to:references:date:message-id:mime-version :content-type; s=sasl; bh=dY/Nf+3jPgLFHRG1PcuL9w2QDuM=; b=yJ0gVa IiFnokZQEeVeQowTTiRB266x0zdNOk7uiQUusJ7SGEnmYcjcFWYMLuiSPZPJhl3j DHXSuqz9HrxEPaSBpfr0E9LveOSBads4NPN2NiQqwXE3O2HhaUvbZbfmv/hK0fA9 mKLvoayrgt9SDJuQHVJNciw4+oF+F/UoIAFA8= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id CE2967EC92 for ; Mon, 10 Aug 2020 23:16:33 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:in-reply-to:references:date:message-id:mime-version:content-type; s=mesmtp; bh=2j4/puzJlmBIyzxb1UBYgLvPQCIdc3h2GIJtgDHKJzM=; b=ENrzs/Q8v2L3C8XV+SRDjuWvoIPAzWdNXAI4adtu8APvH6yGMYnA+JfJDQESeS1KI0IqmLLZcYnVYHukfJeVzxmf1aK7ETVjN3Mdigg3oLW+KGRKdvw4hDkNc26WlJ2DXI40w0d4oidvp0Pv6rX0FSJItPQuslK42rP5dp3G97E= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 496CA7EC90 for ; Mon, 10 Aug 2020 23:16:33 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH] Fix handling of -am-ready-mbox values In-Reply-To: <20200810020704.30150-1-kyle@kyleam.com> References: <20200810020704.30150-1-kyle@kyleam.com> Date: Mon, 10 Aug 2020 23:16:32 -0400 Message-ID: <877du5c1nz.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 0EC35CD8-DB81-11EA-8C8C-01D9BED8090B-24757444!pb-smtp1.pobox.com X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=yJ0gVa I; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=ENrzs/Q8; dmarc=none; spf=pass (aspmx1.migadu.com: domain of kyle@kyleam.com designates 64.147.108.70 as permitted sender) smtp.mailfrom=kyle@kyleam.com X-Spam-Score: -1.00 X-TUID: NYOxMth+HJRV Kyle Meyer writes: > (defun piem-am-ready-mbox () > - "Return buffer containing an am-ready mbox. > -Callers are responsible for killing the buffer." > - (when-let ((fn (run-hook-with-args-until-success > - 'piem-am-ready-mbox-functions))) > - (let ((buffer (generate-new-buffer " *piem am-ready mbox*")) > - (mid (and piem-add-message-id-header (piem-mid))) > - has-content) > + "Generate a buffer containing an am-ready mbox. > +The return value is (BUFFER FORMAT), where FORMAT is either > +\"mbox\" or \"mboxrd\". Callers are responsible for killing the > +buffer." > + (when-let ((res (run-hook-with-args-until-success > + 'piem-am-ready-mbox-functions))) > + (pcase-let ((buffer (generate-new-buffer " *piem am-ready mbox*")) > + (`(,fn ,format) (if (listp res) res (list res "mboxrd"))) > + (mid (and piem-add-message-id-header (piem-mid))) > + (has-content nil)) Bah, caught only after applying, but this logic is flawed. res is a list even if it doesn't include the format. The issue shows up in the text/plain code path of piem-notmuch-am-ready-mbox because it doesn't explicitly specify a format, relying on mboxrd being the default. -- >8 -- Subject: [PATCH] Fix handling of -am-ready-mbox values 0ee97e9 (Explicitly specify --patch-format in git-am calls, 2020-08-09) made it possible for a piem-am-ready-mbox-functions member to specify the format of the mbox by returning (FUNCTION FORMAT). If FUNCTION is returned, then mboxrd is supposed to be taken as the default format. The handling is broken, though, because piem-am-ready-mbox tries to detect the (FUNCTION FORMAT) form with listp, but that of course also returns true when the return value is simply a function. Instead, check to see whether the element matches a valid format value. Switch from (FUNCTION FORMAT) to (FUNCTION . FORMAT) to make it more convenient to pull out FORMAT with cdr-safe. --- piem-gnus.el | 4 ++-- piem-notmuch.el | 2 +- piem.el | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/piem-gnus.el b/piem-gnus.el index 9e42185..244c389 100644 --- a/piem-gnus.el +++ b/piem-gnus.el @@ -77,7 +77,7 @@ (defun piem-gnus-am-ready-mbox () (point-min) (point-max))))) gnus-article-mime-handles)))) (when patches - (list (lambda () + (cons (lambda () (dolist (patch patches) (insert patch))) "mbox")))) @@ -90,7 +90,7 @@ (defun piem-gnus-am-ready-mbox () (buffer-substring-no-properties (point-min) (point-max))))))) (when patch - (list (lambda () (insert patch)) + (cons (lambda () (insert patch)) "mbox"))))))) ;;;###autoload diff --git a/piem-notmuch.el b/piem-notmuch.el index c9c3bed..29f4d27 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -88,7 +88,7 @@ (defun piem-notmuch-am-ready-mbox () (plist-get part :content))) (plist-get body :content))))) (when patches - (list (lambda () + (cons (lambda () (dolist (patch patches) (insert patch))) "mbox")))))))) diff --git a/piem.el b/piem.el index e70c259..ece30bd 100644 --- a/piem.el +++ b/piem.el @@ -99,7 +99,7 @@ (defcustom piem-am-ready-mbox-functions nil The functions are called with no arguments. If a function knows how to create an mbox, it should return a function that takes no arguments and inserts the mbox's contents in the current buffer. -The return value can also be (FUNCTION FORMAT), where FORMAT is +The return value can also be (FUNCTION . FORMAT), where FORMAT is either \"mbox\" or \"mboxrd\" and maps to the --patch-format value passed to `git am'. If unspecified, \"mboxrd\" is used." :type 'hook) @@ -337,13 +337,16 @@ (defun piem--insert-message-id-header (mid) (defun piem-am-ready-mbox () "Generate a buffer containing an am-ready mbox. -The return value is (BUFFER FORMAT), where FORMAT is either +The return value is (BUFFER . FORMAT), where FORMAT is either \"mbox\" or \"mboxrd\". Callers are responsible for killing the buffer." (when-let ((res (run-hook-with-args-until-success 'piem-am-ready-mbox-functions))) (pcase-let ((buffer (generate-new-buffer " *piem am-ready mbox*")) - (`(,fn ,format) (if (listp res) res (list res "mboxrd"))) + (`(,fn . ,format) + (if (member (cdr-safe res) '("mbox" "mboxrd")) + res + (cons res "mboxrd"))) (mid (and piem-add-message-id-header (piem-mid))) (has-content nil)) (with-current-buffer buffer @@ -353,7 +356,7 @@ (defun piem-am-ready-mbox () (goto-char (point-min)) (piem--insert-message-id-header mid))) (if has-content - (list buffer format) + (cons buffer format) (kill-buffer buffer) nil)))) @@ -546,7 +549,7 @@ (defun piem-am (mbox &optional format info coderepo) If CODEREPO is given, switch to this directory before calling `git am'." (interactive - (pcase-let ((`(,mbox ,format) + (pcase-let ((`(,mbox . ,format) (or (piem-am-ready-mbox) (user-error "Could not find am-ready mbox for current buffer")))) base-commit: 0ee97e900f7daef3995284d0b4312c371b3427fa -- 2.28.0