From: Brennan Vincent <brennan@umanwizard.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] emacs: Introduce notmuch-draftify-buffer command.
Date: Wed, 11 Sep 2024 12:09:49 -0400 [thread overview]
Message-ID: <87r09qtbn6.fsf@taipei.mail-host-address-is-not-set> (raw)
In-Reply-To: <87plpbtfj2.fsf@taipei.mail-host-address-is-not-set>
This command inserts the current buffer as a draft. It optionally
begins editing the draft.
This can be useful for email-based Git contribution workflows. For
example, one can use git format-patch to generate a patch, then
notmuch-draftify-buffer on the generated patch to immediately begin
editing a message for submission to an appropriate mailing list.
---
emacs/notmuch-draft.el | 10 ++++++++++
emacs/notmuch-lib.el | 12 ++++++++----
emacs/notmuch-maildir-fcc.el | 16 ++++++++++------
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index fcc45503..4bff68f2 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -278,6 +278,16 @@ applied to newly inserted messages)."
;; message is resaved or sent.
(setq notmuch-draft-id (and draft id)))))
+(defun notmuch-draftify-buffer (arg)
+ "Inserts the current buffer as a draft. With prefix argument, begins editing the draft."
+ (interactive "P")
+ (let ((message-id (notmuch-maildir-notmuch-insert-current-buffer
+ notmuch-draft-folder
+ t
+ notmuch-draft-tags)))
+ (when (and arg message-id)
+ (notmuch-draft-resume (format "id:%s" message-id)))))
+
;;; _
(add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index bf9c4a53..1e371f67 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -935,11 +935,15 @@ supported keyword arguments are:
If notmuch exits with a non-zero status, output from the process
will appear in a buffer named \"*Notmuch errors*\" and an error
-will be signaled."
+will be signaled.
+
+Otherwise, returns the output from the process as a string."
(with-temp-buffer
- (let ((status (notmuch-call-notmuch--helper t args)))
- (notmuch-check-exit-status status (cons notmuch-command args)
- (buffer-string)))))
+ (let ((status (notmuch-call-notmuch--helper t args))
+ (output (buffer-string)))
+ (and (notmuch-check-exit-status status (cons notmuch-command args)
+ output)
+ output))))
(defun notmuch-call-notmuch-sexp (&rest args)
"Invoke `notmuch-command' with ARGS and return the parsed S-exp output.
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index c7b403cf..09fc832d 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -215,12 +215,16 @@ normal fcc."
This inserts the current buffer as a message into the notmuch
database in folder FOLDER. If CREATE is non-nil it will supply
the --create-folder flag to create the folder if necessary. TAGS
-should be a list of tag changes to apply to the inserted message."
- (apply 'notmuch-call-notmuch-process
- :stdin-string (buffer-string) "insert"
- (append (and create (list "--create-folder"))
- (list (concat "--folder=" folder))
- tags)))
+should be a list of tag changes to apply to the inserted message.
+
+Returns the message ID of the inserted message."
+ (let ((output (apply 'notmuch-call-notmuch-process
+ :stdin-string (buffer-string) "insert"
+ (append (and create (list "--create-folder"))
+ (list (concat "--folder=" folder)
+ "--emit-message-id")
+ tags))))
+ (string-trim output)))
(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
"Store message with notmuch insert.
--
2.45.2
next prev parent reply other threads:[~2024-09-11 16:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 20:33 [PATCH] Add --emit-message-id flag to notmuch-insert Brennan Vincent
2024-09-11 15:00 ` [PATCH v2] " Brennan Vincent
2024-09-25 21:51 ` David Bremner
2024-10-03 17:35 ` When exactly is the post-insert hook called? Ralph Seichter
2024-10-03 17:59 ` Ralph Seichter
2024-09-11 16:09 ` Brennan Vincent [this message]
2024-09-25 22:09 ` [PATCH] emacs: Introduce notmuch-draftify-buffer command David Bremner
2024-09-29 0:36 ` Brennan Vincent
2024-09-26 20:25 ` [PATCH v3] Add --emit-message-id flag to notmuch-insert Brennan Vincent
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://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r09qtbn6.fsf@taipei.mail-host-address-is-not-set \
--to=brennan@umanwizard.com \
--cc=notmuch@notmuchmail.org \
/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://yhetil.org/notmuch.git/
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).