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/

42 questions
16
votes
2 answers

Can I turn off or switch the syntax checker for js2-mode?

I have a default setup of js2-mode. This provides nice syntax highlighting and checking but I am now working on a project with a different set of styles (specifically this new project does not use semicolons). This causes every single line of code…
Startec
  • 1,354
  • 1
  • 13
  • 30
6
votes
1 answer

How to highlight graphql template literals (gql) in js(x) files?

Inside of a jsx file, I want to use a gql template literal to define GraphQL queries. Could I in emacs make that section of the jsx file highlight graphql syntax, instead of just showing it as a plain string? Example: import gql from…
vcr
  • 83
  • 8
6
votes
2 answers

Can't get prettier-js working

Am about to give up on getting this package working have tried the following options: From the prettier docs, installed the package from melpa and added the following to init.el: (require 'prettier-js) (add-hook 'js2-mode-hook…
Bauhaus
  • 161
  • 5
5
votes
1 answer

js2-mode on, still emacs hunts for javascript-mode

I enabled js2-mode in emacs by adding this snippet in .emacs, (add-to-list 'auto-mode-alist '("\\.js$'" . js2-mode)) But still for .js files, emacs tries to load javascript-mode alias js-mode as the major mode. And god knows, how did…
Madhavan
  • 1,957
  • 12
  • 28
4
votes
1 answer

What's the relationship between js-mode and js2-mode?

I saw there is a js-mode bundled in Emacs. I've also seen a js2-mode. However, I have also seen Emacs git log on js-mode refers to js2-mode bug reports. What is the relationship between them?
xuhdev
  • 1,839
  • 13
  • 26
3
votes
2 answers

Refactoring javascript

How can I rename functions project wide? I am using spacemacs and also with tern, and it look like tern can only rename variables.
zer09
  • 185
  • 2
  • 7
3
votes
1 answer

Cannot jump to definition in js2-mode or Tern

I am performing Nodejs development in emacs, but my environment seems incorrect. For example, when I run ac-js2-jump-to-definition, I get "no jump location found" in the minibuffer. Also when I run 'tern-find-definition`, I get "No definition…
modulitos
  • 2,432
  • 1
  • 18
  • 36
2
votes
2 answers

How to show all functions in a javascript file?

How to show all functions in a js file? I am using js2, but any solution will do. Additional info: I am expecting an occur style buffer. This can persist and be edited if necessary. Or searched. This is preferable in my opinion to a helm style…
cammil
  • 509
  • 3
  • 12
2
votes
1 answer

Fixing wrong-type-argument to looking-at in Emacs 25 js-mode on large files

When using js-mode (or js2-mode) on Emacs 25.1 (in Debian 9) to edit some large files, any attempt to insert text after some "random" point in the file fails with an elisp stack trace: Debugger entered--Lisp error: (wrong-type-argument stringp nil) …
Brad Spencer
  • 151
  • 6
2
votes
2 answers

Adding global variable on flycheck

I tried to add this to my eslint global variable "globals": { "document": false, "navigator": false, "window": false, "rndr": false, "shrd": false, "path": true, "$": false // <--- I also added this } but still I am…
zer09
  • 185
  • 2
  • 7
2
votes
2 answers

Autocompletion with tide or tern

Autocompletion doesn't work with tide or Tern, I have to M-x company-complete-common. I would like for it to keep suggesting with a dropdown menu as I type, but I can't manage to. It works just fine with elpy and go-mode. I am using emacs 25.3.1 and…
Pedro Queiroga
  • 131
  • 1
  • 4
2
votes
0 answers

activate prettier-js-mode after every save

I am using prettier-js-mode which is great and here is my configuration: (use-package prettier-js :commands (prettier-js-mode prettier) :init (add-hook 'js2-mode-hook 'prettier-js-mode) :bind (:map js2-mode-map ("M-q" . prettier)) :config …
dagda1
  • 595
  • 1
  • 3
  • 16
2
votes
1 answer

How to set globals for js2-mode?

Js2-mode is showing error when there are not registered globals. I've try this code: (defun js2-hook () ;; setting symbols instead of strings also don't work (dolist (global '("angular" "$" "jQuery" "console" "_" "window" "setTimeout")) …
jcubic
  • 691
  • 1
  • 4
  • 16
2
votes
2 answers

How to display the list of functions in iMenu and collapse/uncollapse functions in angular js file

I use js2-mode with emacs-prelude, imenu displays the list of functions and I can collapse and uncollapse the functions defined in a regular js file like this function testFunction1(){ console.debug("test function"); } function…
tutysara
  • 33
  • 5
2
votes
1 answer

How to set project-specific javscript indentation using js2-mode

I have several Javascript projects, where some projects use 2 spaces for indentation and other projects use 4 spaces for indentation. Is there a project-specific way to set the indentation? I am able to manually resolve this issue for each project…
modulitos
  • 2,432
  • 1
  • 18
  • 36
1
2 3