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

二次信任 提交于 2019-12-07 04:59:15

问题


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)


回答1:


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)



回答2:


Could you add this

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


来源:https://stackoverflow.com/questions/21648629/emacs-indentation-for-html-web-mode-doesnt-work-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!