From: ezyang@MIT.EDU (Edward Z. Yang)
Subject: [sup-talk] [PATCH] before-search hook
Date: Wed, 10 Jun 2009 01:44:54 -0400 [thread overview]
Message-ID: <1244612627-sup-982@javelin> (raw)
From a5c72844e8195df7a8eabd5ea592507599de72cb Mon Sep 17 00:00:00 2001
From: Edward Z. Yang <edwardzyang at thewritingpot.com>
Date: Wed, 10 Jun 2009 01:42:50 -0400
Subject: [PATCH] Add before-search hook, for shortcuts for custom search queries.
Signed-off-by: Edward Z. Yang <edwardzyang at thewritingpot.com>
---
lib/sup/hook.rb | 4 ++++
lib/sup/index.rb | 12 +++++++++++-
2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
index 0a0a2f6..d446aa3 100644
--- a/lib/sup/hook.rb
+++ b/lib/sup/hook.rb
@@ -19,6 +19,10 @@ 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. Stick
+ ## to mutation, kiddos!
def method_missing m, *a
case @__locals[m]
when Proc
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
index e403570..19556f0 100644
--- a/lib/sup/index.rb
+++ b/lib/sup/index.rb
@@ -25,6 +25,13 @@ class Index
include Singleton
+ HookManager.register "before-search", <<EOS
+Executes before a string search is applied to the index.
+Variables:
+ subs: The string being searched, use gsub! to change the
+ search (you must use mutation!)
+EOS
+
## these two accessors should ONLY be used by single-threaded programs.
## otherwise you will have a naughty ferret on your hands.
attr_reader :index
@@ -508,7 +515,10 @@ protected
def parse_user_query_string s
extraopts = {}
- subs = s.gsub(/\b(to|from):(\S+)\b/) do
+ subs = String.new s
+ HookManager.run("before-search", :subs => subs)
+
+ subs = subs.gsub(/\b(to|from):(\S+)\b/) do
field, name = $1, $2
if(p = ContactManager.contact_for(name))
[field, p.email]
--
1.6.0.4
next reply other threads:[~2009-06-10 5:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-10 5:44 Edward Z. Yang [this message]
2009-06-10 21:51 ` Edward Z. Yang
2009-06-15 17:44 ` William Morgan
2009-06-26 17:10 ` Edward Z. Yang
2009-07-27 17:40 ` Edward Z. Yang
2009-07-27 19:40 ` William Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1244612627-sup-982@javelin \
--to=ezyang@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox