New emacs js mode

395 views
Skip to first unread message

Thom Blake

unread,
Jun 3, 2011, 1:06:24 PM6/3/11
to nod...@googlegroups.com
Hi folks,

I've put together a new emacs mode for js based on js-mode (formerly
espresso) and js2-mode, the main purpose of which was to support
comma-first style. Check it out at https://github.com/thomblake/js-mode

Mostly indents the way espresso does, except:

* supports comma-first style (or comma-last style)
* supports operator-first style (or operator-last style)
* properly indents comma-last continued var statements
* has all the syntax highlighting, error detection, etc of js2-mode

I know it is compatible with emacs 23.2, but welcome feedback on
compatibility/incompatibility with your version of emacs.

Feel free to file issue reports on github for things like "it indented
like [code block] but I want it to be [code block]".

-Thom Blake

zan

unread,
Jun 3, 2011, 6:45:10 PM6/3/11
to nod...@googlegroups.com
wonderful! thanks!

Mariusz Nowak

unread,
Jun 4, 2011, 5:49:18 AM6/4/11
to nodejs
Thom, Thanks!
I'll definitely check it out.
What's the status for JSON support, do this mode show json files
without errors ?

- Mariusz Nowak

On Jun 3, 7:06 pm, Thom Blake <webmas...@thomblake.com> wrote:
> Hi folks,
>
> I've put together a new emacs mode for js based on js-mode (formerly
> espresso) and js2-mode, the main purpose of which was to support
> comma-first style.  Check it out athttps://github.com/thomblake/js-mode

thomblake

unread,
Jun 17, 2011, 2:13:46 PM6/17/11
to nodejs
Just wanted to note that my emacs js-mode has been made much less
stupid and is now called js3-mode. It is here:

https://github.com/thomblake/js3-mode

-Thom

thomblake

unread,
Jun 17, 2011, 2:16:14 PM6/17/11
to nodejs
Mariusz,

I actually have no idea what you're looking for here. JSON is very
nearly a subset of JS, so it should *appear* the same as JS if you
open it. This mode is designed however for JS files and isn't
necessarily intended to work for anything else.

Mariusz Nowak

unread,
Jun 20, 2011, 5:54:22 AM6/20/11
to nodejs
@thomblake

Following code as stand alone is not right JavaScript code, while it's
proper JSON code:

{ "foo": "bar" }

js2-mode will mark it red as it won't work as JavaScript, a while a go
I prepared a fix for js2-mode to allow syntax highlighting of JSON
files without errors: http://code.google.com/p/js2-mode/issues/detail?id=50#c7

It's good to have proper syntax highlighting when we open package.json
files as well. My question was do your mode supports that ?

Jorge

unread,
Jun 20, 2011, 7:36:45 AM6/20/11
to nod...@googlegroups.com
On 20/06/2011, at 11:54, Mariusz Nowak wrote:

> Following code as stand alone is not right JavaScript code, while it's
> proper JSON code:
>
> { "foo": "bar" }
>
> js2-mode will mark it red as it won't work as JavaScript,

Huh ?
--
Jorge.

thomblake

unread,
Jun 20, 2011, 10:26:30 AM6/20/11
to nodejs
@Mariusz

Ah, I see. A JSON file is usually not a valid JS program, and if it
is then it is by accident. The right answer isn't for your JS mode to
handle .json files as a special case; instead, you should get a JSON
mode like json.el and set it up to handle .json files, since JSON is
really a different animal and is not actually a subset of JS.

That said, I'll add it as an issue in case an obvious path presents
itself.

thomblake

unread,
Jun 20, 2011, 10:35:34 AM6/20/11
to nodejs
Actually, it seems I was misinformed about the existence of a json-
mode for emacs. Will look into it.

thomblake

unread,
Jun 20, 2011, 10:58:38 AM6/20/11
to nodejs
@Mariusz

For the moment, I'm recommending json-mode https://github.com/joshwnj/json-mode

It is based on js-mode and provides syntax highlighting for json
files. Based on some quick testing, it seems to work well.

Mariusz Nowak

unread,
Jun 20, 2011, 11:53:11 AM6/20/11
to nod...@googlegroups.com
Yes, you got it. Good js-mode should imply some support for JSON files as well, and that was my concern.

I haven't looked yet at your js3-mode, but I'll do shortly.

Thanks!

Josh Johnston

unread,
Aug 14, 2011, 11:10:51 PM8/14/11
to nodejs
Hi @Thom, thanks for the plug, and I'm glad you've found json-mode
useful so far. It's my first attempt at scripting emacs so I'd
appreciate any feedback you can give.

Something I also find really useful for editing JSON files is running
them through a beautifier to make them more readable. Especially
handy if you want to edit JSON which has been whitespace-compacted.

I'm doing this in a pretty ad-hoc way, using a command-line script to
format the JSON and piping it via `C-u M-| command RET`. Any
recommendations on how to bundle this functionality more closely with
the plugin?




On Jun 21, 12:58 am, thomblake <webmas...@thomblake.com> wrote:
> @Mariusz
>
> For the moment, I'm recommending json-modehttps://github.com/joshwnj/json-mode
Reply all
Reply to author
Forward
0 new messages