home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / sprint / texmac.zip / COLUMN.SPM next >
Text File  |  1990-12-24  |  10KB  |  365 lines

  1. ; Copyright (c) 1988 Borland International.  All Rights Reserved
  2. ;
  3. ; NAME: COLUMN.SPM
  4. ; VERSION: 1.01
  5. ; DESCRIPTION: Column Macro Package for Sprint
  6. ; LAST UPDATE: 21 March, 1988
  7. ;
  8. ; NOTES: This file must be compiled and loaded AFTER the CORE.SPM package.
  9. ;
  10. ; This package provides a number of functions used for manipulating
  11. ; columns.  You can use them to copy, insert, delete, erase, and perform
  12. ; other operations.
  13.  
  14. ; This package defines a column as all characters that START within
  15. ; the specified range (a la Microsoft Word).  No conversions are made
  16. ; between spaces and tabs.  This choice makes the operations
  17. ; predictable, although the horizontal spacing might be a bit strange
  18. ; if you copy from one set of tab stops (or horizontal position) to
  19. ; another.
  20. ;
  21. ; (The alternate method -- "transparently" converting tabs to spaces
  22. ; and thereby preserving horizontal relationships -- has a different
  23. ; set of trade offs, and results in much larger (and slower) macros. 
  24. ; It can be readily emulated by converting tabs to spaces, performing
  25. ; the column operations, and converting the spaces back to tabs.)
  26. ;
  27. ; Saved column(s) are stored in QH.  Lines (rows) are separated by hard
  28. ; NLs (^J, 10 decimal).
  29. ;
  30. ;----------------------------------------------
  31. ; Q register usage:
  32. ;    Q0 Anything that requires a filename, and result of some macros
  33. ;    Q1 Anything that requires a filename
  34. ;    Q2 Search string, string to replace
  35. ;    Q3 String to replace with
  36. ;    Q4 Environment modify stuff, and formatter commands
  37. ;    Q5 DOS commands and formatter calls
  38. ;    Q6 DOS commands and formatter calls
  39. ;    Q7 Environment names and style dimensions
  40. ;    Q8 used for getting text for footnotes and formatter commands
  41. ;    Q9 used by help system
  42. ;    QA used by glossary; holds current glossary Name
  43. ;    QB used by glossary; holds glossary
  44. ;    QC used by glossary; scratch
  45. ;    QD scratch
  46. ;    QE used by spelling checker; holds bad word stack
  47. ;    QF used to collect keystrokes for replay
  48. ;    QG reserved by WordPerfect
  49. ;    QH used by column
  50. ;    QI Used for macro entry
  51. ;    QJ Holds current Speller engine params
  52. ;    QK Holds a record containing Sprintmerge info.
  53. ;    QL reserved
  54. ;    QM reserved
  55. ;    QN scratch
  56. ;    QO scratch
  57. ;    QP scratch
  58. ;-------------------------------------------===
  59. ;    NUMBERED MARK USAGE:
  60. ;    0-9    used as place markers
  61. ;    A    Marks block beginning
  62. ;    B    Marks block ending
  63. ;    C    marks last find Block position or deletion
  64. ;    D    marks position before certain commands. (^Q)
  65. ;    E    not used
  66. ;    F    not used
  67. ;----------------------------------------------
  68. ;    CONTENTS:
  69. ;    SECTION:  Routines whose definitions are to be removed.
  70. ;    SECTION:    Routines that MUST exist for the compiler to work
  71. ;    SECTION:    Variables -- all the variables are declared here
  72. ;    SECTION:    Forward declarations -- In order to keep the main list
  73. ;            of macros in alphabetical order, a few of them have to be
  74. ;            declared ahead of time -- like a FORWARD declaration
  75. ;            in Pascal
  76. ;    SECTION:    Automatically-called macro definitions (Main, Init,
  77. ;            EditKeys, MacroKeys, etc.)
  78. ;    SECTION:    General and command macros in alphabetical order
  79. ;    SECTION:    Menus (leaves first, root last)
  80. ;    SECTION:    Control and function keys
  81. ; -----------------------------------------------------------------
  82. ; Deletions
  83.  
  84. ; -----------------------------------------------------------------
  85. ; Compiler-Required Definitions
  86.  
  87. ; -----------------------------------------------------------------
  88. ; Variables
  89.  
  90. #define ColC1    ; for column of UL corner
  91. #define ColC2    ; for column of LR corner
  92. #define ColR1    ; for Row (line) of UL Corner
  93. #define ColR2    ; for Row (line) of LR Corner
  94.  
  95. #define ColSaveRaw
  96. #define ColTmp
  97.  
  98. ; -----------------------------------------------------------------
  99. ; Forward Declarations
  100.  
  101. ColInQH :
  102. ColRegionFix :
  103. ColRegionFixNoMod :
  104.  
  105. ; -----------------------------------------------------------------
  106. ; Automatically-Called Macro Definitions
  107.  
  108. ; -----------------------------------------------------------------
  109. ; General Macros
  110.  
  111. ; Get the column's boundaries (corners).
  112.  
  113. ColBounds :
  114.     dcolumn->ColC1 line->ColR1 togmark column->ColC2 line->ColR2
  115.     if (ColC1 > ColC2) (ColC2 (ColC1->ColC2 $)->ColC1)    ; get (ColR1,ColC1)
  116.     if (ColR1 > ColR2) (ColR2 (ColR1->ColR2 $)->ColR1)    ; to upper left
  117.     ColC1->column ColR1->line
  118.     0->append
  119.  
  120. ColCopy :
  121.     mark    {
  122.         ColBounds
  123.         if ((ColR2 - ColR1) > 10) status "\nWorking..."
  124.         ColC1->column
  125.         set markF                        ; for undeletes
  126.         if (ColC1 = ColC2) abort            ; no column marked
  127.         set QH ""
  128.         while (line <= ColR2 && !isend) {    ; for each line of the column
  129.             ColC1->column                ; go to left end of column
  130.             ColRegionFixNoMod
  131.             copy tomark            ; copy the column to kills buffer
  132.             ColInQH
  133.             toeol c                ; go to next line
  134.             }
  135.         }
  136.     Unselect
  137.  
  138. ; Copy a column to colbuf and then erase it.
  139. ColDelete :
  140.     mark    {
  141.         ColBounds
  142.         if ((ColR2 - ColR1) > 10) status "\nWorking..."
  143.         ColC1->column
  144.         set markF                        ; for undeletes
  145.         if (ColC1 = ColC2) abort            ; no column marked
  146.         set QH ""
  147.         while (line <= ColR2 && !isend) {    ; for each line of the column
  148.             if !inruler {
  149.                 ColC1->column                ; go to left end of column
  150.                 ColRegionFix
  151.                 delete tomark                ; copy the column to kills buffer
  152.                 curatt->DelAtt
  153.                 ColInQH
  154.                 }
  155.             toeol c                    ; go to next line
  156.             }
  157.         }
  158.     Unselect
  159.  
  160.  
  161. ; "Detabify":  Expands tabs to the appropriate numbers of spaces in
  162. ; the regular -- not just column -- region.
  163.  
  164. ColDetab :
  165.     if select {
  166.         markregion {
  167.             raw->ColSaveRaw
  168.             0->raw
  169.             while (to (current = '^I' || current = '^F') && !aftermark) {
  170.                 if (current = '^I') {
  171.                     column->ColTmp
  172.                     past (current = '^I')
  173.                     column - ColTmp (erase r past (current = '^I') $)
  174.                         repeat (' ' insert)
  175.                     }
  176.                 else {
  177.                     column->ColTmp
  178.                     past (current = '^F')
  179.                     column - ColTmp (erase r past (current = '^F') $)
  180.                         repeat (' ' insert)
  181.                     }
  182.                 }
  183.             ColSaveRaw->raw
  184.             }
  185.         }
  186.     else    NoBlock
  187.  
  188.  
  189. ; Erase a column (not saved).
  190.  
  191. ColErase :
  192.     mark    {
  193.         ColBounds
  194.         if ((ColR2 - ColR1) > 10) status "\nWorking..."
  195.         if (ColC1 = ColC2) abort                ; if no column marked
  196.         while (line <= ColR2 && !isend) {        ; row by row
  197.             ColC1->column                    ; remove the column width
  198.             ColRegionFix
  199.             erase tomark            ; copy the column to kills buffer
  200.             toeol c
  201.             }
  202.         }
  203.     Unselect
  204.  
  205.  
  206. ColRegionFix :
  207.     int n
  208.     f past isclose        ; don't include leading close delimiters
  209.     r past isopen        ; include all leading open delimiters
  210.     curatt->n
  211.     setmark            ; Set new position (of the left side)
  212.     ColC2->column        ; go to the other side (right) of the column
  213.     if column<ColC1 { 0 return }
  214.     r past isopen        ; don't include trailing open delimiters
  215.     f past isclose        ; include all trailing close delimiters
  216.     if (n > curatt) {    ; add close/opens around start of region
  217.         curatt->n
  218.         swapmark        ; return on the left side (and save right side pos.)
  219.         n->curatt
  220.         1
  221.         }
  222.     else {
  223.         if (n < curatt) (n->curatt) ; add close/opens around end of region
  224.         swapmark
  225.         1
  226.         }
  227.  
  228. ColRegionFixNoMod :
  229.     f past isclose
  230.     r past isopen
  231.     curatt->DelAtt
  232.     setmark
  233.     ColC2->column
  234.     r past isopen
  235.     f past isclose
  236.     swapmark
  237.  
  238. ; Copy a column to QH.
  239.  
  240. ColInQH :
  241.     mark {                    ; move column 'slice' to end of QH
  242.         to QH
  243.         f toend
  244.         DelAtt+32 insert        ; insert attribute value
  245.         undelete
  246.         '^J' insert
  247.         }
  248.  
  249. ; Insert the column currently in colbuf at the current cursor position
  250.  
  251. ColInsert :
  252.     1->ColTmp
  253.     column->int InsColumn            ; column to insert at
  254.     mark    {
  255.         1->int x                    ; 'index' to line in column buffer
  256.         if ((ColR2 - ColR1) > 10) status "\nWorking..."
  257.         ColR2-ColR1 + 1            ; number of lines to insert
  258.         repeat {                    ; repeat loop
  259.             if !inruler {
  260.                 InsColumn->column        ; where text is to be inserted
  261.                 f past isclose
  262.                 mark {
  263.                     to QH
  264.                     x->line
  265.                     if isend break
  266.                     current-32->DelAtt c; Get line attribute
  267.                     copy toeol        ; get text in kills buffer
  268.                     ++x                ; next time, next line
  269.                     }
  270.                 DelAtt->curatt            ; Restore current attribute
  271.                 undelete                ; insert text
  272.                 }
  273.             toeol                ; next line in file
  274.             if isend ('^J' insert)
  275.             else c
  276.             }
  277.         }
  278.  
  279.  
  280. ; Insert a column of tabs at the left edge of the region.
  281.  
  282. ColInsTab :
  283.     mark    {
  284.         ColBounds
  285.         while (line <= ColR2) {
  286.             ColC1->column
  287.             '^I' insert
  288.             ++line
  289.             }
  290.         }
  291.     f c
  292.  
  293.  
  294. ColSDelete :        ; Special ColDelete for sort
  295.                 ; Do not store curatt in QH
  296.     mark    {
  297.         ColBounds
  298.         if ((ColR2 - ColR1) > 10) status "\nWorking..."
  299.         ColC1->column
  300.         set markF                        ; for undeletes
  301.         if (ColC1 = ColC2) abort            ; no column marked
  302.         set QH ""
  303.         while (line <= ColR2 && !isend) {    ; for each line of the column
  304.             if !inruler {
  305.                 ColC1->column                ; go to left end of column
  306.                 ColRegionFix
  307.                 delete tomark                ; copy the column to kills buffer
  308.                 -31->DelAtt
  309.                 ColInQH
  310.                 }
  311.             toeol c                    ; go to next line
  312.             }
  313.         }
  314.     Unselect
  315.  
  316. ColSetOneEnd : setmark 2->select
  317.  
  318.  
  319. ; "Tabify":  Reduce all multiple spaces to tabs and delete trailing
  320. ; whitespace in the regular -- not just column -- region.
  321.  
  322. ColTab :
  323.     if select {
  324.         markregion {
  325.             raw->ColSaveRaw
  326.             0->raw
  327.             while ((to isgray) && !aftermark) {    ; was !to isgray
  328.                 if isnl {
  329.                     erase r past iswhite
  330.                     f c
  331.                     }
  332.                 else    {
  333.                     column->ColTmp
  334.                     past iswhite
  335.                     if (column > ColTmp + 1) {
  336.                         column (erase r past iswhite $) TabIndent
  337.                         }
  338.                     }
  339.                 }
  340.             ColSaveRaw->raw
  341.             }    ;else (swapmark ColTab swapmark)
  342.         }        ; can't figure out what this if here for where's the if?
  343.     else    NoBlock
  344.  
  345. ; -----------------------------------------------------------------
  346. ; Menus
  347.  
  348. ColMenu :
  349.     menu "Columns" {
  350.     "Set one end"            ColSetOneEnd,
  351.     "Copy to clipboard"        ColCopy,
  352.     "Move to clipboard"        ColDelete,
  353.     "Paste from clipboard"    ColInsert,
  354.     "Erase (not saved)"        ColErase,
  355.     "Go to other end"        swapmark,
  356.     "Unselect"            Unselect,
  357.     "Reselect"            2->select,
  358.     "Insert column"        ColInsTab,
  359.     "Tabs to spaces"        status "Expanding tabs to spaces..." ColDetab,
  360.     "X-spaces to tabs"        status "Reducing spaces to tabs..." ColTab
  361.         }
  362.  
  363. ; -----------------------------------------------------------------
  364. ; Control and Function Keys
  365.