不同模式下不同的制表符缩进设置
我目前在保存挂钩中使用 whitespace-cleanup
。使用 indent-tabs-mode
,我可以在没有任何选项卡的情况下保存文件。
一切都很好,我不想在我的文件中出现选项卡。但。
Makefile 确实需要制表符。这是我的问题。如何更改 makefile 模式的设置?
我尝试setq
indent-tabs-mode
(文档说它变成缓冲区本地)或whitespace-style
,它不起作用。
I'm currently using whitespace-cleanup
in my save hook. Using indent-tabs-mode
, I'm able to save files without any tabs.
All is well, I don't want tabs in my files. But.
Makefiles do need tabs. That is my problem. How do I change my settings for makefile-mode?
I tried to setq
either indent-tabs-mode
(the doc says it becomes buffer-local) or whitespace-style
, it does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我的错。在更改模式之前加载文件。
以下代码工作正常,前提是在打开任何文件之前将其加载到 .emacs 中(我有自己的项目管理器,可以重新打开最后一个文件)。
OK, my bad. Files were loaded before changing the mode.
The following code works fine, provided it is loaded in the .emacs before opening any file (I have my own project manager which re-opens last files).
我也遇到了同样的问题,这似乎是 Emacs 中的一个错误(截至 24.2)。使用以下
.emacs
尝试一下:如果您打开一个文件,保存它,然后打开一个 Makefile,您将遇到您所描述的问题。但是,如果您先打开一个 Makefile,保存它,然后打开另一种类型的文件,您将遇到相反的问题:8 个空格将被制表符替换。
问题是
indent-tabs-mode
是缓冲区本地的,但在whitespace.el
中它被设置为一个名为whitespace-indent-tabs- 的常规变量模式
。因此,看到的第一个值才是最重要的。这是另一种解决方法,也可以解决其他一些问题。将其添加到您的
.emacs
中:I've had the same problem, and it seems that this is a bug in Emacs (as of 24.2). Try this, using the following
.emacs
:If you open a file, save it, and then open a Makefile, you'll have the problem you described. But if you open a Makefile first, save it, and then open another type of file, you'll have the opposite problem: 8 spaces will be replaced by tabs.
The problem is that
indent-tabs-mode
is buffer-local, but inwhitespace.el
it is set to a regular variable calledwhitespace-indent-tabs-mode
. Hence, the first value that's seen is the one that counts.Here's another workaround that solves some other problems too. Add this to your
.emacs
:我发现的空白的最佳解决方案是 ethan-wspace。它会清除您自己弄脏的所有空白,但会完好无损地保留其他空白。
它适用于 makefile 中的选项卡,并避免了混乱的 diff 问题,其中有很多 diff 行只是空白更改
The best solution I have found for whitespace is ethan-wspace. It cleans up any whitespace that you made dirty yourself but leaves other whitespace intact.
It works for tabs in makefiles and avoids the messy diff problem where there are lots of diff lines that are just whitespace changes