17

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-jsx-indent-line (after js-jsx-indent-line-after-hack activate) "Workaround sgml-mode and follow airbnb component style." (save-excursion (beginning-of-...


16

TLDR; You have to start the http server (simple-http) and load your HTML files through it. For example, let's say you have a HTML file named hello.html and a JS script file named script.js in /home/user/Documents/javascript folder. hello.html: <!doctype html> <html> <head> <!-- Include skewer.js as a script --> <script ...


12

You can use the built-in sgml-mode for this. M-x sgml-mode - Enable the sgml-mode major mode so that sgml-pretty-print command auto-loads. C-x h - Select the whole buffer. M-x sgml-pretty-print To save space, below is only a part of the formatted text that I get on doing the above on your sample text in the question: <table border="4px" cellpadding="0" ...


11

You can set the variable js-switch-indent-offset to 4.


8

I would absolutely recommend tern. I discovered it halfway through my internship (working in Node.js) last summer, and it worked wonderfully with company-mode and js2-mode. js2-mode by itself is quite powerful. It can handle the usual M-. jumping within a file most of the time, and tern complements it nicely with inter-file/module jumping (esp. in the node ...


8

Instead of running the demo, just perform these minimal steps to ensure that everything is working correctly. Open a new buffer with the name myskewer.js Enable JS2-mode (a dependency of skewer) Enable skewer-mode M-xrun-skewer (a browser opens, go back to myskewer.js) Type alert("hello"); and hit C-xC-e at the end of that line Go back to the browser. You ...


7

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.


7

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.


7

The buffer-local indent-tabs-mode variable controls this (in general, for any mode). Note that javascript-mode is an alias for js-mode, so there isn't a javascript-mode-hook. (defun my-js-mode-hook () "Custom `js-mode' behaviours." (setq indent-tabs-mode nil)) (add-hook 'js-mode-hook 'my-js-mode-hook)


6

If you don't mind installing some npm modules it looks like eslint+flycheck could do the trick like described here.


5

Thanks to @Dmitry's comment above, I was able to resolve this issue by configuring the default plugins for Tern. In the tern file from the repo under bin/tern, I edited the default plugins here: var defaultConfig = { libs: [], loadEagerly: false, plugins: {"commonjs":{}, "node":{}, "requirejs":{}, "node_resolve":{}}, ecmaScript: true, ecmaVersion:...


5

That is because jedi is a Python library that statically analyzes Python code to suggest completion candidates. Installing the jedi.el package enabled its abilities for auto-complete-mode and extended them beyond the suggestion of already used words and predefined ones. If you wish to have the same experience with Javascript, you will either need to find ...


5

On the Emacs master branch (eventually Emacs 27), JSX support is now built into the default JavaScript mode for Emacs, js-mode. (Try it out! You can build from source or e.g. install a snapshot from a PPA.) If the use of JSX is anticipated, then JSX support will be automatically enabled in JavaScript buffers. The default criteria are: file name ends in “...


4

I know nothing about projectile, but if I needed something like what you described, I'd possibly go with something like this: (defun jump-to-test () (interactive) (find-file-other-window (cl-loop with parts = (reverse (split-string (buffer-file-name) "/")) with fname = (file-name-sans-extension (cl-first parts)) for (name . ...


4

This is an issue with the Babel 6 transition to using plugins exclusively. You need to install the es2015 preset plugin: npm install -g babel-preset-es2015 and also require it in the invocation command: #+BEGIN_SRC js :cmd "babel-node --presets es2015" let arr = [1, 2]; let [x, y] = arr; console.log(x); console.log(y); #+END_SRC


4

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.


4

From my experience, you will need just js2-mode for ECMAScript in general, and rjsx-mode (a mode which derives from js2-mode) for jsx editing. These will provide you with some real-time linting like an IDE, and if you need more you can use something like flycheck, and there are plenty of extensions that take advantage of the AST provided by js2-mode. You ...


3

Or you just wait for Emacs 25.1 to come out. It's fixed there.


3

#+INCLUDE: "someFile.html" html should result in an included rendered version of the html file and not just "quote the source file".


3

I had the same issue. Tern was installed in /usr/local/bin, but emacs was not looking for it there. I added this to my init file to add /usr/local/bin to the path. (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin")) (setq exec-path (append exec-path '("/usr/local/bin")))


3

Solution 1 (recommended): A perfect solution for BOTH js-mode and js2-mode: https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-javascript.el Screen shot, Solution 2 (js2-mode only): It's a little bit more complex to set up, but the imenu item will display more context and I GUESS imenu functions extracted this way could be hide/show by js2-...


3

If you're using js2-mode, the js2-indent-switch-body var should be set at true: (setq js2-indent-switch-body t)


3

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', var1, var2); Otherwise, you're going to have to modify the code. (I see no customization option in js.el.) Specifically, you need to do something ...


3

The variable responsible for this is js2-strict-inconsistent-return-warning. Just set it to nil.


3

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-mode-enable-auto-pairing t) (add-hook 'web-mode-hook (lambda () ;; short circuit js mode and just do everything in jsx-mode (if (...


3

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.


3

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 newline-and-indent.) Silly me. Original "workaround": The looking-at(nil) gave a pretty good hint that this was a cc-mode regex left unset by js-mode and js2-mode. ...


3

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 <, >, &, /, SPC and ‘sgml-specials’ keys "electrically" when non-nil. This takes effect when first loading the ‘sgml-mode’ library. As html-mode is derived from sgml-mode, ...


2

It looks like you're expecting js2-minor-mode to handle your indentation? That's not the case. C-hf js2-minor-mode RET js2-minor-mode is an interactive autoloaded Lisp function in `js2-mode.el'. (js2-minor-mode &optional ARG) Minor mode for running js2 as a background linter. This allows you to use a different major mode for JavaScript editing, such ...


2

You can actually do this with a replace-regexp because in your replacement, you can evaluate elisp. Given this code: var stuff = { foo: [1], foo: [2], foo: [3], foo: [4], foo: [5], foo: [6], foo: [7] }; Select all the code in your region then run replace-regexp. For your regexp: you could use this: \([a-z]: +\[\)\([4-9]\|[1-90][0-9]\)\(\]\)...


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