ExecHacks.mesa
Edited by
McGregor on August 17, 1983 5:09 pm
Plass on December 16, 1983 9:27 am
DIRECTORY
FS USING [ComponentPositions, Error, ExpandName],
Menus USING [CreateEntry, AppendMenuEntry, MenuProc],
Rope USING [Concat, Equal, Fetch, Length, ROPE, Run, Size, Substr],
TiogaOps USING [GetSelection, GetRope],
Terminal USING [BlinkBWDisplay, Current],
ViewerClasses USING [Viewer],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerOps USING [EnumProc, EnumerateViewers, PaintViewer],
ViewerTools USING [GetSelectedViewer, GetSelectionContents, SetSelection];
ExecHacks: CEDAR PROGRAM
IMPORTS FS, Menus, Rope, TiogaOps, Terminal, ViewerEvents, ViewerOps, ViewerTools = BEGIN
Blink:
PROC = {Terminal.BlinkBWDisplay[Terminal.Current[]]};
Compile: Menus.MenuProc =
BEGIN
exec: ViewerClasses.Viewer ~ NARROW[parent];
sel: Rope.ROPE ← ViewerTools.GetSelectionContents[];
function: Rope.ROPE ← "Compile ";
IF Rope.Size[sel] <= 1
THEN
BEGIN
selViewer: ViewerClasses.Viewer ← ViewerTools.GetSelectedViewer[];
sel ← selViewer.name;
END;
{fullFName: Rope.
ROPE; cp: FS.ComponentPositions; dirOmitted:
BOOLEAN;
[fullFName, cp, dirOmitted] ← FS.ExpandName[sel ! FS.Error => CONTINUE];
IF fullFName = NIL THEN {Blink[]; RETURN};
sel ← Rope.Substr[fullFName, cp.base.start, cp.base.length];
IF cp.ext.length > 0
THEN {
ext: Rope.ROPE ← Rope.Substr[fullFName, cp.ext.start, cp.ext.length];
IF Rope.Equal[ext, "mesa", FALSE] THEN function ← "Compile "
ELSE IF Rope.Equal[ext, "config", FALSE] THEN function ← "Bind "
ELSE IF Rope.Equal[ext, "cm", FALSE] THEN function ← "@"
ELSE {Blink[]; RETURN};
};
};
sel ← Rope.Concat[function, sel];
sel ← Rope.Concat[sel, "
"];
ViewerTools.SetSelection[exec, NIL];
exec.class.notify[exec, LIST[sel]];
END;
Redo: Menus.MenuProc =
BEGIN
ScanAndStuff:
PROC =
BEGIN
exec: ViewerClasses.Viewer ~ NARROW[parent];
rope: Rope.ROPE;
start, end: INT;
ViewerTools.SetSelection[exec, NIL];
rope ← TiogaOps.GetRope[TiogaOps.GetSelection[].end.node];
IF (start ← Rope.Size[rope]) < 6 THEN ERROR;
start ← start - 4; --one to point to the last char, 2 to skip current %, 1 for prev CR
WHILE Rope.Fetch[rope, start]#'% DO start ← start-1; ENDLOOP;
end ← start ← start+2;
WHILE Rope.Fetch[rope, end]#15C DO end ← end+1; ENDLOOP;
rope ← Rope.Substr[rope, start, end-start+1];
exec.class.notify[exec, LIST[rope]];
END;
ScanAndStuff[! ANY => {Blink[]; CONTINUE}];
END;
Reset: Menus.MenuProc = BEGIN
exec: ViewerClasses.Viewer ~ NARROW[parent];
InputFocus.SetInputFocus[NIL];
exec.class.set[exec, NIL, FALSE];
ViewerTools.SetSelection[exec, NIL];
exec.class.notify[exec, LIST["-- reset --
"]];
END;
quoteCommander: Rope.ROPE ~ "CommandTool:";
lengthQuoteCommander: INT ~ Rope.Length[quoteCommander];
DoMenu: ViewerEvents.EventProc =
BEGIN
IF Rope.Run[s1: viewer.name, s2: quoteCommander] = lengthQuoteCommander
THEN
BEGIN
Menus.AppendMenuEntry[viewer.menu, Menus.CreateEntry[name:"Compile", proc:Compile, fork:FALSE]];
Menus.AppendMenuEntry[viewer.menu, Menus.CreateEntry[name:"Redo", proc:Redo, fork:FALSE]];
ViewerOps.PaintViewer[viewer, menu];
END;
END;
AttachMenuItemsToExecs:
PROC =
BEGIN
PerViewer: ViewerOps.EnumProc =
BEGIN
[] ← DoMenu[v, create, FALSE];
END;
ViewerOps.EnumerateViewers[PerViewer];
END;
[] ← ViewerEvents.RegisterEventProc[DoMenu, create, $Typescript, FALSE];
AttachMenuItemsToExecs[];
END.