Step by step tutorial on using emacs with Ruby

I downloaded emacs from
http://home.att.ne.jp/alpha/z123/emacs-mac-e.html
It said that ruby was installed.

I have spent two hours searching this list and the web, and I cannot
find any tutorial telling beginners what to do. Not in emacs, in emacs
wiki, in ruby sites…

There are a bewildering set of instructions on download this or that –
do I need to with this emacs – and put this code or that code in
…emacs file – do I need to and if so which, do I have to look at the
year the advice is posted!!! –

I have a snipet of ruby that works at the terminal window. I copied it
into emacs. Now what? compile did not do anything.

Here is the snipet

require ‘tk’
root = TkRoot.new
button = TkButton.new(root) {
text “Hello,Anne”
command proc { puts “I said”}
}

button.pack
Tk.mainloop

and here is emacs answer
-- mode: compilation; default-directory: “~/Desktop/” --
Compilation started at Thu Nov 17 10:01:06

make -k ruby
make: Nothing to be done for `ruby’.

Compilation finished at Thu Nov 17 10:01:07

On Fri, 18 Nov 2005, anne001 wrote:

I downloaded emacs from
http://home.att.ne.jp/alpha/z123/emacs-mac-e.html
It said that ruby was installed.

I have spent two hours searching this list and the web, and I cannot
find any tutorial telling beginners what to do. Not in emacs, in emacs
wiki, in ruby sites…

    [...]

and here is emacs answer
-- mode: compilation; default-directory: “~/Desktop/” --
Compilation started at Thu Nov 17 10:01:06

make -k ruby
make: Nothing to be done for `ruby’.

You don’t have a makefile or Makefile to tell it how to build the
the target “ruby”. If your emacs setup calls make -k ruby there’s
something odd there anyway, why would you have a target ruby in your
makefile when ruby is your programming language. Your target should
be make all, possibly, or make <your_script_name> here.

Compilation finished at Thu Nov 17 10:01:07

So what is it I am supposed to do to run this code from emacs?
I read about Mx which I read means
using esc on my mac followed by x
pressing r space offered various completions. I found I could choose
ruby-mode as one of the completion of the esc x command. Is that
helpful? Can I use esc x to run my snipet from emacs?

Ok, let’s reframe the problem: Emacs is an editor with lots of
advanced features. It sounds like you are not fluent in emacs, and
actually, neither am I. So I will do 2 things:

1: Point you at the information I found about emacs which I put here:

http://www.eng.cse.dmu.ac.uk/~hgs/software/#emacs

2: Ask you: If you had a free choice about the editor you could use,
what would it be? We may then be able to find you a port of it for
the Mac or point you at something which behaves in a similar way.

    Hugh

“anne001” [email protected] writes:

I downloaded emacs from
http://home.att.ne.jp/alpha/z123/emacs-mac-e.html
It said that ruby was installed.

I have spent two hours searching this list and the web, and I cannot
find any tutorial telling beginners what to do. Not in emacs, in emacs
wiki, in ruby sites…

For general Emacs usage:
C-h t
C-h i m Emacs

I have a snipet of ruby that works at the terminal window. I copied it
into emacs. Now what? compile did not do anything.

M-x ruby-mode
M-x run-ruby

(possibly, C-u M-x ruby-ruby and give a full path…)
But then I hit some bug in irb, apparently. Hrm. :wink:

Try this:
M-x compile ruby myscript.rb

(Drop the “make” stuff.)

And maybe find some physical Emacs user that will teach you a bit, it
can
be pretty nasty at first, but you don’t want to miss it after…

Thank you

For general Emacs usage:
C-h t
opened a tutorial file in japonese. There is access to tutorial through
the menus. I know the main things, opening a file, finding a word,
macros, opening two windows… basics from ten years ago which have not
changed apparently.

M-x ruby-mode
M-x run-ruby
The first command exists and runs. The second command is not in the
list of commands my install can access.

Try this:
M-x compile ruby myscript.rb
I tried compile from the menu, erased make -k and wrote ruby
myscript.rb

ruby dudruby.rb
/usr/lib/ruby/1.6/tk.rb:7:in require': No such file to load -- tcltklib (LoadError) from /usr/lib/ruby/1.6/tk.rb:7 from dudruby.rb:1:inrequire’
from dudruby.rb:1

Compilation exited abnormally with code 1 at Thu Nov 17 13:26:24

So emacs is not finding tcltklib. That may be a mac issue. I know the
mac has a path,
somehow I need to find this library and add it to the path.

Thank you Christian N. for great progress. Hugh S., a lot of
your links don’t connect
right now. the editor I wanted to use is xcode with rubycocoa, but I
have the same problem, it
does not find tcltklib. Only the terminal ruby finds it.

On Fri, 18 Nov 2005, anne001 wrote:

I tried the following
cd ~/desktop/ruby-*
cd ext
cd cd tcltklib
rm Makefile
and ran
CONFIGURE_ARGS='–with-tcl-include=/usr/local/lib/ruby/1.8/tkextlib/
–with-tcllib=tcllib ruby extconf.rb
but it did not do anything.
Do I need to run make and sudo make install etc?

configure is a shell script that searches your system for utilities.
It then builds the makefile and possibly other files. You can then
run make etc. You could look at this autoconf tutorial to
understand in more detail what is going on.

http://www.galassi.org/mark//mydocs/autoconf_tutorial_toc.html

but that may be excessive to have that much detail.

I could not find a tklib in tkextlib in 1.8

It uses the one on your system. For Tk you need Tcl, (so you may as
well get expect while you are at it.)

One place to find out about those is http://www.tcl.tk/

and I am not sure what the directory, libraries, etc are to tell config
at configuration – if I tried to reinstall Ruby.

It should figure it out: with configure you generally tell it if you
need to. When you have installed the Tcl and Tk (which you may not
need to do if you already have them in fact: see if there is a ‘tclsh’
and a ‘wish’ on your PATH :- use

whereis tclsh; whereis wish;
or
which tclsh; which wish

from a shell.

I think I am on the right track, but don’t know how to proceed

Also you are probably best avoiding 1.8.3 for now, 1.8.4 will come
soon, but 1.8.3 has problems with YAML and with rubygems, so stick
to 1.8.2 for now.

    HTH
    Hugh

On 11/17/05, anne001 [email protected] wrote:

M-x ruby-mode
/usr/lib/ruby/1.6/tk.rb:7:in `require’: No such file to load –

Thank you Christian N. for great progress. Hugh S., a lot of
your links don’t connect
right now. the editor I wanted to use is xcode with rubycocoa, but I
have the same problem, it
does not find tcltklib. Only the terminal ruby finds it.

Which version of OS X are you running? Which ruby are you using?
I suspect you have both 1.6 and 1.8 installed and Xcode and emacs only
know
about 1.6.

When you have installed the Tcl and Tk (which you may not
need to do if you already have them in fact: see if there is a ‘tclsh’
and a ‘wish’ on your PATH

I know my code works from the ruby terminal. so what I need for now is
definitely installed.
whereis tclsh and whereis wish:
/usr/bin/tclsh and /usr/bin/wish

It should figure it out:
ruby at the terminal knows where to look, but emacs does not know where
to look for the library.

(so you may as well get expect while you are at it.
I don’t know what this means.

thank you for your post. It sounds like I need to learn about unix,
configs, path, Strange, so many people seem to use emacs, I thought
it would be easy to get it functional.

When I download ruby 1.8.3, I get a bunch of files. There it is easy to
find the ext directory, and the tcltklib directory. And in it a readme
file which has information on how to configure ruby giving information
about the path.

the end of the text gives an example
If you forgot to give the options when do ‘configure’ on toplevel
directry of Ruby sources, please try something like as the followings.

$ cd ext/tcltklib
$ rm Makefile
$ CONFIGURE_ARGS=’–with-tcl-include=/usr/local/include/tcl8.4/
–with-tcllib=tcl8.4 --with-tklib=tk8.4’ ruby extconf.rb

I tried the following
cd ~/desktop/ruby-*
cd ext
cd cd tcltklib
rm Makefile
and ran
CONFIGURE_ARGS=’–with-tcl-include=/usr/local/lib/ruby/1.8/tkextlib/
–with-tcllib=tcllib ruby extconf.rb
but it did not do anything.
Do I need to run make and sudo make install etc?

I could not find a tklib in tkextlib in 1.8
and I am not sure what the directory, libraries, etc are to tell config
at configuration – if I tried to reinstall Ruby.

I think I am on the right track, but don’t know how to proceed

On Fri, 18 Nov 2005, anne001 wrote:

When you have installed the Tcl and Tk (which you may not
need to do if you already have them in fact: see if there is a ‘tclsh’
and a ‘wish’ on your PATH

I know my code works from the ruby terminal. so what I need for now is
definitely installed.
whereis tclsh and whereis wish:
/usr/bin/tclsh and /usr/bin/wish

I can never remember how to check the versions on those – it’s
stored in a variable rather than an option, but it’s worth finding
out.

It should figure it out:
ruby at the terminal knows where to look, but emacs does not know where
to look for the library.

During compilation invoked from emacs? You need to check that you
are getting the correct shell and environment [variables] when emacs
calls out to the shell to do things. I don’t know enough about
emacs to help with this bit.

(so you may as well get expect while you are at it.
I don’t know what this means.

Expect is a utility for automating applications with a textual
interface. I can’t access http://expect.nist.gov/ just now so
try http://mini.net/tcl/expect for more info instead. The Dejagnu
testing framwork is based on expect.

thank you for your post. It sounds like I need to learn about unix,

Given so much open source is based on it, a good idea. My collected
info is here mainly:

http://www.eng.cse.dmu.ac.uk/~hgs/software/#unix

I’m about half way through fixing the links on that page where I
can.

configs, path, Strange, so many people seem to use emacs, I thought
it would be easy to get it functional.

Yes, it might be worth asking on an emacs list as well.

    Hugh