2011-02-28 92 views
24

出于以下几个原因,我倾向于配置编辑器以在按下TAB时插入空格。Emacs:插入标签而不是空格

但最近我发现标签应该保持为制作文件中的选项卡。

如何在每次需要编写make文件时不重新编辑编辑器而插入标签页(\t,而不是" ")?

我用下面编辑: EmacsKategeditVisual Studio编辑器。

回答

8

只要您在正确的位置按下右键,Emacs的Makefile模式将负责在哪里插入制表符和空格。要么,要么我错过了一些问题的细节。

+3

是的,对于emacs,如果您处于makefile-mode(或BSDmakefile-mode)模式,插入tab而不是空格应该是自动的。如果你不知何故需要插入一个标签,当你不能由于搞砸配置使用“C-q标签”。 – 2011-02-28 19:39:59

55

要在Emacs中手动插入选项卡,请使用ctrl-Q TAB。 control-Q会导致下一个键被插入,而不是被解释为可能的命令。

+1

也有效。谢谢。 – pic11 2011-03-16 17:03:44

+3

这是不是被接受的答案? – Nikhil 2014-03-31 08:45:21

+0

谢谢,这一直在困扰着我一段时间。 – Vincent 2015-03-05 13:07:58

0

EmacsWiki上的NoTabs页面的Smart inference of indentation style部分非常有帮助。它向您展示了如何为大多数项目设置空格,但是如果您正在编辑的文件的多行以tab开始而不是以空格开始的行,则切换到制表符。

下面的代码:

(defun infer-indentation-style() 
    ;; if our source file uses tabs, we use tabs, if spaces spaces, and if   
    ;; neither, we use the current indent-tabs-mode        
    (let ((space-count (how-many "^ " (point-min) (point-max))) 
     (tab-count (how-many "^\t" (point-min) (point-max)))) 
    (if (> space-count tab-count) (setq indent-tabs-mode nil)) 
    (if (> tab-count space-count) (setq indent-tabs-mode t)))) 

[我的C型钩,或任何其他方式我想有智能缩进]

(setq indent-tabs-mode nil) 
(infer-indentation-style) 

这可能仍然是一个编辑应始终具有像makefiles这样的选项卡的新文件时出现问题。对于那些,你的模式钩子将它设置为制表符。例如:

(add-hook 'makefile-mode-hook 
    '(lambda() 
    (setq indent-tabs-mode t) 
    ) 
) 
相关问题