bfallik-bamboom
bfallik-bamboom

Reputation: 445

emacs batch indent vs. cc-mode access-label

I'm trying to batch indent source files using emacs. I'm using the command:

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

where emacs-format-file.el contains:

(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 indents the file to my liking with one exception. The "public", "private", and "protected" keywords are all indented an extra space:

 class Foo
 {
-public:
+ public:

I want to align these keywords with the preceding open bracket. Based on this question I thought setting 'access-label' would fix this but it doesn't seem to have any effect.

What am I missing?

Upvotes: 1

Views: 399

Answers (1)

bfallik-bamboom
bfallik-bamboom

Reputation: 445

Turns out that emacs was processing the header file as C instead of C++. The fix was to change the .el file to manually switch to C++ mode:

(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)
)

Upvotes: 1

Related Questions