tags:

views:

59

answers:

1

I happened to be writing something like this:

int main( int nargs, char **args ) {
    int i, j;
    if ( i > 0 && NEAR( i-1, j ).dist == INFINITY )
    {
        NEAR( i-1, j ).dist = 1.0;
        NEAR( i-1, j ).X = i;
        NEAR( i-1, j ).Y = j;
        newWorkPoints.push_back( IPoint( i-1, j ));
    }
    if ( j > 0 && NEAR( i, j-1 ).dist == INFINITY )
    {
        NEAR( i, j-1 ).dist = 1.0;
        NEAR( i, j-1 ).X = i;
        NEAR( i, j-1 ).Y = j;
        newWorkPoints.push_back( IPoint( i, j-1 ));
    }
    if ( i < maxwid && NEAR( i+1, j ).dist == INFINITY )
    {
        NEAR( i+1, j ).dist = 1.0;
        NEAR( i+1, j ).X = i;
        NEAR( i+1, j ).Y = j;
        newWorkPoints.push_back( IPoint( i+1, j ));
    }
    if ( j < maxheight && NEAR( i, j+1 ).dist == INFINITY )
    {
        NEAR( i, j+1 ).dist = 1.0;
        NEAR( i, j+1 ).X = i;
        NEAR( i, j+1 ).Y = j;
        newWorkPoints.push_back( IPoint( i, j+1 ));
    }
}

When I wrote it, emacs (22.2.1 of 2010-03-30, Ubuntu) indented it very badly:

int main( int nargs, char **args ) {
    int i, j;
    if ( i > 0 && NEAR( i-1, j ).dist == INFINITY )
    {
        NEAR( i-1, j ).dist = 1.0;
        NEAR( i-1, j ).X = i;
        NEAR( i-1, j ).Y = j;
        newWorkPoints.push_back( IPoint( i-1, j ));
    }
    if ( j > 0 && NEAR( i, j-1 ).dist == INFINITY )
    {
        NEAR( i, j-1 ).dist = 1.0;
        NEAR( i, j-1 ).X = i;
        NEAR( i, j-1 ).Y = j;
        newWorkPoints.push_back( IPoint( i, j-1 ));
    }
    if ( i < maxwid && NEAR( i+1, j ).dist == INFINITY )
        {
            NEAR( i+1, j ).dist = 1.0;
            NEAR( i+1, j ).X = i;
            NEAR( i+1, j ).Y = j;
            newWorkPoints.push_back( IPoint( i+1, j ));
        }
        if ( j < maxheight && NEAR( i, j+1 ).dist == INFINITY )
            {
                NEAR( i, j+1 ).dist = 1.0;
                NEAR( i, j+1 ).X = i;
                NEAR( i, j+1 ).Y = j;
                newWorkPoints.push_back( IPoint( i, j+1 ));
            }
            }

It's the occurence of the < in the expression that's doing it. This seems like an unlikely bug! Am I doing something wrong?

+1  A: 

Well, it's hard to tell if you're doing something wrong as you didn't really give enough information. What version of emacs are you using? What version of cc-mode are you using? Is the buffer even in java/c++/c-mode?

The cc-mode manual has good documentation on customizing indentation, and often the first place to start is with interactive customization.

Trey Jackson
I did give the version: (22.2.1 of 2010-03-30, Ubuntu).
David Gluss
I thought I'd try 22.3, as suggested above, and that fixed the problem. To be complete, I decided to reload 22.2 and show that the problem came back...but it didn't!!! So the problem is not reproducible, at least not by me. I didn't touch my init files or run with -q. So I guess we're done here; thanks everyone for your good thoughts that clearly have solved my problem.
David Gluss