Carthage
Carthage

Reputation: 298

Emacs C-mode auto-indent fails after preprocessor macro

Emacs 24.2 for Windows.

case TYPE_LONG: 
 {                           <------- 65383 
   traceCodePath(20);        
   tempLongVal = iterator_long(it);  
   tempLongVal = 10; 
   if (isBigEndian()) 
   { 
     swap_endian64(&tempLongValCon, &tempLongVal); 
     traceCodePath(25);      <------- 65601 
     if (i > 0) 
       {     <------ get weird from here /* ((substatement-open 65601)) */ 
 }           <------ this line aligns with the { below "case"  /* ((block-close 65383)) */ 
 }           <------ the code afterward all align with { below "case" /* ((block-close 65383)) */

c-mode indentation worked well since the beginning, until I added some Preprocessor macro, #ifdef, #else, #end, after that, from some point in code, all afterward indentations get messy. Every line's syntatic symbol is right, but the anchor positions are all wrong, seems they can not recognize the { at their same level, but anchor to some { before them at a upper level.

What's more weird, even I remove those preprocessor macro's again, indentation won't recover again.
What's more more weird, sometimes later, it recovered for no reason. I don't know what operations triggered this, but most possible I think is "save" "revert-buffer" etc.

Hope someone can figure the reason out, thanks in advance.

Upvotes: 4

Views: 1198

Answers (1)

Gauthier
Gauthier

Reputation: 41945

This may very well be related to "bug #14133 24.2; c functions recognition breaks on certain preprocessor macros":

http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-04/msg00055.html

The problem seems to be with spaces preceding #. The way I noticed this is that C-M-a and C-M-e stopped working correctly, and auto-indenting regions was strange just as in your case.

Recoveries were not consistent for me neither.

The patch proposed by Alan Mackenzie solved the problem for my case, you should try it out.

You can also try with emacs 23, I could not reproduce the error in this version.

Upvotes: 1

Related Questions