Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2910
| From | Stu <stu@rubyprogrammer.net> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Ruby for beginners (was: Re: Hello) |
| Date | 2011-04-14 23:01 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <BANLkTik68x3CeTvVaa+7epcZihXMLfijUg@mail.gmail.com> (permalink) |
| References | (2 earlier) <BANLkTi=wnXaEha_SzkCwCCCpsX5NcAC-PA@mail.gmail.com> <587C758D-C14D-4748-BBFC-816CF51BA229@telus.net> <BANLkTik4p4+avWkzAEdeAsi2_1vqqcDG-w@mail.gmail.com> <BANLkTi=8NyWcd8EaRx6=AqnGoXvCOhqTFw@mail.gmail.com> <20110413193121.GF43031@guilt.hydra> |
[Note: parts of this message were removed to make it a legal post.]
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 = <<EOF
def #{name}( *file_to_open)
unless file_to_open.empty?
ed file_to_open.join
else
ed
end
end
EOF
ENV['EDITOR'] = name
instance_eval method_body
"#{name} is now ready to use in irb"
else
ENV['EDITOR'] = 'ed' #Shut up and hack!
puts "setting venerable UNIX line editor ed"
puts "man ed(1) for more information"
puts "#{name} supported out of the box" if editor_exists?( name.to_sym)
puts "There is no need to set it with editor"
end
end
def editor_exists?( editor)
editor_list = (InteractiveEditor::Editors.instance_methods - [:ed])
!( editor_list.grep( /^#{editor}$/).empty?)
end
to use it you simply type:
>> 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 <code@apotheon.net> wrote:
> On Wed, Apr 13, 2011 at 06:08:08PM +0900, Phillip Gawlowski wrote:
> > On Wed, Apr 13, 2011 at 5:23 AM, Stu <stu@rubyprogrammer.net> 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 ]
>
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-12 10:30 -0500
Re: Ruby for beginners (was: Re: Hello) Josh Cheek <josh.cheek@gmail.com> - 2011-04-12 12:32 -0500
Re: Ruby for beginners (was: Re: Hello) andrew mcelroy <sophrinix@gmail.com> - 2011-04-12 12:48 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-12 13:59 -0500
Re: Ruby for beginners (was: Re: Hello) Vincent Manis <vmanis@telus.net> - 2011-04-12 20:30 -0500
Re: Ruby for beginners (was: Re: Hello) Stu <stu@rubyprogrammer.net> - 2011-04-12 22:23 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-13 04:08 -0500
Re: Ruby for beginners (was: Re: Hello) Stu <stu@rubyprogrammer.net> - 2011-04-14 23:01 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-13 04:05 -0500
Re: Ruby for beginners (was: Re: Hello) jake kaiden <jakekaiden@yahoo.com> - 2011-04-13 07:41 -0500
Re: Ruby for beginners (was: Re: Hello) Josh Cheek <josh.cheek@gmail.com> - 2011-04-13 07:59 -0500
Re: Ruby for beginners (was: Re: Hello) Vincent Manis <vmanis@telus.net> - 2011-04-13 09:48 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-13 10:03 -0500
Re: Ruby for beginners (was: Re: Hello) Vincent Manis <vmanis@telus.net> - 2011-04-13 20:35 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-14 09:26 -0500
Re: Ruby for beginners (was: Re: Hello) Jim Maher <jdmaher@jdmaher.com> - 2011-04-14 10:28 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-14 10:42 -0500
Re: Ruby for beginners (was: Re: Hello) Adam Madrigal <ajmxt9@hotmail.com> - 2011-04-14 10:29 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-14 11:45 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-14 14:33 -0500
Re: Ruby for beginners (was: Re: Hello) Vincent Manis <vmanis@telus.net> - 2011-04-14 16:43 -0500
Re: Ruby for beginners (was: Re: Hello) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-14 17:12 -0500
Re: Ruby for beginners (was: Re: Hello) Vincent Manis <vmanis@telus.net> - 2011-04-14 18:03 -0500
Re: Ruby for beginners (was: Re: Hello) Charles Oliver Nutter <headius@headius.com> - 2011-04-14 00:38 -0500
Re: Ruby for beginners (was: Re: Hello) terryowen <terryo.ia@gmail.com> - 2011-04-15 11:45 -0700
Re: Ruby for beginners (was: Re: Hello) jake kaiden <jakekaiden@yahoo.com> - 2011-04-12 15:30 -0500
Ruby for beginners (was: Re: Hello) Jim Maher <jdmaher@jdmaher.com> - 2011-04-13 11:14 -0500
Re: Ruby for beginners (was: Re: Hello) Josh Cheek <josh.cheek@gmail.com> - 2011-04-13 12:27 -0500
Re: Ruby for beginners (was: Re: Hello) jake kaiden <jakekaiden@yahoo.com> - 2011-04-13 20:57 -0500
csiph-web