# \[ANN\] fxirb 0.2.0 - Multiline Edit (and request for help)

**URL:** <https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544>\
**Category:** ruby-talk\
**Created:** [10 April 2005 16:29 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544 "2005-04-10T16:29:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [10 April 2005 16:29 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/1 "2005-04-10T16:29:38Z")

</div>

available at [http://rubyforge.org/projects/fxirb/](http://rubyforge.org/projects/fxirb/)

Finally got around to my 0.2 milestone, proper multiline editing.

You can now:

1. Paste in a multiline block of code and edit it immediately using all  
four arrow keys

2. Enter a multiline block line by line, and have it occupy a single  
multiline slot in the history once it's done

3. Edit a multiline history item using all four arrow keys

Associated behaviour change:

Up/Down arrows now only scroll history if not in multiline mode  
PgUp/PgDn always scroll history

The other major change is the ability to pass in an on\_exit block, which  
is instance\_evaled by the FxIRB widget when its internal IRB thread  
exits. Usage:

fxirb = FXIrb.init(window, nil, 0,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y|TEXT\_WORDWRAP|TEXT\_SHOWACTIVE)  
fxirb.on\_exit {exit}

This should make it possible to embed fxirb in another application, and  
not have the whole application exit when IRB exits.

The target for the 0.3 and 0.4 milestones are a menu-and-button frame in  
standalone mode, and an implementation of 'gets' (I really would like  
some help with the latter - I don't know enough about IRB internals or  
FOX to see what I need to do. To see the problem, just start up FXIrb  
and type in "a = gets")

martin

Changelog:

0.2.0 - Martin DeMello - 2005/04/10  
&nbsp;&nbsp;&nbsp;&nbsp;\* Multiline edit  
&nbsp;&nbsp;&nbsp;&nbsp;\* Settable on\_exit proc

0.1.4 - Martin DeMello - 2005/02/19  
&nbsp;&nbsp;&nbsp;&nbsp;\* Minor code cleanup  
&nbsp;&nbsp;&nbsp;&nbsp;\* Dedentation on ], } or end  
&nbsp;&nbsp;&nbsp;&nbsp;\* Ctrl-D, Ctrl-U and Ctrl-K keys bound

0.1.3 - Martin DeMello - 2004/03/21

&nbsp;&nbsp;&nbsp;&nbsp;\* Added ability to select text, and return the cursor to the proper position  
&nbsp;&nbsp;&nbsp;&nbsp;\* Changed font to Lucida Console  
&nbsp;&nbsp;&nbsp;&nbsp;\* Added indentation

0.1.2 - Frailis - 2003/01/10

&nbsp;&nbsp;&nbsp;&nbsp;\* Fixed commands history

0.1.1 - Frailis - 2003/01/07

&nbsp;&nbsp;&nbsp;&nbsp;\* Removed IOEmulate module because it redirects every "p" operation in a program which embeds FXIrb

0.1.0 - Frailis - 2003/01/02

&nbsp;&nbsp;&nbsp;&nbsp;\* Tested on ruby 1.6.7 and 1.7.3  
&nbsp;&nbsp;&nbsp;&nbsp;\* Added commands history and terminal behaviour

---

<div class="post-metadata">

**Author:** ![B\_K\_Oxley\_binkley](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@B\_K\_Oxley\_binkley](https://rubytalk.org/u/B_K_Oxley_binkley)\
**Post date:** [10 April 2005 17:00 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/2 "2005-04-10T17:00:42Z")

</div>

To use fxirb I need fox12 but am having difficulty using gem to install it on Cygwin. What is the suggestion for getting fox ruby support for Cygwin?

Cheers,  
--binkley

---

<div class="post-metadata">

**Author:** ![Its\_Me](https://avatars.discourse-cdn.com/v4/letter/i/958977/32.png) [@Its\_Me](https://rubytalk.org/u/Its_Me)\
**Post date:** [11 April 2005 03:09 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/3 "2005-04-11T03:09:37Z")

</div>

in message news:Wtc6e.953812$8l.185173@pd7tw1no...

> available at [http://rubyforge.org/projects/fxirb/](http://rubyforge.org/projects/fxirb/)
> 
> Finally got around to my 0.2 milestone, proper multiline editing.

Thanks! I'm getting quite a nice flow between my editor and fxirb now!

btw, on XP some messages (streams?) seem to come out on the command window,  
not the fx window e.g.  
(irb):14: warning: parenthesize argument(s) for future version  
(irb):14: warning: parenthesize argument(s) for future version

> **···**
>
> "Martin DeMello" \<martindemello@yahoo.com\> wrote

---

<div class="post-metadata">

**Author:** ![Csaba\_Henk4](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@Csaba\_Henk4](https://rubytalk.org/u/Csaba_Henk4)\
**Post date:** [11 April 2005 04:34 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/4 "2005-04-11T04:34:37Z")

</div>

> available at [http://rubyforge.org/projects/fxirb/](http://rubyforge.org/projects/fxirb/)
> 
> Finally got around to my 0.2 milestone, proper multiline editing.

That sounds cool. I wanted to give it a try under Linux, but with my  
existing fxruby installation (1.2.2) it segfaulted; then I upgraded my  
fxruby to 1.2.5, which just hanged upon pressing enter.

> The target for the 0.3 and 0.4 milestones are a menu-and-button frame in  
> standalone mode, and an implementation of 'gets' (I really would like  
> some help with the latter - I don't know enough about IRB internals or  
> FOX to see what I need to do. To see the problem, just start up FXIrb  
> and type in "a = gets")

What's the problem? As you can see, I can't try this now.

Csaba

> **···**
>
> On 2005-04-10, Martin DeMello \<martindemello@yahoo.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [10 April 2005 17:29 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/5 "2005-04-10T17:29:42Z")

</div>

Sorry, I've never tried this - I just use the one-click installer.

[http://www.fox-toolkit.org/install.html](http://www.fox-toolkit.org/install.html) suggests that fox compiles  
cleanly under cygwin, at least.

Also, I'm not using any fancy fox features, so it should be possible to get  
this running under Fox 1.0 if that is less problematic than 1.2. Let me  
know if you need to go down that route, and I'll help port it back to  
1.0 (IIRC porting it to 1.2 in the first place was trivial, but I don't  
have a Fox 1.0 install around any more to check it).

martin

> **···**
>
> "B. K. Oxley (binkley)" \<binkley@alumni.rice.edu\> wrote:
> 
> > To use fxirb I need fox12 but am having difficulty using gem to install  
> > it on Cygwin. What is the suggestion for getting fox ruby support for  
> > Cygwin?

---

<div class="post-metadata">

**Author:** ![Peter\_Suk](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@Peter\_Suk](https://rubytalk.org/u/Peter_Suk)\
**Post date:** [10 April 2005 18:21 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/6 "2005-04-10T18:21:08Z")

</div>

Binkley,

Would you be interested in getting together sometime? Feel free to give me a call. 713-807-9023.

--Peter

> **···**
>
> On Apr 10, 2005, at 12:00 PM, B. K. Oxley (binkley) wrote:
> 
> > To use fxirb I need fox12 but am having difficulty using gem to install it on Cygwin. What is the suggestion for getting fox ruby support for Cygwin?
> 
> --  
> There's neither heaven nor hell, save what we grant ourselves.  
> There's neither fairness nor justice, save what we grant each other.

---

<div class="post-metadata">

**Author:** ![Peter\_Suk](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@Peter\_Suk](https://rubytalk.org/u/Peter_Suk)\
**Post date:** [10 April 2005 18:22 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/7 "2005-04-10T18:22:10Z")

</div>

Drat, I didn't mean to send to that address!

--Peter

> **···**
>
> On Apr 10, 2005, at 12:00 PM, B. K. Oxley (binkley) wrote:
> 
> > To use fxirb I need fox12 but am having difficulty using gem to install it on Cygwin. What is the suggestion for getting fox ruby support for Cygwin?
> 
> --  
> There's neither heaven nor hell, save what we grant ourselves.  
> There's neither fairness nor justice, save what we grant each other.

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [11 April 2005 04:29 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/8 "2005-04-11T04:29:38Z")

</div>

Can you paste in a sample session? Not seen this happen on Win2k.

martin

> **···**
>
> itsme213 \<itsme213@hotmail.com\> wrote:
> 
> > "Martin DeMello" \<martindemello@yahoo.com\> wrote
> > 
> > in message news:Wtc6e.953812$8l.185173@pd7tw1no...  
> > \> available at [http://rubyforge.org/projects/fxirb/](http://rubyforge.org/projects/fxirb/)  
> > \>  
> > \> Finally got around to my 0.2 milestone, proper multiline editing.
> > 
> > Thanks! I'm getting quite a nice flow between my editor and fxirb now!
> > 
> > btw, on XP some messages (streams?) seem to come out on the command window,  
> > not the fx window e.g.  
> > (irb):14: warning: parenthesize argument(s) for future version  
> > (irb):14: warning: parenthesize argument(s) for future version

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [11 April 2005 06:34 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/9 "2005-04-11T06:34:38Z")

</div>

I've not tested this at all under linux - I based it off Marco Frailis's  
win32 fxirb. I should make that my next priority, actually - it's  
somewhat more useful than a menu and button frame :).

martin

> **···**
>
> Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> 
> > On 2005-04-10, Martin DeMello \<martindemello@yahoo.com\> wrote:  
> > \> available at [http://rubyforge.org/projects/fxirb/](http://rubyforge.org/projects/fxirb/)  
> > \>  
> > \> Finally got around to my 0.2 milestone, proper multiline editing.
> > 
> > That sounds cool. I wanted to give it a try under Linux, but with my  
> > existing fxruby installation (1.2.2) it segfaulted; then I upgraded my  
> > fxruby to 1.2.5, which just hanged upon pressing enter.

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [11 April 2005 07:09 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/10 "2005-04-11T07:09:37Z")

</div>

The whole thing just hangs up (windows says 'this application is not  
responding'). I thought it might be infinitely recursing  
FXIRBInputMethod#gets, but it isn't, so I'm at a bit of a loss as how to  
even debug it (no stack trace).

martin

> **···**
>
> Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> 
> > \> FOX to see what I need to do. To see the problem, just start up FXIrb  
> > \> and type in "a = gets")
> > 
> > What's the problem? As you can see, I can't try this now.

---

<div class="post-metadata">

**Author:** ![B\_K\_Oxley\_binkley](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@B\_K\_Oxley\_binkley](https://rubytalk.org/u/B_K_Oxley_binkley)\
**Post date:** [13 April 2005 15:01 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/11 "2005-04-13T15:01:00Z")

</div>

B. K. Oxley (binkley) wrote:

> To use fxirb I need fox12 but am having difficulty using gem to install it on Cygwin. What is the suggestion for getting fox ruby support for Cygwin?

Here is how I did it.

\* Download Fox 1.2.16 (latest in Fox 1.2.x series corresponding with the 1.2.x fxruby sources) and unpack.

\* Configure thus:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ ./configure --prefix=/usr/local --without-xcursor

For whatever reason, since Fox's configure script saw I had a xcursor.h header, it hooked in Xcursor support even though Fox otherwise recognized that I was on a Windows system (note that I did not say --with-x). This was ok as far as it went, except that it broke the compile as the X libraries were not in the link paths. Simply saying --wihtout-xcursor fixed that

\* Build normally, install.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ make && make install

\* Build fxruby

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ gem install fxruby

Select the 1.2.5 (ruby) version, the lastest that builds from source.

All done!

Cheers,  
--binkley

---

<div class="post-metadata">

**Author:** ![Csaba\_Henk4](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@Csaba\_Henk4](https://rubytalk.org/u/Csaba_Henk4)\
**Post date:** [11 April 2005 07:44 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/12 "2005-04-11T07:44:38Z")

</div>

A line read by irb is evaluated in an IRB::Irb instance (that class is  
defined in irb.rb). As I can read fxirb.rb, you didn't overwrite #gets  
anywhere seeked by IRB::Irb upon method lookup. So what happens is that  
the good old Kernel#gets is called.

Csaba

> **···**
>
> On 2005-04-11, Martin DeMello \<martindemello@yahoo.com\> wrote:
> 
> > Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> > 
> > > \> FOX to see what I need to do. To see the problem, just start up FXIrb  
> > > \> and type in "a = gets")
> > > 
> > > What's the problem? As you can see, I can't try this now.
> > 
> > The whole thing just hangs up (windows says 'this application is not  
> > responding'). I thought it might be infinitely recursing  
> > FXIRBInputMethod#gets, but it isn't, so I'm at a bit of a loss as how to  
> > even debug it (no stack trace).

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [11 April 2005 08:24 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/13 "2005-04-11T08:24:41Z")

</div>

I tried IRB::Irb#gets and IRB::Context#gets, but neither of them were  
getting called. It did indeed turn out to be Kernel#gets - is it safe to  
just override that?

martin

> **···**
>
> Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> 
> > A line read by irb is evaluated in an IRB::Irb instance (that class is  
> > defined in irb.rb). As I can read fxirb.rb, you didn't overwrite #gets  
> > anywhere seeked by IRB::Irb upon method lookup. So what happens is that  
> > the good old Kernel#gets is called.

---

<div class="post-metadata">

**Author:** ![Csaba\_Henk4](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@Csaba\_Henk4](https://rubytalk.org/u/Csaba_Henk4)\
**Post date:** [11 April 2005 09:44 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/14 "2005-04-11T09:44:37Z")

</div>

I'm sorry, I was wrong. A command read by irb is evaluated  
in the toplevel.

In general, you can access the toplevel object as

&nbsp;&nbsp;eval "self", TOPLEVEL\_BINDING

but with irb, the api-friendly way is as follows:

&nbsp;&nbsp;IRB.context.workspace.main

(that is, with an alternative config this might differ from the toplevel  
object, but this form always gives you the object which is used by irb  
for evaluation).

So, just define #gets as a singleton method of the above object.

Csaba

> **···**
>
> On 2005-04-11, Martin DeMello \<martindemello@yahoo.com\> wrote:
> 
> > Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> > 
> > > A line read by irb is evaluated in an IRB::Irb instance (that class is  
> > > defined in irb.rb). As I can read fxirb.rb, you didn't overwrite #gets  
> > > anywhere seeked by IRB::Irb upon method lookup. So what happens is that  
> > > the good old Kernel#gets is called.
> > 
> > I tried IRB::Irb#gets and IRB::Context#gets, but neither of them were  
> > getting called. It did indeed turn out to be Kernel#gets - is it safe to  
> > just override that?

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [11 April 2005 10:09 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/15 "2005-04-11T10:09:52Z")

</div>

> but with irb, the api-friendly way is as follows:
> 
> &nbsp;&nbsp;IRB.context.workspace.main

irb.context.workspace.main actually

> (that is, with an alternative config this might differ from the toplevel  
> object, but this form always gives you the object which is used by irb  
> for evaluation).
> 
> So, just define #gets as a singleton method of the above object.

perfect! thanks a lot - hopefully I'll actually manage to get something  
working tonight.

martin

> **···**
>
> Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:

---

<div class="post-metadata">

**Author:** ![Csaba\_Henk4](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@Csaba\_Henk4](https://rubytalk.org/u/Csaba_Henk4)\
**Post date:** [12 April 2005 00:24 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/16 "2005-04-12T00:24:39Z")

</div>

Uh-oh. Stupid me, again.

irb.context.workspace.main

starts a new reader first, and when that's completes, it gives you the  
respective IRB::Irb object. So even if that's the toplevel object again,  
I don't think you really want this. IRB.context.workspace.main is the  
correct solution, under the right circumstances... 🙂 no wonder it  
doesn't work for you. For my irb hacks, I use

module IRB  
&nbsp;&nbsp;&nbsp;&nbsp;def self.context  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conf[:MAIN\_CONTEXT]  
&nbsp;&nbsp;&nbsp;&nbsp;end  
end

and having this, what I told you will work.

To put it simply:

IRB.conf[:MAIN\_CONTEXT].workspace.main

is the right thing.

Sorry for iterating confusion.

Though... even the above will break if someone starts a subirb with a  
different workspace.main. Not that likely, but why not. To get the  
evaluator of the current irb object, you have to do something like

IRB.conf[:MAIN\_CONTEXT].workspace.main.jobs.current\_job.context.workspace.main

Whew! OK, I looked up how to simplify that:

IRB.JobManager.current\_job.context.workspace.main

So, the purest solution would be to get #gets dynamically dispatch to  
the vaule of the above expression.

Such things are handled by the module IRB::ExtendCommandBundle of  
'irb/extend-command.rb'.

I guess by adding the right thing to @EXTEND\_COMMANDS of the above,  
the magic would happen. I don't know though if you can actually overwrite  
existing methods this way. Maybe you'd have to do something with  
IRB::ExtendCommandBundle.included.

I'd say that if you are lazy, just use  
"IRB.conf[:MAIN\_CONTEXT].workspace.main", that's a 97% solution at least  
anyway.

Csaba

> **···**
>
> On 2005-04-11, Martin DeMello \<martindemello@yahoo.com\> wrote:
> 
> > Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> > 
> > > but with irb, the api-friendly way is as follows:
> > > 
> > > &nbsp;&nbsp;IRB.context.workspace.main
> > 
> > irb.context.workspace.main actually

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [12 April 2005 18:49 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/17 "2005-04-12T18:49:36Z")

</div>

I'm a bit confused about lifecycle issues now. What I have at the moment  
is this:

module IRB

&nbsp;&nbsp;def IRB.start\_in\_fxirb(im)  
&nbsp;&nbsp;&nbsp;&nbsp;if RUBY\_VERSION \< "1.7.3"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.initialize(nil)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.parse\_opts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.load\_modules  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.setup(nil)  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;irb = Irb.new(nil, im)

&nbsp;&nbsp;&nbsp;&nbsp;@CONF[:IRB\_RC].call(irb.context) if @CONF[:IRB\_RC]  
&nbsp;&nbsp;&nbsp;&nbsp;@CONF[:MAIN\_CONTEXT] = irb.context  
&nbsp;&nbsp;&nbsp;&nbsp;trap("SIGINT") do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;irb.signal\_handle  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;class \<\< irb.context.workspace.main  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def gets  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inp = IRB.conf[:MAIN\_CONTEXT].io  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inp.gets\_mode = true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retval = IRB.conf[:MAIN\_CONTEXT].io.gets  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inp.gets\_mode = false  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retval  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;catch(:IRB\_EXIT) do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;irb.eval\_input  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;print "\n"

&nbsp;&nbsp;end

end

and inside the FXIrb class:

def create  
&nbsp;&nbsp;&nbsp;&nbsp;super  
&nbsp;&nbsp;&nbsp;&nbsp;setFocus  
&nbsp;&nbsp;&nbsp;&nbsp;# IRB initialization  
&nbsp;&nbsp;&nbsp;&nbsp;@inputAdded = 0  
&nbsp;&nbsp;&nbsp;&nbsp;@input = IO.pipe  
&nbsp;&nbsp;&nbsp;&nbsp;$DEFAULT\_OUTPUT = self

&nbsp;&nbsp;&nbsp;&nbsp;@im = FXIRBInputMethod.new  
&nbsp;&nbsp;&nbsp;&nbsp;@irb = Thread.new {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IRB.start\_in\_fxirb(@im)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.crash  
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;@multiline = false  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;@exit\_proc = lambda {exit}  
&nbsp;&nbsp;end  
end

As far as I can make out, inside IRB.start\_in\_fxirb is the only place I  
have access to the IRB.conf[:MAIN\_CONTEXT] object after it is  
initialised to Irb.new, so that I can create the appropriate singleton  
method. Also I looked at the Context and Workspace code, and don't see  
why irb.context.workspace.main would create a new reader. (Thanks for  
being patient, btw - the IRB code is fairly labyrinthine until one gets  
used to it.)

martin

> **···**
>
> Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> 
> > Uh-oh. Stupid me, again.
> > 
> > irb.context.workspace.main
> > 
> > starts a new reader first, and when that's completes, it gives you the  
> > respective IRB::Irb object. So even if that's the toplevel object again,  
> > I don't think you really want this. IRB.context.workspace.main is the  
> > correct solution, under the right circumstances... 🙂 no wonder it  
> > doesn't work for you. For my irb hacks, I use
> > 
> > module IRB  
> > &nbsp;&nbsp;&nbsp;&nbsp;def self.context  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conf[:MAIN\_CONTEXT]  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > end
> > 
> > and having this, what I told you will work.

---

<div class="post-metadata">

**Author:** ![Csaba\_Henk4](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@Csaba\_Henk4](https://rubytalk.org/u/Csaba_Henk4)\
**Post date:** [13 April 2005 21:34 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/18 "2005-04-13T21:34:37Z")

</div>

> I'm a bit confused about lifecycle issues now. What I have at the moment  
> is this:
> 
> module IRB
> 
> &nbsp;&nbsp;def IRB.start\_in\_fxirb(im)

[snip]

> &nbsp;&nbsp;&nbsp;&nbsp;irb = Irb.new(nil, im)

[snip]

> &nbsp;&nbsp;&nbsp;&nbsp;class \<\< irb.context.workspace.main  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def gets

[snip]

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;end
> 
> end
> 
> and inside the FXIrb class:

[snip]

Well, this code look fine to me, but of course, just looking at the code  
is not enough.

> As far as I can make out, inside IRB.start\_in\_fxirb is the only place I  
> have access to the IRB.conf[:MAIN\_CONTEXT] object after it is  
> initialised to Irb.new, so that I can create the appropriate singleton  
> method.

It might be that IRB.start\_in\_fxirb is the appropriate place to define  
the singleton (I'd say so). But what do you mean by "the only place I  
have access to ..."? IRB.conf[:MAIN\_CONTEXT] is a global accessor, it  
should work everywhere (unless you have somewhere another IRB constant,  
which I'm sure is not the case, but even then you could access the  
object as such via TOPLEVEL\_BINDING).

> Also I looked at the Context and Workspace code, and don't see  
> why irb.context.workspace.main would create a new reader. (Thanks for  
> being patient, btw - the IRB code is fairly labyrinthine until one gets  
> used to it.)

Um, what irb is the irb in "irb.context.workspace.main"?

It seems that we were speaking about entirely different things here.

When I said, "irb.context.workspace.main" creates a new reader, that  
happened after checking its effect pasted into an irb prompt. There the  
respective ...main evaluator object's irb method has been called, and  
that just creates a new reader.

Where you use "irb.context.workspace.main", that is after doing  
"irb = Irb.new(nil, im)", so the object which the  
"context.workspace.main" method chain has been passed to, is referred to  
a local, of course that behaves differently from the above. You could as  
well say "irb = 5" and complain that "irb.context.workspace.main" blows  
up with a NoMethodError...

However, I made a mistake here as well, as "irb" is really ambigouous...  
eg., within an IRB::Context object it gives you the main object again  
(although there you could probably do just "workspace.main").

So, both of us should be more careful about being unambiguous when  
referring to objects and methods somewhere living in irb's realm.

\* \* \*

What problems do you have with the code posted? What are "lifecycle  
problems" you refer to?

Csaba

> **···**
>
> On 2005-04-12, Martin DeMello \<martindemello@yahoo.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [14 April 2005 16:34 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/19 "2005-04-14T16:34:35Z")

</div>

I was referring to the fact that I created the Irb.new instance within  
start\_in\_fxirb, and called that within a thread, so I didn't really have  
any other logical place to add a singleton method to the object. Ignore  
the rest - it looks like we were talking at cross purposes 🙂 I was jsut  
a bit worried by your comment about creating a new reader 'cause I  
couldn't see where that was happening.

martin

> **···**
>
> Csaba Henk \<csaba@phony\_for\_avoiding\_spam.org\> wrote:
> 
> > \> As far as I can make out, inside IRB.start\_in\_fxirb is the only place I  
> > \> have access to the IRB.conf[:MAIN\_CONTEXT] object after it is  
> > \> initialised to Irb.new, so that I can create the appropriate singleton  
> > \> method.
> > 
> > It might be that IRB.start\_in\_fxirb is the appropriate place to define  
> > the singleton (I'd say so). But what do you mean by "the only place I  
> > have access to ..."? IRB.conf[:MAIN\_CONTEXT] is a global accessor, it  
> > should work everywhere (unless you have somewhere another IRB constant,  
> > which I'm sure is not the case, but even then you could access the  
> > object as such via TOPLEVEL\_BINDING).

---

<div class="post-metadata">

**Author:** ![Csaba\_Henk4](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@Csaba\_Henk4](https://rubytalk.org/u/Csaba_Henk4)\
**Post date:** [21 April 2005 03:24 UTC](https://rubytalk.org/t/ann-fxirb-0-2-0-multiline-edit-and-request-for-help/17544/20 "2005-04-21T03:24:33Z")

</div>

OK, I see.

Csaba

> **···**
>
> On 2005-04-14, Martin DeMello \<martindemello@yahoo.com\> wrote:
> 
> > > It might be that IRB.start\_in\_fxirb is the appropriate place to define  
> > > the singleton (I'd say so). But what do you mean by "the only place I  
> > > have access to ..."? IRB.conf[:MAIN\_CONTEXT] is a global accessor, it  
> > > should work everywhere (unless you have somewhere another IRB constant,  
> > > which I'm sure is not the case, but even then you could access the  
> > > object as such via TOPLEVEL\_BINDING).
> > 
> > I was referring to the fact that I created the Irb.new instance within  
> > start\_in\_fxirb, and called that within a thread, so I didn't really have  
> > any other logical place to add a singleton method to the object. Ignore  
> > the rest - it looks like we were talking at cross purposes 🙂 I was jsut  
> > a bit worried by your comment about creating a new reader 'cause I  
> > couldn't see where that was happening.
