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 4JR9EofewWHfBgAAsNZ9tg (envelope-from ) for ; Tue, 21 Dec 2021 14:02:47 +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 cEl0DofewWGqbQAAB5/wlQ (envelope-from ) for ; Tue, 21 Dec 2021 14:02:47 +0000 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050::465:101]) (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 69C3334AC9 for ; Tue, 21 Dec 2021 15:02:43 +0100 (CET) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1: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 4JJJ7P1LtDzQlBW; Tue, 21 Dec 2021 15:02:41 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de From: sourcehut@relevant-information.com To: piem@inbox.kyleam.com Cc: Leo Subject: [PATCH v2] Add ability to edit patches before applying them Date: Tue, 21 Dec 2021 15:02:12 +0100 Message-Id: <20211221140212.30248-1-sourcehut@relevant-information.com> In-Reply-To: <878rwjwz52.fsf@kyleam.com> References: <878rwjwz52.fsf@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1640095367; 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=xe6mUGH+9HfKy876hyguiotzfCbfxZHrM/Qtl8I2y68=; b=xz3lZtGqab2nk01y+xU+VMiW59wRwDAXOrWyjEwFYuclvhlJ6ZwPp+V//u6j2KGEj/3xjh G6pHgEUCHHVbkXUZNgsXO49jAG1dbBOyqEKttjIVfsYXZs50aNTAQIA3hUjUvBKZXD9uK6 qaoN2H4t7soCtkzJLw2pyA5ty7VEpRGQW9MjV1QmAfdNOxZHLsBBnZdzMmYwCqldKrb4ZH 6Vqh9h2pQg8HHOHMUPA5qU1Ew5Wr8wR7cbgntXzHO1h4YfWhRKEFbQH4SjWfWncJitumdW ujmflgOdhkgFmhJ3veRSBoSCTnlC9XrPtuvnvndOqAaKosW9Kbn106enKk2nyQ== ARC-Seal: i=1; s=key1; d=kyleam.com; t=1640095367; a=rsa-sha256; cv=none; b=sqo9JS/tF+kKZWVjUd+6vswZzTPqTgGO3+Lq/b2InspHtcKEZv4x35i13aw3cYyiaxaKAN BLBWWKQEN31955wi4+lI1S7ykFu44PSHijUEZCAzO9uHwi7wa5dMimjS5bYGcy7q+1Np24 bzkoEyExtYC36y4CRAUFOaCZcYkmkqnnCGVOqoMDigwL2Wj2VjTc7yMqK4vW0b6dYyjuOq Smn0zcPv8Iez2iWsjMC6nS0HEnSQp6GCGm6We4WwwiwambV4HoNLMk7dHo5t1eWWxOndoE x/VQTSFhsIarLr8yF1KGvOdpZzlK1nExrO5ADrjDJppL/4KLtnAW3NLyuLGTnA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of sourcehut@relevant-information.com designates 2001:67c:2050::465:101 as permitted sender) smtp.mailfrom=sourcehut@relevant-information.com X-Migadu-Spam-Score: -1.87 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of sourcehut@relevant-information.com designates 2001:67c:2050::465:101 as permitted sender) smtp.mailfrom=sourcehut@relevant-information.com X-Migadu-Queue-Id: 69C3334AC9 X-Spam-Score: -1.87 X-Migadu-Scanner: scn0.migadu.com X-TUID: djG6pesXPipS From: Leo Sometimes it is necessary to edit patches before applying them. These changes allows you to do that by providing a new command `piem-edit` that shows the buffer that is prepared by `piem-am-ready-mbox` to the user. --- I wasn't sure if there were cases when `(kill-current-buffer)` could kill the wrong buffer so I let-bound it to be safe. I chose `generate-new-buffer` for the buffer name in `piem-am-ready-mbox` because I thought sometimes the user could want to open two edited patches side by side. That is one of my annoyances with mu4e anyways, not sure if it would actually be an issue in piem though. piem.el | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/piem.el b/piem.el index afe6b7a..eef0649 100644 --- a/piem.el +++ b/piem.el @@ -597,14 +597,18 @@ (defun piem--insert-message-id-header (mid) ;; blank line. Assume we're in a header. (insert (format "Message-Id: <%s>\n" mid)))))))) -(defun piem-am-ready-mbox () +(defun piem-am-ready-mbox (&optional buffer-name) "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." +buffer. + +By default the buffer name is hidden, but when BUFFER-NAME is +non-nil, use that name instead." (when-let ((res (run-hook-with-args-until-success 'piem-am-ready-mbox-functions))) - (pcase-let ((buffer (generate-new-buffer " *piem am-ready mbox*")) + (pcase-let ((buffer (generate-new-buffer + (or buffer-name " *piem am-ready mbox*"))) (`(,fn . ,format) (if (member (cdr-safe res) '("mbox" "mboxrd")) res @@ -981,6 +985,43 @@ (defun piem-am (mbox &optional format info coderepo toggle-worktree) (magit-status-setup-buffer am-directory) (dired am-directory)))) +(defvar-local piem-edit-patch--coderepo nil) +(defvar-local piem-edit-patch--format nil) + +(defun piem-edit () + "Edit an am-ready mbox before feeding it to `git am'." + (interactive) + (pcase-let ((`(,mbox . ,format) + (or (piem-am-ready-mbox "*piem-edit-patch*") + (user-error + "Could not find am-ready mbox for current buffer"))) + (coderepo (piem-inbox-coderepo))) + (pop-to-buffer mbox) + (piem-edit-patch-mode) + (setq piem-edit-patch--coderepo coderepo) + (setq piem-edit-patch--format format))) + +(defun piem-edit-patch-am () + "Apply the patch that is currently edited." + (interactive) + (let ((buf (current-buffer))) + (piem-am buf + "mbox" + (piem-extract-mbox-info (current-buffer)) + piem-edit-patch--coderepo)) + (kill-buffer buf)) + +(defvar piem-edit-patch-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-c") #'piem-edit-patch-am) + map) + "Keymap for editing patches with piem.") + +(define-derived-mode piem-edit-patch-mode text-mode "piem-edit-patch" + "Major mode for editing patches with piem." + :group 'piem + (buffer-enable-undo)) + ;;;; Dispatch base-commit: e519aa44d148d5b8f22d7fe8844dc566046b04c2 -- 2.34.1