Questions tagged [js2-mode]

An improved JavaScript mode for GNU Emacs that emulates many desirable features of IDEs.

You can download it here.

Features:

  • Variable (adjustable) indentation
  • Accurate syntax highlighting
  • Highlighting of syntactic errors and many semantic errors
  • Strict-mode warning reporting (such as duplicate var declaration)
  • Smart line-wrapping in comments and strings
  • Typing helpers (e.g. matching quotes/brackets)
  • Code-folding (collapse element as {...})
  • Supports JavaScript 1.5, 1.6 (including E4X), 1.7 and 1.8
  • Customizable colors, or use font-lock defaults
  • Many customization options

Note - this mode is for GNU Emacs, version 22 and higher. It does not support XEmacs.

js2-mode was written by Steve Yegge. You can find more information on js2-mode at the official website: http://code.google.com/p/js2-mode/

22 questions
34
votes
3 answers

How do I set indent to 2 spaces in js2-mode?

I have this at the end of my .emacs: (setq-default indent-tabs-mode nil) (setq tab-stop-list (number-sequence 2 120 2)) It works fine in other modes – whenever I tab, it adds two spaces. But in js2-mode, it adds 4.
Loren
  • 13,903
  • 8
  • 48
  • 79
23
votes
3 answers

How do I get js2-mode to use spaces instead of tabs in Emacs?

I am using js2-mode to edit Javascript in Emacs, but I can't seem to get it to stop using tabs instead of spaces for indentation. My other modes work fine, just having issues w/ js2.
Patrick Ritchie
  • 2,007
  • 1
  • 17
  • 20
20
votes
3 answers

how to disable js2-mode syntax checking globally in spacemacs

Since im using eslint, syntax checking from js-mode is redundant to me. so how to turn it off globally instead of toggling on and off? I configured eslint not to check for semicolons, but js2-mode still checks it. if js2-mode syntax checking cant be…
shangsunset
  • 1,585
  • 4
  • 22
  • 38
14
votes
3 answers

Using Node.js with JS-comint in Emacs

I use Emacs 24.2. I've installed js-comint and js-mode from MELPA, executed run-js, and now in REPL instead of > sign i have this gibberish: ^[[1G> ^[[0K^[[3G The REPL itself in Inferior Javascript mode works just fine, just the > sign is changed.…
Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
13
votes
7 answers

Emacs + js2-mode: disable indenting completely?

I'm using js2-mode for working with javascript in emacs and for the most part it's very useful. However, the indenting methods are terribly frustrating when working with jQuery, closures, and JSON... for instance, code that I wish to be indented…
Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134
5
votes
1 answer

Emacs: is it possible to automatically insert semicolons in js2-mode?

I'm using this superb js2-mode fork, along with autopairs to make Javascript editing awesome in Emacs. However it occurs to me that since js2-mode is a full parser, it should be possible to automatically insert semi-colons whenever I'm in a…
event_jr
  • 17,467
  • 4
  • 47
  • 62
5
votes
2 answers

How to disable auto-indentation on newline in js2-mode?

I'm editing React .jsx files, and I don't want to indent on newline, how to disable it?
Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
4
votes
0 answers

js2 auto complete not working on emacs

I started using Emacs a couple weeks ago. I installed js2-mode on emacs and works like a charm, but now I would like to have autocompletion when working in there. I already installed ac-js2-mode, but when I work in js2-mode I don't see any…
Cabezota
  • 107
  • 9
4
votes
0 answers

Can Emacs js2-mode be forced into not indenting top-level JS when the file is wrapped in a module function?

A lot of JS code I work with contains files that are defined with the following indentation: define("my_module", function() { // top-level code is not indented because the whole file // is wrapped in a giant closure }); Is there a way to force…
3
votes
1 answer

Hotkey to find syntax warnings in Emacs js2-mode?

I've got like 10,000 lines of JS and there's a missing bracket somewhere in there. js2-mode for emacs is supposed to highlight possible syntax errors, but it would still be incredibly time-consuming to look through all 10,000 lines and try to find…
Dylan
  • 949
  • 3
  • 13
  • 23
3
votes
1 answer

Use flycheck for indent settings in js2-mode

I'm on Emacs 25.2 with js2-mode and flycheck/eslint enabled. Currenty pressing tab (or newline) will indent as per js2-mode-js-indent-level. I would like for it to be dynamic to match flycheck/eslint settings Is there a way to do this ?
haknick
  • 1,892
  • 1
  • 20
  • 28
2
votes
1 answer

Flymake quits right ahead after loading with js2-mode

When opening .js files, js2-mode and, subsequently, flymake-js is automatically loaded. But flymake unloads right ahead with the message Toggling flymake-mode off; better pass an explicit argument. However, when enabling it manually, using M-x…
wnrph
  • 3,293
  • 4
  • 26
  • 38
2
votes
2 answers

How to trim trailing whitespace in js2-mode in emacs

Trimming trailing whitespace works fine on all non-JS files. I've got these lines in my .emacs: (add-hook 'before-save-hook 'delete-trailing-whitespace) (add-hook 'before-save-hook 'whitespace-cleanup) I've also used M-x customize-group
kris
  • 23,024
  • 10
  • 70
  • 79
1
vote
2 answers

Javascript Error: missing = in destructuring declaration

I am getting a javascript error "missing = in destructuring declaration" What could be the problem?
Jineesh
  • 11,187
  • 5
  • 24
  • 25
1
vote
0 answers

Special indentation style for Emacs and javascript

Running js2-mode for emacs, I need a way to alter the indentation style to look like this: var test = ["Test", "Asdfasdf" ]; Rather than the default: var test = ["Test", "Asdfasdf" ]; I've tried to modify stuff like…
tanenbring
  • 780
  • 4
  • 14
1
2