]> git.notmuchmail.org Git - sup/commitdiff
Merge branch 'master' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 9 Sep 2009 14:08:33 +0000 (10:08 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 9 Sep 2009 14:11:20 +0000 (10:11 -0400)
Conflicts:
lib/sup/ferret_index.rb

bin/sup
bin/sup-sync
lib/sup/buffer.rb
lib/sup/ferret_index.rb
lib/sup/hook.rb
lib/sup/modes/console-mode.rb
lib/sup/modes/log-mode.rb
lib/sup/xapian_index.rb

diff --git a/bin/sup b/bin/sup
index 5049879cd16432661bb46fb8176b008f89c1eab2..e53a8e8bfafa2fcffa00cf89d1e75fa26eb62bec 100755 (executable)
--- a/bin/sup
+++ b/bin/sup
@@ -211,7 +211,7 @@ begin
   until Redwood::exceptions.nonempty? || $die
     c = begin
       Ncurses.nonblocking_getch
-    rescue Interrupt => e
+    rescue Interrupt
       raise if BufferManager.ask_yes_or_no "Die ungracefully now?"
       BufferManager.draw_screen
       nil
index 003a72d9c320e97d80687effb750654e0bc337aa..ddcf8c567563574be9ecd3a1b84abf1daf51e024 100755 (executable)
@@ -173,18 +173,22 @@ begin
 
       ## decide what to do based on message labels and the operation we're performing
       dothis, new_labels = case
-      when (op == :restore) && restored_state[m.id] && old_m && (old_m.labels != restored_state[m.id])
-        num_restored += 1
-        [:update_message_state, restored_state[m.id]]
-      when (op == :restore) && restored_state[m.id] && !old_m
-        num_restored += 1
-        m.labels = restored_state[m.id]
-        :add_message
+      when (op == :restore) && restored_state[m.id]
+        if old_m && (old_m.labels != restored_state[m.id])
+          num_restored += 1
+          [:update_message_state, restored_state[m.id]]
+        elsif old_m.nil?
+          num_restored += 1
+          m.labels = restored_state[m.id]
+          :add_message
+        else
+          # labels are the same; don't do anything
+        end
       when op == :discard
         if old_m && (old_m.labels != m.labels)
           [:update_message_state, m.labels]
         else
-          # don't do anything
+          # labels are the same; don't do anything
         end
       else
         ## duplicate behavior of poll mode: if index_state is non-nil, this is a newer
index 67ccd86ea533f15e0706233314ebcdd21188af7e..19f8ec2c0c37644ddf640c663281463d395dc1cb 100644 (file)
@@ -37,7 +37,14 @@ module Ncurses
     end
   end
 
-  module_function :rows, :cols, :curx, :nonblocking_getch, :mutex, :sync
+  ## pretends ctrl-c's are ctrl-g's
+  def safe_nonblocking_getch
+    nonblocking_getch
+  rescue Interrupt
+    KEY_CANCEL
+  end
+
+  module_function :rows, :cols, :curx, :nonblocking_getch, :safe_nonblocking_getch, :mutex, :sync
 
   remove_const :KEY_ENTER
   remove_const :KEY_CANCEL
@@ -385,7 +392,7 @@ EOS
     draw_screen
 
     until mode.done?
-      c = Ncurses.nonblocking_getch
+      c = Ncurses.safe_nonblocking_getch
       next unless c # getch timeout
       break if c == Ncurses::KEY_CANCEL
       begin
@@ -561,7 +568,7 @@ EOS
     end
 
     while true
-      c = Ncurses.nonblocking_getch
+      c = Ncurses.safe_nonblocking_getch
       next unless c # getch timeout
       break unless tf.handle_input c # process keystroke
 
@@ -614,7 +621,7 @@ EOS
     ret = nil
     done = false
     until done
-      key = Ncurses.nonblocking_getch or next
+      key = Ncurses.safe_nonblocking_getch or next
       if key == Ncurses::KEY_CANCEL
         done = true
       elsif accept.nil? || accept.empty? || accept.member?(key)
index 2de8727f2e2652577d0ed4e8634caae8030003ae..789a688d22b03630afdae22cb4dc5ae4e8600ba4 100644 (file)
@@ -8,10 +8,7 @@ class FerretIndex < BaseIndex
 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.
+  subs: The string being searched.
 EOS
 
   def initialize dir=BASE_DIR
index 0212c6bc9dfe26c738cab3d7f8b90929b7dc981a..9c2fb65eb39efa64739a9a6b4b1d8b52ebdf8537 100644 (file)
@@ -122,7 +122,7 @@ private
           debug "read '#{name}' from #{fn_for(name)}"
         end
       rescue SystemCallError => e
-        #log "disabled hook for '#{name}': #{e.message}"
+        #debug "disabled hook for '#{name}': #{e.message}"
         nil
       end
     end
index af3d66d00d1c8fdd85521fecdf8edeef23c6c36b..e9bf47cc914a978c0278d319c37654b2a6c8f97d 100644 (file)
@@ -21,6 +21,7 @@ class Console
 
   def xapian; Index.instance.instance_variable_get :@xapian; end
   def ferret; Index.instance.instance_variable_get :@index; end
+  def special_methods; methods - Object.methods end
 
   ## files that won't cause problems when reloaded
   ## TODO expand this list / convert to blacklist
@@ -67,12 +68,6 @@ class ConsoleMode < LogMode
     super "console"
     @console = Console.new self
     @binding = @console.instance_eval { binding }
-    self << <<EOS
-Sup #{VERSION} console.
-Available commands: #{(@console.methods - Object.methods) * ", "}
-Ctrl-g stops evaluation; 'e' restarts it.
-
-EOS
   end
 
   def execute cmd
@@ -89,13 +84,23 @@ EOS
   end
 
   def prompt
-    BufferManager.ask :console, "eval: "
+    BufferManager.ask :console, ">> "
   end
 
   def run
+    self << <<EOS
+Sup v#{VERSION} console session started.
+Available extra commands: #{(@console.special_methods) * ", "}
+Ctrl-G stops evaluation; 'e' restarts it.
+
+EOS
     while true
-      cmd = prompt or return
-      execute cmd
+      if(cmd = prompt)
+        execute cmd
+      else
+        self << "Console session ended."
+        break
+      end
     end
   end
 end
index 07fa9dd6cda8d4780676119839ee053baee41560..de320ce1c4749f56b8d5502db6e61868b463a206 100644 (file)
@@ -9,9 +9,12 @@ class LogMode < TextMode
     k.add :toggle_follow, "Toggle follow mode", 'f'
   end
 
-  def initialize buffer_name
+  ## if buffer_name is supplied, this mode will spawn a buffer
+  ## upon receiving the << message. otherwise, it will act like
+  ## a regular buffer.
+  def initialize autospawn_buffer_name=nil
     @follow = true
-    @buffer_name = buffer_name
+    @autospawn_buffer_name = autospawn_buffer_name
     @on_kill = []
     super()
   end
@@ -28,8 +31,8 @@ class LogMode < TextMode
   end
 
   def << s
-    unless buffer
-      BufferManager.spawn @buffer_name, self, :hidden => true, :system => true
+    if buffer.nil? && @autospawn_buffer_name
+      BufferManager.spawn @autospawn_buffer_name, self, :hidden => true, :system => true
     end
 
     s.split("\n").each { |l| super(l + "\n") } # insane. different << semantics.
index 1395601367ef49fdebb9ef5019a82a07a0c83ca3..e1cfe65a0c1266d6280d79d5e5fda8c310bd0508 100644 (file)
@@ -16,6 +16,13 @@ class XapianIndex < BaseIndex
   MIN_DATE = Time.at 0
   MAX_DATE = Time.at(2**31-1)
 
+  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.
+EOS
+
   def initialize dir=BASE_DIR
     super
 
@@ -185,7 +192,8 @@ class XapianIndex < 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]