How to change the style of whole file in emacs cc mode ?

428 views Asked by At

I am new to emacs and have a C file which is presently in gnu style in cc-mode. I have changed the style to linux by making the necessary changes in the .emacs file.

I want to change the style of whole file (the prewritten code) to the style linux. I am unable to do so.

I have tried reindenting the entire file, but it is not working. (although, the code I add after setting the style does come in linux style)

Here is the code which I added in .emacs file to change the style to linux.

(setq c-default-style "linux"
      c-basic-offset 4)
1

There are 1 answers

2
Steve Vinoski On

Perform these steps:

  1. Go to the top of the buffer via (beginning-of-buffer), typically bound to M-<.
  2. Go to the very bottom of the buffer via (end-of-buffer), typically bound to M->. This sets a mark at the top of the buffer, then moves to the bottom.
  3. Execute the indent-region function, typically bound to C-M-\.

The final step will indent the region, which will be the entire buffer.