inf-ruby.elが思ったようにうごかないのでCarbon Emacsを久しぶりにアップデートした。
inf-rubyがirbへ送った文字列がそのままエコーされてしまうのだけど、なにがいけないのかなあ。Carbon Emacsの2007年版も2009年版もうごきはあんまりかわらなかった。
こういうのを追求するのは苦手なのでもうあきらめることにしようっと。
irb(main):001:0> 'hello' 'hello' "hello" irb(main):002:0> eval <<'--inf-ruby-43c9869-18864-4338-229881--', nil, nil, 5 "from scratch" --inf-ruby-43c9869-18864-4338-229881-- TypeError: can't convert nil into String from (irb):2:in `eval' from (irb):2 from :0 irb(main):005:0> eval <<'--inf-ruby-6334873-18864-4389-765727--', nil, "/Users/mas/test.rb", 1 "test.rb" --inf-ruby-6334873-18864-4389-765727-- "test.rb" irb(main):008:0>
分散irb(?)はとりあえず今日は次のようにしてみた。
irb_d.rb
require 'irb' require 'drb/drb' module IRB class Context def prompting?; true; end end class Irb attr_accessor :stdout def print(*opts) @stdout ? @stdout.print(*opts) : super end def printf(*opts) @stdout ? @stdout.printf(*opts) : super end end end class IRb def start(input_method, output) irb = IRB::Irb.new(nil, input_method) irb.stdout = output th = Thread.new do catch(:IRB_EXIT) do irb.eval_input end end end end DRb.start_service('druby://:54345', IRb.new) IRB.start(__FILE__)
IRB.startがARGVを検査してくれるのでirbのオプションをそのまま渡せる。
こんな風に起動して、そのままにしておく。デーモン化してもいいかもね。
$ ruby irb_d.rb --noreadline
irb_c.rb
require 'drb/drb' require 'irb' require 'irb/input-method' STDOUT.sync = true IRB.setup(__FILE__) DRb.start_service im = IRB::StdioInputMethod.new im.extend(DRbUndumped) ro = DRbObject.new_with_uri('druby://localhost:54345') th = ro.start(im, $stdout) th.join
クライアント側。inf-ruby.elから使うなら、つぎのように設定しとくといいのかも。
(setq ruby-program-name "ruby /home/foo/irb_c.rb --inf-ruby-mode")
これで複数のEmacsのinf-ruby.elからインタプリタを共有できました。みんなで黒板のように使うときっと楽しい。