Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 648
fakedrake Avatar asked Dec 07 '22 20:12

fakedrake


1 Answers

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.

like image 154
Simon Avatar answered Dec 26 '22 23:12

Simon