Questions tagged [js2-mode]

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

Filter by
Sorted by
Tagged with
1 vote
0 answers
11 views

What is the correct way to make js2-next-error available when using js2-mode as major mode?

I'm using js2-mode. It provides js2-next-error, but apparently only when using js2-minor-mode and not when using js2-mode as a major mode. This is clear from the code in js2-mode.el (in version ...
mhucka's user avatar
  • 163
0 votes
1 answer
35 views

In js2-mode, is there a way to goto the other brace/bracket/paren in the pair?

eg. if I have { foo: "bar", fu: {"baz": bar} } And I have my cursor on the last brace, is there a command that will goto the first brace? Also open to more general packages if there is one ...
Andrew's user avatar
  • 541
1 vote
1 answer
284 views

Why is js2-mode changing my indentation level when I type parenthesis

I'm getting started with some JS code in Spacemacs, and trying to get a good indentation level on my method chaining. The trouble is, once I've got an indentation to the place I want it, something (I'...
Patrick's user avatar
  • 81
1 vote
1 answer
215 views

How to display js2-mode warnings

I am running Emacs 26.1 on Ubuntu 16.4. I am writing Javascript using js2-mode. When the linter underlines a line of code, I want to know what error or warning it has detected. For example, in this ...
Apocalypse Mystic's user avatar
2 votes
2 answers
813 views

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 ...
cammil's user avatar
  • 509
1 vote
0 answers
259 views

Annoying indentation bug with ES6 multiline string using js-mode or js2-mode

I am using js2-mode right now. I am working on a .js file that contain a ES6 multi like string like this: Vue.component("comment", { props: { comment: { type: Object, ...
Ben Boyer's user avatar
  • 111
1 vote
1 answer
258 views

use js2-mode instead of js-mode in org babel source

I want to use js2-mode instead of js-mode inside org-babel sources. Is there a way to define a mode for JavaScript inside those chunks? #+begin_src js console.log(1+1) #+end_src
stlk's user avatar
  • 81
1 vote
1 answer
670 views

ELDoc and company-tern are not working properly in JS2-mode (.js buffer in node) and Javascript, in Emacs

In my Emacs configuration for JavaScript/ JS2-mode, specifically .js buffer in node: (1) company-tern and ELDoc are NOT working properly. For eg. when I type 'console.l', 'log' does not pop up, ...
tom_kp's user avatar
  • 81
1 vote
1 answer
212 views

set js-indent-level from .eslintrc?

when I edit javascript, I'm usually actually editing someone else's code. Is there a way to dynamically set the value of js-indent-level from a .eslintrc file?
Matt's user avatar
  • 43
0 votes
1 answer
193 views

Toggle major mode with a custom key binding

I currently have 2 key bindings for switching between two major modes: (global-set-key (kbd "<f12>") 'js2-jsx-mode) (global-set-key (kbd "<f13>") 'web-mode) How would I reduce that to a ...
pors's user avatar
  • 103
2 votes
1 answer
334 views

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 ...
Brad Spencer's user avatar
3 votes
2 answers
543 views

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's user avatar
  • 185
6 votes
1 answer
1k views

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 ...
vcr's user avatar
  • 83
2 votes
2 answers
216 views

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, "$": ...
zer09's user avatar
  • 185
2 votes
2 answers
3k views

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 ...
Pedro Queiroga's user avatar
4 votes
1 answer
897 views

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's user avatar
  • 1,859
0 votes
1 answer
207 views

How to allow trailing comma in function param list?

I have the following valid javascript with trailing comma in function parameters: const a = (...params) => console.log(params); a( 1, 2, 3, ); But in js2-mode I see the error missing ) ...
Oles Savluk's user avatar
6 votes
2 answers
3k views

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-...
Bauhaus's user avatar
  • 161
2 votes
0 answers
1k views

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 (:...
dagda1's user avatar
  • 605
1 vote
2 answers
451 views

why is add-hook in use-package not erroring for function that does not exist

I have added a (add-hook 'js2-mode-hook 'my-js2-mode-setup) the following hook to a use-package init section: (use-package js2-mode :ensure t :interpreter (("node" . js2-mode)) :mode "\\.\\(js\\...
dagda1's user avatar
  • 605
2 votes
1 answer
396 views

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" "$" "...
jcubic's user avatar
  • 711
0 votes
1 answer
344 views

How to disable warning in js2-mode: function does not always return a value?

Is it possible to disable warning for functions that not always return value in js2-mode?
jcubic's user avatar
  • 711
0 votes
1 answer
2k views

Autocomplete not working for JavaScript

So I can't get Auto-Complete to work for JavaScript. I've tried a variety of solutions but nothing seems to be working. Here is the relevant code snippet: ;; ;;adds js2-mode for javascript ...
iknowhtml's user avatar
0 votes
1 answer
82 views

js2 mode doesn't recognize variable in "for in" statement

When I use a for in statement, js2 mode doesn't recognize the new variable: let foo = {bar: 1}; for(key in foo) { console.log(key); } It prints: Undeclared variable or function 'key'
atevm's user avatar
  • 938
16 votes
2 answers
4k views

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 ...
Startec's user avatar
  • 1,344
1 vote
1 answer
352 views

Adding eldoc support to js2-mode

Since js2-mode does not have eldoc-mode support, I was wondering if I could get some similar functionality to js2-mode with the help of tern-mode. tern-mode has a command tern-get-type which will ...
Chakravarthy Raghunandan's user avatar
1 vote
0 answers
71 views

How to mark / cursor inside of curly braces when opening set of curly braces

I am using js2-mode as well as electric-pair-mode and autocomplete. When I create a function using function () { and press enter the second curly brace is made on the next line but my cursor is ...
Startec's user avatar
  • 1,344
0 votes
1 answer
303 views

Does Flycheck interfere with JS-2 Mode?

I realize that flycheck is a syntax checker that can be used with nearly every language's major mode. My question is how (if at all) it can interact with modes such as (specifically) js2-mode which ...
Startec's user avatar
  • 1,344
2 votes
1 answer
339 views

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 ...
modulitos's user avatar
  • 2,452
1 vote
1 answer
172 views

What is causing my javascript files to auto-format?

If I have a long line in a javascript file such as: let args = [options.loadRaw ? buffer : path.resolve(filePath)].concat(options.commands); At some point when I keep adding to that line, it auto-...
Jorge Israel Peña's user avatar
2 votes
1 answer
462 views

use-package and js2-mode: setting fill-column

I'm using use-package and I want my fill-column to be set to 100 for files edited with js2-mode. I tried to do so in the :config part, like: (use-package js2-mode :config (setq fill-column 100)) ...
marc0s's user avatar
  • 83
1 vote
2 answers
376 views

package listed in `list-packages' but get `Error during download request: Not Found` [closed]

This is the value of my package-archives variable: C-h v package-archives package-archives's value is (("melpa" . "http://melpa.org/packages/") ("gnu" . "http://elpa.gnu.org/...
Marcus Junius Brutus's user avatar
3 votes
1 answer
4k views

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 '...
modulitos's user avatar
  • 2,452
0 votes
1 answer
69 views

Why do my js2-mode hooks work on Mac but not Fedora Linux?

I am getting very inconsistent behavior with js-mode and js2-mode hooks and I am not sure why. I have three "hooks": (add-hook 'js2-mode-hook (lambda () (setq mode-name "Zono-mode"))) (add-hook '...
Startec's user avatar
  • 1,344
0 votes
0 answers
145 views

Need help with a snippet

Can someone help me with this snippet? I found it here # -*- mode: snippet -*- # name: jsdoc comment # key: doc # -- /** * $0 `(save-excursion (let* ((pos-fun (re-search-forward "\\<function\\s-*(...
iLemming's user avatar
  • 1,233
1 vote
0 answers
63 views

js2-mode: How to avoid automatically inserting space after a function call

For example, in js2-mode, when I type the following: console.log( the editor outputs this (assuming the | is my cursor): console.log (|) Why is there a space inserted between the function and the ...
modulitos's user avatar
  • 2,452
1 vote
2 answers
221 views

js-comint mode (node) returning too many undefined responses?

I am using js2-mode and comint-mode to run the Node REPL in emacs. For some reason the prompt is returning a lot of undefined and ...undefined responses, which it wouldn't do normally. for instance, ...
Startec's user avatar
  • 1,344
1 vote
1 answer
787 views

js2-mode: Highlighting and syntax checks only update when the buffer or mode is refreshed

As I'm typing into my buffer in js2-mode, the syntax is not being updated and all my new code is plain white. Additionally, existing text keeps its original color. For example, when I uncomment some ...
modulitos's user avatar
  • 2,452
0 votes
2 answers
2k views

js2-mode with flycheck and jshint

(require 'flycheck) (add-hook 'js2-mode-hook (lambda () (flycheck-mode t))) Used this, to setup flycheck for javascript development. However, i noticed config changes in .jshintrc is not ...
Madhavan's user avatar
  • 1,977
5 votes
1 answer
2k views

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 ...
Madhavan's user avatar
  • 1,977
1 vote
1 answer
792 views

js2-mode customizations not applying

No matter what I do, the customizations I apply to js2-mode are not going into effect. The mode is on and working, but with default settings. I've tried changing the default-tab-width to 2 and ...
cflann's user avatar
  • 113
2 votes
2 answers
2k views

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....
tutysara's user avatar