Emacs indentation for html (web-mode) doesn't work properly

emacs, emacs24, html, indentation

Solution

try put these setting in a hook function:

(defun my-web-mode-hook ()
  "Hooks for 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-indent-style 4)
)
(add-hook 'web-mode-hook  'my-web-mode-hook)

Problem

I'm using web-mode in Emacs to get syntax highlighting and indentation for PHP and HTML. If I have this code in a .php file ``` <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p> ``` And then put the cursor on the middle line and press tab then nothing happens. I want it to look like this: ``` <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p> ``` If I put the text in a tag on a single line and try to indent, it works. This: ``` <p> <a>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a> </p> ``` turns into this, which it should ``` <p> <a>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a> </p> ``` My .emacs file ``` (require 'web-mode) (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.jsp\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . 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-indent-style 4) ```

Original source