# Step by step tutorial on using emacs with Ruby

**URL:** <https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485>\
**Category:** Ruby\
**Created:** [November 17, 2005, 4:14pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485 "2005-11-17T16:14:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 17, 2005, 4:14pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/1 "2005-11-17T16:14:42Z")

</div>

I downloaded emacs from  
[http://home.att.ne.jp/alpha/z123/emacs-mac-e.html](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

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 17, 2005, 4:56pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/2 "2005-11-17T16:56:56Z")

</div>

On Fri, 18 Nov 2005, anne001 wrote:

> I downloaded emacs from  
> [http://home.att.ne.jp/alpha/z123/emacs-mac-e.html](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](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

```

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 17, 2005, 6:54pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/3 "2005-11-17T18:54:44Z")

</div>

“anne001” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I downloaded emacs from  
> [http://home.att.ne.jp/alpha/z123/emacs-mac-e.html](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. 😉

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…

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 17, 2005, 7:40pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/4 "2005-11-17T19:40:16Z")

</div>

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:in`require’  
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.

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 18, 2005, 2:23pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/5 "2005-11-18T14:23:54Z")

</div>

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](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/](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

```

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 21, 2005, 2:21am UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/6 "2005-11-21T02:21:26Z")

</div>

On 11/17/05, anne001 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 18, 2005, 2:45pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/7 "2005-11-18T14:45:05Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 18, 2005, 2:02pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/8 "2005-11-18T14:02:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ccd318/32.png) [@anne](https://www.ruby-forum.com/u/anne)\
**Post date:** [November 18, 2005, 3:15pm UTC](https://www.ruby-forum.com/t/step-by-step-tutorial-on-using-emacs-with-ruby/49485/9 "2005-11-18T15:15:18Z")

</div>

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/](http://expect.nist.gov/) just now so  
try [http://mini.net/tcl/expect](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](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

```
