Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to run javascript in emacs?

534 views
Skip to first unread message

Xah

unread,
Jul 9, 2008, 9:10:44 PM7/9/08
to
I want to run Javascript in a console with emacs. Does anyone have
suggestions on what's the solution?

Here's some detail... In perl/python/php, i can just write the code in
a buffer/file and run it with M-!. I would like to have something
similar for javascript. Basically, with the end result that i just
type in a buffer, save, press some button or command in emacs, and see
results. How can i do this?

I haven't much experience in coding javascript other than coding
simple sample scripts, and today i just downloaded Firebug in Firefox
3 but i don't want to have to switch to the browser.

The context is learning and experimenting with the language. I don't
need the DOM attached. Just need to for example write fibonacci or
prime generator and or other pure string manipulation functions with
js.

Since FF has a js engine... is there a way to call the js interpreter
with operating system's command line? If so, that'd solve my problem.
(am not familiar with FF dev)

Thanks.

Xah
http://xahlee.org/


Xah

unread,
Jul 9, 2008, 11:05:47 PM7/9/08
to
answer to my own question: just installed spidermonkey thru MacPorts.
It works great. (Spidermonkey is the js engine written in C)

Xah

Tim X

unread,
Jul 11, 2008, 12:33:38 AM7/11/08
to
Xah <xah...@gmail.com> writes:

Have a look at mozlab. It provides a REPL into firfox where you can
inspect the current document and execute javascript. There is an elisp
interface which will allow you to run the repl within emacs.

There is also a javascript mode, but I don't know how good it is or what
capabilities it has, but I suspect you could have a buffer running
javascript and define keys that will send the contents to the firefox
repl.

Tim

--
tcross (at) rapttech dot com dot au

Arnaud Diederen (aundro)

unread,
Jul 16, 2008, 6:04:55 AM7/16/08
to

Xah,

in-, and out-ing to a SpiderMonkey is a first step, but is widely
insufficient.

I'm doing a rather important part of my work in JavaScript, and
the problem with SpiderMonkey is that, although it proposes the (solid)
implementation of ECMAScript ed. 3 that is embedded in
Mozilla and FireFox, it will _not_ make the host objects (window,
document, ...) available.

In other words, you'll be able to execute core JavaScript code, but not
DHTML, not interact with a browser HTML DOM tree, which is often
necessary.

An alternative to mozlab is Helmut Eller's Emacs JavaScript shell:
http://the.unwashedmeme.com/blog/2005/06/02/javascript-shellserver-for-emacs/
It's not perfect in every possible way, but might still be helpful.
(I've never used mozlab, so I don't know if it's better than the emacs
js shell)

Now, to follow on Tim's advise about the javascript mode, I must say
it's a rather trivial mode; barely more than a patched c-mode.
I suggest you have a look at Steve Yegge's js2-mode:
http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html

Hope that helps,
Arnaud


David Hansen

unread,
Jul 19, 2008, 12:46:15 AM7/19/08
to help-gn...@gnu.org
On Wed, 16 Jul 2008 12:04:55 +0200 Arnaud Diederen wrote:

> I'm doing a rather important part of my work in JavaScript, and
> the problem with SpiderMonkey is that, although it proposes the (solid)
> implementation of ECMAScript ed. 3 that is embedded in
> Mozilla and FireFox, it will _not_ make the host objects (window,
> document, ...) available.

I worked a bit on a little webkit based toy browser. The (far away)
goal is having something similar to Conkeror w/o the huge memory and CPU
requirements.

It's in no way usable as a browser but you can have a REPL (in theory
even w/o a top level window, but the GTK port of webkit seems to assume
it is always realized). E.g.

w = new Webview("http://www.gnu.org/");
repl(w.mainFrame.context);

lets you do whatever you want within the DOMWindow. If there is
interest I can push it on savannah or somewhere else. But note that it
is not even α.

David

0 new messages