问题
#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?
回答1:
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.
回答2:
cc-mode
has this customizable via c-macro-names-with-semicolon
variable. See the documentation for more info.
回答3:
Why don't you just end the INIT_MACRO line with a ;?
回答4:
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.
来源:https://stackoverflow.com/questions/6666888/emacs-indenting-after-macro-in-c