开发者

emacs indentation problem with pp-macros

开发者 https://www.devze.com 2023-02-18 13:33 出处:网络
I cannot make emacs indent the following code properly. Somehow it cannot parse the preprocessor macros correctly. Any advise would be appreciated.

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

精彩评论

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