0

I changed my Emacs configuration including indentation settings -now when I open an old C++ file I can write code and it looks like this:

int x(int z){
    return z;
}

However, the old code in this file looks like this:

int x(int z){
        return z;
}

In other words its indentation is doubled. How can I reformat the old code so that it's appropriately indented?

2

In short: C-x h and then TAB

It changes formatting for whole buffer.

Details

  • C-x h - marks whole buffer
  • TAB - indent marked region

So, effectively we mark all, then indent ;-)

  • Could you please edit your post to describe what command C-x h TAB runs, and how it resolves OP's problem? It's for the benefit of future readers who may have the same problem. – Dan Apr 11 '17 at 23:42
  • C-x h marks whole buffer and TAB runs c-indent-line-or-region for me. – Alex Apr 12 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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