Monday, February 28, 2011

A Little Elisp to Make Emacs and Racket Play Nicer

I love the power of racket (formerly known as PLT-scheme). And I love the power of emacs. In the past, though, to leverage racket I've used DrRacket. And while DrRacket has some cool features, it's no emacs.

In the past, using Racket within emacs was easier said than done. Racket's module system was quite powerful, but meant that using the standard (load ...) function was a bad idea.

Racket now exports a function call you can use to switch into a module, known as: (enter! ....). In theory, you can now write a tool that has the same advanced behavior with respects to modules that DrRacket has always provided.

And so I present to you a few lines of emacs lisp code which tries to leverage this facility:

(defun racket-enter! ()
  (comint-send-string (scheme-proc)
        (format "(enter! (file \"%s\") #:verbose)\n" buffer-file-name))
  (switch-to-scheme t))
(local-set-key "\C-c\C-v" 'racket-enter!)

Once this code has been evaluated, you're now able to open any .rkt file and hit Control-c + Control-v. Racket will then (enter! ...) that file's context, and you'll essentially be inside that module.

I played around with it tonight and it seems to do what you'd expect.

I'm far from convinced that emacs + this code + the standard scheme mode beats DrRacket. But, it's a start. And one I'm excited to play with further.

Oh, and if you happen to know if someone has a more developed emacs + Racket integration strategy, I'd love to use that instead of rolling my own (though, this certainly has been educational!).


  1. You might like to give Geiser a try:

  2. I was also going to suggest Geiser... Quack is also around but I found Geiser more versatile...

    Unfortunately though, it's still no slime...

  3. Another happy Geiser user. (jao doesn't count; he wrote it :-)

  4. Geiser seems awesome - can't wait to try it out. Thanks for sharing!


  5. Is that how the DrRacket REPL works, enter!?

  6. Grant -

    I think (enter! ...) is more provided to simulate DrRacket's REPL, rather than implementing it.

    But, really, that's just my guess.