* [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
[not found] ` <1261402666-sup-8068@masanjin.net>
@ 2010-01-22 1:32 ` Tero Tilus
2010-02-04 7:06 ` Tero Tilus
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tero Tilus @ 2010-01-22 1:32 UTC (permalink / raw)
To: Sup developers
[-- Attachment #1: Type: text/plain, Size: 451 bytes --]
William Morgan, 2009-12-21 15:38:
> Reformatted excerpts from Tero Tilus's message of 2009-12-19:
> > The detect-missing-attachment hook is pretty self evident but what you
> > had in mind for the dates? Formatter for the thread-index-mode date
> > widget maybe?
>
> Exactly. We already have index-mode-size-widget, so
> index-mode-date-widget would be analogous.
Here they are, finally...
--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
[-- Attachment #2: 0001-index-mode-date-widget-hook-for-rendering-dates-in-t.patch --]
[-- Type: application/octet-stream, Size: 4070 bytes --]
From acf0b4d340dd6a00b3f1601687ac8df0fe6943d2 Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Fri, 22 Jan 2010 02:56:17 +0200
Subject: [PATCH] index-mode-date-widget hook for rendering dates in thread index
Signed-off-by: Tero Tilus <tero@tilus.net>
---
lib/sup/modes/thread-index-mode.rb | 39 ++++++++++++++++++++++++++++-------
1 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index a6bb2b9..208247c 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -16,6 +16,12 @@ Variables:
thread: The message thread to be formatted.
EOS
+ HookManager.register "index-mode-date-widget", <<EOS
+Generates the per-thread date widget for each thread.
+Variables:
+ thread: The message thread to be formatted.
+EOS
+
HookManager.register "mark-as-spam", <<EOS
This hook is run when a thread is marked as spam
Variables:
@@ -53,10 +59,12 @@ EOS
def initialize hidden_labels=[], load_thread_opts={}
super()
@mutex = Mutex.new # covers the following variables:
- @threads = {}
+ @threads = []
@hidden_threads = {}
@size_widget_width = nil
- @size_widgets = {}
+ @size_widgets = []
+ @date_widget_width = nil
+ @date_widgets = []
@tags = Tagger.new self
## these guys, and @text and @lines, are not covered
@@ -226,6 +234,8 @@ EOS
@threads = @ts.threads.select { |t| !@hidden_threads[t] }.sort_by { |t| [t.date, t.first.id] }.reverse
@size_widgets = @threads.map { |t| size_widget_for_thread t }
@size_widget_width = @size_widgets.max_of { |w| w.display_length }
+ @date_widgets = @threads.map { |t| date_widget_for_thread t }
+ @date_widget_width = @date_widgets.max_of { |w| w.display_length }
end
set_cursor_pos @threads.index(old_cursor_thread)||curpos
@@ -719,6 +729,10 @@ protected
HookManager.run("index-mode-size-widget", :thread => t) || default_size_widget_for(t)
end
+ def date_widget_for_thread t
+ HookManager.run("index-mode-date-widget", :thread => t) || default_date_widget_for(t)
+ end
+
def cursor_thread; @mutex.synchronize { @threads[curpos] }; end
def drop_all_threads
@@ -734,6 +748,7 @@ protected
@hidden_threads[t] = true
@threads.delete_at i
@size_widgets.delete_at i
+ @date_widgets.delete_at i
@tags.drop_tag_for t
end
end
@@ -745,9 +760,12 @@ protected
@mutex.synchronize do
@size_widgets[l] = size_widget_for_thread @threads[l]
+ @date_widgets[l] = date_widget_for_thread @threads[l]
- ## if the widget size has increased, we need to redraw everyone
- need_update = @size_widgets[l].size > @size_widget_width
+ ## if a widget size has increased, we need to redraw everyone
+ need_update =
+ (@size_widgets[l].size > @size_widget_width) or
+ (@date_widgets[l].size > @date_widget_width)
end
if need_update
@@ -798,9 +816,9 @@ protected
AUTHOR_LIMIT = 5
def text_for_thread_at line
- t, size_widget = @mutex.synchronize { [@threads[line], @size_widgets[line]] }
-
- date = t.date.to_nice_s
+ t, size_widget, date_widget = @mutex.synchronize do
+ [@threads[line], @size_widgets[line], @date_widgets[line]]
+ end
starred = t.has_label? :starred
@@ -851,10 +869,11 @@ protected
snippet = t.snippet + (t.snippet.empty? ? "" : "...")
size_widget_text = sprintf "%#{ @size_widget_width}s", size_widget
+ date_widget_text = sprintf "%#{ @date_widget_width}s", date_widget
[
[:tagged_color, @tags.tagged?(t) ? ">" : " "],
- [:date_color, sprintf("%#{@date_width}s", date)],
+ [:date_color, date_widget_text],
(starred ? [:starred_color, "*"] : [:none, " "]),
] +
from +
@@ -883,6 +902,10 @@ private
end
end
+ def default_date_widget_for t
+ t.date.to_nice_s
+ end
+
def from_width
[(buffer.content_width.to_f * 0.2).to_i, MIN_FROM_WIDTH].max
end
--
1.5.6.5
[-- Attachment #3: 0001-mentions-attachments-hook-to-detect-missing-attachme.patch --]
[-- Type: application/octet-stream, Size: 1269 bytes --]
From 1b3d73a0c2f4a5bc082429d146630403d96764f2 Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Fri, 22 Jan 2010 03:24:03 +0200
Subject: [PATCH] mentions-attachments hook to detect missing attachments
---
lib/sup/modes/edit-message-mode.rb | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index 8849271..8c97302 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -40,6 +40,16 @@ Return value:
none
EOS
+ HookManager.register "mentions-attachments", <<EOS
+Detects if given message mentions attachments the way it is probable
+that there should be files attached to the message.
+Variables:
+ header: a hash of headers. See 'signature' hook for documentation.
+ body: an array of lines of body text.
+Return value:
+ True if attachments are mentioned.
+EOS
+
attr_reader :status
attr_accessor :body, :header
bool_reader :edited
@@ -444,7 +454,7 @@ private
end
def mentions_attachments?
- @body.any? { |l| l =~ /^[^>]/ && l =~ /\battach(ment|ed|ing|)\b/i }
+ HookManager.run "mentions-attachments", :header => @header, :body => @body
end
def top_posting?
--
1.5.6.5
[-- Attachment #4: Type: text/plain, Size: 143 bytes --]
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
2010-01-22 1:32 ` [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget Tero Tilus
@ 2010-02-04 7:06 ` Tero Tilus
2010-02-22 7:22 ` Rich Lane
2010-02-27 8:16 ` Rich Lane
2 siblings, 0 replies; 7+ messages in thread
From: Tero Tilus @ 2010-02-04 7:06 UTC (permalink / raw)
To: sup-devel
Tero Tilus, 2010-01-22 03:32:
> William Morgan, 2009-12-21 15:38:
> > Reformatted excerpts from Tero Tilus's message of 2009-12-19:
> > > detect-missing-attachment hook
> >
> > index-mode-date-widget
>
> Here they are, finally...
Any feedback on these? Do they need any tuning?
--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
2010-01-22 1:32 ` [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget Tero Tilus
2010-02-04 7:06 ` Tero Tilus
@ 2010-02-22 7:22 ` Rich Lane
2010-02-22 8:07 ` Tero Tilus
2010-02-27 8:16 ` Rich Lane
2 siblings, 1 reply; 7+ messages in thread
From: Rich Lane @ 2010-02-22 7:22 UTC (permalink / raw)
To: Tero Tilus; +Cc: Sup developers
Excerpts from Tero Tilus's message of 2010-01-21 20:32:00 -0500:
> William Morgan, 2009-12-21 15:38:
> > Reformatted excerpts from Tero Tilus's message of 2009-12-19:
> > > The detect-missing-attachment hook is pretty self evident but what you
> > > had in mind for the dates? Formatter for the thread-index-mode date
> > > widget maybe?
> >
> > Exactly. We already have index-mode-size-widget, so
> > index-mode-date-widget would be analogous.
>
> Here they are, finally...
Wouldn't the detect-missing-attachment hook patch cause a regression for
people who don't write their own hook?
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
2010-02-22 7:22 ` Rich Lane
@ 2010-02-22 8:07 ` Tero Tilus
2010-02-22 8:09 ` Tero Tilus
0 siblings, 1 reply; 7+ messages in thread
From: Tero Tilus @ 2010-02-22 8:07 UTC (permalink / raw)
To: Sup developers
Rich Lane, 2010-02-22 09:22:
> Wouldn't the detect-missing-attachment hook patch cause a regression
> for people who don't write their own hook?
Oops. It definitely would. Amended patch attached.
--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
2010-02-22 8:07 ` Tero Tilus
@ 2010-02-22 8:09 ` Tero Tilus
2010-02-27 8:11 ` Rich Lane
0 siblings, 1 reply; 7+ messages in thread
From: Tero Tilus @ 2010-02-22 8:09 UTC (permalink / raw)
To: Sup developers
[-- Attachment #1: Type: text/plain, Size: 187 bytes --]
Tero Tilus, 2010-02-22 10:07:
> Amended patch attached.
Didn't pass my own test. :D
Better luck this time with the attachment.
--
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
[-- Attachment #2: 0001-mentions-attachments-hook-to-detect-missing-attachme.patch --]
[-- Type: application/octet-stream, Size: 1423 bytes --]
From ba316e676e02d65022b5fce7cd735cc40393134c Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Mon, 22 Feb 2010 09:53:38 +0200
Subject: [PATCH] mentions-attachments hook to detect missing attachments
---
lib/sup/modes/edit-message-mode.rb | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
index 8849271..224c5ae 100644
--- a/lib/sup/modes/edit-message-mode.rb
+++ b/lib/sup/modes/edit-message-mode.rb
@@ -40,6 +40,16 @@ Return value:
none
EOS
+ HookManager.register "mentions-attachments", <<EOS
+Detects if given message mentions attachments the way it is probable
+that there should be files attached to the message.
+Variables:
+ header: a hash of headers. See 'signature' hook for documentation.
+ body: an array of lines of body text.
+Return value:
+ True if attachments are mentioned.
+EOS
+
attr_reader :status
attr_accessor :body, :header
bool_reader :edited
@@ -444,7 +454,11 @@ private
end
def mentions_attachments?
- @body.any? { |l| l =~ /^[^>]/ && l =~ /\battach(ment|ed|ing|)\b/i }
+ if HookManager.enabled? "mentions-attachments"
+ HookManager.run "mentions-attachments", :header => @header, :body => @body
+ else
+ @body.any? { |l| l =~ /^[^>]/ && l =~ /\battach(ment|ed|ing|)\b/i }
+ end
end
def top_posting?
--
1.5.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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
2010-02-22 8:09 ` Tero Tilus
@ 2010-02-27 8:11 ` Rich Lane
0 siblings, 0 replies; 7+ messages in thread
From: Rich Lane @ 2010-02-27 8:11 UTC (permalink / raw)
To: Tero Tilus; +Cc: Sup developers
Branch mentions-attachments-hook, merged into next.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget
2010-01-22 1:32 ` [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget Tero Tilus
2010-02-04 7:06 ` Tero Tilus
2010-02-22 7:22 ` Rich Lane
@ 2010-02-27 8:16 ` Rich Lane
2 siblings, 0 replies; 7+ messages in thread
From: Rich Lane @ 2010-02-27 8:16 UTC (permalink / raw)
To: Tero Tilus; +Cc: Sup developers
Branch date-widget-hook, merged to next.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-02-27 8:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1261167840-sup-592@orion>
[not found] ` <1261179239-sup-9258@tilus.net>
[not found] ` <1261246334-sup-1438@masanjin.net>
[not found] ` <1261276156-sup-5510@tilus.net>
[not found] ` <1261402666-sup-8068@masanjin.net>
2010-01-22 1:32 ` [sup-devel] [PATCH] I can haz moar hooks: attachment-mentioned, index-mode-date-widget Tero Tilus
2010-02-04 7:06 ` Tero Tilus
2010-02-22 7:22 ` Rich Lane
2010-02-22 8:07 ` Tero Tilus
2010-02-22 8:09 ` Tero Tilus
2010-02-27 8:11 ` Rich Lane
2010-02-27 8:16 ` Rich Lane
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox