home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 197_01 / block.cmd < prev    next >
OS/2 REXX Batch file  |  1979-12-31  |  3KB  |  125 lines

  1. ;    BLOCK.CMD:    Rectangualar Cut/Paste macros
  2.  
  3. ;    delete a rectangular block of text
  4.  
  5. store-procedure getblock
  6.     ;set up needed variables
  7.     set $discmd FALSE
  8.     delete-buffer "[block]"
  9.     set %rcbuf $cbufname
  10.     set %cline $cwline
  11.  
  12.     ;save block boundries
  13.     set %endpos $curcol
  14.     set %endline $curline
  15.     exchange-point-and-mark
  16.     set %begpos $curcol
  17.     set %begline $curline
  18.     set %blwidth &sub %endpos %begpos
  19.  
  20.     ;detab the region
  21.     &add &sub %endline %begline 1 detab-line
  22.  
  23.     ;scan through the block
  24.     set $curline %begline
  25.     !while &less $curline &add %endline 1
  26.         ;grab the part of this line needed
  27.         !force set $curcol %begpos
  28.         set-mark
  29.         !force set $curcol %endpos
  30.         kill-region
  31.  
  32.         ;bring it back if this is just a copy
  33.         !if %bkcopy
  34.             yank
  35.         !endif
  36.  
  37.         ;put the line in the block buffer
  38.         select-buffer "[block]"
  39.         yank
  40.  
  41.         ;and pad it if needed
  42.         !if &less $curcol %blwidth
  43.             &sub %blwidth $curcol insert-space
  44.             end-of-line
  45.         !endif
  46.         forward-character
  47.  
  48.         ;onward...
  49.         select-buffer %rcbuf
  50.         next-line
  51.     !endwhile
  52.  
  53.         ;unmark the block
  54.         select-buffer "[block]"
  55.         unmark-buffer
  56.         select-buffer %rcbuf
  57.         previous-line
  58.         %cline redraw-display
  59.     set $discmd TRUE
  60. !endm
  61.  
  62. ;    insert/overlay a rectangular block of text
  63.  
  64. store-procedure putblock
  65.     ;set up needed variables
  66.     set $discmd FALSE
  67.     set %rcbuf $cbufname
  68.     set %cline $cwline
  69.  
  70.     ;save block boundries
  71.     set %begpos $curcol
  72.     set %begline $curline
  73.  
  74.     ;scan through the block
  75.     select-buffer "[block]"
  76.     beginning-of-file
  77.     set %endpos &add %begpos $lwidth
  78.     !while ¬ &equ $lwidth 0
  79.  
  80.         ;pad the destination if it is needed
  81.         select-buffer %rcbuf
  82.         beginning-of-line
  83.         !if ¬ &equ $lwidth 0
  84.             detab-line
  85.             previous-line
  86.         !endif
  87.         !force set $curcol %begpos
  88.         !if &less $curcol %begpos
  89.             &sub %begpos $curcol insert-space
  90.             end-of-line
  91.         !endif
  92.  
  93.         ;delete some stuff if this should overlay
  94.         !if %bkcopy
  95.             set-mark
  96.             !force set $curcol %endpos
  97.             kill-region
  98.         !endif
  99.  
  100.         ;grab the line from the block buffer
  101.         select-buffer "[block]"
  102.         beginning-of-line
  103.         set-mark
  104.         end-of-line
  105.         copy-region
  106.         forward-character
  107.  
  108.         ;put the line in the destination position
  109.         select-buffer %rcbuf
  110.         yank
  111.         next-line
  112.  
  113.         ;onward...
  114.         select-buffer "[block]"
  115.     !endwhile
  116.  
  117.     select-buffer %rcbuf
  118.     set $curline %begline
  119.     set $curcol %begpos
  120.     %cline redraw-display
  121.     set $discmd TRUE
  122. !endm
  123.  
  124.  
  125.