unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Sandra Snan <sandra.snan@handgranat.org>
To: notmuch@notmuchmail.org
Subject: Re: [PATCH] To use compose-mail
Date: Wed, 17 Mar 2010 11:05:57 +0100	[thread overview]
Message-ID: <4ba0a931.1067f10a.15c2.5e9f@mx.google.com> (raw)
In-Reply-To: <4b9fe142.0f67f10a.268d.0312@mx.google.com>

I <sandra.snan@handgranat.org> wrote earlier:
> As I wrote in the other mail, Emacs has an interface called compose-mail which uses whatever mailing mode that you’ve selected in mail-user-agent
> so if you like the message mode that’s been hard-coded into notmuch.el, (setq mail-user-agent 'message-user-agent) and this will use that.
> 
> This is a simpler patch that uses as much of the output of notmuch reply as possible, at the expense of emacs more flexible hooks and citing. Both of the patches (unfortunately) still just call message-modes signature function without one of the standard hooks and wrappers, because I haven’t looked into that yet.

That’s not right, I sent the same patch twice.
Here’s the one for just compose-mail because the other one has problems with non-ascii characters. I guess I’d need to re-implement more and more of notmuch reply in the elisp. I started doing that but I figure that I’d send these patches and see if it was something you like at all.

Signed-off-by: Sandra Snan <sandra.snan@handgranat.org>
---
 emacs/notmuch.el |   61 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 117a365..baafac8 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -49,7 +49,7 @@
 
 (require 'cl)
 (require 'mm-view)
-(require 'message)
+(require 'message) ; not sure if this is needed now
 
 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
@@ -76,7 +76,7 @@
     (define-key map (kbd "M-TAB") 'notmuch-show-previous-button)
     (define-key map (kbd "TAB") 'notmuch-show-next-button)
     (define-key map "s" 'notmuch-search)
-    (define-key map "m" 'message-mail)
+    (define-key map "m" 'compose-mail)
     (define-key map "f" 'notmuch-show-forward-current)
     (define-key map "r" 'notmuch-show-reply)
     (define-key map "|" 'notmuch-show-pipe-message)
@@ -435,16 +435,51 @@ buffer."
       mm-handle (> (notmuch-count-attachments mm-handle) 1))))
   (message "Done"))
 
-(defun notmuch-reply (query-string)
-  (switch-to-buffer (generate-new-buffer "notmuch-draft"))
-  (call-process notmuch-command nil t nil "reply" query-string)
-  (message-insert-signature)
+
+(defun jump-to-end-of-header ()
+  (re-search-forward "^[^:]*.: \\|^$")
+  (beginning-of-line)
+  (backward-char)
+  (point))
+
+(defun notmuch-regex-header (re)
   (goto-char (point-min))
-  (if (re-search-forward "^$" nil t)
-      (progn
-	(insert "--text follows this line--")
-	(forward-line)))
-  (message-mode))
+  (if (re-search-forward re nil t)
+      (buffer-substring-no-properties (point) (jump-to-end-of-header))
+    ""))
+
+(defun notmuch-other-headers (al)
+  (beginning-of-line)
+  (if (eq (point-at-bol) (point-at-eol))
+      al
+    (if (re-search-forward "^[^:]*.: \\|^$" nil t)
+	(notmuch-other-headers
+	  (let ((header (buffer-substring-no-properties (point-at-bol) (- (point) 2)))
+		(header-value (buffer-substring-no-properties (point) (jump-to-end-of-header))))
+	    (forward-char)
+	    (if (or (string= "To" header) (string= "Subject" header))
+		al
+	      (acons
+	       header
+	       header-value
+	       al))))
+      al)))
+
+(defun notmuch-reply (query-string)
+  (with-temp-buffer
+    (call-process notmuch-command nil t nil "reply" query-string)
+    (let ((body
+	   (progn (goto-char (point-min))
+		  (if (re-search-forward "^$" nil t)
+		      (buffer-substring-no-properties (+ (point) 1) (point-max))
+		    ""))))
+      (compose-mail
+       (notmuch-regex-header "^To: ")
+       (notmuch-regex-header "^Subject: ")
+       (progn (goto-char (point-min))
+	      (notmuch-other-headers '())))
+      (goto-char (point-max))
+      (insert body))))
 
 (defun notmuch-show-reply ()
   "Begin composing a reply to the current message in a new buffer."
@@ -1229,7 +1264,7 @@ matching this search term are shown if non-nil. "
     (define-key map "p" 'notmuch-search-previous-thread)
     (define-key map "n" 'notmuch-search-next-thread)
     (define-key map "r" 'notmuch-search-reply-to-thread)
-    (define-key map "m" 'message-mail)
+    (define-key map "m" 'compose-mail)
     (define-key map "s" 'notmuch-search)
     (define-key map "o" 'notmuch-search-toggle-order)
     (define-key map "=" 'notmuch-search-refresh-view)
@@ -1651,7 +1686,7 @@ current search results AND that are tagged with the given tag."
     (define-key map "?" 'notmuch-help)
     (define-key map "x" 'kill-this-buffer)
     (define-key map "q" 'kill-this-buffer)
-    (define-key map "m" 'message-mail)
+    (define-key map "m" 'compose-mail)
     (define-key map "e" 'notmuch-folder-show-empty-toggle)
     (define-key map ">" 'notmuch-folder-last)
     (define-key map "<" 'notmuch-folder-first)
-- 
1.7.0

      reply	other threads:[~2010-03-17 10:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-16 19:52 [PATCH] To use compose-mail Sandra Snan
2010-03-17 10:05 ` Sandra Snan [this message]

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=4ba0a931.1067f10a.15c2.5e9f@mx.google.com \
    --to=sandra.snan@handgranat.org \
    --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).