home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * 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 !!! *
- *******************************************************************/
-
- /* Slide-Textra <num>
- *
- * this routine moves lines containing any portion of a selection
- * (or the current cursor line) by <num> spaces.
- *
- * 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.
- *
- */
-
- OPTIONS results
-
-
- parse arg num /* get the argument */
- if (num == "") then num = 1 /* set 1 as default */
-
- moveleft = 0
- if (num < 0) then
- do
- moveleft = 1
- num = abs(num)
- 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 (moveleft ~= 0) then
- do
- maxleft = GetMinLineLen()
- num = min( num, maxleft )
- end
-
-
- if (LinesSelected == 0) then
-
- do
- gotoxy 0 cursy
- call addblanks
- 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)
- do
- gotoxy 0 currline
- call addblanks
- currline = currline + 1
- numLeft = numLeft - 1
- end
- end
- gotoxy 0 starty
- selectto 0 starty+LinesSelected
- end
-
- exit
-
-
- addblanks:
- if (moveleft == 0) then
-
- do
- blstr = '" '
- i = 1
- do while (i < num)
- do
- blstr = blstr || ' '
- i = i + 1
- end
- end
- blstr = blstr || '"'
-
- /* insert spaces at beginning of line */
- text blstr
- end
- else
- /* delete characters from beginning of line */
- if (num > 0) then
- do
- get cursor position; parse var result addbx ' ' addby
- selectto addbx+num addby
- cut
- end
-
- return
-
-
- GetMinLineLen: /* return smallest line length in select range */
- /* or length of cursor line */
- if (LinesSelected == 0) then
- do
- mynum = 1
- theLine = cursy
- end
- else
- do
- mynum = LinesSelected
- theLine = starty
- end
- minlen = 10000
- do while (mynum > 0)
- do
- get line theLine
- thislen = length( result )
- if (thislen < minlen) then minlen = thislen
- mynum = mynum - 1
- theLine = theLine + 1
- end
- end
- if (minlen == 10000) then minlen = 0
- return minlen
-
-
- 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
-