From mboxrd@z Thu Jan 1 00:00:00 1970 From: web-sup@superscript.com (William Erik Baxter) Date: Fri, 18 Sep 2009 15:54:18 -0400 Subject: [sup-talk] [PATCH] Add hooks to sort and format label-list-mode display. Message-ID: <1253303493-sup-288@kronos> --- 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", < 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