/* ** =================================================================================== ** ** Project: Newton Toolkit ** Filename: GlobalData ** ** Copyright © 1993-1998, Lunatech Research. ** All right reserved. ** ** ** Revision history: ** Date Who Changes ** ---------- --- ----------------------------------------------------------- ** 1997-11-29 PAK Initial release ** 1997-12-11 PAK Added balancing ** ** ** Codes used: ** *** CHK: Check whether assumption is correct ** *** REV: Possible revision ** *** TBD: Still to be done ** ** =================================================================================== */ protoEditor:DefineKey({key: 65}, 'EvaluateSelection); protoEditor.Sleep := func(inTicks) begin inTicks := Ticks() + inTicks; while (inTicks > Ticks()) do nil; end; protoEditor.match := func(inOffset, inChar, inCharRev) begin local theMatches := 1; local theChar; local theCharPrev; local theOffset := inOffset - 1; while (theOffset >= 0) do begin theChar := :Peek(theOffset); theCharPrev := :Peek(theOffset - 1); if theCharPrev = chr(92) then theOffset := theOffset - 1; else if theCharPrev = $$ then theOffset := theOffset - 1; else if theChar = $" then begin theOffset := theOffset - 1; while (theOffset >= 0) do begin theChar := :Peek(theOffset); theCharPrev := :Peek(theOffset - 1); if theCharPrev = chr(92) then theOffset := theOffset - 1; else if theChar = $" then break; theOffset := theOffset - 1; end; end; else if theChar = inChar then theMatches := theMatches + 1; else if theChar = inCharRev then begin theMatches := theMatches - 1; if theMatches = 0 then return(theOffset); end; theOffset := theOffset - 1; end; return(nil); end; protoEditor.balanceX := func(inOffset, inChar, inCharRev, inLength) begin :ReplaceSelection("" & inChar); local theOffset := :match(inOffset, inChar, inCharRev); if theOffset then begin :SetSelection(theOffset, 1); :Sleep(10); :ReplaceSelection(" "); :Sleep(10); :ReplaceSelection("" & inCharRev); :Sleep(10); :ReplaceSelection(" "); :Sleep(10); :ReplaceSelection("" & inCharRev); :TellUser(""); end; else :TellUser("Beep, left " & inCharRev & " not found!"); :SetSelection(inOffset + 1, 0); end; protoEditor.balanceSelect := func(inOffset, inLength) begin local theOffset := inOffset + inLength; local theOffsetEnd := :TextLength(); local theChar; local theCharPrev := nil; local theCharRev := nil; while (theOffset < theOffsetEnd) do begin theChar := :Peek(theOffset); if theCharPrev = $$ then nil; else if theChar = $) then theCharRev := $(; else if theChar = $} then theCharRev := ${; else if theChar = $] then theCharRev := $[; if theCharRev then begin local theOffsetRev := :match(theOffset, theChar, theCharRev); if theOffsetRev then if theOffsetRev < inOffset then begin :SetSelection(theOffsetRev, theOffset - theOffsetRev + 1); break; end; theCharRev := nil; end; theOffset := theOffset + 1; theCharPrev := theChar; end; if not theCharRev then :TellUser("Beep, nothing to balance!"); end; protoEditor.rpar := func(inOffset, inLength) :balanceX(inOffset, $), $(, inLength); protoEditor.racc := func(inOffset, inLength) :balanceX(inOffset, $}, ${, inLength); protoEditor.rsqr := func(inOffset, inLength) :balanceX(inOffset, $], $[, inLength); protoEditor:DefineKey($}, 'racc); protoEditor:DefineKey($], 'rsqr); protoEditor:DefineKey({control: true, key: $b}, 'balanceSelect);