views:

564

answers:

2

For those who haven't used DrScheme, window is split in two parts: one part is a file you're editing, and the other is interactive shell. When I run a file, it is loaded into interactive environment, so I can invoke functions I've defined etc. Interactive environment still has all the features of text editor (syntax highlighting, auto completion, etc...)

So is there an IDE for Ruby that doesn't just execute script I'm making, but loads it into irb instead, with all text editor goodies?

+1  A: 

I haven't worked with DrScheme yet, but Netbeans 6.5 includes a full-featured IRB. Have you given it a try?

Sebastian
I can't believe I haven't noticed it before. On the other hand, JRuby irb, which is basically what I'm asking for, crashes as soon as I start it. Regular irb works, but is just a regular irb.
Slartibartfast
+3  A: 

This exact request (even up to the fact that Dr Scheme motivated it) is what finally pushed me to learn Emacs.

Here's what i did to install it under Windows Vista:

  1. Download Emacs from http://ftp.gnu.org/gnu/windows/emacs/emacs-22.3-bin-i386.zip

  2. Unzip it to the directory of your choice

  3. After unzipping it create an includes directory anywhere you wish and copy there both ruby-mode.el and ruby-inf.el (these come with the ruby distribution under the misc directory and can also be downloaded from Ruby's source

  4. Modify your .emacs to tell it where to find your includes and and to use them

; directory to put various el files into
(add-to-list 'load-path "C:/emacs-22.3/includes")
;(1)modify .emacs to use ruby-mode 
(autoload 'ruby-mode "ruby-mode"
  "Mode for editing ruby source files" t)
(setq auto-mode-alist
      (append '(("\\.rb$" . ruby-mode)) auto-mode-alist))
(setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
                              interpreter-mode-alist))
;(2)set to load inf-ruby and set inf-ruby key definition in ruby-mode. 

(autoload 'run-ruby "inf-ruby"
  "Run an inferior Ruby process")
(autoload 'inf-ruby-keys "inf-ruby"
  "Set local key defs for inf-ruby in ruby-mode")
(add-hook 'ruby-mode-hook
      '(lambda ()
         (inf-ruby-keys)
))

(optional) I also installed mode-compile.el from http://perso.tls.cena.fr/boubaker/distrib/mode-compile.el and made the corresponding edits in .emacs

; Install mode-compile
(autoload 'mode-compile "mode-compile"
   "Compile current buffer based on the major mode" t)
(global-set-key "C-cc" 'mode-compile)
(autoload 'mode-compile-kill "mode-compile"
 "Kill compilation launched by `mode-compile'" t)
(global-set-key "C-ck" 'mode-compile-kill)

With those changes Emacs will automatically identify a .rb file as ruby and do syntax highlighting. Then with the chord \C-c\C-s (Control-c, release and then Control-s) irb will start in the box below your file, and you can use all the keys defined by inf-ruby: (\M is the Meta Key which for Windows means Alt)

  "\C-c\C-b" 'ruby-send-block
  "\C-c\M-b" 'ruby-send-block-and-go
  "\C-c\C-x" 'ruby-send-definition
  "\C-c\M-x" 'ruby-send-definition-and-go
  "\C-c\C-r" 'ruby-send-region
  "\C-c\M-r" 'ruby-send-region-and-go
  "\C-c\C-z" 'switch-to-ruby
  "\C-c\C-l" 'ruby-load-file
  "\C-c\C-s" 'run-ruby

If you did the optional step and installed mode-compile, you can also use \C-cc to send the current file to ruby instead of irb

fjom
You need to edit your mode-compile to put "\C-cc" instead of "C-cc".
aronchick