unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] To use compose-mail and mail-citation-hook
@ 2010-03-16 19:46 Sandra Snan
  2010-03-18 13:46 ` Michal Sojka
  0 siblings, 1 reply; 3+ messages in thread
From: Sandra Snan @ 2010-03-16 19:46 UTC (permalink / raw
  To: notmuch

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 version of the patch also tries to yank the body text, calling mail-citation-hook as it does so it works with mu-cite, supercite, trivialcite and so on. I guess I started yak-shaving a bit too much because I kinda began to reconstruct the output of notmuch reply via emacs lisp.

I’ll send another e-mail with the patch for just compose-mail without the mail-citation-hook, too. These patches are mutually exclusive. I’m not used to git so I hope this is all right.

Sandra

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

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 117a365..68e2d43 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,56 @@ 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)
+  (let ((body
+	 (save-excursion
+	   (let ((filename (notmuch-show-get-filename)))
+	     (with-temp-buffer
+	       (insert-file-contents filename)
+	       (set-mark (point-max))
+	       (goto-char (point-min))
+	       (run-hooks 'mail-citation-hook)
+	       (message-insert-signature) ;; FIXME is there a standard hook for signatures, too?
+	       (buffer-substring (point-min) (point-max)))))))
+    (with-temp-buffer
+      (call-process notmuch-command nil t nil "reply" query-string)
+      (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 +1269,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 +1691,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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] To use compose-mail and mail-citation-hook
  2010-03-16 19:46 [PATCH] To use compose-mail and mail-citation-hook Sandra Snan
@ 2010-03-18 13:46 ` Michal Sojka
  2010-03-18 14:01   ` Sandra Snan
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Sojka @ 2010-03-18 13:46 UTC (permalink / raw
  To: Sandra Snan, notmuch

On Tue, 16 Mar 2010, Sandra Snan wrote:
> 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 version of the patch also tries to yank the body text, calling
> mail-citation-hook as it does so it works with mu-cite, supercite,
> trivialcite and so on. I guess I started yak-shaving a bit too much
> because I kinda began to reconstruct the output of notmuch reply via
> emacs lisp.

Hi Sandra,

it seems that many peaple are not happy with the current notmuch reply.
It would be probably better to ignore notmuch reply completely and
implement replying only in elisp.

> I’ll send another e-mail with the patch for just compose-mail without
> the mail-citation-hook, too. These patches are mutually exclusive. I’m
> not used to git so I hope this is all right.

Next time please word-wrap the commit message.

Thanks
Michal

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] To use compose-mail and mail-citation-hook
  2010-03-18 13:46 ` Michal Sojka
@ 2010-03-18 14:01   ` Sandra Snan
  0 siblings, 0 replies; 3+ messages in thread
From: Sandra Snan @ 2010-03-18 14:01 UTC (permalink / raw
  To: notmuch

Michal Sojka <sojkam1@fel.cvut.cz> wrote:
> it seems that many peaple are not happy with the current notmuch reply.
> It would be probably better to ignore notmuch reply completely and
> implement replying only in elisp.

I’ll give it another look.

> > I’ll send another e-mail with the patch for just compose-mail without
> Next time please word-wrap the commit message.

Thanks for the heads up; I didn’t realize that the part that I wrote
in the mail also was used as the commit message.
I’m always welcome to more feedback on how I format and send my
patches because that’s a part of development that’s new to me.

Sandra

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-18 14:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-16 19:46 [PATCH] To use compose-mail and mail-citation-hook Sandra Snan
2010-03-18 13:46 ` Michal Sojka
2010-03-18 14:01   ` Sandra Snan

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).