Re: tabs to spaces
Re: tabs to spaces
- Subject: Re: tabs to spaces
- From: Skeeve <email@hidden>
- Date: Sun, 30 Nov 2008 23:55:19 +0100
And here we go…
property left_align : false -- true or false
on run
return detab(left_align, the clipboard)
end run
to detab(left_align, the_text)
set alignment to "-l=0"
if left_align then set alignment to "-l=1"
return do shell script "perl -015 -se " & (quoted form of "
use strict;
use warnings;
use vars qw/ $l /;
my @lines;
my @widths;
# read each line
while (<>) {
# split at tabs
my @line= split/\\t/;
# store splitted line
push( @lines, \\@line );
# check each column's length
my $i= 0;
foreach ( @line ) {
my $len= length $_;
# get the maximum of this column
$widths[$i]= $len if $len > $widths[$i];
++$i;
}
}
# left align? Then format is negative
my $left= $l ? '-' : '';
# build up a format string
# see perldoc -f sprintf
my $fstr= join ' ', map qq'%$left${_}s',@widths;
# print each line formatted
foreach ( @lines ) {
printf qq'$fstr\\n', @$_;
}") & " -- " & alignment & " <<<" & (quoted form of (the clipboard))
end detab
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden