[英]Emacs xml mode indent with tabs
i desperately try to make my emacs xml (sgml?) mode indent with tabs instead of spaces. 我拼命尝试使用制表符而不是空格来制作我的emacs xml(sgml?)模式缩进。 What i tried so far:
到目前为止我尝试了什么:
(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)))
Nothing works though, indentation will still happen with 2 spaces (emacs23 and emacs24) when editing *.xml files. 没有什么可行,编辑* .xml文件时,仍会在2个空格(emacs23和emacs24)中出现缩进。
Note that i also have 请注意,我也有
(setq indent-tabs-mode nil)
in my .emacs file, but the hook should be called afterwards so this should be overridden. 在我的.emacs文件中,但是之后应该调用钩子,所以应该重写它。
How can i force emacs to indent with tabs in *.xml files? 如何强制emacs缩进* .xml文件中的选项卡? Why are my hooks not working?
为什么我的钩子不起作用?
(c-)tab-always-indent
controls what hitting the TAB key does, not what is inserted. (c-)tab-always-indent
控制击中TAB键的内容,而不是插入的内容。
Setting indent-line-function
to insert-tab
will make you lose the smart indentation of the mode. 将
indent-line-function
设置为insert-tab
将使您失去模式的智能缩进。
If you are using a modern emacs, chances are you are using nxml-mode instead of xml-mode. 如果您使用的是现代emacs,则可能使用的是nxml-mode而不是xml-mode。 In that case
nxml-mode-hook
should be the one where you should do (setq indent-tabs-mode t)
. 在这种情况下,
nxml-mode-hook
应该是你应该做的事情(setq indent-tabs-mode t)
。
If you are using default sgml mode, sgml-mode-hook
should be the one where you should do (setq indent-tabs-mode t)
should be done (in your snippet you are using psgml-mode-hook
) 如果你使用默认的sgml模式,
sgml-mode-hook
应该是你应该做的事情(setq indent-tabs-mode t)
应该完成(在你使用psgml-mode-hook
代码片段中)
(and tab-always-indent and indent-line-function could be leave in their default states) (并且tab-always-indent和indent-line-function可以保持默认状态)
EDIT 编辑
To summarize conversation below: variable nxml-child-indent
should not be less than tab-width
. 总结下面的对话:变量
nxml-child-indent
不应小于tab-width
。
(and since default emacs values for those variables are 2 and 8, imho configuring emacs to indent XML using tabs in emacs is harder than it should be) (并且因为这些变量的默认emacs值是2和8,所以imho配置emacs以使用emacs中的选项卡缩进XML比应该更难)
It took me quite a while to get nxml-mode
to use tabs. 我花了很
nxml-mode
才得到nxml-mode
来使用标签。 I ended up using smart-tabs-mode
, which offers a concise solution. 我最终使用了
smart-tabs-mode
,它提供了一个简洁的解决方案。 For what it's worth, here is the configuration that I finally settled on: 对于它的价值,这里是我最终确定的配置:
;; indentation using smart-tabs-mode
(setq-default tab-width 4)
(smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python 'ruby 'nxml)
;; nxml-mode
(setq
nxml-child-indent 4
nxml-attribute-indent 4
nxml-slash-auto-complete-flag t)
You don't actually need to set nxml-slash-auto-complete-flag
, but it gets you auto end-tag completion, which is really nice. 您实际上不需要设置
nxml-slash-auto-complete-flag
,但它会让您自动完成标记,这非常好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.