I have this config in my init.el:

(setq-default indent-tabs-mode nil)
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(defun my-web-mode-hook ()
  "Hooks for Web mode."
  (setq web-mode-markup-indent-offset 2)
  (setq web-mode-css-indent-offset 2)
  (setq web-mode-code-indent-offset 4)
  (setq web-mode-enable-auto-pairing t)
  (setq web-mode-enable-auto-closing t)
  (setq web-mode-enable-current-element-highlight t)
  (setq web-mode-enable-current-column-highlight t)
(add-hook 'web-mode-hook  'my-web-mode-hook)

And when I have script tag I only have javascript code indented by 1 space instead of 2. Is there a way to fix that?


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.