aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2020-06-06 12:25:49 -0400
committerKyle Meyer <kyle@kyleam.com>2020-06-06 15:13:34 -0400
commitcdb845f4f8210a5535bb7459dcdd761d2c08a0ac (patch)
tree3aa061ddd304d5324a5959c4577340d2c966cb7e
parentfe5b08572ea48e8224bf943b75ac25edc1ffdfad (diff)
downloadpiem-cdb845f4f8210a5535bb7459dcdd761d2c08a0ac.tar.gz
Add piem-am-ready-mbox
This will enable libraries to provide an mbox that piem-am can use.
-rw-r--r--piem.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/piem.el b/piem.el
index b7b763f..35bfe8f 100644
--- a/piem.el
+++ b/piem.el
@@ -91,6 +91,13 @@ should return a function that takes no arguments and inserts the
mbox's contents in the current buffer."
:type 'hook)
+(defcustom piem-am-ready-mbox-functions nil
+ "Functions tried to get an mbox to be fed to `git am'.
+The functions are called with no arguments. If a function knows
+how to create an mbox, it should return a function that takes no
+arguments and inserts the mbox's contents in the current buffer."
+ :type 'hook)
+
(defvar piem-link-re
(rx "/" (group (one-or-more (not (any "/" "\n"))))
"/" (group (one-or-more (not (any "/" "\n"))))
@@ -252,6 +259,21 @@ the following information about the patch series:
"Return the current buffer's message ID."
(run-hook-with-args-until-success 'piem-get-mid-functions))
+(defun piem-am-ready-mbox ()
+ "Return buffer containing an am-ready mbox.
+Callers are responsible for killing the buffer."
+ (when-let ((fn (run-hook-with-args-until-success
+ 'piem-am-ready-mbox-functions)))
+ (let ((buffer (generate-new-buffer " *piem am-ready mbox*"))
+ has-content)
+ (with-current-buffer buffer
+ (funcall fn)
+ (setq has-content (< 1 (point-max))))
+ (if has-content
+ buffer
+ (kill-buffer buffer)
+ nil))))
+
;;;; Patch handling