Re: tabs in source code

[prev] [thread] [next] [lurker] [Date index for 2006/06/20]

From: Martin Ebourne
Subject: Re: tabs in source code
Date: 00:38 on 20 Jun 2006
On Mon, 2006-06-19 at 17:16 -0500, David Champion wrote:
> It's probably from cc-mode.  Try it.  emacs bloody-emacs.c and put in
> some levels of indentation, then check it out in vi or od.
> 
> It does appear that somewhere in the last 12 years they've changed it
> from 4 spaces (also my recollection) to 2 spaces; hate.

% emacs -Q bloody-emacs.c

Entered the code below which indented to look exactly like this[1]:
int main()
{
  if(friday()) {
    while(procrastinating()) {
      switch(toaster_on(sliced_bread)) {
      case Golden:
        add_cheese();
        have_tea();
        break;

      case Black:
        sulk();
      }
    }
  }

  return 0;
}

% cat -vet bloody-emacs.c
int main()$
{$
  if(friday()) {$
    while(procrastinating()) {$
      switch(toaster_on(sliced_bread)) {$
      case Golden:$
^Iadd_cheese();$
^Ihave_tea();$
^Ibreak;$
$
      case Black:$
^Isulk();$
      }$
    }$
  }$
$
  return 0;$
}$

That looks perfectly understandable and sane. It's indented 2 spaces
each time and used a tab instead of 8 spaces. This corresponds with the
defaults of every other unix tool so at least it will display correctly
and look correct by default in any normal editor.

But of course, it's still mixed tabs with spaces in an evil manner
(virtually every tab/space mix is evil, apart from the anal retentive
one, which is just well, you get it). Fortunately one setting later and
it won't do that any more. [2]

Cheers,

Martin.

[1] Note that to display it to yourselves accurately as it appears on my
screen I had to convert the tabs to spaces. That's a hint people.

[2] Emacs has a mode which lets you edit C code in the "correct"
tab/space mix and it handles getting it right automatically. If everyone
used this I'd be happy to as well, but no-one does, so there's no point
me caring.

Generated at 20:01 on 27 Jun 2006 by mariachi 0.52