From: Michael Stapelberg <michael+sup@stapelberg.de>
To: Rich Lane <rlane@club.cc.cmu.edu>
Cc: sup-devel <sup-devel@rubyforge.org>
Subject: Re: [sup-devel] [PATCH] Use multiple body arrays when calling before-edit for each reply type
Date: Fri, 12 Mar 2010 11:17:44 +0100 [thread overview]
Message-ID: <1268388251-sup-2106@midna.zekjur.net> (raw)
In-Reply-To: <1268366964-sup-2310@zyrg.net>
[-- Attachment #1: Type: text/plain, Size: 811 bytes --]
Hi Rich,
Excerpts from Rich Lane's message of Fr Mär 12 05:20:52 +0100 2010:
> lib/sup/modes/reply-mode.rb:
> > + @bodies[k] = Array.new(body)
>
> Why is the body in an array?
That was left over while refactoring. It isn’t necessary.
> The idiomatic way to write this is:
> self.body = @bodies[@type_selector.val] unless @edited
Alright, changed.
> lib/sup/modes/reply-mode.rb:
> > + if new_body != @bodies[@type_selector.val]
> > + @bodies[@type_selector.val] = new_body
> > + @edited = true
> > + end
>
> Is there a reason we can't do this unconditionally?
Yes, I wanted to avoid setting the @edited flag if the user exited the editor
without making any changes. That way, he can benefit from the changing bodies
for a longer time.
Updated patch attached.
Best regards,
Michael
[-- Attachment #2: 0001-Use-multiple-body-arrays-when-calling-before-edit-fo.patch --]
[-- Type: application/octet-stream, Size: 2426 bytes --]
From 5661f904fd66e1a5f294a2fb602691947860cd97 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Tue, 9 Mar 2010 23:56:02 +0100
Subject: [PATCH] Use multiple body arrays when calling before-edit for each reply type
This allows for before-edit hooks which modify the body of the message
based on the different headers (previously, they could only modify
headers).
As an example, I use it to sign mail in english if one of the recipients
(not *the* recipient, but one of them) is speaking english.
---
lib/sup/modes/reply-mode.rb | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/lib/sup/modes/reply-mode.rb b/lib/sup/modes/reply-mode.rb
index 3d39a8a..bbac922 100644
--- a/lib/sup/modes/reply-mode.rb
+++ b/lib/sup/modes/reply-mode.rb
@@ -42,6 +42,7 @@ EOS
def initialize message, type_arg=nil
@m = message
+ @edited = false
## it's important to put this early because it forces a read of
## the full headers (most importantly the list-post header, if
@@ -150,11 +151,13 @@ EOS
:recipient
end)
+ @bodies = {}
@headers.each do |k, v|
- HookManager.run "before-edit", :header => v, :body => body
+ @bodies[k] = body
+ HookManager.run "before-edit", :header => v, :body => @bodies[k]
end
- super :header => @headers[@type_selector.val], :body => body, :twiddles => false
+ super :header => @headers[@type_selector.val], :body => @bodies[@type_selector.val], :twiddles => false
add_selector @type_selector
end
@@ -164,6 +167,7 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ self.body = @bodies[@type_selector.val] unless @edited
update
end
end
@@ -172,6 +176,7 @@ protected
super
if @headers[@type_selector.val] != self.header
self.header = @headers[@type_selector.val]
+ self.body = @bodies[@type_selector.val] unless @edited
update
end
end
@@ -188,6 +193,10 @@ protected
end
def handle_new_text new_header, new_body
+ if new_body != @bodies[@type_selector.val]
+ @bodies[@type_selector.val] = new_body
+ @edited = true
+ end
old_header = @headers[@type_selector.val]
if new_header.size != old_header.size || old_header.any? { |k, v| new_header[k] != v }
@type_selector.set_to :user
--
1.6.5
[-- Attachment #3: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next prev parent reply other threads:[~2010-03-12 10:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-20 22:30 Michael Stapelberg
2010-02-27 18:29 ` Rich Lane
2010-03-09 22:58 ` Michael Stapelberg
2010-03-12 4:20 ` Rich Lane
2010-03-12 10:17 ` Michael Stapelberg [this message]
2010-03-15 5:09 ` Rich Lane
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1268388251-sup-2106@midna.zekjur.net \
--to=michael+sup@stapelberg.de \
--cc=rlane@club.cc.cmu.edu \
--cc=sup-devel@rubyforge.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox