sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit f8ddbefdf1b53cfcb521b0f4efd3cd30fb9ef162
parent 40c05be11a87f565549d139a3d632d35a470a97f
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Sun, 16 Aug 2009 23:39:14 -0700

console: reload

Diffstat:
M lib/sup/modes/console-mode.rb | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/lib/sup/modes/console-mode.rb b/lib/sup/modes/console-mode.rb
@@ -21,6 +21,36 @@ class Console
 
   def xapian; Index.instance.instance_variable_get :@xapian; end
   def ferret; Index.instance.instance_variable_get :@index; end
+
+  ## files that won't cause problems when reloaded
+  ## TODO expand this list / convert to blacklist
+  RELOAD_WHITELIST = %w(sup/xapian_index.rb sup/modes/console-mode.rb)
+
+  def reload
+    old_verbose = $VERBOSE
+    $VERBOSE = nil
+    old_features = $".dup
+    begin
+      fs = $".grep(/^sup\//)
+      fs.reject! { |f| not RELOAD_WHITELIST.member? f }
+      fs.each { |f| $".delete f }
+      fs.each do |f|
+        @mode << "reloading #{f}\n"
+        begin
+          require f
+        rescue LoadError => e
+          raise unless e.message =~ /no such file to load/
+        end
+      end
+    rescue Exception
+      $".clear
+      $".concat old_features
+      raise
+    ensure
+      $VERBOSE = old_verbose
+    end
+    true
+  end
 end
 
 class ConsoleMode < LogMode