discussion and development of piem
 help / color / mirror / code / Atom feed
From: sourcehut@relevant-information.com
To: piem@inbox.kyleam.com
Cc: Leo <sourcehut@relevant-information.com>
Subject: [PATCH v2] Add ability to edit patches before applying them
Date: Tue, 21 Dec 2021 15:02:12 +0100	[thread overview]
Message-ID: <20211221140212.30248-1-sourcehut@relevant-information.com> (raw)
In-Reply-To: <878rwjwz52.fsf@kyleam.com>

From: Leo <sourcehut@relevant-information.com>

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))
+
 \f
 ;;;; Dispatch
 

base-commit: e519aa44d148d5b8f22d7fe8844dc566046b04c2
-- 
2.34.1


  reply	other threads:[~2021-12-21 14:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08 16:01 Adding support for editing patches before applying them sourcehut
2021-12-08 16:01 ` [PATCH 1/1] piem-notmuch-am-ready-mbox: Add option to edit " sourcehut
2021-12-09  3:43   ` Kyle Meyer
2021-12-09  5:20     ` Kyle Meyer
2021-12-09 10:10     ` Leo
2021-12-09 13:00       ` Leo
2021-12-10  5:08         ` Kyle Meyer
2021-12-10  9:31           ` Leo
2021-12-11 21:44             ` Kyle Meyer
2021-12-16 20:05               ` [PATCH] Add ability " sourcehut
2021-12-17  5:58                 ` Kyle Meyer
2021-12-21 14:02                   ` sourcehut [this message]
2021-12-24 18:32                     ` [PATCH v2] " Kyle Meyer
2021-12-27 16:07                       ` Leo
2021-12-27 21:07                         ` distributing piem via *ELPA Kyle Meyer
2021-12-27 21:30                           ` Kyle Meyer
2021-12-09  3:38 ` Adding support for editing patches before applying them Kyle Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://git.kyleam.com/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211221140212.30248-1-sourcehut@relevant-information.com \
    --to=sourcehut@relevant-information.com \
    --cc=piem@inbox.kyleam.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

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