TEditMesaOpsImpl.mesa
Copyright Ó 1985, 1986, 1989, 1991, 1992 by Xerox Corporation. All rights reserved.
Note: much of this module moved to TiogaMesaOpsImpl
Paxton on November 10, 1982 7:33 am
Maxwell, January 14, 1983 9:41 am
Russ Atkinson, September 27, 1983 6:42 pm
Michael Plass, October 28, 1986 11:33:12 am PST
Rick Beach, October 31, 1986 10:07:44 am PST
Doug Wyatt, February 27, 1992 7:09 pm PST
DIRECTORY
Convert USING [AppendInt],
MessageWindow USING [Append],
NodeAddrs USING [GetTextAddr, PutTextAddr, RemTextAddr],
RefText USING [AppendRope],
Rope USING [FromRefText, ROPE],
TEditDocument USING [Selection],
TEditInput USING [CommandProc, currentEvent, Register],
TEditInputOps USING [CallWithLocks],
TEditLocks USING [Lock, Unlock],
TEditMesaOps USING [],
TEditSelection USING [MakeSelection, pSel, SetSelLooks],
TextNode USING [EndPos, Root],
Tioga USING [Node, NodeItself, Span, Event],
TiogaMesaOps USING [SpanMesaLooks];
TEditMesaOpsImpl: CEDAR PROGRAM
IMPORTS Convert, MessageWindow, NodeAddrs, RefText, Rope, TEditInput, TEditInputOps, TEditLocks, TEditSelection, TextNode, TiogaMesaOps
EXPORTS TEditMesaOps
= BEGIN
ROPE: TYPE = Rope.ROPE;
SetSpanMesaLooks: PUBLIC PROC [span: Tioga.Span, event: Tioga.Event] RETURNS [procs, comments, keywords: INT] = {
root: Tioga.Node = TextNode.Root[span.start.node];
[] ¬ TEditLocks.Lock[root, "SetSpanMesaLooks"];
[[procs: procs, comments: comments, keywords: keywords]] ¬ TiogaMesaOps.SpanMesaLooks[root, span, event];
TEditLocks.Unlock[root];
};
SetMesaLooksOp: PUBLIC TEditInput.CommandProc = {
-- scan selection looking for Mesa keywords and comments
-- set the keywords look k
-- set the comments look c
-- set procedure names look n
procs, comments, keywords: INT ¬ 0;
msg: REF TEXT ¬ NEW[TEXT[40]];
Append: PROC [value: INT, what: ROPE, dlm: ROPE] ~ {
msg ¬ Convert.AppendInt[msg, value];
msg ¬ RefText.AppendRope[msg, what];
IF value # 1 THEN msg ¬ RefText.AppendRope[msg, "s"];
msg ¬ RefText.AppendRope[msg, dlm];
};
DoSet: PROC [root: Tioga.Node, tSel: TEditDocument.Selection] = {
span: Tioga.Span ¬ [tSel.start.pos, tSel.end.pos];
firstText: Tioga.Node ~ tSel.start.pos.node;
lastText: Tioga.Node ~ tSel.end.pos.node;
IF firstText # NIL THEN NodeAddrs.PutTextAddr[firstText, $Start, tSel.start.pos.where];
IF lastText # NIL THEN NodeAddrs.PutTextAddr[lastText, $End, tSel.end.pos.where+1];
IF tSel.granularity=point OR (tSel.granularity=char AND tSel.start.pos=tSel.end.pos) THEN {
do the entire node
span.start.where ¬ 0;
span.end.where ¬ TextNode.EndPos[span.end.node] };
[procs, comments, keywords] ¬ SetSpanMesaLooks[span, TEditInput.currentEvent];
tSel.start.pos ¬ [firstText,
IF firstText=NIL THEN Tioga.NodeItself
ELSE NodeAddrs.GetTextAddr[firstText,$Start].location];
tSel.end.pos ¬ [lastText,
IF lastText=NIL
THEN Tioga.NodeItself
ELSE MAX[NodeAddrs.GetTextAddr[lastText, $End].location, 1] - 1
];
IF firstText#NIL THEN NodeAddrs.RemTextAddr[firstText, $Start];
IF lastText#NIL THEN NodeAddrs.RemTextAddr[lastText, $End];
TEditSelection.MakeSelection[new: tSel];
TEditSelection.SetSelLooks[TEditSelection.pSel];
};
TEditInputOps.CallWithLocks[DoSet];
Append[keywords, " keyword", ", "];
Append[comments, " comment", ", "];
Append[procs, " procedure name", "."];
MessageWindow.Append[Rope.FromRefText[msg], TRUE];
};
TEditInput.Register[$SetMesaLooks, SetMesaLooksOp, FALSE];
END.