Opening code written in emacs on Xcode appears badly indented
<p>This is my first post on stack overflow, so please forgive me for any mistakes. </p>

<p>I learned c++ with Xcode and recently started working with a group that uses Emacs. This group has a huge code in c++ and so I did a CMake interface to generate a project in Xcode. What happened is that the code appears badly indented in Xcode. For instance, these lines in emacs:</p>

<pre><code>if ( argc &gt; 4 ) {
  std::string argument( argv[arg_index++] );
  // NOTE: file_name should NOT be "aboveCrack" or "belowCrack"                                                                                                                           
  if ( argument == "aboveCrack" ) {
    surf_to_draw = CrackMn3DGraphDX2::EAboveSurface;
  }
  else if ( argument == "belowCrack" ) {
    surf_to_draw = CrackMn3DGraphDX2::EBelowSurface;
  }
  else {
    // argument 4 is comp. crack surface output name                                                                                                                                      
    got_file_name = true;
    postCompSurface_file_name = argument;
  }
}
if ( !got_file_name &amp;&amp; argc &gt; 5 ) {
  got_file_name = true;
  postCompSurface_file_name = argv[arg_index++];

  if ( argc &gt; 6 ) {
    // get comp. crack surface output style                                                                                                                                               
    postCompSurface_style = argv[arg_index++];
  }
}
</code></pre>

<p>Look like this in Xcode:</p>

<pre><code>if ( argc &gt; 4 ) {
  std::string argument( argv[arg_index++] );
  // NOTE: file_name should NOT be "aboveCrack" or "belowCrack"
  if ( argument == "aboveCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EAboveSurface;
  }
  else if ( argument == "belowCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EBelowSurface;
  }
  else {
// argument 4 is comp. crack surface output name
got_file_name = true;
postCompSurface_file_name = argument;
  }
}
if ( !got_file_name &amp;&amp; argc &gt; 5 ) {
  got_file_name = true;
  postCompSurface_file_name = argv[arg_index++];

  if ( argc &gt; 6 ) {
// get comp. crack surface output style 
postCompSurface_style = argv[arg_index++];
  }
}
</code></pre>

<p>Which is impossible to program with.</p>

<p>I searched and apparently it has something to do with the tabs in Emacs. Based on this, one fix I could find was to open each file in Emacs and do C-x h (mark all) followed by M-x untabify. This transforms the tabs in spaces and everything looks good in Xcode.</p>

<p>The problems with this idea are that it requires to change the files one by one and it won't stop this from happening again in the future.</p>

<p>Therefore, my question is: is there a way to open the Emacs indented files in Xcode preserving the indentation?</p>

<p>Many thanks!</p>

<p>Nathan Shauer</p>