html(网络模式)的Emacs缩进功能无法正常工作 [英] Emacs indentation for html (web-mode) doesn't work properly

查看:163
本文介绍了html(网络模式)的Emacs缩进功能无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Emacs中使用网络模式来获取语法高亮PHP和HTML的缩进。



如果我在.php文件中有这个代码

 < p为H. 
Lorem ipsum dolor sit amet,consectetur adipiscing elit。
< / p>

然后将光标放在中间行,然后按Tab键,没有任何反应。



我希望它像这样:

 < p> 
Lorem ipsum dolor sit amet,consectetur adipiscing elit。
< / p>

如果我将文本放在一行中的标签中,尝试缩进,它可以工作。 / p>

这个:

 < p> 
< a> Lorem ipsum dolor sit amet,consectetur adipiscing elit。< / a>
< / p>

变成这个,应该

 < p为H. 
< a> Lorem ipsum dolor sit amet,consectetur adipiscing elit。< / a>
< / p>






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

解决方案

尝试将这些设置放在钩子函数中:

 (defun my-web-mode-hook()
Hooks for Web模式
(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)
pre>

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)

解决方案

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)

这篇关于html(网络模式)的Emacs缩进功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆