(FILECREATED "24-May-84 19:02:05" {DSK}TEDITHISTORY.;5 22736 changes to: (FNS TEDIT.REDO.INSERTION) previous date: "24-May-84 11:22:30" {DSK}TEDITHISTORY.;3) (PRETTYCOMPRINT TEDITHISTORYCOMS) (RPAQQ TEDITHISTORYCOMS ((FILES TEDIT TEXTOFD TEDITLOOKS) (GLOBALVARS TEDIT.HISTORY.TYPELST TEDIT.HISTORYLST) (INITVARS (TEDIT.HISTORY.TYPELST NIL) (TEDIT.HISTORYLST NIL)) (RECORDS TEDITHISTORYEVENT) (FNS \TEDIT.HISTORYADD TEDIT.UNDO TEDIT.UNDO.INSERTION TEDIT.UNDO.DELETION TEDIT.REDO TEDIT.REDO.INSERTION TEDIT.UNDO.MOVE TEDIT.UNDO.REPLACE TEDIT.REDO.REPLACE TEDIT.REDO.MOVE))) (FILESLOAD TEDIT TEXTOFD TEDITLOOKS) (DECLARE: DOEVAL@COMPILE DONTCOPY (ADDTOVAR GLOBALVARS TEDIT.HISTORY.TYPELST TEDIT.HISTORYLST) ) (RPAQ? TEDIT.HISTORY.TYPELST NIL) (RPAQ? TEDIT.HISTORYLST NIL) [DECLARE: EVAL@COMPILE (RECORD TEDITHISTORYEVENT (THACTION (* A LITATOM, specifying what the event was) THPOINT (* Was the selection to the left or right?) THLEN (* The # of chars involved) THCH# (* The starting ch#) THFIRSTPIECE (* First piece involved) THOLDINFO (* Old info, for undo) THAUXINFO (* Auxiliary info about the event, primarily for redo) THTEXTOBJ (* Place to remember a second textobj, for those like MOVE who need to remember both a source and a destination.) ) THPOINT ←(QUOTE LEFT)) ] (DEFINEQ (\TEDIT.HISTORYADD [LAMBDA (TEXTOBJ EVENT) (* jds "10-Jan-84 16:26") (* Add a new event to the history list. For now, this just re-sets the whole list to be the one event...) (replace TXTHISTORY of TEXTOBJ with EVENT]) (TEDIT.UNDO [LAMBDA (TEXTOBJ) (* jds "21-May-84 14:10") (* Undo the last thing this guy did.) (* Format of the history list: (Selector-kind-of-last-op --info--)) (PROG ((SEL (fetch SEL of TEXTOBJ)) EVENT CH# LEN FIRSTPIECE) (COND ((SETQ EVENT (fetch TXTHISTORY of TEXTOBJ)) (* There really is something to UNDO. Decide what, & fix it.) (SETQ LEN (fetch THLEN of EVENT)) (* Length of the text that was inserted/deleted/changed) (SETQ CH# (fetch THCH# of EVENT)) (* Starting CH# of the change) (SETQ FIRSTPIECE (fetch THFIRSTPIECE of EVENT)) (* First piece affected by the change) (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR)) (\SHOWSEL SEL NIL NIL) [SELECTQ (fetch THACTION of EVENT) ((Insert Copy Include) (* It was an insertion) (TEDIT.UNDO.INSERTION TEXTOBJ EVENT LEN CH# FIRSTPIECE)) (Delete (* It was a deletion) (TEDIT.UNDO.DELETION TEXTOBJ EVENT LEN CH# FIRSTPIECE)) (Looks (* It was a character-looks change) (TEDIT.UNDO.LOOKS TEXTOBJ EVENT LEN CH# FIRSTPIECE)) (ParaLooks (* It was a PARA looks change) (TEDIT.UNDO.PARALOOKS TEXTOBJ EVENT LEN CH# FIRSTPIECE)) (Move (TEDIT.UNDO.MOVE TEXTOBJ EVENT LEN CH# FIRSTPIECE) (* He moved some text) ) (Replace (TEDIT.UNDO.REPLACE TEXTOBJ EVENT LEN CH# FIRSTPIECE) (* He replaced one piece of text with another.) ) (Get (* He did a GET -- not undoable.) (TEDIT.PROMPTPRINT TEXTOBJ "You can't UNDO a GET." T)) (Put (* He did a PUT -- not undoable.) (TEDIT.PROMPTPRINT TEXTOBJ "You can't undo a Put." T)) (COND ((AND (SETQ UNDOFN (ASSOC (fetch THACTION of EVENT) TEDIT.HISTORY.TYPELST)) (SETQ UNDOFN (CADDR UNDOFN))) (* TEDIT.HISTORY.TYPELST is an ALST of form (type redofn undofn)) (APPLY* UNDOFN TEXTOBJ EVENT LEN CH# FIRSTPIECE)) (T (TEDIT.PROMPTPRINT TEXTOBJ (CONCAT "UNDO not implemented for " (fetch THACTION of EVENT)) T] (\SHOWSEL SEL NIL T))) (T (TEDIT.PROMPTPRINT TEXTOBJ "Nothing to UNDO." T]) (TEDIT.UNDO.INSERTION [LAMBDA (TEXTOBJ EVENT LEN CH# FIRSTPIECE) (* jds " 1-Mar-84 16:01") (* UNDO a prior Insert, Copy, or Include.) (PROG (OBJ DELETEFN) (replace \INSERTFIRSTCH of TEXTOBJ with -1) (replace \INSERTNEXTCH of TEXTOBJ with -1) (bind (TL ← 0) while (ILESSP TL LEN) do (* Delete enough inserted pieces to cover the insertion we're undoing.) [COND ([AND (SETQ OBJ (fetch POBJ of FIRSTPIECE)) (SETQ DELETEFN (IMAGEOBJPROP OBJ (QUOTE WHENDELETEDFN] (* If it's an object, and has a deletion fn, call it.) (APPLY* DELETEFN OBJ (fetch DS of TEXTOBJ) NIL (fetch STREAMHINT of TEXTOBJ] (\DELETEPIECE FIRSTPIECE (fetch PCTB of TEXTOBJ)) (* Delete the piece) (SETQ TL (IPLUS TL (fetch PLEN of FIRSTPIECE))) (* Track the length of what we've deleted) (SETQ FIRSTPIECE (fetch NEXTPIECE of FIRSTPIECE)) (* Move to the next piece)) (replace TEXTLEN of TEXTOBJ with (IDIFFERENCE (fetch TEXTLEN of TEXTOBJ) LEN)) (* Reset the text length and EOF ptr of the text stream.) (\FIXDLINES (fetch LINES of TEXTOBJ) (fetch SEL of TEXTOBJ) CH# (IPLUS CH# LEN -1) TEXTOBJ) (* Fix the line descriptors & selection) (TEDIT.UPDATE.SCREEN TEXTOBJ) (* Fix up the display for all this foofaraw) (replace POINT of (fetch SEL of TEXTOBJ) with (QUOTE LEFT)) (\FIXSEL (fetch SEL of TEXTOBJ) TEXTOBJ) (* Really fix the selection) (replace THACTION of EVENT with (QUOTE Delete)) (* Make the UNDO be UNDOable, by changing the event to a deletion.) ]) (TEDIT.UNDO.DELETION [LAMBDA (TEXTOBJ EVENT LEN CH# FIRSTPIECE) (* jds " 1-Mar-84 15:52") (* UNDO a prior Deletion of text.) (PROG ((INSPC# (\CHTOPCNO CH# (fetch PCTB of TEXTOBJ))) (NPC (fetch NEXTPIECE of FIRSTPIECE)) (PCTB (fetch PCTB of TEXTOBJ)) (SEL (fetch SEL of TEXTOBJ)) (OTEXTLEN (fetch TEXTLEN of TEXTOBJ)) NEWPIECE INSPC OBJECT INSERTFN) (replace \INSERTFIRSTCH of TEXTOBJ with -1) (* Force a recomputation of piece lengths, etc.) (replace \INSERTNEXTCH of TEXTOBJ with -1) [COND ((IGREATERP CH# (\EDITELT PCTB INSPC#)) (SETQ INSPC (\SPLITPIECE (\EDITELT PCTB (ADD1 INSPC#)) CH# TEXTOBJ INSPC#)) (add INSPC# 1)) (T (SETQ INSPC (\EDITELT PCTB (ADD1 INSPC#] (SETQ NEWPIECE (create PIECE using FIRSTPIECE)) (replace THFIRSTPIECE of EVENT with NEWPIECE) (bind (TL ← 0) while (ILESSP TL LEN) do (\INSERTPIECE NEWPIECE INSPC TEXTOBJ) (* Insert the piece back in) [COND ([AND (SETQ OBJECT (fetch POBJ of NEWPIECE)) (SETQ INSERTFN (IMAGEOBJPROP OBJECT (QUOTE WHENINSERTEDFN] (* If this is an imageobject, and it has an insertfn, call it.) (APPLY* INSERTFN OBJECT (\TEDIT.MAINW TEXTOBJ) NIL (TEXTSTREAM TEXTOBJ] (SETQ TL (IPLUS TL (fetch PLEN of FIRSTPIECE))) (* Keep track of how much we've re-inserted) (SETQ FIRSTPIECE NPC) (* Move to the next piece to insert) (AND NPC (SETQ NPC (fetch NEXTPIECE of NPC))) (SETQ NEWPIECE (create PIECE using FIRSTPIECE))) (* Done here because \INSERTPIECE creams the NEXTPIECE field.) (replace TEXTLEN of TEXTOBJ with (IPLUS (fetch TEXTLEN of TEXTOBJ) LEN)) (* Reset the text length and EOF ptr of the text stream.) (\FIXILINES TEXTOBJ SEL CH# LEN OTEXTLEN) (* Fix the line descriptors & selection) (TEDIT.UPDATE.SCREEN TEXTOBJ) (* Fix up the display for all this foofaraw) (replace CH# of SEL with CH#) (* Make the selection point at the re-inserted text) (replace CHLIM of SEL with (IPLUS CH# LEN -1)) (replace DCH of SEL with LEN) (replace POINT of SEL with (fetch THPOINT of EVENT)) (TEDIT.SET.SEL.LOOKS SEL (QUOTE NORMAL)) (\FIXSEL SEL TEXTOBJ) (* Really fix the selection) (replace THACTION of EVENT with (QUOTE Insert)) (* Make the UNDO be UNDOable, by changing the event to a insertion.) ]) (TEDIT.REDO [LAMBDA (TEXTOBJ) (* jds "21-May-84 16:39") (* REDO the last thing this guy did.) (PROG ((SEL (fetch SEL of TEXTOBJ)) EVENT CH) (COND ([AND (SETQ EVENT (fetch TXTHISTORY of TEXTOBJ)) (NOT (ZEROP (fetch DCH of SEL] (* There really is something to REDO Decide what, & do it.) (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR)) (\SHOWSEL SEL NIL NIL) (SELECTQ (fetch THACTION of EVENT) [(Insert Copy Include) (* It was an insertion) (TEDIT.REDO.INSERTION TEXTOBJ EVENT (IMAX 1 (SELECTQ (fetch POINT of SEL) (LEFT (fetch CH# of SEL)) (RIGHT (ADD1 (fetch CHLIM of SEL))) NIL] (Delete (* It was a deletion) (\TEDIT.DELETE SEL TEXTOBJ)) (Replace (TEDIT.REDO.REPLACE TEXTOBJ EVENT)) [Looks (* It was a looks change) (TEDIT.REDO.LOOKS TEXTOBJ EVENT (IMAX 1 (SELECTQ (fetch POINT of SEL) (LEFT (fetch CH# of SEL)) (RIGHT (ADD1 (fetch CHLIM of SEL))) NIL] [ParaLooks (* It was a Paragraph looks change) (TEDIT.REDO.PARALOOKS TEXTOBJ EVENT (IMAX 1 (SELECTQ (fetch POINT of SEL) (LEFT (fetch CH# of SEL)) (RIGHT (ADD1 (fetch CHLIM of SEL))) NIL] (Find (* EXACT-MATCH SEARCH COMMAND) [RESETLST (RESETSAVE (CURSOR WAITINGCURSOR)) (TEDIT.PROMPTPRINT TEXTOBJ "Searching..." T) (SETQ SEL (fetch SEL of TEXTOBJ)) (\SHOWSEL SEL NIL NIL) (SETQ CH (TEDIT.FIND TEXTOBJ (fetch THAUXINFO of EVENT))) (COND (CH (TEDIT.PROMPTPRINT TEXTOBJ "done.") (replace CH# of SEL with CH) [replace CHLIM of SEL with (SUB1 (IPLUS CH (NCHARS (fetch THAUXINFO of EVENT] (replace DCH of SEL with (NCHARS (fetch THAUXINFO of EVENT))) (replace POINT of SEL with (QUOTE RIGHT)) (\FIXSEL SEL TEXTOBJ) (TEDIT.NORMALIZECARET TEXTOBJ) (\SHOWSEL SEL NIL T)) (T (TEDIT.PROMPTPRINT TEXTOBJ "[Not found]"] (replace \INSERTNEXTCH of TEXTOBJ with -1)) ((Move ReplaceMove) (* He moved some text) (TEDIT.REDO.MOVE TEXTOBJ EVENT (fetch THLEN of EVENT) (IMAX 1 (SELECTQ (fetch POINT of SEL) (LEFT (fetch CH# of SEL)) (RIGHT (ADD1 (fetch CHLIM of SEL))) NIL)) (fetch THFIRSTPIECE of EVENT))) (Get (* He did a GET -- not undoable.) (TEDIT.PROMPTPRINT TEXTOBJ "You can't REDO a GET." T)) (Put (* He did a PUT -- not undoable.) (TEDIT.PROMPTPRINT TEXTOBJ "You can't REDO a PUT." T)) (TEDIT.PROMPTPRINT TEXTOBJ (CONCAT "REDO of the action " (fetch THACTION of EVENT) " isn't implemented.") T)) (\SHOWSEL SEL NIL T))) (T (TEDIT.PROMPTPRINT TEXTOBJ "Nothing to REDO." T]) (TEDIT.REDO.INSERTION [LAMBDA (TEXTOBJ EVENT CH#) (* jds "24-May-84 17:07") (* REDO a prior Insert/Copy/Include of text.) (PROG (INSPC INSPC# NPC (SEL (fetch SEL of TEXTOBJ)) (PCTB (fetch PCTB of TEXTOBJ)) (LEN (fetch THLEN of EVENT)) (FIRSTPIECE (create PIECE using (fetch THFIRSTPIECE of EVENT) PNEW ← T)) (OTEXTLEN (fetch TEXTLEN of TEXTOBJ)) OBJ COPYFN) (replace THFIRSTPIECE of EVENT with FIRSTPIECE) (* So we can UNDO this, and remove the right set of pieces.) (replace \INSERTNEXTCH of TEXTOBJ with -1) (* Force any further insertions to make new pieces.) (SETQ NPC (fetch NEXTPIECE of FIRSTPIECE)) (SETQ INSPC# (\CHTOPCNO CH# PCTB)) (* Piece # of the piece we're to insert inside or in front of) (SETQ INSPC (\EDITELT PCTB (ADD1 INSPC#))) [SETQ INSPC (COND ((IEQP CH# (\EDITELT PCTB INSPC#)) (* We're inserting just before an existing piece) INSPC) (T (* We must split this piece, and insert before the second part.) (PROG1 (\SPLITPIECE INSPC CH# TEXTOBJ INSPC#) (add INSPC# \EltsPerPiece] (bind (TL ← 0) while (ILESSP TL LEN) do (* Loop thru the pieces of the prior insertion, inserting copies of enough of them to cover the length of the insertion.) [COND ((SETQ OBJ (fetch POBJ of FIRSTPIECE)) (* This piece describes an object) [COND [(SETQ COPYFN (IMAGEOBJPROP OBJ (QUOTE COPYFN))) (SETQ OBJ (APPLY* COPYFN OBJ (fetch STREAMHINT of TEXTOBJ) (fetch STREAMHINT of TEXTOBJ))) (COND ((EQ OBJ (QUOTE DON'T)) (TEDIT.PROMPTPRINT TEXTOBJ "COPY of this object not allowed." T) (RETFROM (QUOTE TEDIT.COPY))) (T (replace POBJ of FIRSTPIECE with OBJ] (OBJ (replace POBJ of FIRSTPIECE with (COPY OBJ] (COND ((SETQ COPYFN (IMAGEOBJPROP OBJ (QUOTE WHENCOPIEDFN))) (* If there's an eventfn for copying, use it.) (APPLY* COPYFN OBJ (fetch DS of TEXTOBJ) (fetch STREAMHINT of TEXTOBJ) (fetch STREAMHINT of TEXTOBJ] (\INSERTPIECE FIRSTPIECE INSPC TEXTOBJ) (* Insert the piece back in) (SETQ TL (IPLUS TL (fetch PLEN of FIRSTPIECE))) (* Keep track of how much we've re-inserted) (SETQ FIRSTPIECE (create PIECE using NPC PNEW ← T)) (* Move to the next piece to insert) (AND NPC (SETQ NPC (fetch NEXTPIECE of NPC))) (* Done here because \INSERTPIECE creams the NEXTPIECE field.)) (replace TEXTLEN of TEXTOBJ with (IPLUS (fetch TEXTLEN of TEXTOBJ) LEN)) (* Reset the text length and EOF ptr of the text stream.) (\FIXILINES TEXTOBJ SEL CH# LEN OTEXTLEN) (* Fix the line descriptors & selection) (TEDIT.UPDATE.SCREEN TEXTOBJ) (* Fix up the display for all this foofaraw) (replace CH# of SEL with CH#) (* Make the selection point at the re-inserted text) (replace CHLIM of SEL with (IPLUS CH# LEN -1)) (replace DCH of SEL with LEN) (TEDIT.SET.SEL.LOOKS SEL (QUOTE NORMAL)) (\FIXSEL SEL TEXTOBJ) (* Really fix the selection) (replace THACTION of EVENT with (QUOTE Insert)) (* Make the UNDO be UNDOable, by changing the event to a insertion.) ]) (TEDIT.UNDO.MOVE [LAMBDA (TEXTOBJ EVENT LEN CH# FIRSTPIECE) (* jds " 8-Feb-84 18:34") (SETQ TEDIT.MOVE.PENDING NIL) (* First, Turn off the global flag that got us here.) (PROG ((TOOBJ (fetch THAUXINFO of EVENT)) (FROMOBJ TEXTOBJ) (SOURCECH# (fetch THOLDINFO of EVENT)) (CH# (fetch THCH# of EVENT)) TOSEL) (\SHOWSEL (fetch SEL of TOOBJ) NIL NIL) (\SHOWSEL (fetch SEL of FROMOBJ) NIL NIL) (TEDIT.UNDO.INSERTION FROMOBJ EVENT LEN CH# FIRSTPIECE) (\SHOWSEL (fetch SEL of TOOBJ) NIL NIL) (\COPYSEL (fetch SEL of TOOBJ) TEDIT.SELECTION) (\SHOWSEL (fetch SEL of FROMOBJ) NIL NIL) (TEDIT.UNDO.DELETION TOOBJ EVENT LEN SOURCECH# (fetch THFIRSTPIECE of EVENT)) (replace THACTION of EVENT with (QUOTE Move)) (replace THTEXTOBJ of EVENT with TOOBJ) (replace THAUXINFO of EVENT with FROMOBJ) (replace THOLDINFO of EVENT with CH#) (replace THCH# of EVENT with SOURCECH#) (\SHOWSEL (fetch SEL of FROMOBJ) NIL NIL) (SETQ TOSEL (fetch SEL of TOOBJ)) (replace CH# of TOSEL with SOURCECH#) (replace CHLIM of TOSEL with (IPLUS SOURCECH# LEN -1)) (replace DCH of TOSEL with LEN) (TEDIT.SET.SEL.LOOKS (fetch SEL of TOOBJ) (QUOTE NORMAL)) (\FIXSEL TOSEL TOOBJ) (\SHOWSEL (fetch SEL of TOOBJ) NIL T]) (TEDIT.UNDO.REPLACE [LAMBDA (TEXTOBJ EVENT LEN CH# FIRSTPIECE) (* jds "10-Jan-84 17:04") (PROG ((OLDEVENT (fetch THOLDINFO of EVENT)) (CH# (fetch THCH# of EVENT)) (SEL (fetch SEL of TEXTOBJ))) (\SHOWSEL SEL NIL NIL) (TEDIT.UNDO.INSERTION TEXTOBJ EVENT LEN CH# FIRSTPIECE) (\SHOWSEL SEL NIL NIL) (TEDIT.UNDO.DELETION TEXTOBJ OLDEVENT (fetch THLEN of OLDEVENT) CH# (fetch THFIRSTPIECE of OLDEVENT)) (replace THOLDINFO of OLDEVENT with EVENT) (replace THACTION of OLDEVENT with (QUOTE Replace)) (replace THOLDINFO of EVENT with NIL) (\TEDIT.HISTORYADD TEXTOBJ OLDEVENT) (replace CH# of SEL with CH#) (replace CHLIM of SEL with (IPLUS CH# (fetch THLEN of OLDEVENT) -1)) (replace DCH of SEL with (fetch THLEN of OLDEVENT)) (replace POINT of SEL with (fetch THPOINT of EVENT)) (replace THPOINT of OLDEVENT with (fetch THPOINT of EVENT)) (\FIXSEL SEL TEXTOBJ) (\SHOWSEL SEL NIL T]) (TEDIT.REDO.REPLACE [LAMBDA (TEXTOBJ EVENT) (* jds "10-Jan-84 16:59") (PROG ((OLDEVENT (fetch THOLDINFO of EVENT)) (CH# (fetch CH# of (fetch SEL of TEXTOBJ))) (SEL (fetch SEL of TEXTOBJ))) (\SHOWSEL SEL NIL NIL) (\TEDIT.DELETE SEL TEXTOBJ) (\SHOWSEL SEL NIL NIL) (TEDIT.REDO.INSERTION TEXTOBJ EVENT CH#) (replace THOLDINFO of EVENT with (SETQ OLDEVENT (fetch TXTHISTORY of TEXTOBJ))) (replace THACTION of OLDEVENT with (QUOTE Replace)) (replace THACTION of EVENT with (QUOTE Replace)) (replace THCH# of EVENT with CH#) (\TEDIT.HISTORYADD TEXTOBJ EVENT]) (TEDIT.REDO.MOVE [LAMBDA (TEXTOBJ EVENT LEN CH# FIRSTPIECE) (* jds " 8-Feb-84 19:14") (PROG ((FROMOBJ TEXTOBJ) (SOURCECH# (fetch THOLDINFO of EVENT)) (OLDCH# (fetch THCH# of EVENT)) (SEL (fetch SEL of TEXTOBJ)) (MOVESEL (fetch MOVESEL of TEXTOBJ)) OLDCHLIM) (replace CH# of MOVESEL with OLDCH#) (replace CHLIM of MOVESEL with (IPLUS OLDCH# LEN -1)) (replace DCH of MOVESEL with LEN) (replace SET of MOVESEL with T) (\FIXSEL MOVESEL TEXTOBJ) (TEDIT.SET.SEL.LOOKS MOVESEL (QUOTE MOVE)) (TEDIT.MOVE MOVESEL SEL]) ) (DECLARE: DONTCOPY (FILEMAP (NIL (1633 22714 (\TEDIT.HISTORYADD 1643 . 2020) (TEDIT.UNDO 2022 . 4865) ( TEDIT.UNDO.INSERTION 4867 . 7257) (TEDIT.UNDO.DELETION 7259 . 10407) (TEDIT.REDO 10409 . 14003) ( TEDIT.REDO.INSERTION 14005 . 18211) (TEDIT.UNDO.MOVE 18213 . 19930) (TEDIT.UNDO.REPLACE 19932 . 21203) (TEDIT.REDO.REPLACE 21205 . 22001) (TEDIT.REDO.MOVE 22003 . 22712))))) STOP