summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (OGD) <j.van.meeuwen@ogd.nl>2009-12-21 23:45:45 +0100
committerJeroen van Meeuwen (OGD) <j.van.meeuwen@ogd.nl>2009-12-21 23:45:45 +0100
commitaa922d29856703b87ae6eebd7529f088c4ea0968 (patch)
tree8f6c865a7caa9987f4b44b7f86e03fb87bf33dfc
parent44c689d58539d56b8fdf2553986a519207f3df92 (diff)
downloadruby-aa922d29856703b87ae6eebd7529f088c4ea0968.tar.gz
ruby-aa922d29856703b87ae6eebd7529f088c4ea0968.tar.xz
ruby-aa922d29856703b87ae6eebd7529f088c4ea0968.zip
irb to save history
-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 7580e39d4..0b5d6ba57 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 5260bfcdd..5ecc5f502 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 db22ca639..5bbcc9558 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