4

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.

Gauthier
  • 40,309
  • 11
  • 63
  • 97
Carthage
  • 298
  • 2
  • 8
  • I receive a tumbleweed badge today. It is ironic to me... Update myself: It is easy to reproduce this error, just open a new buffer, and switch to c-mode, then enter following code: `code void main(void) { #ifdef MACRO_A int i = 1; #else int i = 2; #endif if (i > 0) { /* ((substatement-open 75)) */ } /* ((defun-close 17)) */ }` – Carthage Mar 07 '13 at 09:53
  • Your example code in comment works fine for me, but I do not have indentation setup in GNU mode, as you have. I do get strange indentation problems in combination with preprocessor macros, though. I believe mine are related to opening curly brackets, my syntax is indeed wrong if the preprocessor macros are regarded as blank lines (which they are). Another annoying effect is that the function to go to that start/end of a function do not work. – Gauthier Mar 27 '13 at 08:58
  • Oh: works fine for me, except for the comment ((substatement..., which appears on column 0. – Gauthier Mar 27 '13 at 09:00
  • I test with 24.3, the problem still exist. – Carthage Apr 12 '13 at 02:41

1 Answers1

1

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.

Gauthier
  • 40,309
  • 11
  • 63
  • 97