4

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.

AFoglia
  • 7,968
  • 3
  • 35
  • 51

1 Answers1

3

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
  • 110,348
  • 25
  • 193
  • 263
  • `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 Jun 03 '09 at 20:05
  • 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&paste from an emacs session where I did C-C C-o 4 and reindented with TAB; 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 Jun 03 '09 at 21:29
  • 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 Jun 03 '09 at 21:54
  • 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 Jun 04 '09 at 03:53
  • 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 Jun 04 '09 at 15:58
  • 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 Jun 04 '09 at 19:07
  • 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 Sep 27 '09 at 06:35
  • Which version, Ian? If it's the current version, that might be worth a bug report. – Charlie Martin Oct 10 '09 at 23:57