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];
};