gpt4 book ai didi

xml - 带制表符的 Emacs xml 模式缩进

转载 作者:数据小太阳 更新时间:2023-10-29 02:17:40 24 4
gpt4 key购买 nike

我拼命尝试使我的 emacs xml(sgml?)模式缩进为制表符而不是空格。到目前为止我尝试了什么:

(defun my-xml-hook ()
(setq c-tab-always-indent t
tab-width 4
indent-tabs-mode t) ; use tabs for indentation
(setq indent-line-function 'insert-tab)
)
(add-hook 'xml-mode-hook 'my-xml-hook)
(defun local-sgml-mode-hook
(setq fill-column 70
indent-tabs-mode t
next-line-add-newlines nil
sgml-indent-data t)
(auto-fill-mode t)
(setq indent-line-function 'insert-tab)
)
(add-hook 'psgml-mode-hook '(lambda () (local-psgml-mode-hook)))

虽然没有任何效果,但在编辑 *.xml 文件时缩进仍然会出现 2 个空格(emacs23 和 emacs24)。

注意我也有

(setq indent-tabs-mode nil)

在我的 .emacs 文件中,但钩子(Hook)应该在之后调用,所以它应该被覆盖。

如何强制 emacs 在 *.xml 文件中缩进制表符?为什么我的 Hook 不起作用?

最佳答案

(c-)tab-always-indent 控制按下 TAB 键的作用,而不是插入的作用。

indent-line-function设置为insert-tab会让你失去模式的智能缩进。

如果您使用的是现代 emacs,您很可能使用的是 nxml-mode 而不是 xml-mode。在那种情况下,nxml-mode-hook 应该是您应该执行的操作 (setq indent-tabs-mode t)

如果您使用默认的 sgml 模式,sgml-mode-hook 应该是您应该做的地方 (setq indent-tabs-mode t) 应该做(在您使用的代码段中 psgml-mode-hook)

(tab-always-indent 和 indent-line-function 可以保持默认状态)

编辑

总结以下对话:变量 nxml-child-indent 不应小于 tab-width

(因为这些变量的默认 emacs 值是 2 和 8,恕我直言,配置 emacs 以在 emacs 中使用制表符缩进 XML 比它应该做的要难)

关于xml - 带制表符的 Emacs xml 模式缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18122400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com