Calaf
Calaf

Reputation: 10817

How can I indent inline Javascript in web-mode?

I'm typing away a little html/js in Emacs using web-mode.el

<html>
    <body>
        <script>
         var i = 0;
        </script>
    </body>
</html>

and I find that the line after <script> is indented by just 1 space.

My .emacs contains:

(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))

(setq web-mode-markup-indent-offset 4)
(setq web-mode-css-indent-offset 4)
(setq web-mode-code-indent-offset 4)
(setq web-mode-attr-indent-offset 4)
(setq web-mode-attr-value-indent-offset 4)
(setq web-mode-indentless-elements 4)
(setq web-mode-markup-indent-offset 4)
(setq web-mode-sql-indent-offset 4)
  1. Which variable did I miss?
  2. How could I have found the answer myself?

Upvotes: 3

Views: 1885

Answers (1)

Scott Weldon
Scott Weldon

Reputation: 10217

The variable you are looking for is web-mode-script-padding:

(setq web-mode-script-padding 4)

If you want to do the same for <style> tags, you can use web-mode-style-padding:

(setq web-mode-style-padding 4)

Finally, if you want to do the same for inline server-side code, such as PHP, you can use web-mode-block-padding:

(setq web-mode-block-padding 4)

This information can be found at Web Mode's homepage, under the Customization section. (To be fair, that page doesn't contain an example of what this code does, so it would be easy to skip over it.)

Upvotes: 6

Related Questions