Search code examples
cemacsmacrosauto-indent

Emacs indenting after macro in C


#define INIT_MACRO create(); some(); enviroment();
...
void function(){
  INIT_MACRO
    extra_indented();
  normal_indented();
}

how do i make emacs deal correctly with the above situation when it is requested to automatically indent?

EDIT the only solution i see is to tell emacs to treat lines containing only caps, underscores and spaces as if they have a semicolon at the end... but how would i do that?


Solution

  • This works:

    #define INIT_MACRO do { create(); some(); enviroment(); } while (0)
    ...
    void function(){
      INIT_MACRO;
      extra_indented();
      normal_indented();
    }
    

    It is usually better to use this trick to avoid problems when you use:

    if (...)
      MACRO();
    else
      ...
    

    and a semicolon on each line is easier to read in my opinion.