Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I use this emacs style in my emacs?

And how can I format all my existing code using this style?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Quoting the documentation embedded as comments in the linked file:

;; Provides the google C/C++ coding style. You may wish to add
;; `google-set-c-style' to your `c-mode-common-hook' after requiring this
;; file. For example:
;;
;;    (add-hook 'c-mode-common-hook 'google-set-c-style)

What this means is that you should copy the google-c-style.el file somewhere Emasc will find it (in your ~/.emacs.d directory, for example). Then add the following lines in your init file:

(require 'google-c-style)
(add-hook 'c-mode-common-hook 'google-set-c-style)

As to formatting existing code using this style, in any given buffer you can use

  • C-xh : select the entire buffer contents
  • C-M-\ : indent the region

If you have a whole lot of open buffers, you can use ibuffer to automate reindenting all of them:

  • M-xibufferRET : open the buffers list
  • mark all buffers to be indented (for example using m)
  • E(indent-region (point-min) (point-max))RET : reindent all marked buffers
  • S : save all marked buffers if you are satisfied with the result
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.