[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] CVS diff: hard vs. soft tabs



On Fri, 2003-10-10 at 11:28, Nori Heikkinen wrote:
> on Fri, 10 Oct 2003 12:06:07PM -0400, Mental Patient insinuated:
> > Nori Heikkinen wrote:
> [...]
> > >now it's time to check it into CVS.  i don't want every single line
> > >to show up as different just because of tab characters, so i need
> > >to find a good solution on how to transform my indents back into
> > >tab characters.  clearly the reverse -- "s,  ,^I," -- won't just
> > >work, as there are places where two spaces exist that i wouldn't
> > >want a tab.
> > >
> > >is there some way to open the file in emacs (in which i assumer it
> > >was originally written; i use vim) and run it through a
> > >re-indentder with hard tabs on?  or could i do this in vim?
> > >
> > 
> > I've done this with mixed results. In general if you're going to
> > work on projects, its a good idea to come up with your format
> > conventions first. :)
> 
> right, that would have been nice ... but, as you say, i just inherited
> this one.  not much i could have done about setting conventions first.
> 
> > For things like indenting, etc, you could always adjust what you
> > have your tabstop set to.
> 
> what i have my tabstop set to doesn't matter -- that's how my editor
> interprets hard tabs on disk.  what i have is _no_ hard tabs on disk,
> and i want to put them there.  that's more complex, right?
> 
> </nori>

Assuming that all of your indentation is at the beginning of a line, (I
can't think where else it would be, but had to mention it just in case),
you can just use a relatively simple regexp to do it for you. Using
Perl, I'd do:

#!/usr/bin/perl

open (INFILE, $ARGV[0]);
open (OUTFILE, >$ARGV[1]);

foreach (<INFILE>) {
  $_ =~ s/^ {2}/\t/;
  while ($_ =~ /^\t {2}/) {
    $_ =~ s/\t {2}/\t\t/;
  }
  print OUTFILE $_;
}

close INFILE;
close OUTFILE;

-- 
Alex Malinovich
Support Free Software, delete your Windows partition TODAY!
Encrypted mail preferred. You can get my public key from any of the
pgp.net keyservers. Key ID: A6D24837

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: