discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: sourcehut@relevant-information.com
Cc: piem@inbox.kyleam.com
Subject: Re: [PATCH 1/1] piem-notmuch-am-ready-mbox: Add option to edit patches before applying them
Date: Thu, 09 Dec 2021 00:20:53 -0500	[thread overview]
Message-ID: <87o85qfj62.fsf@kyleam.com> (raw)
In-Reply-To: <87r1amfnoa.fsf@kyleam.com>

Kyle Meyer writes:

> I wonder if we can redesign this a bit to more closely and transparently
> connect the "edit" and "am" parts.  Something like:
>
>   * from a notmuch message, invoke piem-notmuch-edit-message [*] (or
>     whatever name)
>
>     This commands puts the message (or perhaps thread) into a dedicated
>     piem mode for editing, setting up any buffer-local variables piem
>     needs for record-keeping/linking (e.g., what piem-inbox-coderepo
>     returns in the notmuch message) and then ...
>
>   * once the user is done editing, they can hit, say, 'C-c C-c' to call
>     a wrapper command that feeds the mbox to piem-am
>
>     (Perhaps there could also be a b4 variant.)

Here's a sketch of what that could look like.

diff --git a/Makefile b/Makefile
index b8d9fe6f..83635de6 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,8 @@ EMACS   = emacs
 # Rely on EMACSLOADPATH for everything but the current directory.
 BATCH   = $(EMACS) --batch -Q -L . -L tests
 
-EL = piem.el piem-b4.el piem-elfeed.el piem-eww.el piem-gnus.el \
-     piem-lei.el piem-maildir.el piem-notmuch.el piem-rmail.el \
+EL = piem.el piem-b4.el piem-edit-patch.el piem-elfeed.el piem-eww.el \
+     piem-gnus.el piem-lei.el piem-maildir.el piem-notmuch.el piem-rmail.el \
      tests/piem-lei-tests.el tests/piem-rmail-tests.el tests/piem-tests.el
 ELC = $(EL:.el=.elc)
 
@@ -32,6 +32,7 @@ docs: Documentation/piem.html Documentation/piem.info
 		-c TOP_NODE_UP_URL=/ Documentation/piem.texi
 
 piem-b4.elc: piem-b4.el piem.elc
+piem-edit-patch.elc: piem-edit-patch.el piem-b4.elc piem.elc
 piem-elfeed.elc: piem-elfeed.el piem.elc
 piem-eww.elc: piem-eww.el piem.elc
 piem-gnus.elc: piem-gnus.el piem.elc
diff --git a/piem-edit-patch.el b/piem-edit-patch.el
new file mode 100644
index 00000000..9b309dec
--- /dev/null
+++ b/piem-edit-patch.el
@@ -0,0 +1,66 @@
+;;; piem-edit-patch.el --- TODO  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021  all contributors <piem@inbox.kyleam.com>
+
+;; TODO
+
+;;; Code:
+
+(require 'piem)
+(require 'piem-b4)                      ; not used yet
+
+(define-derived-mode piem-edit-patch-mode nil "piem-edit-patch"
+  "TODO"
+  :group 'piem)
+
+(defvar piem-edit-patch-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-c C-c") #'piem-edit-patch-am)
+    map)
+  "TODO")
+
+(defvar-local piem-edit-patch--coderepo nil)
+(defvar-local piem-edit-patch--format nil)
+(defvar-local piem-edit-patch--mid nil)
+
+(defun piem-edit-patch-open (&optional entire-thread)
+  (interactive "P")
+  (if-let ((mid (or (piem-mid)
+                     (user-error
+                      "No message ID found for the current buffer")))
+           (fn (if entire-thread
+                   ;; NEEDSWORK: B4 isn't wired up, so caller would
+                   ;; need to prune non-patch messages.
+                   (run-hook-with-args-until-success
+                    'piem-mid-to-thread-functions mid)
+                 (run-hook-with-args-until-success
+                  'piem-am-ready-mbox-functions))))
+      (let ((coderepo (piem-inbox-coderepo))
+            (format "mboxrd"))
+        (when (member (cdr-safe fn) '("mbox" "mboxrd"))
+          (setq format (cdr fn))
+          (setq fn (car fn)))
+        (with-current-buffer (get-buffer-create
+                              (format "*piem-edit-patch-%s*" mid))
+          (erase-buffer)
+          (funcall fn)
+          (unless (/= (point-max) 1)
+            (error "Failed to generated mbox"))
+          (goto-char (point-min))
+          (piem-edit-patch-mode)
+          (setq piem-edit-patch--coderepo coderepo)
+          (setq piem-edit-patch--format format)
+          (setq piem-edit-patch--mid mid)
+          (pop-to-buffer (current-buffer))))
+    (user-error "Do not know how to generate patch for current buffer")))
+
+(defun piem-edit-patch-am (&optional toggle-worktree)
+  (interactive "P")
+  (piem-am (current-buffer)
+           piem-edit-patch--format
+           (piem-extract-mbox-info (current-buffer))
+           piem-edit-patch--coderepo
+           toggle-worktree))
+
+;;; piem-edit-patch.el ends here
+(provide 'piem-edit-patch)

  reply	other threads:[~2021-12-09  5:21 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 [this message]
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                   ` [PATCH v2] " sourcehut
2021-12-24 18:32                     ` 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=87o85qfj62.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=piem@inbox.kyleam.com \
    --cc=sourcehut@relevant-information.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).