Using emacs as your JRubyArt Ide

Jeremy Laviole edited this page May 1, 2018 · 11 revisions

Emacs is cool

Emacs looks like an old editor, but is has loads of very good features. And as it is based on an interpreted language (ELisp) it is quite good for interpreted languages.

Install emacs

  1. Install emacs24.

  2. Install the emacs packages inf-ruby and rvm

  3. Add this to your .emacs

(setq auto-mode-alist (cons '("\\.pde$" . java-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.pde\\w?" . java-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.vert\\w?" . c-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.glsl\\w?" . c-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.frag\\w?" . c-mode) auto-mode-alist))
(add-to-list 'auto-mode-alist
	     '("\\.\\(?:gemspec\\|irbrc\\|gemrc\\|rake\\|rb\\|ru\\|thor\\)\\'" . ruby-mode))
(add-to-list 'auto-mode-alist
	     '("\\(Capfile\\|Gemfile\\(?:\\.[a-zA-Z0-9._-]+\\)?\\|[rR]akefile\\)\\'" . ruby-mode))

;; Get the Packages for emacs24. 

(require 'package)
(add-to-list 'package-archives
  '("melpa" . "") t)
(add-to-list 'package-archives 
    '("marmalade" .


## command to load JRuby 
(defun jruby ()
  (inf-ruby "jruby"))

## F7 is my personnal choice. 
(global-set-key [f7]     'jruby)

## If you use RVM, uncomment this. 
##(require 'rvm)
##(rvm-use-default) ;; use rvm's default ruby for the current Emacs session

A reminder of the commands to install the packages :

  • package-refresh-contents
  • package install all of this one by one: inf-ruby, rvm

Try it !

  1. Launch emacs, open k9_samples/contributed/jwishy.rb
  2. Add this at the beginning of the file :
require 'jruby_art'
require 'jruby_art/app'

Processing::App::SKETCH_PATH = __FILE__

class MyApp < Processing::App

Add this at the end of the file : 

end unless ( != nil)

The sketch is ready.

Start the REPL

  1. Hit [F7] to start Ruby.
  2. you can send buffers to the REPL with [C-c][C-l], or the selected code with [C-c][C-r]
  3. Go to the jwishy.rb buffer and do [C-c][C-l] i.e. (control + c, control + l).
  4. Have fun with the sketch ! You can change @x_wiggle or @y_wiggle and hit [C-c][C-l] to update in real time.
  5. If you have PRY, you can also interact easily with the sketch values...
cd $app   # go in the sketch
@x_wiggle # get the wiggle value
@x_wiggle = 400  # set the value
@y_wiggle = 300

Use with PRY

Edit the file ~/.irbrc and put this in it:

require 'rubygems'
require 'pry'

Edit files with emacs with Pry, put this in ~/.pryrc

Pry.editor = "emacs"