Last edit
Summary: Fixed links
Changed:
< Usually this name refers to Karl Landstrom's implementation: http://www.karllandstrom.se/downloads/emacs/javascript.el
< Another obsolete implementation by Peter Kruse: http://hotzenplotz.dyndns-home.com/javascript-mode.el
< The one from XEmacs also works fine in GNU Emacs: http://cvs.xemacs.org/viewcvs.cgi/XEmacs/packages/xemacs-packages/prog-modes/javascript-mode.el
to
> Usually this name refers to Karl Landstrom's implementation: https://web.archive.org/web/20130313070358/http://www.karllandstrom.se/downloads/emacs/javascript.el
> Another obsolete implementation by Peter Kruse: https://web.archive.org/web/20190406114129/http://wal.sh/code/elisp/trunk/javascript-kruse.el
For more general information on working with JavaScript in Emacs, see the JavaScript page.
For a long while there was debate and back-and-forth about JavaScript support in Emacs. There were a number of different options, in various stages of maturity and completion. As of Emacs 23.2, there is a standard major mode for editing javascript: js-mode. It is derived and updated from Espresso-mode.
Espresso-mode itself is a fork of Karl Landstrom’s JavaScript mode (described below), but with additional features and robustness improvements. For the legacy page, see http://www.nongnu.org/espresso. For the current js-mode, just get a current Emacs (23.2 or later). If you have a back-rev of Emacs, see EmacsDevelopmentSources for how to get js-mode.
js-mode includes:
beginning-of-defun
, end-of-defun
, and so on.imenu
support using the aforementioned class definition recognition. In addition to recognizing top-level functions, imenu
will recognize methods.Anything with the name “javascript-mode” or “javascript” is likely deprecated – and decrepit. The following links are kept around for information, but if you are using JavaScript, you want js-mode or Js2Mode.
Usually this name refers to Karl Landstrom’s implementation: https://web.archive.org/web/20130313070358/http://www.karllandstrom.se/downloads/emacs/javascript.el
Another obsolete implementation by Peter Kruse: https://web.archive.org/web/20190406114129/http://wal.sh/code/elisp/trunk/javascript-kruse.el
The Mewde Project contain XEmacs’ javascript mode while adding Mozilla Spider Monkey Project Javascript-Shell support. It works inside Emacs, but only primitively.
The following fix from Sylecn addresses a bug where the metadata block in Greasemonkey scripts confuses the syntax highlighter:
(eval-after-load 'js '(progn (setq js--regexp-literal-fix "[^=][=(,:]\\(?:\\s-\\|\n\\)*\\(/\\)\\(?:\\\\.\\|[^/*\\]\\)\\(?:\\\\.\\|[^/\\]\\)*\\(/\\)") (setq js-font-lock-syntactic-keywords-fix ;; "|" means generic string fence `((,js--regexp-literal-fix (1 "|") (2 "|")))) (setq js-font-lock-syntactic-keywords js-font-lock-syntactic-keywords-fix)))