2011-02-28 75 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) 
    ) 
)