mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@5638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7f55b0c39e
commit
776206b3e7
3 changed files with 55 additions and 8 deletions
|
@ -1,6 +1,13 @@
|
|||
Sat Feb 7 19:56:11 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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]
|
||||
|
||||
Fri Feb 6 22:48:16 2004 Dave Thomas <dave@pragprog.com>
|
||||
|
||||
* lib/rdoc/generators/html_generator.rb (gen_url): Support
|
||||
* lib/rdoc/generators/html_generator.rb (gen_url): Support
|
||||
https in RDoc hyperlinks
|
||||
|
||||
Fri Feb 6 22:41:22 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
|
||||
|
|
|
@ -180,17 +180,20 @@ module IRB
|
|||
end
|
||||
end
|
||||
|
||||
# enumerate possible rc files
|
||||
def IRB.rc_files(rc)
|
||||
yield File.expand_path("~/.irb#{rc}") if ENV.key?("HOME")
|
||||
yield ".irb#{rc}"
|
||||
yield "irb#{rc.sub(/\A_?/, '.')}"
|
||||
yield "_irb#{rc}"
|
||||
yield "$irb#{rc}"
|
||||
end
|
||||
|
||||
# running config
|
||||
def IRB.run_config
|
||||
if @CONF[:RC]
|
||||
rcs = []
|
||||
rcs.push File.expand_path("~/.irbrc") if ENV.key?("HOME")
|
||||
rcs.push ".irbrc"
|
||||
rcs.push "irb.rc"
|
||||
rcs.push "_irbrc"
|
||||
rcs.push "$irbrc"
|
||||
catch(:EXIT) do
|
||||
for rc in rcs
|
||||
rc_files("rc") do |rc|
|
||||
begin
|
||||
load rc
|
||||
throw :EXIT
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue