source: program to adjust tabs 
Author Message
 source: program to adjust tabs

Well, after reading the thread about preferred indentation, and then
running up against a program that used 8-column tabs to a depth of
ridiculousness, which I basically needed to rewrite anyway, I wrote
the following script to alter the indentation of anything that uses
lots of tabs to have leading four-space indentation.

The hardest part of this job is the fact that if you take a program
that uses tabs *within* the line, say to line up declarations or
comments, and you just{*filter*}with the leading tabs, these things won't
line up any more. This script takes care of them, too.

You run it by saying something like "retab *.c".

Share and Enjoy,

#!/usr/local/bin/perl -pi.orig

# retab programs from 8 character indents to 4 character indents,
# but preserving column alignment in declarations. Output should
# produce 8 character tabs as much as possible, and assumes 8 character
# tab stops in the input.

# make leading spaces into tabs first
undef while s/^(\t*)        /$1\t/;

# check for nothing to do
if (/^\t/) {
    # split off leading tabs for separate handling
    $tabs = $1;

    # put out leading tabs
    print "\t" while $tabs =~ s/\t\t//;

    # put out four spaces
    if ($tabs) {
        print "    ";
        # might have to change alignment of rest of line
        if (/^([^\t]*)\t/) {
            # fix the internal tabs
            s/\t/\t\t/ if (length($1) % 8) < 4;


# end of retab

Greg Rose                 Australian Computing and Communications Institute

Sat, 18 Feb 1995 15:29:08 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Nonmember submission: when is a tab a tab?

2. Adjust a Time/Date value?

3. adjusting HTML

4. How need to adjust existing widget (SpecPERL)

5. How to adjust a notebook?

6. Tk::Adjuster doesn't adjust LabFrames (?)

7. PATCH: adjust Tk::Balloon position

8. configuring Tk::Adjust

9. Wanted - source for Perl database program and interpreter

10. why's my program printing it's own source

11. ANNOUNCE: FreeCode, hundreds of FREE source code programs

12. source code of Larry Wall's Programming Perl


Powered by phpBB® Forum Software