home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
wp_dtp
/
textra_1.lha
/
Scripts
/
indent.textra
< prev
next >
Wrap
Text File
|
1992-11-20
|
4KB
|
173 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 !!! *
*******************************************************************/
/* INDENT <num> {DIC}
*
* this routine moves lines containing any portion of a selection
* (or the current cursor line) by <NUM> TABs.
*
* If <num> is positive, the move is to the right. Negative, left.
*
* If <num> is not provided, it's default value is 1. A move to
* the left will terminate if a line either runs out of characters
* or some character other than BLANK enters the first column.
*
* If DIC is specified, then Don't Indent Comments
*/
/* Converted from SLIDE.TEXTRA by Phil Burk */
/* 00001 mdh 10-nov-92 Added ability to cancel script */
/* 00002 mdh 20-nov-92 check version (cause of 'CheckCancel') */
OPTIONS results
rex = 0; result = "NOTSUPPORTED" /*00002*/
textraversion
parse var result maj min rex
if (result == "NOTSUPPORTED") | (rex < 3) then do
notify "Textra V1.13 or later required for this script."
exit
end
tabchar = d2c(9)
parse upper arg num ' ' dic /* get the argument */
if (num == "") then num = 1 /* set 1 as default */
moveleft = 0
if (num < 0) then
do
moveleft = 1
num = abs(num)
prefs TabWidth read
tabwidth = result
end
get select position /* get the select boundary, if any */
if (result == "NO SELECT") then /* is nothing selected? */
do
get cursor position /* nothing selected, get cursor pos */
parse var result cursx ' ' cursy
LinesSelected = 0 /* means 'just cursor' */
end
else
do
/* yes, there is a selection, get it's boundaries */
parse var result startx ' ' starty ' ' endx ' ' endy
LinesSelected = (endy - starty)
/* if only the 'eol' of the previous line is selected
(nothing on this line is actually included, i.e. x==0),
then don't include it.
*/
if (endx > 0) then LinesSelected = LinesSelected + 1
end
if (LinesSelected == 0) then
do
gotoxy 0 cursy
call addtabs
if (moveleft == 0) then
gotoxy cursx+num cursy
else
do
newx = max(cursx-num,0)
gotoxy newx cursy
end
end
else
do
currline = starty; numLeft = LinesSelected
do while (numLeft > 0)
CheckCancel; if (result == CANCEL) then exit /*00001*/
do
gotoxy 0 currline
call addtabs
currline = currline + 1
numLeft = numLeft - 1
end
end
gotoxy 0 starty
selectto 0 starty+LinesSelected
end
exit
addtabs:
if (moveleft == 0) then
do
if (dic = 'DIC') then
do
get cursor char; firstchar = result
if (firstchar = '\') then return
if (firstchar = '(') then return
if (firstchar = '/') then return /* Arexx comment. */
end
do
blstr = '"' || tabchar
i = 1
do while (i < num)
do
blstr = blstr || tabchar
i = i + 1
end
end
blstr = blstr || '"'
/* insert tabs at beginning of line */
text blstr
end
end
else
/* delete characters from beginning of line */
if (num > 0) then
do i = 1 to num
get cursor char; firstchar = result
if (firstchar = tabchar) then del
/* If it's a SPACE, remove enough for a TAB */
if (firstchar = d2c(32)) then
do j = 1 to tabwidth
get cursor char; firstchar = result
if (firstchar = d2c(32)) then del
end
end
return
Debug: procedure
parse arg theString
get select position /* get the select boundary, if any */
if (result == "NO SELECT") then /* is nothing selected? */
do
get cursor position /* nothing selected, get cursor pos */
parse var result cursxdbg ' ' cursydbg
WasSelected = 0 /* means 'just cursor' */
end
else
do
/* yes, there is a selection, get it's boundaries */
parse var result cursxdbg ' ' cursydbg ' ' endxdbg ' ' endydbg
WasSelected = 1
end
lastline
text theString
gotoxy cursxdbg cursydbg
if (WasSelected == 1) then selectto endxdbg endydbg
return