summaryrefslogtreecommitdiffstats
path: root/lib/irb/input-method.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-02-07 10:56:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-02-07 10:56:16 +0000
commit9782077515b6c95e13e97b429ccbed2f78934fc0 (patch)
treeca6bc1031b6c0e103f7d78121380511fa0225bd7 /lib/irb/input-method.rb
parent7bc3dfa20f9f462780d811ec8c0a9bb3b4375e98 (diff)
downloadruby-9782077515b6c95e13e97b429ccbed2f78934fc0.tar.gz
ruby-9782077515b6c95e13e97b429ccbed2f78934fc0.tar.xz
ruby-9782077515b6c95e13e97b429ccbed2f78934fc0.zip
* lib/irb/init.rb (IRB.rc_files): yield possible rc file names.
* lib/irb/input-method.rb (IRB::ReadlineInputMethod::initialize): load and save history automatically. [ruby-core:02352] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@5638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/irb/input-method.rb')
-rw-r--r--lib/irb/input-method.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index ec834b17b..d1fc83a97 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -85,12 +85,49 @@ module IRB
require "readline"
class ReadlineInputMethod < InputMethod
include Readline
+
+ def ReadlineInputMethod.create_finalizer(hist, file)
+ 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
+ if file
+ open(file, 'w' ) do |f|
+ hist = hist.to_a
+ f.puts(hist[-num..-1] || hist)
+ end
+ end
+ end
+ end
+ end
+
def initialize
super
@line_no = 0
@line = []
@eof = false
+
+ loader = proc {|f| f.each {|l| HISTORY << l.chomp}}
+ if hist = IRB.conf[:HISTORY_FILE]
+ hist = File.expand_path(hist)
+ begin
+ open(hist, &loader)
+ rescue
+ end
+ else
+ IRB.rc_files("_history") do |hist|
+ begin
+ open(hist, &loader)
+ rescue
+ hist = nil
+ else
+ break
+ end
+ end
+ end
+ ObjectSpace.define_finalizer(self, ReadlineInputMethod.create_finalizer(HISTORY, hist))
end
def gets