Re: Re: Tex-Edit string manipulation.
Re: Re: Tex-Edit string manipulation.
- Subject: Re: Re: Tex-Edit string manipulation.
- From: "Marc K. Myers" <email@hidden>
- Date: Mon, 27 Aug 2001 02:16:25 -0400
- Organization: [very little]
>
Date: Sun, 26 Aug 2001 18:16:28 -0600
>
Subject: Re: Tex-Edit string manipulation.
>
From: Rachel <email@hidden>
>
To: <email@hidden>
>
CC: <email@hidden>
>
>
OK, here is the masterpiece.
>
Thanks, Marc for shoving me in the right direction. Feel free to op[timize
>
this script and return it to me.
>
PS:Are we allowed attachments on this list?
>
>
Rachel
>
******************
>
set theMargin to 12
>
tell window 1 of application "Tex-Edit Plus"
>
set someSpaces to ""
>
repeat with i from 1 to theMargin
>
set someSpaces to someSpaces & " "
>
end repeat
>
strip removing leading spaces
>
set x to ""
>
repeat with i from 1 to (count lines)
>
set theText to line i
>
if character 1 of theText is return then --paragraph break
>
set x to ""
>
set theDiff to ""
>
set y to ""
>
else
>
set x to word 1 of theText
>
try
>
set theDiff to text 1 thru (theMargin - (length of x)) of
>
someSpaces
>
set y to text from word 2 to word -1 of theText
>
on error -- line will be only first word
>
set theDiff to ""
>
set y to ""
>
end try
>
end if
>
set theText to x & theDiff & y & return
>
set line i to theText
>
end repeat
>
end tell
>
>
*******************
>
>
Entity Marc K. Myers spoke thus:
>
>
> Rachel wrote:
>
>>
>
>> Marc:
>
>> this looks like it should work, but I keep getting an error: CANT GET
>
>> CHARACTER 1 OF "".
>
>> I will play with it at my leisure, but I thought every line had at least a
>
>> CR. Ideas?
>
>> Rachel
>
>>
>
>> Entity Marc K. Myers spoke thus:
>
>>> I'd do it this way (it assumes that the text should start in column 26):
>
>>>
>
>>> set someSpaces to " "
>
>>> tell window 1 of application "Tex-Edit Plus"
>
>>> repeat with i from 1 to (count paragraphs)
>
>>> set theText to paragraph i
>
>>> set x to word 1 of theText
>
>>> set y to text from word 2 to word -1 of theText
>
>>> set theDiff to 25 - (length of x)
>
>>> set theText to x & (text 1 thru theDiff of someSpaces) & y
>
>>> set paragraph i to theText
>
>>> end repeat
>
>>> end tell
>
>
>
> Every line _does_ have a carriage return, but I suspect that you have
>
> lines that contain _only_ a carriage return. Put in code to filter out
>
> those lines and you should be OK. (Hint: if length of paragraph i > 0
>
> then process else skip the paragraph.)
This comparison returns "false" if there is nothing in the paragraph but
a return:
if character 1 of theText is return
because the return doesn't count as a character. Therefore you can't
use it to check for such a paragraph. Instead, check the length of the
paragraph. A paragraph with nothing in it but a return will have a
length of 0. Other than that your script looks very good.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[8/27/01 2:13:26 AM]