Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run ruby from emacs buffer

Tags:

emacs

ruby

How can I run a ruby piece of code from a buffer, without actually saving the buffer in a file? A scenario would be to a) switch to the scratch buffer b) M-x ruby-mode c) type ruby code d) "compile" the buffer and print results in another buffer. I don't want to save the buffer contents in a file and then "compile" that file

UPDATE 1-9-2011 Which are the latest versions of ruby-mode and inf-ruby and where can I get them? I use the ubuntu natty version of ruby mode and the elpa version of inf-ruby of emacs 23.2. On a clean emacs config, the following config (see underneath) fail with:

can't convert nil into String 
from (irb):1:in `eval' 
from (irb):1". 

Configuration is just the following, no other configuration directives in emacs.d:

(require 'ruby-mode)
(load-file "Configs/.emacs.d/elpa/inf-ruby-2.1/inf-ruby.el")

(autoload 'inf-ruby "inf-ruby" "Run an inferior Ruby pathrocess" t)
(autoload 'inf-ruby-keys "inf-ruby" "" t)
(eval-after-load 'ruby-mode
  '(add-hook 'ruby-mode-hook 'inf-ruby-keys))
like image 595
Vassilis Avatar asked Apr 21 '11 09:04

Vassilis


2 Answers

You can do this with inf-ruby.el.

With inf-ruby installed, M-x inf-ruby starts a new ruby interpreter in the background, to which you can send code using the ruby-send-* commands, such as ruby-send-region (bound by default to C-c C-r). To send the whole buffer, select all with C-x h then hit C-c C-r.

Update, 2011-09-02: The latest version of inf-ruby.el (2.1.1, available in ELPA) is that maintained by 'nonsequitur' on github, and snapshot packages are available in Melpa.

like image 188
sanityinc Avatar answered Nov 15 '22 08:11

sanityinc


A few options for you to try

1. Rinari from Github

It claims to be

aimed towards making Emacs into a top-notch Ruby and Rails development environment


2. ruby-compilation.el is what you need.

There's a thread on that here which I have used and found helpful.

Chris

like image 22
Chris McCauley Avatar answered Nov 15 '22 08:11

Chris McCauley