discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [RFC PATCH 06/14] edit patch: Inject values via interactive arguments
Date: Wed, 29 Dec 2021 18:50:28 -0500	[thread overview]
Message-ID: <20211229235036.372313-7-kyle@kyleam.com> (raw)
In-Reply-To: <20211229235036.372313-1-kyle@kyleam.com>

piem-edit stores values in buffer-local variables that
piem-edit-patch-am then uses in a non-interactive call to piem-am.
That works, but the caller doesn't have access to piem-am's
toggle-worktree argument.  And this functionality gap will grow bigger
when an upcoming commit moves transition piem-am to a transient,
moving the current piem-am to a suffix.

Instead teach piem-am--arguments how to pull the mbox and coderepo
from these buffer-local values so that piem-edit-patch-am can just
call piem-am interactively.
---
 piem.el | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/piem.el b/piem.el
index 6241cb1f..eea81a8e 100644
--- a/piem.el
+++ b/piem.el
@@ -933,9 +933,14 @@ (defun piem--git-am (mbox format dir)
       (magit-status-setup-buffer dir)
     (dired dir)))
 
+(defvar-local piem-edit-patch--coderepo nil)
+(defvar-local piem-edit-patch--format nil)
+
 (defun piem-am--arguments ()
   (pcase-let ((`(,mbox . ,format)
-               (or (piem-am-ready-mbox)
+               (or (and (derived-mode-p 'piem-edit-patch-mode)
+                        (cons (current-buffer) piem-edit-patch--format))
+                   (piem-am-ready-mbox)
                    (user-error
                     "Could not find am-ready mbox for current buffer"))))
     ;; We're responsible for cleaning up the buffer created by
@@ -944,7 +949,8 @@ (defun piem-am--arguments ()
     (list (cons :interactive mbox)
           format
           (piem-extract-mbox-info mbox)
-          (piem-inbox-coderepo-maybe-read)
+          (or piem-edit-patch--coderepo
+              (piem-inbox-coderepo-maybe-read))
           current-prefix-arg)))
 
 ;;;###autoload
@@ -998,9 +1004,6 @@ (defun piem-am (mbox &optional format info coderepo toggle-worktree)
 \f
 ;;;;; Patch editing
 
-(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)
@@ -1017,12 +1020,7 @@ (defun piem-edit ()
 (defun piem-edit-patch-am ()
   "Apply the patch that is currently edited."
   (interactive)
-  (let ((buf (current-buffer)))
-    (piem-am buf
-             piem-edit-patch--format
-             (piem-extract-mbox-info (current-buffer))
-             piem-edit-patch--coderepo)
-    (kill-buffer buf)))
+  (call-interactively #'piem-am))
 
 (defvar piem-edit-patch-mode-map
   (let ((map (make-sparse-keymap)))
-- 
2.34.0


  parent reply	other threads:[~2021-12-29 23:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-29 23:50 [RFC PATCH 00/14] am, b4-am: Add commands to extend an existing branch Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 01/14] am: Give better name to default piem-am-read-worktree-function value Kyle Meyer
2022-02-05 17:37   ` Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 02/14] am: Add dedicated function for reading worktree Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 03/14] am: Extract git-am logic to dedicated function Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 04/14] am: Add function for reading piem-am's arguments Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 05/14] am: Add comment header for patch editing subsection Kyle Meyer
2021-12-29 23:50 ` Kyle Meyer [this message]
2022-02-05 17:48   ` [RFC PATCH 06/14] edit patch: Inject values via interactive arguments Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 07/14] am, b4-am: Rename piem-am to piem-am-create Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 08/14] am, b4-am: Rewrite -create docstrings to emphasize branch creation Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 09/14] piem-am-create: Move info argument to the end Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 10/14] piem-am--arguments: Make info extraction optional Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 11/14] b4: Move logic for checking arguments to a dedicated function Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 12/14] am, b4-am: Add commands that extend an existing branch Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 13/14] am: Move functionality under a dedicated transient Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 14/14] b4: Add piem-b4-am-from-mid-extend to transient 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=20211229235036.372313-7-kyle@kyleam.com \
    --to=kyle@kyleam.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).