-- file: EditorMisc.Mesa
-- edited by Brotz, March 3, 1983 5:36 PM

DIRECTORY
Ascii USING [ControlA, ControlB, DEL],
DMSTimeDefs USING [MapPackedTimeToTimeZoneString, timeStringLength],
dsD: FROM "DisplayDefs" USING [lineHeight],
Editor USING [cancelCode, DeUnderlineSelection, InitializeSelection, ResetBuffers,
TurnOnDeliver, UpdateScreen],
exD: FROM "ExceptionDefs" USING [AppendExceptionString, ClearExceptionsRegion,
commandsAre, DisplayBothExceptionLines, GetExceptionString, nil, pressToContinue,
unrecCommand],
inD: FROM "InteractorDefs" USING [AdjustBoundaries, CharIndex, IdleLoop,
MessageTextNbrPtr, TextNbrSizes, TextSelection, TextSelectionPtr],
intCommon USING [actionPoint, boundarySet, cmTextNbr, commandType, dmTextNbr,
editorType, keystream, newTargetSelection, target, TOCCommandRegion, TOCRegion,
tocTextNbr],
TimeDefs USING [CurrentDayTime],
vmD: FROM "VirtualMgrDefs" USING [CharIndex, ComposedMessage, ComposedMessagePtr,
DeleteRangeInMessage, GetMessageSize, InsertMessageChar, InsertRangeInMessage,
InsertSubstringInMessage, MessageRange, StartMessageInsertion, StopMessageInsertion];

EditorMisc: PROGRAM
IMPORTS DMSTimeDefs, Editor, exD, inD, intC: intCommon, TimeDefs, vmD
EXPORTS Editor =

BEGIN
OPEN Editor, inD;


TCommand: PUBLIC PROCEDURE [mnp: MessageTextNbrPtr] =
BEGIN
target: TextSelectionPtr = @intC.target;
modelessEditor: BOOLEAN = (intC.editorType = modeless);
timeString: STRING ← [DMSTimeDefs.timeStringLength];
start: CharIndex ← IF modelessEditor THEN target.point ELSE target.start;
targetIndex, end: CharIndex;
deletedChars: CARDINAL ← 0;
composedMessage: vmD.ComposedMessagePtr = vmD.ComposedMessage[mnp.message];
IF ~modelessEditor OR intC.newTargetSelection THEN
BEGIN
ResetBuffers[mnp];
targetIndex ← 0;
IF modelessEditor AND target.pendingDelete THEN
BEGIN
start ← target.start;
vmD.InsertRangeInMessage[targetIndex: 0, targetMessage: mnp.deletionBuffer,
from: vmD.MessageRange[start, target.end, composedMessage]];
vmD.DeleteRangeInMessage
[from: vmD.MessageRange[start, target.end, composedMessage]];
deletedChars ← target.end - start;
InitializeSelection[target];
intC.commandType ← replace;
END
ELSE intC.commandType ← insert;
intC.actionPoint ← start;
DeUnderlineSelection[target, target];
intC.newTargetSelection ← FALSE;
END
ELSE BEGIN -- continue modeless insertion --
targetIndex ← vmD.GetMessageSize[mnp.insertionBuffer];
intC.commandType ← SELECT intC.commandType FROM
delete, replace => replace,
ENDCASE => insert;
END;
DMSTimeDefs.MapPackedTimeToTimeZoneString
[LOOPHOLE[TimeDefs.CurrentDayTime[]], timeString, arpaMsg];
vmD.StartMessageInsertion[composedMessage, start];
[] ← vmD.InsertSubstringInMessage
[composedMessage, timeString, 0, timeString.length];
vmD.StopMessageInsertion[composedMessage];
end ← start + timeString.length;
target↑ ← TextSelection[mnp, start, end, end, 0, char, FALSE];
IF modelessEditor THEN target.start ← end;
vmD.InsertRangeInMessage
[targetIndex: targetIndex, targetMessage: mnp.insertionBuffer,
from: vmD.MessageRange[start, end, composedMessage]];
UpdateScreen[start: start, nCharsDeleted: deletedChars,
nCharsInserted: timeString.length,mnp: mnp];
TurnOnDeliver[];
END; -- of TCommand --


BracketCommand: PUBLIC PROCEDURE [mnp: MessageTextNbrPtr, char: CHARACTER] =
BEGIN
target: TextSelectionPtr = @intC.target;
start, end: CharIndex;
hyphens: STRING = "-------------------
"L;
composedMessage: vmD.ComposedMessagePtr ← vmD.ComposedMessage[mnp.message];
bracketLength: CARDINAL = IF char = ’- THEN hyphens.length ELSE 1;
ResetBuffers[mnp];
intC.actionPoint ← start ← target.start;
intC.commandType ← replace;
end ← target.end;
vmD.InsertRangeInMessage[targetIndex: 0, targetMessage: mnp.deletionBuffer,
from: vmD.MessageRange[start, end, composedMessage]];
vmD.StartMessageInsertion[composedMessage, end];
IF char = ’- THEN
[] ← vmD.InsertSubstringInMessage[composedMessage, hyphens, 0, hyphens.length]
ELSE [] ← vmD.InsertMessageChar
[composedMessage,
SELECT char FROM
’b => Ascii.ControlB, ’[ => ’], ’< => ’>, ’( => ’), ’{ => ’}, ENDCASE => char];
vmD.StopMessageInsertion[composedMessage];
vmD.StartMessageInsertion[composedMessage, start];
IF char = ’- THEN
[] ← vmD.InsertSubstringInMessage[composedMessage, hyphens, 0, hyphens.length]
ELSE [] ← vmD.InsertMessageChar
[composedMessage,
SELECT char FROM ’b => Ascii.ControlA, ’’ => 140C, ENDCASE => char];
vmD.StopMessageInsertion[composedMessage];
target.point ← target.end ← end + bracketLength;
target.start ← target.start + bracketLength;
target.mode ← char;
target.pendingDelete ← FALSE;
vmD.InsertRangeInMessage[targetIndex: 0, targetMessage: mnp.insertionBuffer,
from: vmD.MessageRange[start, end + 2 * bracketLength, composedMessage]];
UpdateScreen[start: start, nCharsDeleted: end - start,
nCharsInserted: end - start + 2 * bracketLength, mnp: mnp];
target.point ← target.end;
intC.newTargetSelection ← TRUE;
END; -- of BracketCommand --


ButlersBoundaryCommand: PUBLIC PROCEDURE [commandNumber: CARDINAL] =
BEGIN
tocCommandLines: CARDINAL
← intC.TOCCommandRegion.bottomY - intC.TOCCommandRegion.topY;
linesAvailable: CARDINAL
← intC.tocTextNbr.nLines + intC.dmTextNbr.nLines + intC.cmTextNbr.nLines;
textNbrSizes: TextNbrSizes ← intC.boundarySet[commandNumber];
total: CARDINAL ← textNbrSizes.toc + textNbrSizes.dm + textNbrSizes.cm;
tocLines, dmLines, cmLines: CARDINAL;
IF total = 0 THEN RETURN;
tocLines ← (textNbrSizes.toc * linesAvailable) / total;
cmLines ← (textNbrSizes.cm * linesAvailable) / total;
dmLines ← linesAvailable - tocLines - cmLines;
AdjustBoundaries
[tocdmY: intC.TOCRegion.topY + dsD.lineHeight * tocLines,
dmcmY: intC.TOCRegion.topY + tocCommandLines + dsD.lineHeight * (tocLines+dmLines)];
END; -- of ButlersBoundaryCommand --


UnrecognizedCommand: PUBLIC PROCEDURE =
BEGIN
s: STRING ← [70];
char: CHARACTER;
exD.GetExceptionString[exD.unrecCommand, s];
exD.AppendExceptionString[exD.pressToContinue, s];
exD.DisplayBothExceptionLines[s, exD.nil, NIL, exD.commandsAre];
DO
UNTIL ~intC.keystream.endof[intC.keystream] DO
IdleLoop[];
ENDLOOP;
IF (char ← intC.keystream.get[intC.keystream]) = cancelCode
OR char = Ascii.DEL
THEN EXIT;
ENDLOOP;
exD.ClearExceptionsRegion[];
END; -- of UnrecognizedCommand --


END. -- of EditorMisc --