不同模式下的不同选项卡缩进设置

时间:2011-09-08 14:16:29

标签: emacs whitespace indentation

我目前在我的保存挂钩中使用whitespace-cleanup。使用indent-tabs-mode,我可以在没有任何标签的情况下保存文件。

一切都很好,我不希望我的文件中有标签。但

Makefile确实需要标签。那是我的问题。如何更改makefile-mode的设置?

我尝试setq indent-tabs-mode(文档说它变成缓冲区本地)或whitespace-style,它不起作用。

3 个答案:

答案 0 :(得分:3)

好的,我的坏。在更改模式之前加载了文件。

以下代码工作正常,只要在打开任何文件之前将其加载到.emacs中(我有自己的项目管理器,它会重新打开最后的文件)。

(defun my-tabs-makefile-hook ()
  (setq indent-tabs-mode t))
(add-hook 'makefile-mode-hook 'my-tabs-makefile-hook)

答案 1 :(得分:2)

我遇到了同样的问题,似乎这是Emacs中的一个错误(截至24.2)。试试这个,使用以下.emacs

(setq-default indent-tabs-mode nil)
(add-hook 'after-save-hook 'whitespace-cleanup)

如果你打开一个文件,保存它,然后打开一个Makefile,你就会遇到你描述的问题。但是如果先打开Makefile,保存它,然后打开另一种类型的文件,你就会遇到相反的问题:8个空格将被标签取代。

问题是indent-tabs-mode是缓冲区本地的,但在whitespace.el中它被设置为一个名为whitespace-indent-tabs-mode的常规变量。因此,看到的第一个值是重要的值。

这是解决其他一些问题的另一种解决方法。将其添加到您的.emacs

(defadvice whitespace-cleanup (around whitespace-cleanup-indent-tab
                                      activate)
  "Fix whitespace-cleanup indent-tabs-mode bug"
  (let ((whitespace-indent-tabs-mode indent-tabs-mode)
        (whitespace-tab-width tab-width))
    ad-do-it))

答案 2 :(得分:0)

我在空白处找到的最佳解决方案是ethan-wspace。它清理你自己弄脏的任何空白,但保留其他空白。

它适用于makefile中的制表符,避免了杂乱的差异问题,其中有很多只是空白变化的差异线

相关问题