tags:

views:

309

answers:

1

I'm having no luck getting Emacs (cc-mode) to indent multiline template arguments. Here's an example line:

typedef ::boost::zip_iterator< ::boost::tuple<
vector<int>::const_iterator, vector<float>::const_iterator > >;

I'd like the second line to be indented, as like in a function. It is indented, until I enter the second-to-last >, at which point the second line up moves to the left to align with the typedef.

When I start typing the second line, the syntactic analysis is ((statement-cont 52)), until the second-to-last >, at which point it becomes ((defun-block-intro 46)). Deleting the character doesn't return to the old syntactic analysis.

I expected to have template-args-cont as the syntactic analysis.

I'm using the emacs 22.2 (ubuntu intrepid) and cc-mode version 5.31.5 that came with it.

+1  A: 

You should just need to set template-args-cont to some useful value. To experiment with it, put your cursor on the second line and enter C-cC-o for c-set-offset. Insert a convenient value. With 4, I get:

typedef ::boost::zip_iterator< ::boost::tuple<
    vector<int>::const_iterator, vector<float>::const_iterator > >;

If that doesn't work, check your version: I have cc-mode version 5.31.6. To check, do M-x c-version. I get

Using CC Mode version 5.31.6
Charlie Martin
`C-cC-o` lets me change the offset for the syntactic symbol, for template-args-cont I'm already setting that in my .emacs as +, and that's the default `C-cC-o` offers to set it to. Setting it to a number make no difference.As best as I can tell, cc-mode isn't recognizing this line as having a template-args-cont syntax.(I'm using cc-mode version 5.31.5.)
AFoglia
Well, the obvious thing is to upgrade to 5.31.6, or al least have a look at the change log. In any case, the example up above is cut got identical results with indent-region. If that doesn't work, then you may have done something artistic elsewhere in your .emacs; try staring emacs with --no-init-file and see what happens.
Charlie Martin
Except I think 5.31.6 is only bundled with Emacs 23. It's not available for download on the cc-mode site http://cc-mode.sourceforge.net/index.php . The template-args-cont symbol was introduced 5.15, so this isn't a new feature.I did try doing emacs --no-init-file and that didn't change the indentation.
AFoglia
well then you're left with an issue that it works for me and doesn't work for you. I'm running "GNU Emacs 22.3.1 (i386-apple-darwin9.6.0, Carbon Version 1.6.0) of 2009-01-02 on seijiz.local" You *are* reindenting the line with TAB or indent-region after you change the value, right? It won't change the indentation until you do.
Charlie Martin
Of course.I was afraid it was something complicated like this. I think I just need to get emacs to recognize the syntax as template-args-cont, but I have no idea how.Thanks for your help though.
AFoglia
Ah. Look at the lines above. Any chance you're missing a ';'? Paste in about ten lines around the line at issue and let me see them if that doesn't give you the hint you need.
Charlie Martin
CC-mode does not recognize template-args-cont in defun-block, so if the typedef is in a function, only statement-cont is effective.
Ian Yang
Which version, Ian? If it's the current version, that might be worth a bug report.
Charlie Martin