From: Stu Date: 2011-04-15T13:01:08+09:00 Subject: Re: Ruby for beginners (was: Re: Hello) --0016e68ee14a473d7a04a0ed17f0 Content-Type: text/plain; charset=ISO-8859-1 yup! glad my post caught someones eye =) you can go a step further and put this in irbrc: add this to your irbrc def editor( *name) name = name.first unless editor_exists?( name.to_sym) || name == 'ed' method_body = <> editor 'ed' or >> editor 'xedit' then the xedit command will be available to you. or put your favorite editor inside irbrc to be there when you need it. This is one of my first experiment into metaprogramming. I'm sure there are better ways to accomplish the same thing =) Simple way to extend interactive_editor. ~Stu On Wed, Apr 13, 2011 at 2:44 PM, Chad Perrin wrote: > On Wed, Apr 13, 2011 at 06:08:08PM +0900, Phillip Gawlowski wrote: > > On Wed, Apr 13, 2011 at 5:23 AM, Stu wrote: > > > For what it's worth I have been using interactive_editor gem in irb for > a > > > bit now. It allows me to open nvi or vim within irb and also supports > other > > > cli editors( emacs, pico/nano, and even ed for those still <3 the > original > > > unix line editor) > > > > CLI editors are great -- for advanced users. > > > > But the vast majority of people are used to WIMP interfaces, and that's > > who should be targeted. vim and EMACS are nice editors, but they > > overwhelm non-technically-trained people far too soon. > > This is not a problem. Once you have your .irbrc file set up, start irb > and try this: > > irb(main):001:0> ENV['EDITOR'] = 'xedit' > => "xedit" > irb(main):002:0> ed > > I use xedit here because it's likely to be just about anywhere people are > using the X Window System. Replace it with gvim, scite, or gedit if you > like. You can also set your EDITOR environment variable in your standard > shell environment (of course), or add the editor setting line above to > your .irbrc file if you like, so that setting up interactive_editor > config in .irbrc looks like this: > > require 'rubygems' > require 'interactive_editor' > ENV['EDITOR'] = 'xedit' > > Then . . . you just enter "ed" at the irb prompt and it automatically > opens that editor, even if it's a GUI editor. Some editors may benefit > from special command line options. > > > > > > (How do you generate a random string? Sit down a new student in front > > of a vim session.) > > How do you generate the complete works of Shakespeare within your > lifetime? Teach your monkeys how to use Vim. (It's not as hard as it > seems, once you get past the initial confusion over modal editing). > > Anyway, interactive_editor supports nano "natively" (without the > environment variable trick), which is *really* easy for beginners to > understand. They'll just have to learn to use arrow keys instead of the > mouse. > > -- > Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] > --0016e68ee14a473d7a04a0ed17f0--