4
#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?

4

4 回答 4

10

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.

于 2011-07-12T15:40:04.100 回答
4

cc-mode has this customizable via c-macro-names-with-semicolon variable. See the documentation for more info.

于 2013-05-13T05:41:52.410 回答
1

Why don't you just end the INIT_MACRO line with a ;?

于 2011-07-12T16:50:24.997 回答
0

Using a macro as function wrapper without (); at the end when you call it and without surrounding the define with do { and } while(0) is not done anyway.. makes the code ugly, hard to maintain and it's not supported by one C coding standard... with other words it's called bleeding eye code. So it is not possible with the default settings.

You would need to make your own major / minor mode. To support this new type of syntax... Or you could have a look at your current cc-mode.el.

于 2011-07-12T17:22:15.790 回答