无法更改 Emacs HTML 标记之间的默认缩进
我对 Emacs 缩进范例感到困惑。
我的 .emacs
文件中有这样的内容:
(setq-default tab-width 4)
如果我在以下情况下按 TAB 键,
<ul>
(caret)
</ul>
它最终会像这样
<ul>
(caret)
</ul>
(HTML 标记之间有 2 个空格缩进。)
它应该最终像这样:
<ul>
(caret)
</ul>
我尝试了一切:
(setq-default tab-width 4)
(setq-default indent-tabs-mode t)
(setq tab-stop-list '(4 8 12 16))
我已将有关缩进的所有可能的 Emacs 设置设置为 4,但 2 个空格缩进仍然存在。
有什么建议吗?
I'm confused about the Emacs indentation paradigm.
I have this in my .emacs
file:
(setq-default tab-width 4)
If I press TAB in the following situation
<ul>
(caret)
</ul>
it end up like this
<ul>
(caret)
</ul>
(with 2 spaces indentation between the HTML tags.)
It should end up like this:
<ul>
(caret)
</ul>
I tried everything:
(setq-default tab-width 4)
(setq-default indent-tabs-mode t)
(setq tab-stop-list '(4 8 12 16))
I've set every possible Emacs setting about indentation to 4 but that 2 space indentation is still there.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置制表符宽度不适用于这种情况,但我理解您的困惑; Emacs 提供了多个与选项卡相关的变量,并且为特定场景确定正确的变量可能会令人困惑。
这篇 EmacsWiki 文章提供了有关设置 HTML 缩进级别的更多详细信息;一般来说,EmacsWiki 是 Emacs 技巧的重要资源。
在这种特定情况下,由于您使用的是 Emacs 的标准 HTML 模式(
html-mode
,由sgml-mode
定义),因此您要设置的变量是sgml-basic-offset
。该变量默认为 2,但您可以将其更改为 4,如下所示:要使此更改仅特定于
html-mode
,您可以使用以下代码:这一切都假设您正在使用 Emacs 22 岁或以上;如果情况并非如此,我链接到的 EmacsWiki 页面包含早期版本 Emacs 的解决方法。
Setting the tab width isn't applicable in this scenario, but I understand your confusion; Emacs provides several tab-related variables and determining the correct one for a particular scenario can be confusing.
This EmacsWiki article provides more details about setting the indentation level for HTML; in general, EmacsWiki is a great resource for Emacs tips.
In this specific case, since you're using Emacs' standard HTML mode (
html-mode
, as defined bysgml-mode
), the variable that you want to set issgml-basic-offset
. That variable defaults to 2, but you can change it to 4 as follows:To make this change specific only to
html-mode
, you can use the following code:This all assumes that you're using Emacs 22 or later; if that's not the case, the EmacsWiki page that I linked to contains a workaround for earlier versions of Emacs.