generic-x.el (which comes with Emacs)
doesn’t handle indentation well, and fails to correctly
highlight C-style (
/* … */) comments. But
it’s fine for short-term use: since it ships with Emacs,
it’s already there when you need it.
To enable it, add
(require 'generic-x) to
~/.emacs. This will automatically
associate files with
.js extensions with
hasn’t been updated in many years, and relies on
hilit19, an obsolete syntax highlighting library.
Definitely not recommended.
My recommendation: Karl Landström’s
indentation well, and both C- and C++-style (
…) comments. A winner! To use, place
load-path and add the following to your
Joost Diepenmaat has a slight
tweak of Karl’s mode which
a few font-lock fixes for quoted strings and regular
expressions. I haven’t tried it myself.
There’s also ecmascript-mode.el,
which is a derived mode from
doesn’t appear to do anything that
regardless of your personal settings. Thanks to krupan and
Mathias for the link.
MozRepl comes with its own js-mode.el, which appears to be a very
minimal variant on
cc-mode. Thanks to RetroJ for
pointing this out.
In addition to all of the above, there’s the
with XEmacs, which I’m told works in Emacs as well
(and is even bundled with Aquamacs). Thanks to Reed and Xah for
Robustness tip: simple failover
Say you’ve installed
machine B. Ideally, your
file should detect if
should use it, but if it isn’t, it should fall back on
generic-x.el. This is pretty easy stuff.
generic-x as above.
Then check for the presence of
This way, you can copy your
~/.emacs file to some other machine, and
you know it won’t break.