1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
shyouhei 2009-08-09 08:44:15 +00:00
parent 66c9241789
commit 4ed5e8bb9f
5 changed files with 51 additions and 22 deletions

View file

@ -1,3 +1,8 @@
Sun Aug 9 17:43:44 2009 Keiju Ishitsuka <keiju@ruby-lang.org>
* 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]
Wed Aug 5 15:29:54 2009 NAKAMURA Usaku <usa@ruby-lang.org> Wed Aug 5 15:29:54 2009 NAKAMURA Usaku <usa@ruby-lang.org>
* io.c (rb_io_flush): fsync() after buffer is flushed on win32. * io.c (rb_io_flush): fsync() after buffer is flushed on win32.

View file

@ -65,13 +65,21 @@ module IRB
trap("SIGINT") do trap("SIGINT") do
irb.signal_handle irb.signal_handle
end end
catch(:IRB_EXIT) do begin
irb.eval_input catch(:IRB_EXIT) do
irb.eval_input
end
ensure
irb_at_exit
end end
# print "\n" # print "\n"
end end
def IRB.irb_at_exit
@CONF[:AT_EXIT].each{|hook| hook.call}
end
def IRB.irb_exit(irb, ret) def IRB.irb_exit(irb, ret)
throw :IRB_EXIT, ret throw :IRB_EXIT, ret
end end

View file

@ -50,23 +50,24 @@ module IRB
module HistorySavingAbility module HistorySavingAbility
include Readline include Readline
def HistorySavingAbility.create_finalizer # def HistorySavingAbility.create_finalizer
proc do # proc do
if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0 # if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
if hf = IRB.conf[:HISTORY_FILE] # if hf = IRB.conf[:HISTORY_FILE]
file = File.expand_path(hf) # file = File.expand_path(hf)
end # end
file = IRB.rc_file("_history") unless file # file = IRB.rc_file("_history") unless file
open(file, 'w' ) do |f| # open(file, 'w' ) do |f|
hist = HISTORY.to_a # hist = HISTORY.to_a
f.puts(hist[-num..-1] || hist) # f.puts(hist[-num..-1] || hist)
end # end
end # end
end # end
end # end
def HistorySavingAbility.extended(obj) 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.load_history
obj obj
end end
@ -80,6 +81,19 @@ module IRB
end end
end 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
end end

View file

@ -114,6 +114,8 @@ module IRB
# @CONF[:LC_MESSAGES] = "en" # @CONF[:LC_MESSAGES] = "en"
@CONF[:LC_MESSAGES] = Locale.new @CONF[:LC_MESSAGES] = Locale.new
@CONF[:AT_EXIT] = []
@CONF[:DEBUG_LEVEL] = 1 @CONF[:DEBUG_LEVEL] = 1
end end

View file

@ -1,15 +1,15 @@
#define RUBY_VERSION "1.8.7" #define RUBY_VERSION "1.8.7"
#define RUBY_RELEASE_DATE "2009-08-05" #define RUBY_RELEASE_DATE "2009-08-09"
#define RUBY_VERSION_CODE 187 #define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20090805 #define RUBY_RELEASE_CODE 20090809
#define RUBY_PATCHLEVEL 195 #define RUBY_PATCHLEVEL 196
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8 #define RUBY_VERSION_MINOR 8
#define RUBY_VERSION_TEENY 7 #define RUBY_VERSION_TEENY 7
#define RUBY_RELEASE_YEAR 2009 #define RUBY_RELEASE_YEAR 2009
#define RUBY_RELEASE_MONTH 8 #define RUBY_RELEASE_MONTH 8
#define RUBY_RELEASE_DAY 5 #define RUBY_RELEASE_DAY 9
#ifdef RUBY_EXTERN #ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[]; RUBY_EXTERN const char ruby_version[];