google / styleguide

Style guides for Google-originated open-source projects
https://google.github.io/styleguide/
Apache License 2.0
37.12k stars 13.29k forks source link

`google-c-style.el` not indenting class properly #240

Open aqing1987 opened 7 years ago

aqing1987 commented 7 years ago

Hi there, I use emacs GNU Emacs 24.5.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.30) in ubuntu 16.04 desktop.

I use the goole-c-style.el for c++ coding, but the public notation indent is not right according to cppguide.html # Class Format #

class MyClass : public OtherClass {
 public:      // Note the 1 space indent!
  MyClass();  // Regular 2 space indent.  
  }
};

My code snippet as below:

// simple derived class
class RatedPlayer : public TableTennisPlayer {
public: // **_NO 1 space indent here_**
  aa();
};

and my init.el content as below:

(setq emacs-load-start-time (current-time))
    (add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))

(let ((file-name-handler-alist nil))
  (require 'init-gui-frames)
  (require 'google-c-style)

  (add-hook 'c-mode-common-hook 'google-set-c-style)
  (add-hook 'c-mode-common-hook 'google-make-newline-indent)
  )

Any help ? Thank you!

wangkuiyi commented 7 years ago

It seems like you didn't make your header files opened in C++ mode. It might be in C mode, where google-c-style.el doesn't work as you expected.

To tell Emacs to open header files in C++ mode, you can add the following lines to your ~.emacs file:

(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(add-hook 'c-mode-common-hook 'google-set-c-style)