出于以下几个原因,我倾向于配置编辑器以在按下TAB时插入空格。Emacs:插入标签而不是空格
但最近我发现标签应该保持为制作文件中的选项卡。
如何在每次需要编写make文件时不重新编辑编辑器而插入标签页(\t
,而不是" "
)?
我用下面编辑: Emacs,Kate,gedit和Visual Studio编辑器。
出于以下几个原因,我倾向于配置编辑器以在按下TAB时插入空格。Emacs:插入标签而不是空格
但最近我发现标签应该保持为制作文件中的选项卡。
如何在每次需要编写make文件时不重新编辑编辑器而插入标签页(\t
,而不是" "
)?
我用下面编辑: Emacs,Kate,gedit和Visual Studio编辑器。
只要您在正确的位置按下右键,Emacs的Makefile模式将负责在哪里插入制表符和空格。要么,要么我错过了一些问题的细节。
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)
)
)
是的,对于emacs,如果您处于makefile-mode(或BSDmakefile-mode)模式,插入tab而不是空格应该是自动的。如果你不知何故需要插入一个标签,当你不能由于搞砸配置使用“C-q标签”。 – 2011-02-28 19:39:59