TextEdit.mesa
Copyright Ó 1985, 1986, 1991, 1992 by Xerox Corporation. All rights reserved.
written by Bill Paxton, February 1981
last edit by Bill Paxton, April 23, 1982 6:14 am
last edit by Russ Atkinson, July 22, 1983 9:51 am
Michael Plass, April 1, 1985 4:05:55 pm PST
Doug Wyatt, February 27, 1992 12:49 pm PST
This package provides editing, filing, and various other operations for text nodes
Overview:
a text node contains a rope and runs of looks
looks are represented by a vector of 32 bits
each character in a text node has looks vector associated with it
run encoding is used to reduce the storage needed to represent the looks
see Tioga.mesa for more details about node structure and looks
Text editing
operations are provided to edit the contents of text nodes
unlike ropes or runs of looks, text nodes are mutable
i.e., the edit changes the node rather than returning a new node
the looks related command is
ChangeLooks
the text related commands are
ReplaceText, DeleteText, CopyText, MoveText, MoveTextOnto, TransposeText
in addition there is a command taking a rope as source
ReplaceByRope
a command is available for changing capitalization
ChangeCaps
Persistent addresses in text of a node
You can associate an address with a character location in a text node
the address persists with the same character even if the text is edited
the address is an arbitrary REF ANY supplied by the client program
see NodeAddrs.Mesa for the persistent addressing operations
Property lists
Each node includes a property list of key-value pairs
The keys are ATOMs and the values are arbitrary REF ANYs
Clients can register routines to read/write properties to files
and to copy property values when nodes are copied
see NodeProps.Mesa for the property list operations
Character property lists
Each character may include a property list of key-value pairs
The keys are ATOMs and the values are arbitrary REF ANYs
Filing
There are operations to read and write files containing text nodes
The characters go at the front of the file, followed by 0's
then the information about looks, etc.
and finally a password and a pointer to the end of the text.
Thus programs that simply want to look at the characters can read up to 0's
operations to read/write nodes to files are found in PutGet.Mesa
Edit notification procedures
Client's can register procedures to be called before/after edits
the client procedure is called with the node(s) changed by the edit
and a record describing the details of the edit
see EditNotify.Mesa for more information
Tree editing
nodes can have children
there is a set of tree editing operations available
see EditSpan.Mesa for details
DIRECTORY
Char USING [XCHAR],
Rope USING [ROPE],
Rosary USING [ROSARY, Item],
Tioga USING [allLooks, CapChange, CharSet, Event, Looks, Node, noLooks, PropList];
TextEdit: CEDAR DEFINITIONS ~ BEGIN
Node: TYPE ~ Tioga.Node;
ROPE: TYPE ~ Rope.ROPE;
ROSARY: TYPE ~ Rosary.ROSARY;
XCHAR: TYPE ~ Char.XCHAR;
CharSet: TYPE ~ Tioga.CharSet;
Looks: TYPE ~ Tioga.Looks;
noLooks: Looks ~ Tioga.noLooks;
allLooks: Looks ~ Tioga.allLooks;
PropList: TYPE ~ Tioga.PropList;
MaxLen: INT ~ LAST[INT];
MaxNat: NAT ~ LAST[NAT];
Event: TYPE ~ Tioga.Event;
Ref: TYPE ~ Node; -- for compatibility
RefTextNode: TYPE ~ Node; -- for compatibility
Offset: TYPE ~ INT; -- for compatibility
General operations
FetchChar: PROC [text: Node, index: INT] RETURNS [XCHAR];
fetches the indexed character
FetchLooks: PROC [text: Node, index: INT] RETURNS [Looks];
returns the looks for the character at the given location
Size: PROC [text: Node] RETURNS [INT];
Private details of node contents
Item: TYPE ~ Rosary.Item;
ItemFromLooks: PROC [Looks] RETURNS [Item];
LooksFromItem: PROC [Item] RETURNS [Looks];
ItemFromCharSet: PROC [CharSet] RETURNS [Item];
CharSetFromItem: PROC [Item] RETURNS [CharSet];
ItemFromPropList: PROC [PropList] RETURNS [Item];
PropListFromItem: PROC [Item] RETURNS [PropList];
Operations to create a text node
FromRope: PROC [rope: ROPE] RETURNS [Node];
create a text node from an ordinary rope
DocFromNode: PROC [child: Node] RETURNS [root: Node];
returns root node which has one child
child typically created by FromRope or FromString
Operations to add or delete looks
ChangeLooks: PROC [root: Node, text: Node, remove, add: Looks ¬ noLooks,
start: INT ¬ 0, len: INT ¬ MaxLen, event: Event ¬ NIL];
first remove then add in the given range
Character Properties
GetCharProp: PROC [node: Node, index: INT, name: ATOM] RETURNS [value: REF];
PutCharProp: PROC [node: Node, index: INT, name: ATOM, value: REF,
nChars: INT ¬ 1, event: Event ¬ NIL, root: Node ¬ NIL];
Places the value on the character property lists of the chars in the specified range.
Use value = NIL to remove a character property.
GetCharPropList: PROC [node: Node, index: INT] RETURNS [PropList];
PutCharPropList: PROC [node: Node, index: INT, propList: PropList,
nChars: INT ¬ 1, event: Event ¬ NIL, root: Node ¬ NIL];
Replaces the character property lists of the chars in the specified range.
MapPropsAction: TYPE ~ PROC [name: ATOM, value: REF] RETURNS [quit: BOOL ¬ FALSE];
MapCharProps: PROC [node: Node, index: INT, action: MapPropsAction] RETURNS [quit: BOOL];
Used for traversing all the properites attached to a particular character.
ModifyPropsAction: TYPE ~ PROC [value: REF, index: INT, nChars: INT]
RETURNS
[quit: BOOL ¬ FALSE, newValue: REF];
ModifyCharProps: PROC [node: Node, name: ATOM, index: INT ¬ 0, nChars: INT ¬ INT.LAST, action: ModifyPropsAction, event: Event ¬ NIL, root: Node ¬ NIL] RETURNS [quit: BOOL];
Used for traversing and altering the values of a character property over a range of characters; the action procedure is called for runs of properties, but adjacent runs are not necessarily merged.
GetPropFromList: PROC [propList: PropList, key: ATOM] RETURNS [value: REF];
PutPropOnList: PROC [propList: PropList, key: ATOM, value: REF] RETURNS [new: PropList];
Equivalent to Prop.Get, Prop.Put; retained here only for compatibility.
Node Properties
GetProp: PROC [node: Node, name: ATOM] RETURNS [value: REF];
PutProp: PROC [node: Node, name: ATOM, value: REF, event: Event ¬ NIL];
GetFormat: PROC [node: Node] RETURNS [ATOM];
PutFormat: PROC [node: Node, format: ATOM, event: Event ¬ NIL];
GetComment: PROC [node: Node] RETURNS [BOOL];
PutComment: PROC [node: Node, comment: BOOL, event: Event ¬ NIL];
ChangeStyle: PROC [node: Node, name: ROPE, event: Event ¬ NIL];
appends <name> style to end of node prefix
Editing Operations for text
NOTE: edit operations do not create or delete addrs,
but they can change their locations within the text
TwoSpanProc: TYPE ~ PROC [destRoot, sourceRoot: Node,
dest: Node, destStart: INT ¬ 0, destLen: INT ¬ MaxLen,
source: Node, sourceStart: INT ¬ 0, sourceLen: INT ¬ MaxLen,
event: Event ¬ NIL] RETURNS [resultStart, resultLen: INT];
DestSpanProc: TYPE ~ PROC [destRoot, sourceRoot: Node,
dest: Node, destLoc: INT ¬ 0,
source: Node, start: INT ¬ 0, len: INT ¬ MaxLen,
event: Event ¬ NIL] RETURNS [resultStart, resultLen: INT];
OneSpanProc: TYPE ~ PROC [root: Node,
text: Node, start: INT ¬ 0, len: INT ¬ MaxLen,
event: Event ¬ NIL];
TransposeProc: TYPE ~ PROC [alphaRoot, betaRoot: Node,
alpha: Node, alphaStart: INT ¬ 0, alphaLen: INT ¬ MaxLen,
beta: Node, betaStart: INT ¬ 0, betaLen: INT ¬ MaxLen,
event: Event ¬ NIL
] RETURNS [alphaResultStart, alphaResultLen, betaResultStart, betaResultLen: INT];
ReplaceText: TwoSpanProc;
replace the dest text by a copy of the source text
addrs that are in the replaced text move to destStart
addrs that are after the replaced text are adjusted
DeleteText: OneSpanProc;
delete the specified range of text
addrs that are in the deleted section move to start
CopyText: DestSpanProc;
copy the specified text
add length of inserted text to addrs that are beyond destLoc
MoveText: DestSpanProc;
move [start..start+len) in source to destLoc in dest
no-op if dest=source and destLoc IN [start..start+len]
addrs that are in the moved text do one of the following:
move with the text if dest = source,
or move to start if dest # source
MoveTextOnto: TwoSpanProc;
move [start..start+len) onto [destStart..destStart+destLen)
implemented by appropriate calls on MoveText and DeleteText
TransposeText: TransposeProc;
transpose the alpha text and the beta text
addrs treated same as in Move
move with the text if alpha = beta,
or move to respective starts if alpha # beta
ReplaceByRope: PROC [root: Node, dest: Node, start: INT ¬ 0, len: INT ¬ MaxLen,
rope: ROPE, looks: Looks ¬ noLooks, charSet: CharSet ¬ 0, charProps: PropList ¬ NIL,
event: Event ¬ NIL] RETURNS [resultStart, resultLen: INT];
all chars in the rope get the specifed looks, charSet and charProps
ReplaceByContents: PROC [root: Node, dest: Node, destStart, destLen: INT,
sourceRope: ROPE, sourceRuns, sourceCharSets, sourceCharProps: ROSARY,
sourceStart, sourceLen: INT, event: Event ¬ NIL] RETURNS [resultStart, resultLen: INT];
replace with the specified rope and rosaries
Caps and Lowercase
ModifyCharsAction: TYPE ~ PROC [set: CharSet, char: CHAR] RETURNS [CHAR];
Note that this can only modify the 8-bit CHAR, not the CharSet.
ModifyChars: PROC [root: Node, dest: Node, start: INT ¬ 0, len: INT ¬ MaxLen,
action: ModifyCharsAction, event: Event ¬ NIL];
General purpose routine for modifying a run of characters. ChangeCaps uses this.
CapChange: TYPE ~ Tioga.CapChange; -- {allCaps, allLower, initCaps, firstCap}
ChangeCaps: PROC [root: Node, dest: Node, start: INT ¬ 0, len: INT ¬ MaxLen,
how: CapChange ¬ allCaps, event: Event ¬ NIL];
Newline Delimiter
GetNewlineDelimiter: PROC [root: Node] RETURNS [ROPE];
PutNewlineDelimiter: PROC [root: Node, val: ROPE, event: Event ¬ NIL];
END.