vondruch / rpms / ruby

Forked from rpms/ruby 6 years ago
Clone
94f00da
Thu Jul 23 15:04:20 2009  Keiju Ishitsuka  <keiju@ruby-lang.org>
94f00da
94f00da
ruby* lib/irb.rb, lib/irb/init.rb, lib/irb/ext/save-history.rb: add
94f00da
ruby  IRB::irb_at_exit. no use finalizer saving history. [ruby-dev-38563]
94f00da
94f00da
Index: lib/irb/ext/save-history.rb
94f00da
===================================================================
94f00da
--- lib/irb/ext/save-history.rb	(revision 24225)
94f00da
+++ lib/irb/ext/save-history.rb	(revision 24254)
94f00da
@@ -50,23 +50,24 @@
94f00da
   module HistorySavingAbility
94f00da
     include Readline
94f00da
 
94f00da
-    def HistorySavingAbility.create_finalizer
94f00da
-      proc do
94f00da
-	if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
94f00da
-	  if hf = IRB.conf[:HISTORY_FILE]
94f00da
-	    file = File.expand_path(hf)
94f00da
-	  end
94f00da
-	  file = IRB.rc_file("_history") unless file
94f00da
-	  open(file, 'w' ) do |f|
94f00da
-	    hist = HISTORY.to_a
94f00da
-	    f.puts(hist[-num..-1] || hist)
94f00da
-	  end
94f00da
-	end
94f00da
-      end
94f00da
-    end
94f00da
+#     def HistorySavingAbility.create_finalizer
94f00da
+#       proc do
94f00da
+# 	if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
94f00da
+# 	  if hf = IRB.conf[:HISTORY_FILE]
94f00da
+# 	    file = File.expand_path(hf)
94f00da
+# 	  end
94f00da
+# 	  file = IRB.rc_file("_history") unless file
94f00da
+# 	  open(file, 'w' ) do |f|
94f00da
+# 	    hist = HISTORY.to_a
94f00da
+# 	    f.puts(hist[-num..-1] || hist)
94f00da
+# 	  end
94f00da
+# 	end
94f00da
+#       end
94f00da
+#     end
94f00da
 
94f00da
     def HistorySavingAbility.extended(obj)
94f00da
-      ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
94f00da
+#      ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
94f00da
+      IRB.conf[:AT_EXIT].push proc{obj.save_history}
94f00da
       obj.load_history
94f00da
       obj
94f00da
     end
94f00da
@@ -80,6 +81,19 @@
94f00da
 	end
94f00da
       end
94f00da
     end
94f00da
+
94f00da
+    def save_history
94f00da
+      if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
94f00da
+	if history_file = IRB.conf[:HISTORY_FILE]
94f00da
+	  history_file = File.expand_path(history_file)
94f00da
+	end
94f00da
+	history_file = IRB.rc_file("_history") unless history_file
94f00da
+	open(history_file, 'w' ) do |f|
94f00da
+	  hist = HISTORY.to_a
94f00da
+	  f.puts(hist[-num..-1] || hist)
94f00da
+	end
94f00da
+      end
94f00da
+    end
94f00da
   end
94f00da
 end
94f00da
 
94f00da
Index: lib/irb/init.rb
94f00da
===================================================================
94f00da
--- lib/irb/init.rb	(revision 24225)
94f00da
+++ lib/irb/init.rb	(revision 24254)
94f00da
@@ -114,6 +114,8 @@
94f00da
 #    @CONF[:LC_MESSAGES] = "en"
94f00da
     @CONF[:LC_MESSAGES] = Locale.new
94f00da
     
94f00da
+    @CONF[:AT_EXIT] = []
94f00da
+    
94f00da
     @CONF[:DEBUG_LEVEL] = 1
94f00da
   end
94f00da
 
94f00da
Index: lib/irb.rb
94f00da
===================================================================
94f00da
--- lib/irb.rb	(revision 24225)
94f00da
+++ lib/irb.rb	(revision 24254)
94f00da
@@ -65,13 +65,21 @@
94f00da
     trap("SIGINT") do
94f00da
       irb.signal_handle
94f00da
     end
94f00da
-    
94f00da
-    catch(:IRB_EXIT) do
94f00da
-      irb.eval_input
94f00da
+
94f00da
+    begin
94f00da
+      catch(:IRB_EXIT) do
94f00da
+	irb.eval_input
94f00da
+      end
94f00da
+    ensure
94f00da
+      irb_at_exit
94f00da
     end
94f00da
 #    print "\n"
94f00da
   end
94f00da
 
94f00da
+  def IRB.irb_at_exit
94f00da
+    @CONF[:AT_EXIT].each{|hook| hook.call}
94f00da
+  end
94f00da
+
94f00da
   def IRB.irb_exit(irb, ret)
94f00da
     throw :IRB_EXIT, ret
94f00da
   end