Subject: [sup-talk] [PATCH] New hook: after-save

From: [email-masked] (Henri Ducrocq)
Date: Tue, 26 May 2009 16:14:24 +0100

This hook is run when the user presses on '$' to save the state and
index.
I'm using this to update a file used by my dzen status bar to display the
number of unread emails in my inbox.

diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 56dcdff..e3e70bb 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -20,6 +20,12 @@ Variables:
   thread: The message thread being marked as spam.
 EOS
 
+  HookManager.register "after-save", <<EOS
+Executes immediately after saving the index.
+Variables:
+num_inbox_total_unread: the total number of unread messages in the inbox
+EOS
+
   register_keymap do |k|
     k.add :load_threads, "Load #{LOAD_MORE_THREAD_NUM} more threads", 'M'
     k.add_multi "Load all threads (! to confirm) :", '!' do |kk|
@@ -409,6 +415,7 @@ EOS
         end
       end
     end
+    HookManager.run "after-save", :num_inbox_total_unread => lambda { Index.num_results_for :labels => [:inbox, :unread] }
   end
 
   def cleanup

-- 
Henri

---

From: [email-masked] (William Morgan)
Date: Thu, 28 May 2009 08:07:58 -0700

> number of unread emails in my inbox.

I think I'd prefer to modify the current after-poll hook to an
"after-state-change-hook" (or a better name) and have it fire after
either a poll or a save happens.
-- 
William <wmorgan-sup at masanjin.net>