diff options
author | Leo <sourcehut@relevant-information.com> | 2021-12-21 15:02:12 +0100 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2021-12-24 13:20:25 -0500 |
commit | a996e8d46f822aa97d392cefac304f06cd91fd20 (patch) | |
tree | 8600d4eaa7520bcb995ebfe320b9598eaba3b15e | |
parent | 955abe41dc76d5a2bcddfc38c1267f9857660a35 (diff) | |
download | piem-a996e8d46f822aa97d392cefac304f06cd91fd20.tar.gz |
Add ability to edit patches before applying them
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.
[km] Fixed let-binding in piem-edit-patch-am.
Message-Id: <20211221140212.30248-1-sourcehut@relevant-information.com>
-rw-r--r-- | piem.el | 47 |
1 files changed, 44 insertions, 3 deletions
@@ -597,14 +597,18 @@ public-inbox's configuration), return the value of ;; 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 @@ this triggers the creation of a new 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 |