06.02.05
Javascript ShellServer for Emacs
UPDATE: Any new development is at: https://trac.acceleration.net/JsShellServer/wiki. This page may be interesting for a what is it / history perspective, but isn’t updated.
We’ve been using the Javascript Shell a lot, and more recently been modifying it a bit.
It is great for doing the experimental development, but when it comes time to wrap up a bunch of functions and commands into a .js file for inclusion on a webpage or a Greasemonkey script it doesn’t work all that well.
What I really wanted was the ability to be editing a javascript file in Emacs, which has a decent javascript-mode, but have the same kind of interactivity as you do with the Shell or when developing in Emacs with Python or SLIME.
Emacs slave does just that. Helmut Eller did the dirty work of digging through XPCom references and such to be able to host a server inside of Firefox, and some nice elisp (inspired by SLIME I believe) for interacting with it.
Helmut Eller decided Javascript wasn’t for him and went back to hacking in Lisp. I’ve made a few modifications/improvements so that it better suits my needs and hereby present it to everyone else so that they can continue to take advantage of this fine bit of code.
- It’s now embedded inside the Javascript Shell with a button at the top to start the server.
- All evaluation is done within whatever context the shell is in. This means that you can modify the DOM of webpage you are looking at interactively from Emacs.
- The debugger is turned off. Partly because one of the features (the debugger service flags) will crash Firefox when you try to read them. The other reason is that when running Tabbrowser Extensions, Greasemonkey, and all the others I get a lot of Javascript errors and don’t really want to go into debugging mode for each one of them. If you are interested look into set_debugger_hooks().
- I rewrote some of how the Shell does the evaluation so that it will return a value instead of doing something that resembles CPS with the javascript: url that went to print directly. There was a comment about needing that for browser compatibility reasons so I’m guessing this version won’t work outside of Mozilla now. Oh no, my extension that uses Mozilla XPCom objects won’t work in IE!
Setup
You need to install my modified version of Extension Developer’s Extension. Given that Ted and Jesse seem to be going in a different direction with the Shell than I am. I should probably go ahead and split this out into seperate extension. I just haven’t done it yet (and secretly hope this might become part of the ‘official’ version of EDE).
You need to also get js-mode.el which I put in XEmacs\xemacs-packages\lisp\prog-modes. You should also add the following to the Emacs init file.
;;Sweet Sweet javascript mode (add-hook 'javascript-mode-hook 'js-mode) (autoload 'js-mode "js-mode" nil t)
Use
Once you have restarted Firefox after installing the extension open the Shell, there should be a new button at the top “Start ShellServer”. Click that. From Emacs, open a Javascript file and hit M-x js-connect RET RET. You’re now connected. Try to evaluate the current function definition hit C-M-x. C-c C-r for current region; C-c C-e for current line. To see the others you might want to just go look at js-mode.el
I haven’t had any problems with it yet, but I seem to have repeated Helmut’s trick of getting it going, then setting it aside to play with Lisp some more. If you see an *ahem* ‘Opportunity for enhancement’ or if you do something cool with it let me know.
“I really want someone to make Javascript a ‘real’ language. Like with libraries and package-management and all the other things that make a language good.” -Russ
Chris Balz said,
December 11, 2006 at 5:10 pm
Any plans to update this for Firefox 2.0, or any tips on how to get Firefox to accept the connectin request from Emacs (4007)?
Leo said,
March 7, 2007 at 5:30 am
I would like some tips about javascripts modes for Emacs. Which of the available javascript modes for Emacs do you find best for you and why?
Hans said,
November 21, 2007 at 2:57 am
Hi,
is there a new version of the Firefox extension available? The old link does not work, and as others have noted, it would not be accepted by Firefox 2.0 anyway.
Thanks,
Hans