Index: lib/sup/modes/thread-index-mode.rb
===================================================================
--- lib/sup/modes/thread-index-mode.rb	(revision 673)
+++ lib/sup/modes/thread-index-mode.rb	(working copy)
@@ -8,6 +8,14 @@
   MIN_FROM_WIDTH = 15
   LOAD_MORE_THREAD_NUM = 20
 
+
+  HookManager.register "index-mode-widget", <<EOS
+Executes when formatting the output of the number of messages for each thread in the thread index.
+Variables:
+      thread: The message thread to be formatted.
+EOS
+
+
   register_keymap do |k|
     k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
     k.add :reload, "Refresh view", '@'
@@ -36,7 +44,7 @@
     @hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS
     @date_width = DATE_WIDTH
     @size_width = nil
-    
+    @widgets = {}
     @tags = Tagger.new self
     
     initialize_threads
@@ -136,7 +144,13 @@
   def update
     ## let's see you do THIS in python
     @threads = @ts.threads.select { |t| !@hidden_threads[t] }.sort_by { |t| t.date }.reverse
+
+    @widgets = @threads.map { |t| HookManager.run "index-mode-widget", :thread => t }
+    @size_width = (@widgets.map { |w| (w != nil ? w.length : 0) }).max
+    if @size_width == 0
     @size_width = (@threads.max_of { |t| t.size } || 0).num_digits
+    end
+
     regen_text
   end
 
@@ -467,12 +481,12 @@
 
   def update_text_for_line l
     return unless l # not sure why this happens, but it does, occasionally
-    @text[l] = text_for_thread @threads[l]
+    @text[l] = text_for_thread @threads[l], @widgets[l]
     buffer.mark_dirty if buffer
   end
 
   def regen_text
-    @text = @threads.map_with_index { |t, i| text_for_thread t }
+    @text = @threads.map_with_index { |t, i| text_for_thread t, @widgets[i] }
     @lines = @threads.map_with_index { |t, i| [t, i] }.to_h
     buffer.mark_dirty if buffer
   end
@@ -500,7 +514,7 @@
     authors.compact.uniq.map { |a| [a, new[a]] }
   end
 
-  def text_for_thread t
+  def text_for_thread t, widget
     date = t.date.to_nice_s
 
     new = t.has_label?(:unread)
@@ -550,6 +564,8 @@
 
     snippet = t.snippet + (t.snippet.empty? ? "" : "...")
 
+    widget ||= (t.size == 1 ? " " * (@size_width + 2) : sprintf("(%#{ @size_width}d)", t.size))
+
     [ 
       [:tagged_color, @tags.tagged?(t) ? ">" : " "],
       [:none, sprintf("%#{@date_width}s", date)],
@@ -557,7 +573,7 @@
     ] +
       from +
       [
-      [subj_color, t.size == 1 ? " " * (@size_width + 2) : sprintf("(%#{@size_width}d)", t.size)],
+      [subj_color, sprintf("%#{@size_width}s", widget)],
       [:to_me_color, dp ? " >" : (p ? ' +' : "  ")],
       [subj_color, t.subj + (t.subj.empty? ? "" : " ")],
     ] +
