js2-mode: a new JavaScript mode for Emacs — cover art: a single warm Emacs window at evening rendered as a small storybook printer's case, with a typed JavaScript fragment laid in beautifully coloured wooden type and a perfect syntax-tree of fine wire branching above it. 🤓

2008 · Stevey's Blog Rants · Announcement

“This mode includes a recursive-descent parser that I ported from Mozilla Rhino. That means it's always right. It doesn't use heuristics or guesswork; it's exactly the same parser used by JavaScript engines.”
— From js2-mode: a new JavaScript mode for Emacs, March 2008
Read the essay

© 2008 Steve Yegge. Originally published at Stevey's Blog Rants.

AI Notes

One half of a larger plan to make it possible to write Emacs extensions in JavaScript instead of Emacs-Lisp — js2-mode was the editor side, and Ejacs (the runtime) would land later the same year. The technical move that made js2-mode survive was the parser: Steve had ported Mozilla's Rhino recursive-descent JavaScript parser to Emacs Lisp — roughly ten thousand lines of elisp — so syntax highlighting and structure recognition came from a real JavaScript parse tree, not font-lock regex heuristics. "It doesn't use heuristics or guesswork; it's exactly the same parser used by JavaScript engines." The post is candid about the parts that didn't work: a month of incremental-parsing work abandoned in favour of asynchronous full-restart parsing; 1,500 lines of doomed-indent.el thrown out after the cc-engine approach proved intractable, replaced with a "bounce indenter" cycling among likely indentation points (built on Karl Landström's lightweight 200-line approach). Code folding, comment/string filling, syntax-error highlighting, strict-mode warnings, jsdoc highlighting.

One of the most-cited pieces of Steve's engineering output. Steve is the original author of js2-mode.el; mooz/js2-mode is the canonical maintained fork today, and johan/js2-mode-yegge mirrors the original. The larger "write Emacs in JavaScript" plan never fully landed, but the editor side outlived the project that birthed it.

Related listings

  • 2008

    Ejacs: a JavaScript interpreter for Emacs

    The companion project — same year, same parser, same goal. js2-mode is the editor; Ejacs is the interpreter. Both are pieces of the same plan to let Emacs people write extensions in JavaScript instead of Elisp.

  • 2008

    XEmacs is Dead. Long Live XEmacs!

    Same month, same Steve, same Emacs subculture — the eulogy for XEmacs. The two posts together are a snapshot of where the Emacs world stood in spring 2008.

  • 2008

    Emergency Elisp

    Steve's crash course in writing Elisp under duress, from earlier the same year — the prose context for the kind of programmer who would happily port a Rhino parser to ten thousand lines of elisp.