出於以下幾個原因,我傾向於配置編輯器以在按下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