Skip to main content
19 votes
Accepted

How to edit jsx (react) files in emacs?

Solution 1: Step 1, Use https://github.com/felipeochoa/rjsx-mode Step 2, Install Emacs 25+, see https://github.com/mooz/js2-mode/issues/291 Step 3, Patch rjsx-mode with below code (defadvice js-...
chen bin's user avatar
  • 4,877
18 votes

How to edit jsx (react) files in emacs?

In Emacs release 27 and later, JSX support is built into the default JavaScript mode for Emacs, js-mode. If the use of JSX is anticipated, then JSX support will be automatically enabled in JavaScript ...
Jackson Ray Hamilton's user avatar
13 votes
Accepted

How to indent 4 spaces for case in switch in javascript mode

You can set the variable js-switch-indent-offset to 4.
jrm's user avatar
  • 422
9 votes
Accepted

How can I make emacs support javascript ES6 template string literals?

You need to add backticks as a string delimiter to the js-mode syntax table like this: (modify-syntax-entry ?` "\"" js-mode-syntax-table) More information here.
dshepherd's user avatar
  • 1,281
7 votes

How can I make emacs support javascript ES6 template string literals?

For the record, ES6 template string literals are supported out-of-the-box in js2-mode, complete with font-locking for the interpolated variables as well.
PythonNut's user avatar
  • 10.4k
6 votes

smartparens with strict mode in javascript

Use quoted-insert (C-q) to get around this. E.g. C-q < inserts <. Or, create a key binding to toggle smartparens-strict-mode off and on. This is a waste of keys IMO, but up to you.
Tianxiang Xiong's user avatar
4 votes
Accepted

eglot - javascript

In order to use lsp for javascript you have to install its corresponding lsp-server e.g. javascript-typescript-langserver. If you have node and npm already installed you can just install the package ...
caisah's user avatar
  • 4,096
4 votes
Accepted

customize js2-mode switch indentation

js2-mode derives from js-mode. So you need set up js-mode in this case. (setq js-switch-indent-offset 2) is enough.
chen bin's user avatar
  • 4,877
4 votes

Evaluate JavaScript source block in org-mode

For future passengers, :results value (the default option) requires an explicit return statement to display its value. On the other hand, :results output displays everything from the standard output. ...
Firmin Martin's user avatar
3 votes
Accepted

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

The variable responsible for this is js2-strict-inconsistent-return-warning. Just set it to nil.
caisah's user avatar
  • 4,096
3 votes

How to edit jsx (react) files in emacs?

I use web-mode with the following configuration: (require 'web-mode) (add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode)) ;; (setq web-...
amirouche's user avatar
  • 131
3 votes

Stop javascript-mode from lining up function parameters after newline

I found that Colin's answer fixed some instances of strange JS indentation, but not all of them. I've tweaked his code further to get indentation behavior that doesn't produce errors when linting (...
Matt Superdock's user avatar
3 votes

Stop javascript-mode from lining up function parameters after newline

The code that handles this is the function js--proper-indentation, based on analysis from syntax-ppss. Easiest solution (if you can tolerate it) is to write your code like console.log( 'Example',...
Colin Fraizer's user avatar
3 votes

Changing how argument lists are indented in JavaScript

Support for this was recently added in the Emacs development tree, in response to the bug#27503 feature request, which in turn was inspired by a duplicate of this question. The user option which ...
Basil's user avatar
  • 12.5k
3 votes

How to indent 4 spaces for case in switch in javascript mode

If you're using js2-mode, the js2-indent-switch-body var should be set at true: (setq js2-indent-switch-body t)
hs0ucy's user avatar
  • 31
3 votes

How can I make emacs support javascript ES6 template string literals?

Or you just wait for Emacs 25.1 to come out. It's fixed there.
Dmitry's user avatar
  • 3,803
3 votes
Accepted

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

In addition to what @wasamasa said, js2-mode derives from js-mode and shares its indentation engine. Thus, fixing an indentation bug in js-mode fixes it in js2-mode as well.
Dmitry's user avatar
  • 3,803
3 votes
Accepted

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

It turned out that my personal config (and those of the people I tested this with) manually bound C-m to c-context-line-break in js-mode. So the right answer is to not do this (and leave it as ...
Brad Spencer's user avatar
3 votes

Javascript ES6, React, and EMACS

I suggest you install Indium (https://indium.readthedocs.io/) to get a stepping debugger, REPL and object inspector. Tern, company-tern, and js2-mode, js2-refactor, xref-js2, eslintd-fix, gulp-task-...
Damien Cassou's user avatar
3 votes
Accepted

How to prevent Emacs from converting JavaScript symbols to HTML code?

This is because you've configured: (setq sgml-quick-keys 'indent) C-hv sgml-quick-keys tells us: sgml-quick-keys is a variable defined in ‘sgml-mode.el’. Documentation: Use <, >, &, /, ...
phils's user avatar
  • 51.7k
3 votes

Emacs acting strangely with indentation

With web-mode, make sure your treating your code as React, not JavaScript. Using your init file, and saving your example code to a file with a .js extension, I get the behavior you describe. Saving ...
nega's user avatar
  • 3,276
2 votes

Embbed html/javascript in org-mode html export

In my current org version 9.0.10, the right command is #+INCLUDE: "someFile.html" export html with the word export.
boclodoa's user avatar
  • 141
2 votes

How prettify (newlines and indentation) an optimized HTML/JS file?

The default HTML mode also works. C-x h - Select the whole buffer M-x indent-region (aka C-M-\)
rleir's user avatar
  • 121
2 votes

How to use skewer-mode?

In case port 8080 is already in use: you can configure skewer/simple-httpd to use another port by customizing the httpd-port variable. (M-x customize-variable<ret>httpd-port)
serv-inc's user avatar
  • 838
2 votes

Unable to Set Javascript Indent on Spacemacs

Turns out I needed js-indent-level because I was in js-mode. Still unsure how I ended up in js-mode and not js2-mode.
Adam Thompson's user avatar
2 votes
Accepted

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

It warns you that the key variable is undeclared, and using it like this, you leak it into the global namespace. Try this is your browser console: > let foo = {bar: 1}; > for(key in foo) {} &...
Dmitry's user avatar
  • 3,803
2 votes
Accepted

How to get two space indentation for JS/JSX?

While in web mode, check the variables you've set by using M-: web-mode-code-indent-offset. Is it 2 or 4? Your config is: (use-package web-mode :ensure t :config '(setq web-mode-code-indent-...
amitp's user avatar
  • 2,541
2 votes
Accepted

How to enable type-check rules with flycheck-tslint

Instead, it complains about not being able to resolve any packages […] and since the path does not match the buffer path all thos results are displayed at the minibuffer instead of actaully ...
Clément's user avatar
  • 3,995
2 votes
Accepted

Web-mode uses 1 space indent instead of 2

Try (setq web-mode-script-padding 2). You should also call my-web-mode-hook only once, after you first load web-mode and not every time the mode is activated: (with-eval-after-load 'web-mode (my-...
caisah's user avatar
  • 4,096

Only top scored, non community-wiki answers of a minimum length are eligible