* [sup-talk] [PATCH] Add hooks to sort and format label-list-mode display.
@ 2009-09-18 19:54 William Erik Baxter
2009-10-01 16:58 ` William Morgan
0 siblings, 1 reply; 3+ messages in thread
From: William Erik Baxter @ 2009-09-18 19:54 UTC (permalink / raw)
---
lib/sup/modes/label-list-mode.rb | 37 ++++++++++++++++++++++++++++++++++---
1 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/lib/sup/modes/label-list-mode.rb b/lib/sup/modes/label-list-mode.rb
index f65ec2e..d94f56f 100644
--- a/lib/sup/modes/label-list-mode.rb
+++ b/lib/sup/modes/label-list-mode.rb
@@ -8,6 +8,24 @@ class LabelListMode < LineCursorMode
k.add :toggle_show_unread_only, "Toggle between showing all labels and those with unread mail", 'u'
end
+ HookManager.register "label-list-filter", <<EOS
+Filter the label list, typically to sort.
+Variables:
+ counted: an array of counted labels.
+Return value:
+ An array of counted labels with sort_by output structure.
+EOS
+
+ HookManager.register "label-list-format", <<EOS
+Create the sprintf format string for label-list-mode.
+Variables:
+ width: the maximum label width
+ tmax: the maximum total message count
+ umax: the maximum unread message count
+Return value:
+ A format string for sprintf
+EOS
+
def initialize
@labels = []
@text = []
@@ -50,14 +68,22 @@ protected
@text = []
labels = LabelManager.all_labels
- counts = labels.map do |label|
+ counted = labels.map do |label|
string = LabelManager.string_for label
total = Index.num_results_for :label => label
unread = (label == :unread)? total : Index.num_results_for(:labels => [label, :unread])
[label, string, total, unread]
- end.sort_by { |l, s, t, u| s.downcase }
+ end
+
+ if HookManager.enabled? "label-list-filter"
+ counts = HookManager.run "label-list-filter", :counted => counted
+ else
+ counts = counted.sort_by { |l, s, t, u| s.downcase }
+ end
width = counts.max_of { |l, s, t, u| s.length }
+ tmax = counts.max_of { |l, s, t, u| t }
+ umax = counts.max_of { |l, s, t, u| u }
if @unread_only
counts.delete_if { | l, s, t, u | u == 0 }
@@ -78,8 +104,13 @@ protected
next
end
+ fmt = HookManager.run "label-list-format", :width => width, :tmax => tmax, :umax => umax
+ if !fmt
+ fmt = "%#{width + 1}s %5d %s, %5d unread"
+ end
+
@text << [[(unread == 0 ? :labellist_old_color : :labellist_new_color),
- sprintf("%#{width + 1}s %5d %s, %5d unread", string, total, total == 1 ? " message" : "messages", unread)]]
+ sprintf(fmt, string, total, total == 1 ? " message" : "messages", unread)]]
@labels << [label, unread]
yield i if block_given?
end.compact
--
1.5.3.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [sup-talk] [PATCH] Add hooks to sort and format label-list-mode display.
2009-09-18 19:54 [sup-talk] [PATCH] Add hooks to sort and format label-list-mode display William Erik Baxter
@ 2009-10-01 16:58 ` William Morgan
[not found] ` <1254418284-sup-3486@kronos>
0 siblings, 1 reply; 3+ messages in thread
From: William Morgan @ 2009-10-01 16:58 UTC (permalink / raw)
Hi William,
Sorry for the delay. I like this patch but I can't get it to apply
cleanly to master. git am -3 complains:
Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Cannot fall back to three-way merge.
Patch failed at 0001.
If you can resubmit against a recent master, I will apply it. Thanks!
--
William <wmorgan-sup at masanjin.net>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [sup-talk] [PATCH] Add hooks to sort and format label-list-mode display.
[not found] ` <1254418284-sup-3486@kronos>
@ 2009-10-12 13:30 ` William Morgan
0 siblings, 0 replies; 3+ messages in thread
From: William Morgan @ 2009-10-12 13:30 UTC (permalink / raw)
To: sup-talk
Branch label-list-mode-hooks, merged into next. Thanks!
--
William <wmorgan-sup@masanjin.net>
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-10-12 13:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-18 19:54 [sup-talk] [PATCH] Add hooks to sort and format label-list-mode display William Erik Baxter
2009-10-01 16:58 ` William Morgan
[not found] ` <1254418284-sup-3486@kronos>
2009-10-12 13:30 ` William Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox