(FILECREATED "31-May-85 15:36:57" {PHYLUM}<NOTECARDS>RELEASE1.2I>INTERMEZZOTEDITFIXES.;4 13728 changes to: (VARS INTERMEZZOTEDITFIXESCOMS) (FNS \TEDIT.MARK.LINES.DIRTY TEDIT.GET) previous date: "29-May-85 17:50:53" {PHYLUM}<NOTECARDS>RELEASE1.2I>INTERMEZZOTEDITFIXES.;2) (* Copyright (c) 1985 by Xerox Corporation. All rights reserved.) (PRETTYCOMPRINT INTERMEZZOTEDITFIXESCOMS) (RPAQQ INTERMEZZOTEDITFIXESCOMS ((FNS TEDIT.PUT TEDIT.GET \TEDIT.MARK.LINES.DIRTY))) (DEFINEQ (TEDIT.PUT (LAMBDA (STREAM FILE FORCENEW UNFORMATTED?) (* fgh: "29-May-85 17:50") (* If the guy was editing a file, make a new updated version; else, ask for a file name) (* If FILE is specd, it's used; else the user must give us one) (* * Fixes for NoteCards: Changed fetch FULLNAME and fetch FULLFILENAME to be (FULLNAME X) calls. Changed type? LITATOM to be (LITATOM X) calls. FGH 5/29/85) (PROG ((TEXTOBJ (TEXTOBJ STREAM)) (TEDIT.PUT.FINISHEDFORMS NIL) (TEDIT.GET.FINISHEDFORMS NIL) (OUTPUT.FILE.WRITTEN NIL) OCURSOR OFILE FONTFILEUSED PROPS WINDOW PUTFN CACHE MENUSTREAM FILENAME TITLE CH#S PC) (COND (FILE (* We were given a file to use.) (SETQ OFILE FILE)) (FORCENEW (* He insists on a new file. (without giving us one NIL)) (SETQ OFILE (\TEDIT.MAKEFILENAME (TEDIT.GETINPUT TEXTOBJ "File to PUT to: ")))) (T (* Get a file to put the text into) (SETQ OFILE (\TEDIT.MAKEFILENAME (TEDIT.GETINPUT TEXTOBJ "File to PUT to: " (\TEXTSTREAM.FILENAME TEXTOBJ)))))) (SETQ PUTFN (TEXTPROP TEXTOBJ (QUOTE PUTFN))) (SETQ CACHE (TEXTPROP TEXTOBJ (QUOTE CACHE))) (COND ((NOT OFILE) (* There's no file to put to; don't bother.) (RETURN)) ((AND PUTFN (EQ (APPLY* PUTFN (fetch STREAMHINT of TEXTOBJ) (FULLNAME OFILE (QUOTE NEW)) (QUOTE BEFORE)) (QUOTE DON'T))) (* He doesn't want this document put. Bail out.) (RETURN))) (RESETLST (RESETSAVE (SETQ OFILE (OPENSTREAM OFILE (QUOTE OUTPUT) (QUOTE NEW) NIL (COND (UNFORMATTED? (* If the user forced no formatting, respect his wish.) (QUOTE ((TYPE TEXT)))) ((TEDIT.FORMATTEDFILEP TEXTOBJ) (* If this file has objects, para looks, or font changes, then we need a binary file.) (QUOTE ((TYPE BINARY)))) (T (* Otherwise, we can get by with a text file) (QUOTE ((TYPE TEXT))))))) (QUOTE (AND RESETSTATE (DELFILE (CLOSEF? OLDVALUE))))) (replace DESC of (fetch THISLINE of TEXTOBJ) with NIL) (TEDIT.PROMPTPRINT TEXTOBJ (CONCAT "PUTting file " (fetch FULLNAME of OFILE) "...") T) (COND ((IGREATERP (fetch TEXTLEN of TEXTOBJ) 0) (SETQ FONTFILEUSED (TEDIT.PUT.PCTB TEXTOBJ OFILE UNFORMATTED?)))) (CLOSEF OFILE) (* Close the file, to free it up.) (COND ((NOT CACHE) (* CSLI if caching do not need to reopen the output file anyway) (SETQ OFILE (OPENSTREAM (FULLNAME OFILE (QUOTE OLD)) (QUOTE INPUT))))) (* changed TEMPORary for ns filing with caching. may not work in general) (* And re-open it for INPUT only) (CLOSEF? (fetch TXTFILE of TEXTOBJ)) (* Close the old text file) (replace TXTFILE of TEXTOBJ with OFILE) (* And remember the new one for next time.) (replace \DIRTY of TEXTOBJ with NIL) (* We can safely QUIT now without losing anything.) ) (SETQ CH#S (REVERSE (CDR FONTFILEUSED))) (* The true filepos's of the pieces in the output file.) (UNINTERRUPTABLY (SETQ PC (ELT (fetch PCTB of TEXTOBJ) (ADD1 \FirstPieceOffset))) (while (AND PC CH#S) do (* Run thru the pieces in the PCTB, pointing them to the new file and their new locations.) (COND ((fetch POBJ of PC)) (T (replace PFPOS of PC with (pop CH#S)) (replace PFILE of PC with OFILE) (replace PSTR of PC with NIL))) (SETQ PC (fetch NEXTPIECE of PC)))) (TEDIT.PROMPTPRINT TEXTOBJ "done.") (* Tell him we're finished.) (SETQ TITLE (TEXTSTREAM.TITLE TEXTOBJ)) (* find and set the title) (\TEDIT.WINDOW.TITLE TEXTOBJ (\TEDIT.ORIGINAL.WINDOW.TITLE TITLE)) (SETQ MENUSTREAM (TEDITMENU.STREAM TEXTOBJ)) (COND ((AND MENUSTREAM (LITATOM TITLE)) (* if we have a filename then put it in the GET and PUT fields of the menu) (SETQ FILENAME (PACKFILENAME (QUOTE VERSION) NIL (QUOTE BODY) TITLE)) (MBUTTON.SET.FIELD MENUSTREAM (QUOTE Get) FILENAME) (MBUTTON.SET.FIELD MENUSTREAM (QUOTE Put) FILENAME))) (replace \INSERTPCVALID of TEXTOBJ with NIL) (* Make sure any new insertions happen for real, and not as appends. Since all the pieces now point to the file rather than the strings.) (replace \INSERTPC of TEXTOBJ with NIL) (* make sure that TEDIT doesn't try to just add to the \INSERTPC since it will now have a pfile property) (\TEDIT.HISTORYADD TEXTOBJ (create TEDITHISTORYEVENT THACTION ←(QUOTE Put) THCH# ← 0 THLEN ← 0 THFIRSTPIECE ← NIL)) (* Remember we did this.) (AND PUTFN (APPLY* PUTFN (fetch STREAMHINT of TEXTOBJ) (FULLNAME (fetch TXTFILE of TEXTOBJ) (QUOTE OLD)) (QUOTE AFTER))) (* CSLI changed to not presume ofile is the txtfile anymore) ))) (TEDIT.GET (LAMBDA (TEXTOBJ FILE UNFORMATTED?) (* fgh: "30-May-85 15:12") (* Get a new file (overwriting the one being edited.)) (PROG (OFILE OCURSOR LINES USER.CMFILE RESP TITLE FILENAME MENUSTREAM (SEL (fetch SEL of TEXTOBJ)) (PCTB (fetch PCTB of TEXTOBJ)) (TEDIT.GET.FINISHEDFORMS NIL) (GETFN (TEXTPROP TEXTOBJ (QUOTE GETFN)))) (COND ((AND (fetch \DIRTY of TEXTOBJ) (PROGN (AND (fetch PROMPTWINDOW of TEXTOBJ) (FRESHLINE (fetch PROMPTWINDOW of TEXTOBJ))) (NOT (MOUSECONFIRM "Not saved yet; LEFT go Get anyway." T (fetch PROMPTWINDOW of TEXTOBJ))))) (* Only do the GET if he knows he'll zorch himself.) (RETURN))) (SETQ OFILE (OR FILE (\TEDIT.MAKEFILENAME (TEDIT.GETINPUT TEXTOBJ "File to GET: ")))) (COND ((AND OFILE (INFILEP OFILE)) (* Only if there's a file to load and the file exists.) (COND ((AND GETFN (EQ (APPLY* GETFN (fetch STREAMHINT of TEXTOBJ) (FULLNAME OFILE) (QUOTE BEFORE)) (QUOTE DON'T))) (RETURN))) (RESETLST (RESETSAVE (TTYDISPLAYSTREAM (OR (fetch PROMPTWINDOW of TEXTOBJ) PROMPTWINDOW))) (RESETSAVE (CURSOR WAITINGCURSOR)) (\SHOWSEL (fetch SEL of TEXTOBJ) NIL NIL) (\TEXTCLOSEF (fetch STREAMHINT of TEXTOBJ)) (* CLOSE the old files) (SETQ OFILE (OPENSTREAM OFILE (QUOTE INPUT))) (* And open the new one.) (SETQ PCTB (replace PCTB of TEXTOBJ with (TEDIT.BUILD.PCTB OFILE TEXTOBJ NIL NIL (fetch DEFAULTCHARLOOKS of TEXTOBJ) (fetch FMTSPEC of TEXTOBJ) UNFORMATTED?))) (for FORM in TEDIT.GET.FINISHEDFORMS do (EVAL FORM)) (* Do any necessary cleanup for outside packages) (SETQ LINES (fetch LINES of TEXTOBJ)) (replace TXTFILE of TEXTOBJ with OFILE) (replace \DIRTY of TEXTOBJ with NIL) (replace NEXTLINE of LINES with NIL) (replace \INSERTPCVALID of TEXTOBJ with NIL) (* The old cached piece is no longer valid--keep people from stepping on it, to prevent lost type-in and smashing other docuemnts to which it has been moved...) (replace TEXTLEN of TEXTOBJ with (SUB1 (\EDITELT PCTB (SUB1 (\EDITELT PCTB \PCTBLastPieceOffset))))) (replace CH# of SEL with (replace CHLIM of SEL with 1)) (replace DCH of SEL with 0) (replace POINT of SEL with (QUOTE LEFT)) (replace SET of SEL with T) (replace SET of (fetch SCRATCHSEL of TEXTOBJ) with NIL) (replace SET of (fetch SHIFTEDSEL of TEXTOBJ) with NIL) (replace SET of (fetch MOVESEL of TEXTOBJ) with NIL) (replace SET of TEDIT.SELECTION with NIL) (replace SET of TEDIT.SHIFTEDSELECTION with NIL) (replace CARETLOOKS of TEXTOBJ with (\TEDIT.GET.INSERT.CHARLOOKS TEXTOBJ SEL)) (\FILLWINDOW (fetch YBOT of LINES) LINES TEXTOBJ NIL (\TEDIT.PRIMARYW TEXTOBJ)) (\FIXSEL SEL TEXTOBJ) (\SHOWSEL SEL NIL T) (SETQ TITLE (TEXTSTREAM.TITLE TEXTOBJ)) (* find and set the title) (\TEDIT.WINDOW.TITLE TEXTOBJ (\TEDIT.ORIGINAL.WINDOW.TITLE TITLE)) (SETQ MENUSTREAM (TEDITMENU.STREAM TEXTOBJ)) (COND ((AND MENUSTREAM (type? LITATOM TITLE)) (* if we have a filename then put it in the GET and PUT fields of the menu) (SETQ FILENAME (PACKFILENAME (QUOTE VERSION) NIL (QUOTE BODY) TITLE)) (MBUTTON.SET.FIELD MENUSTREAM (QUOTE Get) FILENAME) (MBUTTON.SET.FIELD MENUSTREAM (QUOTE Put) FILENAME))) (\TEDIT.SET.WINDOW.EXTENT TEXTOBJ (\TEDIT.PRIMARYW TEXTOBJ)) (\TEDIT.HISTORYADD TEXTOBJ (create TEDITHISTORYEVENT THACTION ←(QUOTE Get)))) (AND GETFN (APPLY* GETFN (fetch STREAMHINT of TEXTOBJ) (fetch FULLNAME of (fetch TXTFILE of TEXTOBJ)) (QUOTE AFTER)))) (OFILE (TEDIT.PROMPTPRINT TEXTOBJ "[File not found.]")) (T (TEDIT.PROMPTPRINT TEXTOBJ "[Get aborted.]" T)))))) (\TEDIT.MARK.LINES.DIRTY (LAMBDA (TEXTOBJ CH1 CHLIM) (* fgh: "31-May-85 15:33") (* Mark dirty the lines that intersect the range ch1 t chlim inclusive) (bind (CH# ←(IMIN CH1 (fetch TEXTLEN of TEXTOBJ))) (CHLIM# ←(COND ((IEQP CHLIM -1) (ADD1 (fetch TEXTLEN of TEXTOBJ))) (T CHLIM))) for WW inside (fetch \WINDOW of TEXTOBJ) do (bind (LL ←(WINDOWPROP WW (QUOTE LINES))) while LL do (* Mark changed lines as DIRTY.) (COND ((AND (ILEQ (fetch CHAR1 of LL) CHLIM#) (IGEQ (fetch CHARTOP of LL) CH#)) (* The dirty range overlaps with this line -- it is between the 1st char on the line, and the last char examined when deciding where to break the line.) (replace DIRTY of LL with T))) (SETQ LL (fetch NEXTLINE of LL))) finally (replace TXTNEEDSUPDATE of TEXTOBJ with T)))) ) (PUTPROPS INTERMEZZOTEDITFIXES COPYRIGHT ("Xerox Corporation" 1985)) (DECLARE: DONTCOPY (FILEMAP (NIL (500 13637 (TEDIT.PUT 510 . 7302) (TEDIT.GET 7304 . 12419) (\TEDIT.MARK.LINES.DIRTY 12421 . 13635))))) STOP