summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-09 08:44:15 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-09 08:44:15 +0000
commit4ed5e8bb9f9b231fd6a815be664e4fec5e26f09a (patch)
treeba84997ddbb17212c3dccb9ecc966d9f3cea5de2 /lib
parent66c9241789cd80fde9aa8731f4daa04f0c20b08d (diff)
merge revision(s) 24254:
* lib/irb.rb, lib/irb/init.rb, lib/irb/ext/save-history.rb: add IRB::irb_at_exit. no use finalizer saving history. [ruby-dev-38563] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@24483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/irb.rb14
-rw-r--r--lib/irb/ext/save-history.rb44
-rw-r--r--lib/irb/init.rb2
3 files changed, 42 insertions, 18 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index 7580e39d43..0b5d6ba57e 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -65,13 +65,21 @@ module IRB
trap("SIGINT") do
irb.signal_handle
end
-
- catch(:IRB_EXIT) do
- irb.eval_input
+
+ begin
+ catch(:IRB_EXIT) do
+ irb.eval_input
+ end
+ ensure
+ irb_at_exit
end
# print "\n"
end
+ def IRB.irb_at_exit
+ @CONF[:AT_EXIT].each{|hook| hook.call}
+ end
+
def IRB.irb_exit(irb, ret)
throw :IRB_EXIT, ret
end
diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb
index 5260bfcdd8..5ecc5f5027 100644
--- a/lib/irb/ext/save-history.rb
+++ b/lib/irb/ext/save-history.rb
@@ -50,23 +50,24 @@ module IRB
module HistorySavingAbility
include Readline
- def HistorySavingAbility.create_finalizer
- proc do
- if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
- if hf = IRB.conf[:HISTORY_FILE]
- file = File.expand_path(hf)
- end
- file = IRB.rc_file("_history") unless file
- open(file, 'w' ) do |f|
- hist = HISTORY.to_a
- f.puts(hist[-num..-1] || hist)
- end
- end
- end
- end
+# def HistorySavingAbility.create_finalizer
+# proc do
+# if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
+# if hf = IRB.conf[:HISTORY_FILE]
+# file = File.expand_path(hf)
+# end
+# file = IRB.rc_file("_history") unless file
+# open(file, 'w' ) do |f|
+# hist = HISTORY.to_a
+# f.puts(hist[-num..-1] || hist)
+# end
+# end
+# end
+# end
def HistorySavingAbility.extended(obj)
- ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
+# ObjectSpace.define_finalizer(obj, HistorySavingAbility.create_finalizer)
+ IRB.conf[:AT_EXIT].push proc{obj.save_history}
obj.load_history
obj
end
@@ -80,6 +81,19 @@ module IRB
end
end
end
+
+ def save_history
+ if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
+ if history_file = IRB.conf[:HISTORY_FILE]
+ history_file = File.expand_path(history_file)
+ end
+ history_file = IRB.rc_file("_history") unless history_file
+ open(history_file, 'w' ) do |f|
+ hist = HISTORY.to_a
+ f.puts(hist[-num..-1] || hist)
+ end
+ end
+ end
end
end
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index db22ca639b..5bbcc9558b 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -114,6 +114,8 @@ module IRB
# @CONF[:LC_MESSAGES] = "en"
@CONF[:LC_MESSAGES] = Locale.new
+ @CONF[:AT_EXIT] = []
+
@CONF[:DEBUG_LEVEL] = 1
end