home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR4
/
TEXMAC.ZIP
/
COLUMN.SPM
< prev
next >
Wrap
Text File
|
1990-12-24
|
10KB
|
365 lines
; Copyright (c) 1988 Borland International. All Rights Reserved
;
; NAME: COLUMN.SPM
; VERSION: 1.01
; DESCRIPTION: Column Macro Package for Sprint
; LAST UPDATE: 21 March, 1988
;
; NOTES: This file must be compiled and loaded AFTER the CORE.SPM package.
;
; This package provides a number of functions used for manipulating
; columns. You can use them to copy, insert, delete, erase, and perform
; other operations.
; This package defines a column as all characters that START within
; the specified range (a la Microsoft Word). No conversions are made
; between spaces and tabs. This choice makes the operations
; predictable, although the horizontal spacing might be a bit strange
; if you copy from one set of tab stops (or horizontal position) to
; another.
;
; (The alternate method -- "transparently" converting tabs to spaces
; and thereby preserving horizontal relationships -- has a different
; set of trade offs, and results in much larger (and slower) macros.
; It can be readily emulated by converting tabs to spaces, performing
; the column operations, and converting the spaces back to tabs.)
;
; Saved column(s) are stored in QH. Lines (rows) are separated by hard
; NLs (^J, 10 decimal).
;
;----------------------------------------------
; Q register usage:
; Q0 Anything that requires a filename, and result of some macros
; Q1 Anything that requires a filename
; Q2 Search string, string to replace
; Q3 String to replace with
; Q4 Environment modify stuff, and formatter commands
; Q5 DOS commands and formatter calls
; Q6 DOS commands and formatter calls
; Q7 Environment names and style dimensions
; Q8 used for getting text for footnotes and formatter commands
; Q9 used by help system
; QA used by glossary; holds current glossary Name
; QB used by glossary; holds glossary
; QC used by glossary; scratch
; QD scratch
; QE used by spelling checker; holds bad word stack
; QF used to collect keystrokes for replay
; QG reserved by WordPerfect
; QH used by column
; QI Used for macro entry
; QJ Holds current Speller engine params
; QK Holds a record containing Sprintmerge info.
; QL reserved
; QM reserved
; QN scratch
; QO scratch
; QP scratch
;-------------------------------------------===
; NUMBERED MARK USAGE:
; 0-9 used as place markers
; A Marks block beginning
; B Marks block ending
; C marks last find Block position or deletion
; D marks position before certain commands. (^Q)
; E not used
; F not used
;----------------------------------------------
; CONTENTS:
; SECTION: Routines whose definitions are to be removed.
; SECTION: Routines that MUST exist for the compiler to work
; SECTION: Variables -- all the variables are declared here
; SECTION: Forward declarations -- In order to keep the main list
; of macros in alphabetical order, a few of them have to be
; declared ahead of time -- like a FORWARD declaration
; in Pascal
; SECTION: Automatically-called macro definitions (Main, Init,
; EditKeys, MacroKeys, etc.)
; SECTION: General and command macros in alphabetical order
; SECTION: Menus (leaves first, root last)
; SECTION: Control and function keys
; -----------------------------------------------------------------
; Deletions
; -----------------------------------------------------------------
; Compiler-Required Definitions
; -----------------------------------------------------------------
; Variables
#define ColC1 ; for column of UL corner
#define ColC2 ; for column of LR corner
#define ColR1 ; for Row (line) of UL Corner
#define ColR2 ; for Row (line) of LR Corner
#define ColSaveRaw
#define ColTmp
; -----------------------------------------------------------------
; Forward Declarations
ColInQH :
ColRegionFix :
ColRegionFixNoMod :
; -----------------------------------------------------------------
; Automatically-Called Macro Definitions
; -----------------------------------------------------------------
; General Macros
; Get the column's boundaries (corners).
ColBounds :
dcolumn->ColC1 line->ColR1 togmark column->ColC2 line->ColR2
if (ColC1 > ColC2) (ColC2 (ColC1->ColC2 $)->ColC1) ; get (ColR1,ColC1)
if (ColR1 > ColR2) (ColR2 (ColR1->ColR2 $)->ColR1) ; to upper left
ColC1->column ColR1->line
0->append
ColCopy :
mark {
ColBounds
if ((ColR2 - ColR1) > 10) status "\nWorking..."
ColC1->column
set markF ; for undeletes
if (ColC1 = ColC2) abort ; no column marked
set QH ""
while (line <= ColR2 && !isend) { ; for each line of the column
ColC1->column ; go to left end of column
ColRegionFixNoMod
copy tomark ; copy the column to kills buffer
ColInQH
toeol c ; go to next line
}
}
Unselect
; Copy a column to colbuf and then erase it.
ColDelete :
mark {
ColBounds
if ((ColR2 - ColR1) > 10) status "\nWorking..."
ColC1->column
set markF ; for undeletes
if (ColC1 = ColC2) abort ; no column marked
set QH ""
while (line <= ColR2 && !isend) { ; for each line of the column
if !inruler {
ColC1->column ; go to left end of column
ColRegionFix
delete tomark ; copy the column to kills buffer
curatt->DelAtt
ColInQH
}
toeol c ; go to next line
}
}
Unselect
; "Detabify": Expands tabs to the appropriate numbers of spaces in
; the regular -- not just column -- region.
ColDetab :
if select {
markregion {
raw->ColSaveRaw
0->raw
while (to (current = '^I' || current = '^F') && !aftermark) {
if (current = '^I') {
column->ColTmp
past (current = '^I')
column - ColTmp (erase r past (current = '^I') $)
repeat (' ' insert)
}
else {
column->ColTmp
past (current = '^F')
column - ColTmp (erase r past (current = '^F') $)
repeat (' ' insert)
}
}
ColSaveRaw->raw
}
}
else NoBlock
; Erase a column (not saved).
ColErase :
mark {
ColBounds
if ((ColR2 - ColR1) > 10) status "\nWorking..."
if (ColC1 = ColC2) abort ; if no column marked
while (line <= ColR2 && !isend) { ; row by row
ColC1->column ; remove the column width
ColRegionFix
erase tomark ; copy the column to kills buffer
toeol c
}
}
Unselect
ColRegionFix :
int n
f past isclose ; don't include leading close delimiters
r past isopen ; include all leading open delimiters
curatt->n
setmark ; Set new position (of the left side)
ColC2->column ; go to the other side (right) of the column
if column<ColC1 { 0 return }
r past isopen ; don't include trailing open delimiters
f past isclose ; include all trailing close delimiters
if (n > curatt) { ; add close/opens around start of region
curatt->n
swapmark ; return on the left side (and save right side pos.)
n->curatt
1
}
else {
if (n < curatt) (n->curatt) ; add close/opens around end of region
swapmark
1
}
ColRegionFixNoMod :
f past isclose
r past isopen
curatt->DelAtt
setmark
ColC2->column
r past isopen
f past isclose
swapmark
; Copy a column to QH.
ColInQH :
mark { ; move column 'slice' to end of QH
to QH
f toend
DelAtt+32 insert ; insert attribute value
undelete
'^J' insert
}
; Insert the column currently in colbuf at the current cursor position
ColInsert :
1->ColTmp
column->int InsColumn ; column to insert at
mark {
1->int x ; 'index' to line in column buffer
if ((ColR2 - ColR1) > 10) status "\nWorking..."
ColR2-ColR1 + 1 ; number of lines to insert
repeat { ; repeat loop
if !inruler {
InsColumn->column ; where text is to be inserted
f past isclose
mark {
to QH
x->line
if isend break
current-32->DelAtt c; Get line attribute
copy toeol ; get text in kills buffer
++x ; next time, next line
}
DelAtt->curatt ; Restore current attribute
undelete ; insert text
}
toeol ; next line in file
if isend ('^J' insert)
else c
}
}
; Insert a column of tabs at the left edge of the region.
ColInsTab :
mark {
ColBounds
while (line <= ColR2) {
ColC1->column
'^I' insert
++line
}
}
f c
ColSDelete : ; Special ColDelete for sort
; Do not store curatt in QH
mark {
ColBounds
if ((ColR2 - ColR1) > 10) status "\nWorking..."
ColC1->column
set markF ; for undeletes
if (ColC1 = ColC2) abort ; no column marked
set QH ""
while (line <= ColR2 && !isend) { ; for each line of the column
if !inruler {
ColC1->column ; go to left end of column
ColRegionFix
delete tomark ; copy the column to kills buffer
-31->DelAtt
ColInQH
}
toeol c ; go to next line
}
}
Unselect
ColSetOneEnd : setmark 2->select
; "Tabify": Reduce all multiple spaces to tabs and delete trailing
; whitespace in the regular -- not just column -- region.
ColTab :
if select {
markregion {
raw->ColSaveRaw
0->raw
while ((to isgray) && !aftermark) { ; was !to isgray
if isnl {
erase r past iswhite
f c
}
else {
column->ColTmp
past iswhite
if (column > ColTmp + 1) {
column (erase r past iswhite $) TabIndent
}
}
}
ColSaveRaw->raw
} ;else (swapmark ColTab swapmark)
} ; can't figure out what this if here for where's the if?
else NoBlock
; -----------------------------------------------------------------
; Menus
ColMenu :
menu "Columns" {
"Set one end" ColSetOneEnd,
"Copy to clipboard" ColCopy,
"Move to clipboard" ColDelete,
"Paste from clipboard" ColInsert,
"Erase (not saved)" ColErase,
"Go to other end" swapmark,
"Unselect" Unselect,
"Reselect" 2->select,
"Insert column" ColInsTab,
"Tabs to spaces" status "Expanding tabs to spaces..." ColDetab,
"X-spaces to tabs" status "Reducing spaces to tabs..." ColTab
}
; -----------------------------------------------------------------
; Control and Function Keys