• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: tabs to spaces
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tabs to spaces


  • Subject: Re: tabs to spaces
  • From: Skeeve <email@hidden>
  • Date: Mon, 01 Dec 2008 00:00:05 +0100

Where was my indentation gone? :-(

Sorry for polluting the list...


property left_align : 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


And here again what I forgit to mention: I tested with the clipboard filled by OpenOffice. The line seperator is ASCII 13 here. To acknowledge that there is the "-015" right after "perl". Should the seperator be ASCII 10, you can remove the "-015" or replace it with "-012".
_______________________________________________
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
References: 
 >tabs to spaces (From: Scott Haneda <email@hidden>)
 >Re: tabs to spaces (From: Skeeve <email@hidden>)

  • Prev by Date: Re: tabs to spaces
  • Next by Date: Re: tabs to spaces
  • Previous by thread: Re: tabs to spaces
  • Next by thread: Re: tabs to spaces
  • Index(es):
    • Date
    • Thread