home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / textutil / gcmacro.zip / BLOCK.S next >
Text File  |  1993-05-10  |  7KB  |  182 lines

  1. /*****************************************************************************
  2.   2 May 93: G. Grafton Cole                                  BLOCK FUNCTIONS
  3.  
  4.   I burned these macros into SE.  They cost bytes but I use the heck out of
  5.     blocks.  They were hacked rather quickly and I am sure they can be
  6.     improved and made more elegant, but I have not had time.
  7.  ****************************************************************************/
  8.  
  9. integer                                  // global
  10.    blockfill_mode,                  // block fill toggle flag
  11.    blockoverwrite_mode,             // block overwrite toggle flag
  12.    mark_flag                        // block begin mark flag
  13.  
  14. /*******************  Block Overwrite Toggle Flag *************************/
  15. proc BlockOverwriteToggle()                   // Over write toggle
  16.   blockoverwrite_mode = blockoverwrite_mode ^ 1
  17.   set(ShowHelpLine, BlockOverWrite_mode | BlockFill_mode)
  18.   Message("Block overwrite turned ", iif(blockoverwrite_mode, "ON", "OFF"))
  19. end
  20.  
  21. /*******************  Block Fill Toggle Flag ******************************/
  22. proc BlockFillToggle()                       // Fill toggle
  23.   blockfill_mode = blockfill_mode ^ 1
  24.   set(ShowHelpLine, BlockOverWrite_mode | BlockFill_mode)
  25.   Message("Block fill turned ", iif(blockfill_mode, "ON", "OFF"))
  26. end
  27.  
  28. /***************************************************************************
  29.   Modified Block Copy:  a toggle determins type of copy
  30.        when SET  blockoverwrite_mode:    copy overwrites existing text
  31.        else:                             does a normal Block Copy
  32.  
  33.          _OVERWRITE_ works only with column block operations
  34.  **************************************************************************/
  35. proc mCopyBlock()
  36.   if blockoverwrite_mode
  37.     CopyBlock(_OVERWRITE_)
  38.   else
  39.     CopyBlock()
  40.   endif
  41. end
  42.  
  43. /***************************************************************************
  44.   Modified Block Delete:  a toggle determins type of delete
  45.        when SET  blockfill_mode:    deleted block is filled with spaces
  46.        else:                        does a normal Block Delete
  47.  **************************************************************************/
  48. proc mDelBlock()
  49.   if blockfill_mode
  50.     FillBlock(" ")
  51.   else
  52.     DelBlock()
  53.   endif
  54. end
  55.  
  56. /***************************************************************************
  57.   Modified Block Move:  two toggle determine type of move
  58.        when set  blockfill_mode:         source block is filled with spaces
  59.                  blockoverwrite_mode:    moved block overwrites existing text
  60.        else:                             does a normal Block Move
  61.  
  62.     A char block must contain full lines ie, block begin and end must be
  63.     in column 1, else overwrite is ignored.
  64.  
  65.          _OVERWRITE_ works only with column block operations
  66.  **************************************************************************/
  67. proc mMoveBlock()
  68.   integer
  69.        type = IsBlockMarked(),      // type of block
  70.        temp_id,                     // temp buffer id
  71.        curr_id = GetBufferId(),     // current file id
  72.        num_lines,                   // number of lines in source block
  73.        j = 1
  74.  
  75.   If not (BlockOverWrite_mode or BlockFill_mode)    // no fill or overwrite
  76.      MoveBlock()                                    // do it and leave
  77.      goto DONE
  78.   endif
  79.  
  80.   PushPosition()                    // save TARGET block cursor position
  81.   GotoBlockEnd()                    // save the position of the source
  82.   PushPosition()                    //   block end
  83.   GotoBlockBegin()                  // save the position of the source
  84.   PushPosition()                    //   block start
  85.  
  86.   temp_id = CreateTempBuffer()      // create temp buffer
  87.   CopyBlock()                       // copy source block to temp
  88.   PushBlock()                       // save it
  89.   num_lines = NumLines()             // get # lines in block
  90.  
  91.   GotoBufferId(curr_id)             // return current file
  92.   PopPosition()                     // cursor to beginning source block
  93.  
  94.   if type == _COLUMN_               // COLUMN BLOCK
  95.     CopyBlock(_OVERWRITE_)          // put source block back
  96.     mDelBlock()                     // delete and/or fill
  97.     KillPosition()                  // discard source block end cursor position
  98.   else                              // CHR BLOCK
  99.     MarkChar()                      // begin marking
  100.     PopPosition()                   // end block cursor position
  101.     MarkChar()
  102.     mDelBlock()
  103.   endif
  104.  
  105.   GotoBufferId(temp_id)             // back to temp
  106.   PopBlock()                        // get block back
  107.  
  108.   GotoBufferId(curr_id)             // back to current file
  109.   PopPosition()                     // back to target cursor position
  110.  
  111.   if BlockOverWrite_mode
  112.     if type == _COLUMN_
  113.       CopyBlock(_OVERWRITE_)
  114.     else                            // CHR BLOCK
  115.       CopyBlock()                   // overwrite only if the block contains
  116.       GotoBlockEnd()                // full lines.  If the beginning or end
  117.       if CurrCol() == 1             // of the block does not fall in column 1
  118.         GotoBlockBegin()            // make no attempt to delete those areas
  119.         if CurrCol() == 1           // that would have been covered by the
  120.           Up()                      // block.  Should have use a column block!
  121.           while j < num_lines
  122.             DelLine()
  123.             j = j + 1
  124.             Up()
  125.           endwhile
  126.         endif
  127.       endif
  128.     endif
  129.   else
  130.     CopyBlock()
  131.   endif
  132.  
  133. DONE:
  134. end
  135.  
  136. /****************************************************************************
  137.   An enhanced 'all in one' move.  You can move blocks all over heck and gone
  138.     and not loose formating.  Saves setting all the toggles.
  139.  
  140.         Set Block Fill and Block Over Write Modes ON
  141.         Moves the Block and then unmarks it
  142.         Then flips Fill and Over Write Modes to OFF
  143.  ****************************************************************************/
  144. proc mMarkColumnMove()
  145.    blockoverwrite_mode = 1        // force fill and overwrite true
  146.    blockfill_mode = 1
  147.  
  148.    mMoveBlock()
  149.    BlockOverwriteToggle()
  150.    BlockFillToggle()
  151.    UnMarkBlock()
  152. end
  153.  
  154. /*****************************************************************************
  155.   Save current Column block position when marking.  When assigned to a key you
  156.     can return to the source block after moving it.
  157.  ****************************************************************************/
  158.  
  159. proc mKN()
  160.    mark_flag = mark_flag ^ 1
  161.    if mark_flag                        // mark it only once
  162.      PlaceMark("block")
  163.    endif
  164.    MarkColumn()
  165. end
  166.  
  167. proc mKB()
  168.    PlaceMark("block")
  169.    MarkChar()
  170. end
  171.  
  172. /************* If block marked print it else print entire file  **************/
  173. proc mKP()
  174.    If Query(BlockId)
  175.       PrintBlock()
  176.    else
  177.       PrintFile()
  178.    endif
  179. end
  180.  
  181. /*-----------------------  END BLOCK MACROS  ------------------------------*/
  182.