I think this is a bug in emacs indent mode
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?
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.
精彩评论