js-comint.el

Introduction

js-comint.el is a comint mode for emacs which allows you to run a compatible javascript repl such as Spidermonkey or Rhino inside of emacs. At first blush this may seem a little useless, but when paired with Steve Yegge's js2-mode it becomes a useful way of testing non-html-centric javascript code while editing it.

For example, put js-comint.el in your load-path, and then add the following lines to your .emacs:

(require 'js-comint) (setq inferior-js-program-command "/usr/bin/java org.mozilla.javascript.tools.shell.Main") (add-hook 'js2-mode-hook '(lambda () (local-set-key "\C-x\C-e" 'js-send-last-sexp) (local-set-key "\C-\M-x" 'js-send-last-sexp-and-go) (local-set-key "\C-cb" 'js-send-buffer) (local-set-key "\C-c\C-b" 'js-send-buffer-and-go) (local-set-key "\C-cl" 'js-load-file-and-go) ))

You can then try out any piece of javascript code in a javascript interpreter by simply typing C-x C-e at the end of the sexp. js-comint will use js2-mode to find the last sexp, run Rhino , and load the sexp it just found into the interpreter. This, it turns out, is extremely useful, particularly when you're writing non-domish, algorithmic javascript.