sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit f3d3bb09ffc817b15b32874a3f33a4480fd863dc
parent 28ed14d7ed3c8fff5e24966157ef877c02d189fe
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Mon, 27 Jul 2009 14:04:52 -0400

Merge branch 'custom-search-hook' into next

Conflicts:

	lib/sup/index.rb

Diffstat:
M lib/sup/ferret_index.rb | 14 +++++++++++++-
M lib/sup/hook.rb | 5 +++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/lib/sup/ferret_index.rb b/lib/sup/ferret_index.rb
@@ -4,6 +4,16 @@ module Redwood
 
 class FerretIndex < BaseIndex
 
+  HookManager.register "custom-search", <<EOS
+Executes before a string search is applied to the index,
+returning a new search string.
+Variables:
+  subs: The string being searched. Be careful about shadowing:
+    this variable is actually a method, so use a temporary variable
+    or explicitly call self.subs; the substitutions in index.rb
+    don't actually work.
+EOS
+
   def initialize dir=BASE_DIR
     super
 
@@ -327,7 +337,9 @@ class FerretIndex < BaseIndex
   def parse_query s
     query = {}
 
-    subs = s.gsub(/\b(to|from):(\S+)\b/) do
+    subs = HookManager.run("custom-search", :subs => s) || s
+
+    subs = subs.gsub(/\b(to|from):(\S+)\b/) do
       field, name = $1, $2
       if(p = ContactManager.contact_for(name))
         [field, p.email]
diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
@@ -19,6 +19,11 @@ class HookManager
 
     attr_writer :__locals
 
+    ## an annoying gotcha here is that if you try something
+    ## like var = var.foo(), var will magically get allocated
+    ## to Nil and method_missing will never get called.  You
+    ## can work around this by calling self.var or simply
+    ## not assigning it to itself.
     def method_missing m, *a
       case @__locals[m]
       when Proc