简体   繁体   English

hma(web-mode)的Emacs缩进无法正常工作

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

I'm using web-mode in Emacs to get syntax highlighting and indentation for PHP and HTML. 我在Emacs中使用web模式来获取PHP和HTML的语法高亮和缩进。

If I have this code in a .php file 如果我在.php文件中有此代码

<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. 然后将光标放在中间行并按Tab键然后没有任何反应。

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 我的.emacs文件

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

在此输入图像描述

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)

你能加上这个吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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