home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 626a.lha / Textra_v1.12 / Scripts / indent.textra < prev    next >
Text File  |  1992-01-03  |  4KB  |  161 lines

  1.     /*******************************************************************
  2.      *   TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved.  *
  3.      * Freely distributable ONLY as a component of the TEXTRA package. *
  4.      * This banner may not be removed or altered (improvements to the  *
  5.      *    actual program welcome).  Please document and send to me.    *
  6.      *        !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!!          *
  7.      *******************************************************************/
  8.  
  9. /* INDENT <num> {DIC}
  10.  *
  11.  * this routine moves lines containing any portion of a selection
  12.  * (or the current cursor line) by <NUM> TABs.
  13.  *
  14.  * If <num> is positive, the move is to the right. Negative, left.
  15.  *
  16.  * If <num> is not provided, it's default value is 1.  A move to
  17.  * the left will terminate if a line either runs out of characters
  18.  * or some character other than BLANK enters the first column.
  19.  *
  20.  * If DIC is specified, then Don't Indent Comments
  21.  */
  22.  
  23. /* Converted from SLIDE.TEXTRA by Phil Burk */
  24.  
  25. OPTIONS results
  26.  
  27. tabchar = d2c(9)
  28.  
  29. parse upper arg num ' ' dic  /* get the argument */
  30. if (num == "") then num = 1   /* set 1 as default */
  31.  
  32. moveleft = 0
  33. if (num < 0) then
  34.     do
  35.         moveleft = 1
  36.         num = abs(num)
  37.         prefs TabWidth read
  38.         tabwidth = result
  39.     end
  40.  
  41. get select position   /* get the select boundary, if any */
  42.  
  43. if (result == "NO SELECT") then   /* is nothing selected? */
  44.  
  45.     do
  46.         get cursor position   /* nothing selected, get cursor pos */
  47.         parse var result   cursx ' ' cursy
  48.         LinesSelected = 0   /* means 'just cursor' */
  49.     
  50.     end
  51.     
  52. else
  53.  
  54.     do
  55.         /* yes, there is a selection, get it's boundaries */
  56.         parse var result   startx ' ' starty ' ' endx ' ' endy
  57.         LinesSelected = (endy - starty)
  58.     
  59.         /* if only the 'eol' of the previous line is selected
  60.            (nothing on this line is actually included, i.e. x==0),
  61.            then don't include it.
  62.         */
  63.         if (endx > 0) then  LinesSelected = LinesSelected + 1
  64.     
  65.     end
  66.  
  67. if (LinesSelected == 0) then
  68.  
  69.     do
  70.         gotoxy 0 cursy
  71.         call addtabs
  72.         if (moveleft == 0) then
  73.             gotoxy cursx+num cursy
  74.         else
  75.             do
  76.                 newx = max(cursx-num,0)
  77.                 gotoxy newx cursy
  78.             end
  79.     end
  80.  
  81. else
  82.  
  83.     do
  84.         currline = starty; numLeft = LinesSelected
  85.         do while (numLeft > 0)
  86.             do
  87.                 gotoxy 0 currline
  88.                 call addtabs
  89.                 currline = currline + 1
  90.                 numLeft = numLeft - 1
  91.             end
  92.         end
  93.         gotoxy 0 starty
  94.         selectto 0 starty+LinesSelected
  95.     end
  96.     
  97. exit
  98.  
  99.  
  100. addtabs:
  101.     if (moveleft == 0) then
  102.         do
  103.             if (dic = 'DIC') then
  104.                 do
  105.                     get cursor char; firstchar = result
  106.                     if (firstchar = '\') then return
  107.                     if (firstchar = '(') then return
  108.                     if (firstchar = '/') then return /* Arexx comment. */
  109.                 end
  110.             do
  111.                 blstr = '"' || tabchar
  112.                 i = 1
  113.                 do while (i < num)
  114.                     do
  115.                         blstr = blstr || tabchar
  116.                         i = i + 1
  117.                     end
  118.                 end
  119.                 blstr = blstr || '"'
  120.     
  121.                 /* insert tabs at beginning of line */
  122.                 text blstr
  123.             end
  124.         end
  125.     else
  126. /* delete characters from beginning of line */
  127.         if (num > 0) then
  128.             do i = 1 to num
  129.                 get cursor char; firstchar = result
  130.                 if (firstchar = tabchar) then del
  131. /* If it's a SPACE, remove enough for a TAB */
  132.                 if (firstchar = d2c(32)) then
  133.                     do j = 1 to tabwidth
  134.                         get cursor char; firstchar = result
  135.                         if (firstchar = d2c(32)) then del
  136.                     end
  137.                 
  138.             end
  139. return
  140.  
  141. Debug: procedure
  142.     parse arg theString
  143.     get select position   /* get the select boundary, if any */
  144.     if (result == "NO SELECT") then   /* is nothing selected? */
  145.         do
  146.             get cursor position   /* nothing selected, get cursor pos */
  147.             parse var result   cursxdbg ' ' cursydbg
  148.             WasSelected = 0   /* means 'just cursor' */
  149.         end
  150.     else
  151.         do
  152.             /* yes, there is a selection, get it's boundaries */
  153.             parse var result   cursxdbg ' ' cursydbg ' ' endxdbg ' ' endydbg
  154.             WasSelected = 1
  155.         end
  156.     lastline
  157.     text theString
  158.     gotoxy cursxdbg cursydbg
  159.     if (WasSelected == 1) then   selectto endxdbg endydbg
  160. return
  161.