unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* how to run javascript in emacs?
@ 2008-07-10  1:10 Xah
  2008-07-10  3:05 ` Xah
  2008-07-11  4:33 ` Tim X
  0 siblings, 2 replies; 5+ messages in thread
From: Xah @ 2008-07-10  1:10 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to run javascript in emacs?
  2008-07-10  1:10 how to run javascript in emacs? Xah
@ 2008-07-10  3:05 ` Xah
  2008-07-11  4:33 ` Tim X
  1 sibling, 0 replies; 5+ messages in thread
From: Xah @ 2008-07-10  3:05 UTC (permalink / raw)
  To: help-gnu-emacs

answer to my own question: just installed spidermonkey thru MacPorts.
It works great. (Spidermonkey is the js engine written in C)

 Xah

On Jul 9, 6:10 pm, Xah <xah...@gmail.com> wrote:
> 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/
>
> ☄



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to run javascript in emacs?
  2008-07-10  1:10 how to run javascript in emacs? Xah
  2008-07-10  3:05 ` Xah
@ 2008-07-11  4:33 ` Tim X
  2008-07-16 10:04   ` Arnaud Diederen (aundro)
  1 sibling, 1 reply; 5+ messages in thread
From: Tim X @ 2008-07-11  4:33 UTC (permalink / raw)
  To: help-gnu-emacs

Xah <xahlee@gmail.com> writes:

> 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/
>
> ☄

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to run javascript in emacs?
  2008-07-11  4:33 ` Tim X
@ 2008-07-16 10:04   ` Arnaud Diederen (aundro)
  2008-07-19  4:46     ` David Hansen
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaud Diederen (aundro) @ 2008-07-16 10:04 UTC (permalink / raw)
  To: help-gnu-emacs


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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how to run javascript in emacs?
  2008-07-16 10:04   ` Arnaud Diederen (aundro)
@ 2008-07-19  4:46     ` David Hansen
  0 siblings, 0 replies; 5+ messages in thread
From: David Hansen @ 2008-07-19  4:46 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-07-19  4:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-10  1:10 how to run javascript in emacs? Xah
2008-07-10  3:05 ` Xah
2008-07-11  4:33 ` Tim X
2008-07-16 10:04   ` Arnaud Diederen (aundro)
2008-07-19  4:46     ` David Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).