无论主要模式如何,如何强制使用空格而不是制表符?
我希望所有制表符都是 4 个空格。我在 .emacs 中有以下内容,
(setq-default indent-tabs-mode nil)
(setq c-basic-indent 4)
(setq tab-width 4)
但这会被我可以使用的一些主要模式主题覆盖。有没有办法通过我的 .emacs 文件强制解决此问题?
I want all tabs to be 4 spaces. I have the following in .emacs
(setq-default indent-tabs-mode nil)
(setq c-basic-indent 4)
(setq tab-width 4)
But this gets overwritten by some of the major mode themes that I can use. Is there a way to force this issue through my .emacs
file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试覆盖任何主要模式覆盖的内容:
请注意,不基于
c-mode
的主要模式不太可能关心c-basic-indent
并且可能会使用自己的、特定于模式的缩进变量。在这种情况下,无法手动配置这些变量。Try this to overwrite whatever any major mode overwrites:
Note though that major modes that aren't based on
c-mode
are not likely to care aboutc-basic-indent
and may potentially use their own, mode-specific indentation variables. In such cases, there's no way around configuring these variables manually.声明默认的 C 缩进样式,而不是声明特定的样式参数。
Declare a default C indentation style, rather than declaring specific style parameters.
我用一个特别丑陋的黑客“解决”了这个问题。我没有尝试弄清楚如何获得正确的主要模式挂钩,而是执行了以下操作:
这严重破坏了一些东西(我关心的是,这些东西是 Python 和 Makefile)。因此,我还执行了以下操作:
我不知道 Thomas 提到的 after-change-major-mode-hook,但如果他的解决方案由于某种原因不适合您,我已经使用这个几年了,没有发生任何事故。
编辑:经过仔细检查,我认为您提出的问题并不完全是我回答的问题。我想取消所有选项卡是获得一致缩进的一种方法。 :)
I "solved" this problem with a particularly ugly hack. Rather than try to figure out how to get the right major mode hooks in place, I just did the following:
This horribly breaks some things (that I care about, those things are Python and Makefiles). Thus, I also did the following:
I wasn't aware of the
after-change-major-mode-hook
mentioned by Thomas, but if his solution doesn't work for you for some reason, I've been using this for a few years now without incident.Edit: Upon closer inspection, I don't think you're asking exactly the question I answered. I guess nuking all the tabs is one way to get consistent indentation. :)