home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
626a.lha
/
Textra_v1.12
/
Scripts
/
paragraph.textra
< prev
next >
Wrap
Text File
|
1991-12-16
|
6KB
|
212 lines
/******************************************************************
* TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved. *
* Freely distributable ONLY as a component of the TEXTRA package. *
* This banner may not be removed or altered (improvements to the *
* actual program welcome). Please document and send to me. *
* !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!! *
******************************************************************/
/* Usage: Paragraph <1st-line-indent> <left-margin> <right-margin>
*
* Paragraph is a general purpose formatting script. It operates on
* the current SELECT range and accepts 3 arguments, all required...
*
* <1st-line-indent> - the amount to indent the FIRST line of
* each paragraph (counted from leftmost column)
*
* <left-margin> - the amount to indent the rest of each paragraph
*
* <right-margin> - the 'word wrap' point for all lines of all
* selected paragraphs
*
* Paragraphs are recognized as single-spaced blocks of text which
* are separated by a blank line.
*
* NOTE: Paragraph.textra supercedes the earlier WrapAt.textra script.
* This script does all that one did plus more.
*
*/
OPTIONS results
parse arg numIndent leftMargin rightMargin /* get the arguments */
if ((numIndent == "") | (leftMargin == "") | (rightMargin == "")) then do
notify "Usage: Paragraph <1st-line-indent> <left-margin> <right-margin>"
exit
end
/* make sure rightMargin is legal */
if ((rightMargin > 120) | (rightMargin <= leftMargin)) then
do
notify "Right-Margin must > Left-Margin AND < 120"
exit
end
get select position
if (result == "NO SELECT") then /* is nothing selected? */
do
notify "There MUST be a select range to use the Paragraph script."
exit
end
/* yes, there is a selection, get it's boundaries */
parse var result startx ' ' starty ' ' endx ' ' endy
currx = startx
curry = starty
nomore = 0
bsto = -1
/* temporarily make sure auto indent is off */
prefs autoindent read; autoistate = result
prefs autoindent off
/* if nothing on the endline is actually selected, don't include it */
if (endx == 0) then endy = endy - 1
gotoxy 0 curry
get cursor char
do while ((result == " ") | (result == " ") /*TAB*/)
del
get cursor char
end
do for (numIndent)
text '" "'
end
do while ((curry <= endy) & (nomore == 0))
do
if (bsto == -1) then do
gotoxy 0 curry
currx = 0; nowony = curry
end
else do
currx = bsto; bsto = -1
end
do while ((currx <= rightMargin) & (nowony == curry) & (nomore == 0))
hopselect next word
if (result == "NOT FOUND") then do
nomore = 1
gotoxy 1000 curry
end
else do
get select position
parse var result dummy' 'dummy' 'currx' 'nowony
gotoxy currx nowony
end
end
inbetween = (nowony - 1) - curry
/* COMMENTED OUT delete any blank lines between
notify "deleting"
todelete = (nowony - 1) - curry
if (todelete > 0) then do
tmp = todelete
do while (tmp > 0)
selectline curry+1; del
tmp = tmp - 1
end
endy = endy - todelete
nowony = nowony - todelete
gotoxy currx nowony
end
*/
if (currx > rightMargin) then do
/* line is too long */
hopto prev word;
get cursor position; parse var result PrevEndsAt' 'dummy
if (PrevEndsAt > rightMargin) then
hopto prev word
hopto next word
newline
get cursor char
do while ((result == " ") | (result == " ") /*TAB*/)
del
get cursor char
end
do for (leftMargin)
text '" "'
end
endy = endy + 1 /* cause we inserted a newline */
curry = curry + 1
nomore = 0
end
else if (nomore == 0) then do
/* curr line is not long enough */
gotoxy 0 nowony
if ((curry < endy) & (inbetween == 0)) then do
backspace; get cursor position; parse var result tempx' 'tempy
thechar = " "
do while (((thechar == " ") | (thechar == " ") /*TAB*/ ) & (tempx ~= 0))
do
left 1
tempx = tempx - (1)
get cursor char; thechar = result
end
end
if (tempx ~= 0) then
right 1
get cursor char
do while ((result == " ") | (result == " ") /*TAB*/ )
do
del
get cursor char
end
end
if (tempx ~= 0) then do
if (thechar == ".") then
text '" "'
else
text '" "'
end
if (tempx == 0) then
do for (numIndent)
text '" "'
end
get cursor position; parse var result bsto' 'nowony
endy = endy - 1
end
else
if (curry < endy) then do
get cursor char
do while ((result == " ") | (result == " ") /*TAB*/)
del
get cursor char
end
do for (numIndent)
text '" "'
end
end
curry = nowony
end
/*
ask "Do it again?"
if (result == "NO") then exit
*/
end
end
/* restore autoindent */
prefs autoindent autoistate