开发者

emacs indentation problem with pp-macros

I cannot make emacs indent the following code properly. Somehow it cannot parse the preprocessor macros correctly. Any advise would be appreciated.

#ifdef WIN32
void func1()
#else
    void func1(int parameter)
#endi开发者_JS百科f
{

    if (a > 2 || 
#ifdef WIN32
        (b < 3))
#else
        (b > 3))
#endif
        c = 1;
        else if (b > 2 || 
#ifdef WIN32
                 (a > 4))
#else
            (a < 4))
#endif
            c = 2;

mystatement;
}


The problem is that Emacs will parse both parts of an #if #else construct. To get correct indentation, you have to make sure that you don't have unbalanced parentheses or braces. Concretely, you could rewrite the following:

if (a > 2 ||
#ifdef WIN32
    (b < 3))
#else
    (b > 3))
#endif

Into:

if (a > 2 ||
#ifdef WIN32
    (b < 3)
#else
    (b > 3)
#endif
    )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜