简体   繁体   中英

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?

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM