2012-12-05 61 views
1

我試圖使用emacs批量縮進源文件。我使用的命令:emacs批量縮進與cc模式訪問標籤

$ emacs -batch Source.h -l emacs-format-file.el -f emacs-format-function 

其中的emacs-格式file.el包含:

(defun emacs-format-function() 
(c-set-style "gnu") 
(setq c-basic-offset 4) 
(c-set-offset 'access-label nil) 
(c-set-offset 'substatement-open 0) 
(indent-region (point-min) (point-max) nil) 
(untabify (point-min) (point-max)) 
(save-buffer) 
) 

Emacs的縮進文件,我喜歡有一個例外。 「公」,「私」和「保護」的關鍵字都縮進一個額外的空間:

class Foo 
{ 
-public: 
+ public: 

我想與前面的開放式支架對準這些關鍵字。基於this question我認爲設置'訪問標籤'會解決這個問題,但它似乎沒有任何影響。

我錯過了什麼?

回答

1

原來,emacs正在將頭文件處理爲C而不是C++。修復方法是將.el文件更改爲手動切換到C++模式:

(defun c++-indent-region() 
    (c++-mode) 
    (c-set-style "gnu") 
    (setq c-basic-offset 4) 
    (indent-region (point-min) (point-max) nil) 
    (untabify (point-min) (point-max)) 
    (save-buffer) 
)