(FILECREATED "10-Mar-85 15:29:27" {ERIS}<LISPCORE>LISPUSERS>EMACS.;9 72917  

      changes to:  (FNS EMACS.GETCARETPTR)

      previous date: "28-Feb-85 11:56:58" {ERIS}<LISPCORE>LISPUSERS>EMACS.;8)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT EMACSCOMS)

(RPAQQ EMACSCOMS ((* EMACS -- By Kelly Roach *)
	(COMS (* EMACS *)
	      (INITVARS (BytesPerPage 512)
			(EMACS.COMMANDS NIL)
			(EMACS.MCOMMANDS NIL)
			(EMACS.XCOMMANDS NIL)
			(EMACS.LIST (QUOTE ((1 EMACS.GOTO.BOL)
					    (2 EMACS.BACK.BYTE)
					    (4 EMACS.FWD.DELETE.BYTE)
					    (5 EMACS.GOTO.EOL)
					    (6 EMACS.FWD.BYTE)
					    (9 EMACS.TAB)
					    (11 EMACS.KILL.LINE)
					    (12 EMACS.REDISPLAY)
					    (14 EMACS.NEXT.LINE)
					    (16 EMACS.PREVIOUS.LINE)
					    (17 EMACS.QUOTE.BYTE)
					    (19 EMACS.SEARCH)
					    (20 EMACS.TRANSPOSE.BYTES)
					    (22 EMACS.NEXT.SCREENFULL)
					    (24 EMACS.CX)
					    (26 EMACS.CZ)
					    (41 EMACS.RPAREN)
					    (93 EMACS.RBRACKET)
					    (125 EMACS.RBRACE)
					    (127 EMACS.BACK.DELETE.BYTE))))
			(EMACS.MLIST (QUOTE ((1 EMACS.GOTO.BOD)
					     (2 EMACS.SAFE.BACK.SEXPR)
					     (5 EMACS.GOTO.EOD)
					     (6 EMACS.FWD.SEXPR)
					     (11 EMACS.KILL.SEXPR)
					     (62 EMACS.GOTO.BOF)
					     (60 EMACS.GOTO.EOF)
					     (66 EMACS.BACK.WORD)
					     (68 EMACS.FWD.DELETE.WORD)
					     (69 EMACS.EDIT)
					     (70 EMACS.FWD.WORD)
					     (71 EMACS.GRIND)
					     (52 EMACS.SNARF)
					     (86 EMACS.PREVIOUS.SCREENFULL)
					     (94 EMACS.JOIN.LINES)
					     (127 EMACS.BACK.DELETE.WORD))))
			(EMACS.XLIST (QUOTE ((22 EMACS.CXCV)
					     (23 EMACS.CXCW)
					     (26 EMACS.CXCZ))))
			(\BQUOTE.LEVEL 0))
	      (RECORDS EMACSSTREAM)
	      (FNS EMACS.INIT EMACS.INIT.BACKGROUND DEDITEmacs EMACS.INIT.COMMANDS EMACS.COMMAND 
		   EMACS.OPERATE EMACS.GETKEY EMACS EMACS.PROCESS EMACS.TEDIT1 EMACS.WINDOW 
		   EMACS.SETFILEPTR EMACS.GETCARETPTR EMACS.SETCARETPTR EMACS.SHOWCARET EMACS.BOL 
		   EMACS.EOL EMACS.DELETE.BYTES EMACS.BOFP EMACS.EOFP EMACS.CCHAR EMACS.PEEKBIN 
		   EMACS.FBYTE EMACS.FWORD EMACS.FSKIP EMACS.FSKIPTO EMACS.BBYTE EMACS.BCHAR 
		   EMACS.BPEEKCHAR EMACS.BWORD EMACS.BSKIP EMACS.BSKIPTO EMACS.SET.EOF EMACS.GOTO.BOL 
		   EMACS.BACK.BYTE EMACS.FWD.DELETE.BYTE EMACS.GOTO.EOL EMACS.FWD.BYTE 
		   EMACS.KILL.LINE EMACS.REDISPLAY EMACS.NEXT.LINE EMACS.PREVIOUS.LINE 
		   EMACS.QUOTE.BYTE EMACS.SEARCH EMACS.TRANSPOSE.BYTES EMACS.NEXT.SCREENFULL 
		   EMACS.CXCV EMACS.CXCW EMACS.CXCZ EMACS.FWD.SEXPR EMACS.BACK.DELETE.BYTE 
		   EMACS.GOTO.BOD EMACS.BOD EMACS.GOTO.EOD EMACS.EOD EMACS.KILL.SEXPR EMACS.GOTO.BOF 
		   EMACS.GOTO.EOF EMACS.BACK.WORD EMACS.FWD.DELETE.WORD EMACS.EDIT EMACS.FWD.WORD 
		   EMACS.GRIND EMACS.SNARF EMACS.MT EMACS.PREVIOUS.SCREENFULL EMACS.JOIN.LINES 
		   EMACS.BACK.DELETE.WORD NEW.TEDIT.SELECT.LINE.SCANNER))
	(COMS (* BALANCE *)
	      (PROPS (ACCESSFNS EMACS.TAB)
		     (DATATYPE EMACS.TAB)
		     (DEFEXPR EMACS.TAB)
		     (DEFFEXPR EMACS.TAB)
		     (DEFVAR EMACS.TAB)
		     (DO EMACS.TAB)
		     (FOR EMACS.TAB)
		     (LAMBDA EMACS.TAB)
		     (PROG EMACS.TAB)
		     (RECORD EMACS.TAB)
		     (SELECT EMACS.TAB)
		     (SELECTQ EMACS.TAB)
		     (UNTIL EMACS.TAB)
		     (WHILE EMACS.TAB))
	      (INITVARS (EMACS.DELIMS NIL)
			(EMACS.SDELIMS NIL)
			(EMACS.LDELIMS NIL)
			(EMACS.RDELIMS NIL)
			(EMACS.SCACHE NIL)
			(EMACS.BCACHE NIL)
			(EMACS.SYNTAX NIL)
			(EMACS.CR 1)
			(EMACS.WS 2)
			(EMACS.SD 4)
			(EMACS.NONCR 8)
			(EMACS.NONWS 16)
			(EMACS.NONSD 32)
			(EMACS.BQ 64)
			(EMACS.ALPHA 128)
			(EMACS.BD 256)
			(EMACS.SPACE 512))
	      (FNS EMACS.DELIMS EMACS.CR EMACS.RPAREN EMACS.RBRACKET EMACS.RBRACE EMACS.RANGLE 
		   EMACS.SDELIM.COMMAND EMACS.LDELIM.COMMAND EMACS.RDELIM.COMMAND EMACS.SDELIM 
		   EMACS.LDELIM EMACS.RDELIM EMACS.OPEN.STRING EMACS.CLOSE.STRING EMACS.OPEN.BALANCE 
		   EMACS.CLOSE.BALANCE EMACS.FLUSH.CACHE EMACS.SCACHE EMACS.BCACHE 
		   EMACS.SAFE.BACK.SEXPRS EMACS.SAFE.BACK.SEXPR EMACS.BACK.SEXPR EMACS.BACK.WORD 
		   EMACS.BACK.SKIPSEPRS EMACS.BACK.ESCAPEDP EMACS.TAB EMACS.TAB.INDENT 
		   EMACS.INIT.SYNTAX))
	(DECLARE: DONTEVAL@LOAD DOCOPY (P (EMACS.INIT)
					  (MOVD? (QUOTE TEDIT.SELECT.LINE.SCANNER)
						 (QUOTE OLD.TEDIT.SELECT.LINE.SCANNER))
					  (MOVD (QUOTE NEW.TEDIT.SELECT.LINE.SCANNER)
						(QUOTE TEDIT.SELECT.LINE.SCANNER))
					  (MOVD (QUOTE EMACS)
						(QUOTE TEDIT))))))



(* EMACS -- By Kelly Roach *)




(* EMACS *)


(RPAQ? BytesPerPage 512)

(RPAQ? EMACS.COMMANDS NIL)

(RPAQ? EMACS.MCOMMANDS NIL)

(RPAQ? EMACS.XCOMMANDS NIL)

(RPAQ? EMACS.LIST (QUOTE ((1 EMACS.GOTO.BOL)
			  (2 EMACS.BACK.BYTE)
			  (4 EMACS.FWD.DELETE.BYTE)
			  (5 EMACS.GOTO.EOL)
			  (6 EMACS.FWD.BYTE)
			  (9 EMACS.TAB)
			  (11 EMACS.KILL.LINE)
			  (12 EMACS.REDISPLAY)
			  (14 EMACS.NEXT.LINE)
			  (16 EMACS.PREVIOUS.LINE)
			  (17 EMACS.QUOTE.BYTE)
			  (19 EMACS.SEARCH)
			  (20 EMACS.TRANSPOSE.BYTES)
			  (22 EMACS.NEXT.SCREENFULL)
			  (24 EMACS.CX)
			  (26 EMACS.CZ)
			  (41 EMACS.RPAREN)
			  (93 EMACS.RBRACKET)
			  (125 EMACS.RBRACE)
			  (127 EMACS.BACK.DELETE.BYTE))))

(RPAQ? EMACS.MLIST (QUOTE ((1 EMACS.GOTO.BOD)
			   (2 EMACS.SAFE.BACK.SEXPR)
			   (5 EMACS.GOTO.EOD)
			   (6 EMACS.FWD.SEXPR)
			   (11 EMACS.KILL.SEXPR)
			   (62 EMACS.GOTO.BOF)
			   (60 EMACS.GOTO.EOF)
			   (66 EMACS.BACK.WORD)
			   (68 EMACS.FWD.DELETE.WORD)
			   (69 EMACS.EDIT)
			   (70 EMACS.FWD.WORD)
			   (71 EMACS.GRIND)
			   (52 EMACS.SNARF)
			   (86 EMACS.PREVIOUS.SCREENFULL)
			   (94 EMACS.JOIN.LINES)
			   (127 EMACS.BACK.DELETE.WORD))))

(RPAQ? EMACS.XLIST (QUOTE ((22 EMACS.CXCV)
			   (23 EMACS.CXCW)
			   (26 EMACS.CXCZ))))

(RPAQ? \BQUOTE.LEVEL 0)
[DECLARE: EVAL@COMPILE 

(ACCESSFNS EMACSSTREAM ((TEXTOBJ (fetch (STREAM F3) of DATUM))
			(WINDOW (fetch (TEXTOBJ SELWINDOW) of (fetch (EMACSSTREAM TEXTOBJ)
								 of DATUM)))
			(SELECTION (fetch (TEXTOBJ SEL) of (fetch (EMACSSTREAM TEXTOBJ) of DATUM)))
			(CARETPTR (EMACS.GETCARETPTR DATUM))
			(FILEPTR (GETFILEPTR DATUM))
			(DIRTY (fetch (TEXTOBJ \DIRTY) of (fetch (EMACSSTREAM TEXTOBJ) of DATUM)))
			(BCACHE (EMACS.BCACHE DATUM))
			(SCACHE (EMACS.SCACHE DATUM))))
]
(DEFINEQ

(EMACS.INIT
  (LAMBDA NIL                                                (* kbr: "19-Feb-85 15:11")
                                                             (* Initializes EMACS. *)
    (PROG NIL
          (SETQ TEDIT.INTERRUPTS (QUOTE ((7 ERROR)
					  (8 HELP))))
          (RPLACA (CDR DEFAULTCARET)
		  0)
          (SETQ BXCARET DEFAULTCARET)
          (SETQ BXHICARET DEFAULTCARET)
          (SETQ TEDIT.LINECURSOR DEFAULTCURSOR)
          (COND
	    ((BOUNDP (QUOTE TEDIT.DEFAULT.FMTSPEC))          (* Doesn't exist in older TEDITs *)
	      (replace (FMTSPEC TABSPEC) of TEDIT.DEFAULT.FMTSPEC with (QUOTE (56)))))
          (SETQ EMACS.READTABLE (COPYREADTABLE FILERDTBL))
          (EMACS.INIT.COMMANDS)
          (EMACS.INIT.SYNTAX)
          (EMACS.INIT.BACKGROUND)
          (DEFDEDITCOM (QUOTE Emacs)
		       (QUOTE DEDITEmacs))
          (CHANGECCODE (QUOTE NILL)
		       (QUOTE TTYDISPLAYSTREAM)
		       (QUOTE \TEDIT.COMMAND.LOOP)))))

(EMACS.INIT.BACKGROUND
  (LAMBDA NIL                                                (* kbr: "19-Feb-85 15:11")
                                                             (* Fix up BackgroundMenu. *)
    (PROG NIL
          (SETQ BackgroundMenuCommands (FOR BUCKET IN BackgroundMenuCommands
					  WHEN (NOT (EQ (CAR BUCKET)
							(QUOTE TEdit)))
					  COLLECT BUCKET))
          (ADDTOVAR BackgroundMenuCommands (EMACS (QUOTE (EMACS))
						  "Opens an Edit Window."))
          (SETQ BackgroundMenu NIL)                          (* BackgroundMenu recreated by WINDOW package next time
							     user buttons background. *)
      )))

(DEDITEmacs
  (LAMBDA NIL                                                (* kbr: "19-Feb-85 15:11")
                                                             (* Fn to let DEDIT call EMACS on DEDIT top selection.
							     *)
    (PROG (EXPR)
          (CURSOR T)
          (SETQ EXPR (CAR (TOPSELECTION)))
          (SETQ EXPR (READ (EMACS (MKSTRING EXPR)
				  NIL T)
			   EMACS.READTABLE))
          (DEDITZAPCAR (TOPSELECTION)
		       EXPR))))

(EMACS.INIT.COMMANDS
  (LAMBDA NIL                                                (* kbr: "19-Feb-85 15:11")
                                                             (* Initialize TEDIT.READTABLE.
							     *)
    (PROG NIL
          (SETQ EMACS.COMMANDS (ARRAY 128 (QUOTE POINTER)
				      NIL 0))
          (SETQ EMACS.MCOMMANDS (ARRAY 128 (QUOTE POINTER)
				       NIL 0))
          (SETQ EMACS.XCOMMANDS (ARRAY 128 (QUOTE POINTER)
				       NIL 0))
          (FOR BUCKET IN EMACS.LIST DO (SETA EMACS.COMMANDS (CAR BUCKET)
					     (CADR BUCKET)))
          (FOR BUCKET IN EMACS.MLIST DO (SETA EMACS.MCOMMANDS (CAR BUCKET)
					      (CADR BUCKET)))
          (FOR BUCKET IN EMACS.XLIST DO (SETA EMACS.XCOMMANDS (CAR BUCKET)
					      (CADR BUCKET)))
                                                             (* TEDIT.READTABLE's harray not big enough so we make 
							     it bigger. *)
          (replace (READTABLEP READMACRODEFS) of TEDIT.READTABLE with (HARRAY 256))
          (FOR I FROM 0 TO 255 DO (TEDIT.SETFUNCTION I (EMACS.COMMAND I)
						     TEDIT.READTABLE)))))

(EMACS.COMMAND
  (LAMBDA (I)                                                (* kbr: "19-Feb-85 15:11")
    (\BQUOTE (LAMBDA (STREAM)
	       (EMACS.OPERATE (\COMMA I)
			      STREAM)))))

(EMACS.OPERATE
  (LAMBDA (I STREAM)                                         (* kbr: "19-Feb-85 15:11")
                                                             (* Accept token from user *)
    (PROG (N FN PTR CH)
          (EMACS.SETFILEPTR STREAM (fetch (EMACSSTREAM CARETPTR) of STREAM))
          (SETQ N 1)
          (while (EQUAL I (CHARCODE ↑U))
	     do (SETQ N (ITIMES 4 N))
		(SETQ I (EMACS.GETKEY)))
          (SETQ FN (ELT EMACS.COMMANDS I))
          (SELCHARQ I
		    ((ESC ↑Z)
		      (SETQ FN (ELT EMACS.MCOMMANDS (EMACS.GETKEY))))
		    (↑X (SETQ FN (ELT EMACS.XCOMMANDS (EMACS.GETKEY))))
		    (COND
		      ((IGEQ I 128)
			(SETQ FN (ELT EMACS.MCOMMANDS (IDIFFERENCE I 128))))
		      (T (SETQ FN (ELT EMACS.COMMANDS I)))))
          (COND
	    ((NULL FN)                                       (* Insert char I N times. *)
	      (SETQ PTR (GETFILEPTR STREAM))
	      (COND
		((AND (NOT (ZEROP PTR))
		      (EQUAL (\BACKPEEKBIN STREAM)
			     (CHARCODE CR))
		      (NOT (MEMB I (CHARCODE (SP TAB)))))    (* Start of a def *)
		  (EMACS.FLUSH.CACHE)))
	      (SETQ CH (MKSTRING (CHARACTER I)))
	      (COND
		((IEQP N 1)
		  (TEDIT.INSERT STREAM CH))
		(T (TEDIT.INSERT STREAM (ALLOCSTRING N CH))))
	      (EMACS.SETFILEPTR STREAM (IPLUS PTR N)))
	    (T (for J from 1 to N do (APPLY* FN STREAM))
	       (COND
		 ((NOT (BITTEST (ELT EMACS.SYNTAX I)
				(LOGOR EMACS.CR EMACS.SD EMACS.BD)))
		   (EMACS.FLUSH.CACHE)))))
          (EMACS.SHOWCARET STREAM))))

(EMACS.GETKEY
  (LAMBDA NIL                                                (* kbr: "19-Feb-85 15:11")
    (PROG (CODE)
          (CARET (QUOTE OFF))
          (SETQ CODE (\GETKEY))
          (CARET T)
          (RETURN CODE))))

(EMACS
  (LAMBDA (TEXT WINDOW DONTSPAWN PROPS)                      (* kbr: "19-Feb-85 15:11")
    (PROG (PROCESS)                                          (* Get TEXT. *)
          (COND
	    ((AND (NOT (NULL TEXT))
		  (LITATOM TEXT))
	      (SETQ TEXT (OPENFILE TEXT (QUOTE INPUT)
				   (QUOTE OLD)))))           (* Get WINDOW. *)
          (COND
	    ((NULL WINDOW)
	      (SETQ WINDOW (EMACS.WINDOW DONTSPAWN PROPS))))
          (COND
	    (DONTSPAWN                                       (* Don't spawn a process. *)
		       (RETURN (EMACS.TEDIT1 TEXT WINDOW T PROPS)))
	    (T                                               (* Spawn a process. *)
	       (SETQ PROCESS (ADD.PROCESS (\BQUOTE (EMACS.PROCESS (QUOTE (\COMMA TEXT))
								  (QUOTE (\COMMA WINDOW))
								  (QUOTE (\COMMA PROPS))))
					  (QUOTE EMACS)
					  (QUOTE NO)))
	       (TTY.PROCESS PROCESS)
	       (RETURN PROCESS))))))

(EMACS.PROCESS
  (LAMBDA (TEXT WINDOW PROPS)                                (* kbr: "19-Feb-85 15:11")
    (PROG NIL
          (WINDOWPROP WINDOW (QUOTE PROCESS)
		      (THIS.PROCESS))
          (RETURN (EMACS.TEDIT1 TEXT WINDOW NIL PROPS)))))

(EMACS.TEDIT1
  (LAMBDA (TEXT WINDOW UNSPAWNED PROPS)                      (* kbr: "19-Feb-85 15:11")
    (PROG (ANSWER)
          (RESETLST (RESETSAVE (TTYDISPLAYSTREAM WINDOW))
		    (RESETSAVE NIL (LIST (QUOTE INPUT)
					 (INFILE T)))
		    (RESETSAVE NIL (LIST (QUOTE OUTPUT)
					 (OUTFILE T)))
		    (SETQ ANSWER (\TEDIT1 TEXT WINDOW UNSPAWNED PROPS)))
          (RETURN ANSWER))))

(EMACS.WINDOW
  (LAMBDA (DONTSPAWN PROPS)                                  (* kbr: "19-Feb-85 15:11")
    (PROG (WINDOW)
          (COND
	    ((AND DONTSPAWN TEDIT.DEFAULT.WINDOW)
	      (SETQ WINDOW TEDIT.DEFAULT.WINDOW))
	    (T (SETQ WINDOW (TEDIT.CREATEW "Indicate region for EMACS"))))
          (WINDOWPROP WINDOW (QUOTE TEDIT.PROPS)
		      PROPS)
          (RETURN WINDOW))))

(EMACS.SETFILEPTR
  (LAMBDA (STREAM PTR)                                       (* kbr: "19-Feb-85 15:11")
                                                             (* Patch around bug in TEDIT SETFILEPTR.
							     *)
    (PROG NIL
          (COND
	    ((IGREATERP (GETEOFPTR STREAM)
			0)
	      (SETFILEPTR STREAM PTR)
	      (SETFILEPTR STREAM PTR))))))

(EMACS.GETCARETPTR
  (LAMBDA (STREAM)                                           (* kbr: "10-Mar-85 15:21")
    (PROG (SELECTION ANSWER)
          (SETQ SELECTION (fetch (EMACSSTREAM SELECTION) of STREAM))
          (SETQ ANSWER (SELECTQ (fetch (SELECTION POINT) of SELECTION)
				(LEFT (SUB1 (fetch (SELECTION CH#) of SELECTION)))
				(RIGHT (SUB1 (fetch (SELECTION CHLIM) of SELECTION)))
				(SHOULDNT)))
          (RETURN ANSWER))))

(EMACS.SETCARETPTR
  (LAMBDA (STREAM PTR)                                       (* kbr: "19-Feb-85 15:11")
                                                             (* Move caret to new filepos.
							     *)
    (PROG (EOF)
          (SETQ EOF (GETEOFPTR STREAM))
          (SETQ PTR (IMIN (IMAX PTR 0)
			  EOF))
          (TEDIT.SETSEL STREAM (ADD1 PTR)
			0
			(QUOTE LEFT))
          (EMACS.SETFILEPTR STREAM PTR))))

(EMACS.SHOWCARET
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:11")
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (EMACS.SETCARETPTR STREAM PTR)
          (TEDIT.NORMALIZECARET (fetch (EMACSSTREAM TEXTOBJ) of STREAM))
          (EMACS.SETFILEPTR STREAM PTR))))

(EMACS.BOL
  (LAMBDA (STREAM PTR)                                       (* kbr: "19-Feb-85 15:11")
                                                             (* Beginning of line wrt filepos PTR.
							     *)
    (PROG (OLDPTR BOL)
          (SETQ OLDPTR (GETFILEPTR STREAM))
          (EMACS.SETFILEPTR STREAM PTR)
          (EMACS.BSKIP STREAM EMACS.NONCR)
          (SETQ BOL (GETFILEPTR STREAM))
          (EMACS.SETFILEPTR STREAM OLDPTR)
          (RETURN BOL))))

(EMACS.EOL
  (LAMBDA (STREAM PTR)                                       (* kbr: "19-Feb-85 15:11")
                                                             (* End of line wrt filepos PTR.
							     *)
    (PROG (OLDPTR EOL)
          (SETQ OLDPTR (GETFILEPTR STREAM))
          (EMACS.SETFILEPTR STREAM PTR)
          (EMACS.FSKIP STREAM EMACS.NONCR)
          (SETQ EOL (GETFILEPTR STREAM))
          (EMACS.SETFILEPTR STREAM OLDPTR)
          (RETURN EOL))))

(EMACS.DELETE.BYTES
  (LAMBDA (STREAM PTR1 PTR2)                                 (* kbr: "19-Feb-85 15:11")
                                                             (* Delete between PTR1 & PTR2 inclusive.
							     *)
    (PROG (PTR LENGTH)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ PTR1 (IMAX 0 PTR1))
          (SETQ PTR2 (IMIN (GETEOFPTR STREAM)
			   PTR2))
          (SETQ LENGTH (IPLUS PTR2 (IMINUS PTR1)
			      1))
          (TEDIT.DELETE STREAM (ADD1 PTR1)
			LENGTH)
          (COND
	    ((ILEQ PTR PTR1)
	      (EMACS.SETFILEPTR STREAM PTR))
	    ((ILEQ PTR PTR2)
	      (EMACS.SETFILEPTR STREAM PTR1))
	    (T (EMACS.SETFILEPTR STREAM (IDIFFERENCE PTR LENGTH)))))))

(EMACS.BOFP
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:11")
    (ZEROP (GETFILEPTR STREAM))))

(EMACS.EOFP
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:11")
    (IEQP (GETFILEPTR STREAM)
	  (GETEOFPTR STREAM))))

(EMACS.CCHAR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:11")
                                                             (* Caret char. Char being pointed at by caret.
							     *)
    (PROG (ANSWER)
          (SETQ ANSWER (\BIN STREAM))
          (\BACKBIN STREAM)
          (RETURN ANSWER))))

(EMACS.PEEKBIN
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:11")
    (PROG (PTR ANSWER)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ ANSWER (\BIN STREAM))
          (EMACS.SETFILEPTR STREAM PTR)
          (RETURN ANSWER))))

(EMACS.FBYTE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:11")
                                                             (* Forward a char. *)
    (COND
      ((NOT (EMACS.EOFP STREAM))
	(\BIN STREAM)))))

(EMACS.FWORD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:11")
                                                             (* Forward a word. *)
    (CAR (NLSETQ (RATOM STREAM)))))

(EMACS.FSKIP
  (LAMBDA (STREAM CLASS LIMIT)                               (* kbr: "19-Feb-85 15:11")
                                                             (* Skip chars in CLASS. *)
    (COND
      ((NULL LIMIT)
	(SETQ LIMIT (GETEOFPTR STREAM))))
    (PROG NIL
          (while (AND (ILESSP (GETFILEPTR STREAM)
			      LIMIT)
		      (BITTEST (ELT EMACS.SYNTAX (OR (NUMBERP (EMACS.PEEKBIN STREAM))
						     256))
			       CLASS))
	     do (\BIN STREAM)))))

(EMACS.FSKIPTO
  (LAMBDA (STREAM CLASS)                                     (* kbr: "19-Feb-85 15:12")
                                                             (* Skip chars in CLASS. *)
    (PROG NIL
          (WHILE (AND (NOT (EMACS.EOFP STREAM))
		      (NOT (BITTEST (ELT EMACS.SYNTAX (OR (NUMBERP (\BIN STREAM))
							  256))
				    CLASS)))
	     DO                                              (* Continue reading. *)))))

(EMACS.BBYTE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Backward a byte. *)
    (COND
      ((NOT (EMACS.BOFP STREAM))
	(\BACKBIN STREAM)))))

(EMACS.BCHAR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Backward a char. *)
    (PROG (BYTE1 BYTE2)
          (SETQ BYTE1 (EMACS.BBYTE STREAM))
          (COND
	    ((NOT (EMACS.BOFP STREAM))
	      (SETQ BYTE2 (\BACKPEEKBIN STREAM))))
          (COND
	    ((EQ BYTE2 (CHARCODE %%))
	      (EMACS.BBYTE STREAM)))
          (RETURN BYTE1))))

(EMACS.BPEEKCHAR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Backwards peek at char. *)
    (PROG (PTR BYTE)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ BYTE (EMACS.BCHAR STREAM))
          (SETFILEPTR STREAM PTR)
          (RETURN BYTE))))

(EMACS.BWORD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Backward a word. *)
    (PROG NIL
          (EMACS.BSKIP STREAM EMACS.WS)
          (EMACS.BSKIP STREAM EMACS.NONWS))))

(EMACS.BSKIP
  (LAMBDA (STREAM CLASS LIMIT)                               (* kbr: "19-Feb-85 15:12")
                                                             (* Skip chars in CLASS. *)
    (COND
      ((NULL LIMIT)
	(SETQ LIMIT 0)))
    (PROG NIL
          (while (AND (IGREATERP (GETFILEPTR STREAM)
				 LIMIT)
		      (BITTEST (ELT EMACS.SYNTAX (OR (NUMBERP (\BACKPEEKBIN STREAM))
						     256))
			       CLASS))
	     do (\BACKBIN STREAM)))))

(EMACS.BSKIPTO
  (LAMBDA (STREAM CLASS)                                     (* kbr: "19-Feb-85 15:12")
                                                             (* Skip chars in CLASS. *)
    (PROG NIL
          (WHILE (AND (NOT (EMACS.BOFP STREAM))
		      (NOT (BITTEST (ELT EMACS.SYNTAX (OR (NUMBERP (\BACKBIN STREAM))
							  256))
				    CLASS)))
	     DO                                              (* Continue reading. *)))))

(EMACS.SET.EOF
  (LAMBDA (STREAM PTR)                                       (* kbr: "19-Feb-85 15:12")
                                                             (* Temporarily reset eof of STREAM.
							     *)
    (PROG NIL
          (replace (STREAM EPAGE) of STREAM with (LRSH PTR 8))
          (replace (STREAM EOFFSET) of STREAM with (LOGAND PTR 255))
          (replace (TEXTOBJ TEXTLEN) of (fetch (EMACSSTREAM TEXTOBJ) of STREAM) with PTR))))

(EMACS.GOTO.BOL
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go to beginning of line. *)
    (PROG NIL
          (EMACS.BSKIP STREAM EMACS.NONCR))))

(EMACS.BACK.BYTE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go back a byte. *)
    (PROG NIL
          (EMACS.BBYTE STREAM))))

(EMACS.FWD.DELETE.BYTE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Delete byte. *)
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (EMACS.DELETE.BYTES STREAM PTR PTR))))

(EMACS.GOTO.EOL
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go to end of line. *)
    (PROG NIL
          (EMACS.FSKIP STREAM EMACS.NONCR))))

(EMACS.FWD.BYTE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go forward a byte. *)
    (PROG NIL
          (EMACS.FBYTE STREAM))))

(EMACS.KILL.LINE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Delete a line. *)
    (PROG (PTR EOL)
          (SETQ PTR (GETFILEPTR STREAM))
          (EMACS.FSKIP STREAM EMACS.NONCR)
          (SETQ EOL (GETFILEPTR STREAM))
          (COND
	    ((IGREATERP EOL PTR)
	      (EMACS.DELETE.BYTES STREAM PTR (SUB1 EOL)))
	    ((ILESSP EOL (GETEOFPTR STREAM))
	      (EMACS.DELETE.BYTES STREAM EOL EOL)))
          (EMACS.SETFILEPTR STREAM PTR))))

(EMACS.REDISPLAY
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Redisplay EMACS screen. *)
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (REDISPLAYW (fetch (EMACSSTREAM WINDOW) of STREAM))
          (EMACS.SETFILEPTR STREAM PTR))))

(EMACS.NEXT.LINE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go down a line. *)
    (PROG (PTR BOL EOL NBOL NEOL OFFSET)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ BOL (EMACS.BOL STREAM PTR))                  (* First byte on line is at OFFSET = 0.0 *)
          (SETQ OFFSET (IPLUS PTR (IMINUS BOL)))
          (SETQ EOL (EMACS.EOL STREAM PTR))
          (SETQ NBOL (ADD1 EOL))
          (COND
	    ((ILEQ (GETEOFPTR STREAM)
		   NBOL)
	      (EMACS.SETFILEPTR STREAM (GETEOFPTR STREAM)))
	    (T (SETQ NEOL (EMACS.EOL STREAM NBOL))
	       (SETQ OFFSET (IMIN OFFSET (IDIFFERENCE NEOL NBOL)))
	       (EMACS.SETFILEPTR STREAM (IPLUS NBOL OFFSET)))))))

(EMACS.PREVIOUS.LINE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go up a line. *)
    (PROG (PTR BOL PBOL PEOL OFFSET)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ BOL (EMACS.BOL STREAM PTR))                  (* First byte on line is at OFFSET = 0.0 *)
          (SETQ OFFSET (IPLUS PTR (IMINUS BOL)))
          (SETQ PEOL (SUB1 BOL))
          (COND
	    ((IGEQ 0 PEOL)
	      (EMACS.SETFILEPTR STREAM 0))
	    (T (SETQ PBOL (EMACS.BOL STREAM PEOL))
	       (SETQ OFFSET (IMIN OFFSET (IDIFFERENCE PEOL PBOL)))
	       (EMACS.SETFILEPTR STREAM (IPLUS PBOL OFFSET)))))))

(EMACS.QUOTE.BYTE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Quote next byte. *)
    (PROG (PTR CH)                                           (* TBW: Fix use TEDIT's use of terminal table.
							     *)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ CH (EMACS.GETKEY))
          (TEDIT.INSERT STREAM CH (ADD1 PTR))
          (EMACS.SETFILEPTR STREAM (ADD1 PTR)))))

(EMACS.SEARCH
  (LAMBDA (STREAM)                                           (* kbr: "28-Feb-85 11:10")
                                                             (* Search for string. *)
    (PROG (PTR TEXTOBJ WINDOW STRING NEWPTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ TEXTOBJ (fetch (EMACSSTREAM TEXTOBJ) of STREAM))
          (SETQ WINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))
          (ERSETQ (RESETLST (RESETSAVE (\TEDIT.MARKACTIVE TEXTOBJ)
				       (QUOTE (AND (\TEDIT.MARKINACTIVE OLDVALUE))))
			    (replace (TEXTOBJ EDITOPACTIVE) of TEXTOBJ with (QUOTE Find))
			    (SETQ STRING (WINDOWPROP WINDOW (QUOTE TEDIT.LAST.FIND.STRING)))
			    (SETQ STRING (TEDIT.GETINPUT STREAM "Text to find: " STRING
							 (CHARCODE (CR ↑S))))
			    (COND
			      (STRING (WINDOWPROP WINDOW (QUOTE TEDIT.LAST.FIND.STRING)
						  (MKSTRING STRING))
				      (RESETLST (RESETSAVE (CURSOR WAITINGCURSOR))
						(SETQ NEWPTR (FILEPOS STRING STREAM PTR)))
				      (COND
					(NEWPTR (EMACS.SETFILEPTR STREAM (IPLUS NEWPTR (NCHARS STRING)
										)))
					(T (FRESHLINE PROMPTWINDOW)
					   (printout PROMPTWINDOW "String '" STRING "' not found." T)
					   (EMACS.SETFILEPTR STREAM PTR))))))))))

(EMACS.TRANSPOSE.BYTES
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Transpose bytes. *)
    (PROG (PTR CODE CH)
          (COND
	    ((OR (EMACS.BOFP STREAM)
		 (EMACS.EOFP STREAM))
	      (RETURN)))
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ CODE (\BIN STREAM))
          (COND
	    ((NUMBERP CODE)
	      (SETQ CH (MKSTRING (CHARACTER CODE))))
	    (T                                               (* IMAGEOBJ *)
	       (SETQ CH CODE)))
          (EMACS.DELETE.BYTES STREAM PTR PTR)
          (EMACS.SETFILEPTR STREAM (SUB1 PTR))
          (TEDIT.INSERT STREAM CH PTR)
          (EMACS.SETFILEPTR STREAM (ADD1 PTR)))))

(EMACS.NEXT.SCREENFULL
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Forward one screenfull. *)
    (PROG (WINDOW DELTAX DELTAY)
          (SETQ WINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))
          (SETQ DELTAX 0)
          (SETQ DELTAY (IDIFFERENCE (WINDOWPROP WINDOW (QUOTE HEIGHT))
				    (FONTPROP (DSPFONT NIL WINDOW)
					      (QUOTE HEIGHT))))
          (replace (TEXTOBJ EDITOPACTIVE) of (fetch (EMACSSTREAM TEXTOBJ) of STREAM) with NIL)
          (\TEDIT.SCROLLFN WINDOW DELTAX DELTAY))))

(EMACS.CXCV
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Visit a file. *)
    (PROG (PTR FILE)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ FILE (MKATOM (TEDIT.GETINPUT STREAM "File to GET:")))
          (SETFILEPTR STREAM PTR)
          (COND
	    ((NULL FILE)
	      (TEDIT.PROMPTPRINT (fetch (EMACSSTREAM TEXTOBJ) of STREAM)
				 "[Visit aborted.]" T)
	      (RETURN)))
          (SETQ FILE (INFILEP FILE))
          (COND
	    ((NULL FILE)
	      (TEDIT.PROMPTPRINT (fetch (EMACSSTREAM TEXTOBJ) of STREAM)
				 "[Visit couldn't find file.]" T)
	      (RETURN)))
          (COND
	    ((FOR WINDOW IN (ACTIVEWINDOWS) THEREIS (EQ (WINDOWPROP WINDOW (QUOTE EMACS.VISITING))
							FILE))
	      (TEDIT.PROMPTPRINT (fetch (EMACSSTREAM TEXTOBJ) of STREAM)
				 "[Already visiting file.]" T)
	      (RETURN)))
          (COND
	    ((NULL FILE)
	      (RETURN)))
          (COND
	    ((fetch (EMACSSTREAM DIRTY) of STREAM)
	      (EMACS.CXCW STREAM)))
          (TEDIT.GET (fetch (EMACSSTREAM TEXTOBJ) of STREAM)
		     FILE)
          (WINDOWPROP (fetch (EMACSSTREAM WINDOW) of STREAM)
		      (QUOTE EMACS.VISITING)
		      FILE)
          (EMACS.SETFILEPTR STREAM 0))))

(EMACS.CXCW
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Write buffer out to file.
							     *)
    (PROG NIL
          (TEDIT.PUT (fetch (EMACSSTREAM TEXTOBJ) of STREAM)))))

(EMACS.CXCZ
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Eval FORM in front of caret in lisp EXEC process.
							     *)
    (PROG (FORM)
          (SETQ FORM (READ STREAM))
          (PROCESS.EVAL (QUOTE EXEC)
			FORM))))

(EMACS.FWD.SEXPR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go forward a sexpr. *)
    (PROG (EOD EOD SEXPR PTR)                                (* SETQ EOD (EMACS.EOD STREAM))
                                                             (* SETQ EOF (GETEOFPTR STREAM))
          (RESETLST                                          (* Accept uncaught BQUOTE commas.
							     *)
		    (RESETSAVE \BQUOTE.LEVEL (IQUOTIENT MAX.FIXP 2))
                                                             (* RESETSAVE (EMACS.SET.EOF STREAM EOD) 
							     (\BQUOTE (EMACS.SET.EOF (\COMMA STREAM) 
							     (\COMMA EOF))))
		    (SETQ SEXPR (NLSETQ (READ STREAM)))
		    (SETQ PTR (GETFILEPTR STREAM)))
          (COND
	    ((NULL SEXPR)
	      (FLASHWINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))))
          (SETFILEPTR STREAM PTR))))

(EMACS.BACK.DELETE.BYTE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Delete byte in backwards direction.
							     *)
                                                             (* TBW: Delete selection if there is a selection.
							     *)
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (EMACS.DELETE.BYTES STREAM (SUB1 PTR)
			      (SUB1 PTR)))))

(EMACS.GOTO.BOD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go to top of definition. *)
    (PROG NIL
          (SETFILEPTR STREAM (EMACS.BOD STREAM)))))

(EMACS.BOD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Determine top of definition.
							     *)
    (PROG (PTR ANSWER)
          (SETQ PTR (GETFILEPTR STREAM))                     (* Find lparen preceded by CR.
							     *)
          (EMACS.BSKIP STREAM EMACS.CR)
          (DO (COND
		((EMACS.BOFP STREAM)
		  (RETURN)))
	      (EMACS.BSKIP STREAM EMACS.NONCR)
	      (COND
		((EMACS.BOFP STREAM)
		  (RETURN)))
	      (COND
		((OR (EMACS.BOFP STREAM)
		     (EQ (\PEEKBIN STREAM)
			 (CHARCODE "(")))
		  (RETURN)))
	      (EMACS.BBYTE STREAM))
          (SETQ ANSWER (GETFILEPTR STREAM))
          (SETFILEPTR STREAM PTR)
          (RETURN ANSWER))))

(EMACS.GOTO.EOD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go to top of next definition.
							     *)
    (PROG NIL
          (SETFILEPTR STREAM (EMACS.EOD STREAM)))))

(EMACS.EOD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Determine top of next definition.
							     *)
    (PROG (PTR ANSWER)
          (SETQ PTR (GETFILEPTR STREAM))                     (* Find two CRs. *)
          (EMACS.FSKIP STREAM EMACS.CR)
          (DO (COND
		((EMACS.EOFP STREAM)
		  (RETURN)))
	      (EMACS.FSKIP STREAM EMACS.NONCR)
	      (COND
		((EMACS.EOFP STREAM)
		  (RETURN)))
	      (EMACS.FBYTE STREAM)
	      (COND
		((OR (EMACS.EOFP STREAM)
		     (EQ (\PEEKBIN STREAM)
			 (CHARCODE CR)))
		  (\BACKBIN STREAM)
		  (RETURN))))
          (SETQ ANSWER (GETFILEPTR STREAM))
          (SETFILEPTR STREAM PTR)
          (RETURN ANSWER))))

(EMACS.KILL.SEXPR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Delete expression. *)
    (PROG (PTR1 PTR2)
          (SETQ PTR1 (GETFILEPTR STREAM))
          (EMACS.FWD.SEXPR STREAM)
          (SETQ PTR2 (GETFILEPTR STREAM))
          (EMACS.DELETE.BYTES STREAM PTR1 (SUB1 PTR2))
          (EMACS.SETFILEPTR STREAM PTR1))))

(EMACS.GOTO.BOF
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:12")
                                                             (* Go to beginning of file. *)
    (PROG NIL
          (EMACS.SETFILEPTR STREAM 0))))

(EMACS.GOTO.EOF
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Go to end of file. *)
    (PROG NIL
          (EMACS.SETFILEPTR STREAM (GETEOFPTR STREAM)))))

(EMACS.BACK.WORD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (SA CH SNX OTHERS)
          (EMACS.BACK.SKIPSEPRS STREAM)
          (COND
	    ((EMACS.BOFP STREAM)
	      (ERROR!)))
          (SETQ SA (fetch (READTABLEP READSA) of EMACS.READTABLE))
          (do (COND
		((EMACS.BOFP STREAM)
		  (RETURN)))
	      (SETQ CH (\BACKBIN STREAM))
	      (SETQ SNX (\GETBASEBYTE SA CH))
	      (COND
		((EQ SNX OTHER.RC)
		  (SETQ OTHERS T))
		(T (\BIN STREAM)
		   (COND
		     ((EMACS.BACK.ESCAPEDP STREAM)           (* "%%%%%%c" *)
		       (\BACKBIN STREAM)
		       (while (NOT (EMACS.BOFP STREAM))
			  do (SETQ CH (\BACKBIN STREAM))
			     (SETQ SNX (\GETBASEBYTE SA CH))
			     (COND
			       ((NOT (EQ SNX ESCAPE.RC))
				 (\BIN STREAM)
				 (RETURN))))
		       (SETQ OTHERS T))
		     ((EQ SNX SEPRCHAR.RC)
		       (RETURN))
		     (OTHERS (RETURN))
		     (T (\BACKBIN STREAM)
			(RETURN)))))))))

(EMACS.FWD.DELETE.WORD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Delete word. *)
    (PROG (PTR1 PTR2)
          (SETQ PTR1 (GETFILEPTR STREAM))
          (EMACS.FWORD STREAM)
          (SETQ PTR2 (GETFILEPTR STREAM))
          (EMACS.DELETE.BYTES STREAM PTR1 (SUB1 PTR2))
          (EMACS.SETFILEPTR STREAM PTR1))))

(EMACS.EDIT
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* DEDIT expression. *)
    (PROG (EXPR PTR1 PTR2)
          (SKIPSEPRS STREAM)
          (SETQ PTR1 (GETFILEPTR STREAM))
          (SETQ EXPR (EMACS.FWD.SEXPR STREAM))
          (SETQ PTR2 (GETFILEPTR STREAM))
          (EMACS.DELETE.BYTES STREAM PTR1 (SUB1 PTR2))
          (SETQ EXPR (EDITE EXPR))
          (PRINTDEF EXPR NIL NIL NIL NIL STREAM))))

(EMACS.FWD.WORD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Forward a word. *)
    (PROG NIL
          (EMACS.FWORD STREAM))))

(EMACS.GRIND
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Grind expression. *)
    (PROG (EXPR PTR1 PTR2)
          (SKIPSEPRS STREAM)
          (SETQ PTR1 (GETFILEPTR STREAM))
          (SETQ EXPR (EMACS.FWD.SEXPR STREAM))
          (SETQ PTR2 (GETFILEPTR STREAM))
          (EMACS.DELETE.BYTES STREAM PTR1 (SUB1 PTR2))
          (PRINTDEF EXPR NIL NIL NIL NIL STREAM))))

(EMACS.SNARF
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Snarf expression from DEDIT window.
							     *)
    (PROG (EXPR)
          (SETQ EXPR (CAR (TOPSELECTION)))
          (PRINTDEF EXPR NIL NIL NIL NIL STREAM))))

(EMACS.MT
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Transpose words. *)
    (PROG (PTR BPTR1 BPTR2 FPTR1 FPTR2)
          (SETQ PTR (GETFILEPTR STREAM))
          (EMACS.BSKIP STREAM EMACS.WS)
          (SETQ BPTR2 (GETFILEPTR STREAM))
          (EMACS.BWORD)
          (SETQ BPTR1 (GETFILEPTR STREAM))
          (EMACS.SETFILEPTR STREAM PTR)
          (EMACS.FSKIP STREAM EMACS.WS)
          (SETQ FPTR1 (GETFILEPTR STREAM))
          (EMACS.FWORD STREAM)
          (SETQ FPTR2 (GETFILEPTR STREAM))                   (* How do I move? *)
      )))

(EMACS.PREVIOUS.SCREENFULL
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Backwards a screenfull. *)
    (PROG (WINDOW DELTAX DELTAY)
          (SETQ WINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))
          (SETQ DELTAX 0)
          (SETQ DELTAY (IDIFFERENCE (FONTPROP (DSPFONT NIL WINDOW)
					      (QUOTE HEIGHT))
				    (WINDOWPROP WINDOW (QUOTE HEIGHT))))
          (replace (TEXTOBJ EDITOPACTIVE) of (fetch (EMACSSTREAM TEXTOBJ) of STREAM) with NIL)
          (\TEDIT.SCROLLFN WINDOW DELTAX DELTAY))))

(EMACS.JOIN.LINES
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Move current line up *)
    (PROG (PTR BOL EOL PBOL PEOL PTR1 PTR2)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ BOL (EMACS.BOL STREAM PTR))
          (SETQ EOL (EMACS.EOL STREAM PTR))
          (COND
	    ((ZEROP BOL)
	      (RETURN)))
          (SETQ PEOL (SUB1 BOL))
          (SETQ PBOL (EMACS.BOL STREAM PEOL))
          (EMACS.SETFILEPTR STREAM BOL)
          (EMACS.BSKIP STREAM EMACS.WS)
          (SETQ PTR1 (IMAX (GETFILEPTR STREAM)
			   PBOL))
          (EMACS.SETFILEPTR STREAM BOL)
          (EMACS.FSKIP STREAM EMACS.WS)
          (SETQ PTR2 (IMIN (GETFILEPTR STREAM)
			   (ADD1 EOL)))
          (EMACS.SETFILEPTR STREAM PTR1)
          (EMACS.DELETE.BYTES STREAM PTR1 (SUB1 PTR2))
          (\BOUT STREAM (CHARCODE SP))
          (EMACS.SETFILEPTR STREAM (ADD1 PTR1)))))

(EMACS.BACK.DELETE.WORD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:13")
                                                             (* Delete backward a word. *)
    (PROG (PTR1 PTR2)
          (SETQ PTR1 (GETFILEPTR STREAM))
          (EMACS.BWORD STREAM)
          (SETQ PTR2 (GETFILEPTR STREAM))
          (EMACS.DELETE.BYTES STREAM PTR2 (SUB1 PTR1)))))

(NEW.TEDIT.SELECT.LINE.SCANNER
  (LAMBDA (X Y TEXTOBJ LINE.LIST REGION WORDSELFLG SELOPERATION WINDOW)
                                                             (* kbr: "19-Feb-85 15:13")
    (PROG (SELECTION PTR)
          (SETQ SELECTION (OLD.TEDIT.SELECT.LINE.SCANNER X Y TEXTOBJ LINE.LIST REGION WORDSELFLG 
							 SELOPERATION WINDOW))
          (COND
	    ((EQ (TYPENAME SELECTION)
		 (QUOTE SELECTION))
	      (replace (SELECTION POINT) of SELECTION with (QUOTE LEFT))
	      (EMACS.SETFILEPTR (fetch (TEXTOBJ STREAMHINT) of TEXTOBJ)
				(SUB1 (fetch (SELECTION CH#) of SELECTION)))))
          (EMACS.FLUSH.CACHE)
          (RETURN SELECTION))))
)



(* BALANCE *)


(PUTPROPS ACCESSFNS EMACS.TAB 2)

(PUTPROPS DATATYPE EMACS.TAB 2)

(PUTPROPS DEFEXPR EMACS.TAB 2)

(PUTPROPS DEFFEXPR EMACS.TAB 2)

(PUTPROPS DEFVAR EMACS.TAB 2)

(PUTPROPS DO EMACS.TAB 1)

(PUTPROPS FOR EMACS.TAB 1)

(PUTPROPS LAMBDA EMACS.TAB 2)

(PUTPROPS PROG EMACS.TAB 2)

(PUTPROPS RECORD EMACS.TAB 2)

(PUTPROPS SELECT EMACS.TAB 2)

(PUTPROPS SELECTQ EMACS.TAB 2)

(PUTPROPS UNTIL EMACS.TAB 1)

(PUTPROPS WHILE EMACS.TAB 1)

(RPAQ? EMACS.DELIMS NIL)

(RPAQ? EMACS.SDELIMS NIL)

(RPAQ? EMACS.LDELIMS NIL)

(RPAQ? EMACS.RDELIMS NIL)

(RPAQ? EMACS.SCACHE NIL)

(RPAQ? EMACS.BCACHE NIL)

(RPAQ? EMACS.SYNTAX NIL)

(RPAQ? EMACS.CR 1)

(RPAQ? EMACS.WS 2)

(RPAQ? EMACS.SD 4)

(RPAQ? EMACS.NONCR 8)

(RPAQ? EMACS.NONWS 16)

(RPAQ? EMACS.NONSD 32)

(RPAQ? EMACS.BQ 64)

(RPAQ? EMACS.ALPHA 128)

(RPAQ? EMACS.BD 256)

(RPAQ? EMACS.SPACE 512)
(DEFINEQ

(EMACS.DELIMS
  (LAMBDA (LCHARCODE RCHARCODE)                              (* kbr: "19-Feb-85 15:13")
                                                             (* Make LCHARCODE & RCHARCODE into delimiters.
							     If LCHARCODE = RCHARCODE, then string style.
							     Otherwise paren style. *)
    (PROG (BUCKET)
          (SETQ BUCKET (CONS LCHARCODE RCHARCODE))
          (COND
	    ((MEMBER BUCKET EMACS.DELIMS)                    (* Already there. *)
	      (RETURN)))
          (PUSH EMACS.DELIMS BUCKET)
          (COND
	    ((IEQP LCHARCODE RCHARCODE)
	      (SETSYNTAX LCHARCODE (QUOTE STRINGDELIM)
			 EMACS.READTABLE)
	      (SETA EMACS.SYNTAX LCHARCODE (LOGOR EMACS.NONWS EMACS.NONCR EMACS.SD))
	      (SETA EMACS.COMMANDS LCHARCODE (EMACS.SDELIM.COMMAND (MKSTRING (CHARACTER LCHARCODE))))
	      (PUSH EMACS.SDELIMS LCHARCODE))
	    (T (SETSYNTAX LCHARCODE (QUOTE LEFTPAREN)
			  EMACS.READTABLE)
	       (SETSYNTAX RCHARCODE (QUOTE RIGHTPAREN)
			  EMACS.READTABLE)
	       (FOR I IN (LIST LCHARCODE RCHARCODE) DO (SETA EMACS.SYNTAX I
							     (LOGOR EMACS.NONCR EMACS.NONWS 
								    EMACS.NONSD EMACS.BD)))
	       (SETA EMACS.COMMANDS LCHARCODE (EMACS.LDELIM.COMMAND (MKSTRING (CHARACTER LCHARCODE))))
	       (SETA EMACS.COMMANDS RCHARCODE (EMACS.RDELIM.COMMAND (MKSTRING (CHARACTER RCHARCODE))))
	       (PUSH EMACS.LDELIMS LCHARCODE)
	       (PUSH EMACS.RDELIMS RCHARCODE))))))

(EMACS.CR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM (CHARACTER (CHARCODE CR)))
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((NOT (EQ (EMACS.SCACHE STREAM)
		      (QUOTE OUTSIDE)))
	      (FLASHWINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))
	      (EMACS.SETCARETPTR STREAM EMACS.SCACHE)
	      (DISMISS 1000)
	      (EMACS.SETCARETPTR STREAM (ADD1 PTR))
	      (SETQ EMACS.SCACHE (QUOTE OUTSIDE))
	      (SETQ EMACS.BCACHE NIL))))))

(EMACS.RPAREN
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM ")")
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((EQ (EMACS.SCACHE STREAM)
		 (QUOTE OUTSIDE))
	      (EMACS.CLOSE.BALANCE STREAM))))))

(EMACS.RBRACKET
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM "]")
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((EQ (EMACS.SCACHE STREAM)
		 (QUOTE OUTSIDE))
	      (EMACS.CLOSE.BALANCE STREAM))))))

(EMACS.RBRACE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM "}")
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((EQ (EMACS.SCACHE STREAM)
		 (QUOTE OUTSIDE))
	      (EMACS.CLOSE.BALANCE STREAM))))))

(EMACS.RANGLE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM ">")
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((EQ (EMACS.SCACHE STREAM)
		 (QUOTE OUTSIDE))
	      (EMACS.CLOSE.BALANCE STREAM))))))

(EMACS.SDELIM.COMMAND
  (LAMBDA (SDELIM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Return sdelim fn to be inserted in EMACS.COMMANDS.
							     SDELIM = 1 letter string. *)
    (PROG (ANSWER)
          (SETQ ANSWER (\BQUOTE (LAMBDA (STREAM)
				  (EMACS.SDELIM (\COMMA SDELIM)
						STREAM))))
          (RETURN ANSWER))))

(EMACS.LDELIM.COMMAND
  (LAMBDA (LDELIM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Return LDELIM fn to be inserted in EMACS.COMMANDS.
							     LDELIM = 1 letter string. *)
    (PROG (ANSWER)
          (SETQ ANSWER (\BQUOTE (LAMBDA (STREAM)
				  (EMACS.LDELIM (\COMMA LDELIM)
						STREAM))))
          (RETURN ANSWER))))

(EMACS.RDELIM.COMMAND
  (LAMBDA (RDELIM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Return RDELIM fn to be inserted in EMACS.COMMANDS.
							     RDELIM = 1 letter string. *)
    (PROG (ANSWER)
          (SETQ ANSWER (\BQUOTE (LAMBDA (STREAM)
				  (EMACS.RDELIM (\COMMA RDELIM)
						STREAM))))
          (RETURN ANSWER))))

(EMACS.SDELIM
  (LAMBDA (SDELIM STREAM)                                    (* kbr: "19-Feb-85 15:14")
                                                             (* Insert string delimiter SDELIM & update caches.
							     SDELIM = 1 letter string *)
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM SDELIM)
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((EMACS.BACK.ESCAPEDP STREAM)
	      (RETURN)))
          (COND
	    ((EQ (EMACS.SCACHE STREAM)
		 (QUOTE OUTSIDE))
	      (EMACS.OPEN.STRING STREAM))
	    (T (EMACS.CLOSE.STRING STREAM))))))

(EMACS.LDELIM
  (LAMBDA (LDELIM STREAM)                                    (* kbr: "19-Feb-85 15:14")
                                                             (* Insert LDELIM & update caches.
							     LDELIM = 1 letter string *)
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM LDELIM)
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((EMACS.BACK.ESCAPEDP STREAM)
	      (RETURN)))
          (COND
	    ((EQ (EMACS.SCACHE STREAM)
		 (QUOTE OUTSIDE))
	      (EMACS.OPEN.BALANCE STREAM))))))

(EMACS.RDELIM
  (LAMBDA (RDELIM STREAM)                                    (* kbr: "19-Feb-85 15:14")
                                                             (* Insert RDELIM & update caches.
							     RDELIM = 1 letter string *)
    (PROG (PTR)
          (SETQ PTR (GETFILEPTR STREAM))
          (TEDIT.INSERT STREAM RDELIM)
          (EMACS.SETFILEPTR STREAM (ADD1 PTR))
          (COND
	    ((EMACS.BACK.ESCAPEDP STREAM)
	      (RETURN)))
          (COND
	    ((EQ (EMACS.SCACHE STREAM)
		 (QUOTE OUTSIDE))
	      (EMACS.CLOSE.BALANCE STREAM))))))

(EMACS.OPEN.STRING
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (LPTR)                                             (* We should be 1 char after left delim.
							     *)
          (SETQ LPTR (SUB1 (GETFILEPTR STREAM)))
          (SETQ EMACS.SCACHE LPTR))))

(EMACS.CLOSE.STRING
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (LPTR RPTR LDELIM RDELIM MATCHED)                  (* We should be 1 char after right delim.
							     *)
          (SETQ EMACS.SCACHE (QUOTE OUTSIDE))
          (SETQ RPTR (SUB1 (GETFILEPTR STREAM)))
          (EMACS.SETFILEPTR STREAM RPTR)
          (SETQ RDELIM (\PEEKBIN STREAM))
          (EMACS.BSKIP STREAM EMACS.NONSD)
          (EMACS.BBYTE STREAM)
          (SETQ LPTR (GETFILEPTR STREAM))
          (SETQ LDELIM (\PEEKBIN STREAM))
          (SETQ MATCHED (IEQP LDELIM RDELIM))
          (COND
	    (MATCHED (EMACS.SETCARETPTR STREAM LPTR)
		     (DISMISS 200))
	    (T (FLASHWINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))
	       (EMACS.SETCARETPTR STREAM LPTR)
	       (DISMISS 1000)))
          (EMACS.SETCARETPTR STREAM (ADD1 RPTR))
          (EMACS.SETFILEPTR STREAM (ADD1 RPTR)))))

(EMACS.OPEN.BALANCE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (LPTR)                                             (* We should be 1 char after left delim.
							     *)
          (SETQ LPTR (SUB1 (GETFILEPTR STREAM)))
          (COND
	    ((NUMBERP EMACS.BCACHE)                          (* We were at top level. *)
	      (SETQ EMACS.BCACHE (LIST LPTR)))
	    (T (push EMACS.BCACHE LPTR))))))

(EMACS.CLOSE.BALANCE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (PTR LPTR RPTR LDELIM RDELIM BALANCED)             (* LPTR & RPTR point at balancing delims *)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ RPTR (SUB1 PTR))
          (EMACS.SETFILEPTR STREAM RPTR)
          (SETQ RDELIM (\PEEKBIN STREAM))
          (EMACS.BCACHE STREAM)
          (SETQ BALANCED (NOT (NUMBERP EMACS.BCACHE)))
          (COND
	    (BALANCED (SETQ LPTR (CAR EMACS.BCACHE))
		      (EMACS.SETFILEPTR STREAM LPTR)
		      (SETQ LDELIM (\PEEKBIN STREAM))
		      (EMACS.SETCARETPTR STREAM LPTR)
		      (COND
			((IEQP (CDR (ASSOC LDELIM EMACS.DELIMS))
			       RDELIM)                       (* Correct match *)
			  (DISMISS 200))
			(T                                   (* Flash incorrect match. *)
			   (FLASHWINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))
			   (DISMISS 1000)))
		      (pop EMACS.BCACHE))
	    (T                                               (* Flash beginning of non-list def.
							     *)
	       (EMACS.SETCARETPTR STREAM EMACS.BCACHE)
	       (FLASHWINDOW (fetch (EMACSSTREAM WINDOW) of STREAM))
	       (DISMISS 1000)))
          (EMACS.SETCARETPTR STREAM PTR)
          (EMACS.SETFILEPTR STREAM PTR))))

(EMACS.FLUSH.CACHE
  (LAMBDA NIL                                                (* kbr: "19-Feb-85 15:14")
                                                             (* Lose cached info about string & paren balancing.
							     *)
    (PROG NIL                                                (* Hopefully we can change things so that not all 
							     commands flush all of cache.
							     *)
          (SETQ EMACS.SCACHE NIL)
          (SETQ EMACS.BCACHE NIL))))

(EMACS.SCACHE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Return <number> or OUTSIDE, computing if necessary.
							     *)
    (PROG (PTR ANSWER)
          (COND
	    (EMACS.SCACHE (RETURN EMACS.SCACHE)))            (* Recompute. *)
          (SETQ PTR (GETFILEPTR STREAM))
          (EMACS.SETFILEPTR STREAM (EMACS.BOL STREAM PTR))
          (SETQ ANSWER (QUOTE OUTSIDE))
          (while (ILESSP (GETFILEPTR STREAM)
			 PTR)
	     do                                              (* Find opening. *)
		(EMACS.FSKIP STREAM EMACS.NONSD PTR)
		(EMACS.FBYTE STREAM)
		(COND
		  ((IGEQ (GETFILEPTR STREAM)
			 PTR)
		    (RETURN)))
		(SETQ ANSWER (GETFILEPTR STREAM))            (* Find closing. *)
		(EMACS.FSKIP STREAM EMACS.NONSD PTR)
		(EMACS.FBYTE STREAM)
		(COND
		  ((IGEQ (GETFILEPTR STREAM)
			 PTR)
		    (RETURN)))
		(SETQ ANSWER (QUOTE OUTSIDE)))               (* Store ANSWER, restore fileptr, & return *)
          (SETQ EMACS.SCACHE ANSWER)
          (EMACS.SETFILEPTR STREAM PTR)
          (RETURN ANSWER))))

(EMACS.BCACHE
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Return (<number1> ... <numberN>) or OUTSIDE *)
    (PROG (PTR SCACHE ANSWER)
          (COND
	    (EMACS.BCACHE (RETURN EMACS.BCACHE)))            (* Recompute. *)
          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ SCACHE (EMACS.SCACHE STREAM))
          (COND
	    ((NOT (EQ SCACHE (QUOTE OUTSIDE)))               (* Move off string. *)
	      (EMACS.SETFILEPTR STREAM SCACHE)
	      (COND
		((OR (EMACS.BOFP STREAM)
		     (IEQP (\BACKPEEKBIN STREAM)
			   (CHARCODE CR)))                   (* A string def! *)
		  (SETQ ANSWER SCACHE)
		  (GO EXIT)))))
          (COND
	    ((NULL (EMACS.SAFE.BACK.SEXPRS STREAM))          (* Unsuccessful read = unbalanced parens.
							     Treat as if top level. *)
	      (SETQ ANSWER (GETFILEPTR STREAM)))
	    ((OR (ZEROP (GETFILEPTR STREAM))
		 (IEQP (\BACKPEEKBIN STREAM)
		       (CHARCODE CR)))                       (* Top level. *)
	      (SETQ ANSWER (GETFILEPTR STREAM)))
	    (T                                               (* Opening delim present. *)
	       (SETQ ANSWER (LIST (SUB1 (GETFILEPTR STREAM))))))
      EXIT(EMACS.SETFILEPTR STREAM PTR)
          (SETQ EMACS.BCACHE ANSWER)
          (RETURN ANSWER))))

(EMACS.SAFE.BACK.SEXPRS
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")

          (* Backwards read sexprs up to but not including opening delim. Return T if successful backwards read.
	  Otherwise NIL & leave fileptr near failure point. *)


    (PROG (ANSWER)
          (DO (EMACS.BACK.SKIPSEPRS STREAM)
	      (COND
		((OR (ZEROP (GETFILEPTR STREAM))
		     (IEQP (\BACKPEEKBIN STREAM)
			   (CHARCODE CR))
		     (AND (FMEMB (\BACKPEEKBIN STREAM)
				 EMACS.LDELIMS)
			  (NOT (EMACS.BACK.ESCAPEDP STREAM))))
                                                             (* Up against delimiter. *)
		  (SETQ ANSWER T)
		  (RETURN))
		((NULL (NLSETQ (EMACS.BACK.SEXPR STREAM)))   (* Error reading backwards. *)
		  (FLASHWINDOW STREAM)
		  (RETURN))))
          (RETURN ANSWER))))

(EMACS.SAFE.BACK.SEXPR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Return T if successful backwards read.
							     Otherwise NIL & leave fileptr near failure point.
							     *)
    (PROG NIL
          (COND
	    ((NULL (NLSETQ (EMACS.BACK.SEXPR STREAM)))       (* Error reading backwards. *)
	      (FLASHWINDOW STREAM)
	      (RETURN NIL)))
          (RETURN T))))

(EMACS.BACK.SEXPR
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (RDELIM LDELIM)
          (EMACS.BACK.SKIPSEPRS STREAM)
          (COND
	    ((EMACS.BOFP STREAM)
	      (ERROR!))
	    ((EMACS.BACK.ESCAPEDP STREAM)                    (* Atom *)
	      (EMACS.BACK.WORD STREAM)
	      (RETURN)))
          (SETQ RDELIM (\BACKPEEKBIN STREAM))
          (SETQ LDELIM (for BUCKET in EMACS.DELIMS when (IEQP (CDR BUCKET)
							      RDELIM)
			  do (RETURN (CAR BUCKET))))
          (COND
	    ((NULL LDELIM)                                   (* Atom *)
	      (EMACS.BACK.WORD STREAM))
	    ((IEQP LDELIM RDELIM)                            (* String delimiters *)
	      (\BACKBIN STREAM)
	      (WHILE (AND (NOT (EMACS.BOFP STREAM))
			  (OR (NOT (IEQP (\BACKPEEKBIN STREAM)
					 LDELIM))
			      (EMACS.BACK.ESCAPEDP STREAM)))
		 DO (\BACKBIN STREAM))
	      (COND
		((EMACS.BOFP STREAM)
		  (ERROR!)))
	      (\BACKBIN STREAM))
	    (T                                               (* Left Right delimters *)
	       (\BACKBIN STREAM)
	       (do (EMACS.BACK.SKIPSEPRS STREAM)
		   (COND
		     ((EMACS.BOFP STREAM)
		       (ERROR!))
		     ((AND (FMEMB (\BACKPEEKBIN STREAM)
				  EMACS.LDELIMS)
			   (NOT (EMACS.BACK.ESCAPEDP STREAM)))
		       (RETURN)))
		   (EMACS.BACK.SEXPR STREAM)
		   (COND
		     ((OR (EMACS.BOFP STREAM)
			  (IEQP (\BACKPEEKBIN STREAM)
				(CHARCODE CR)))              (* At top of definition in middle of read.
							     *)
		       (ERROR!))))
	       (\BACKBIN STREAM)
	       (EMACS.BSKIP STREAM EMACS.BQ))))))

(EMACS.BACK.WORD
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
    (PROG (SA CH SNX OTHERS)
          (EMACS.BACK.SKIPSEPRS STREAM)
          (COND
	    ((EMACS.BOFP STREAM)
	      (ERROR!)))
          (SETQ SA (fetch (READTABLEP READSA) of EMACS.READTABLE))
          (do (COND
		((EMACS.BOFP STREAM)
		  (RETURN)))
	      (SETQ CH (\BACKBIN STREAM))
	      (SETQ SNX (\GETBASEBYTE SA CH))
	      (COND
		((EQ SNX OTHER.RC)
		  (SETQ OTHERS T))
		(T (\BIN STREAM)
		   (COND
		     ((EMACS.BACK.ESCAPEDP STREAM)           (* "%%%%%%c" *)
		       (\BACKBIN STREAM)
		       (while (NOT (EMACS.BOFP STREAM))
			  do (SETQ CH (\BACKBIN STREAM))
			     (SETQ SNX (\GETBASEBYTE SA CH))
			     (COND
			       ((NOT (EQ SNX ESCAPE.RC))
				 (\BIN STREAM)
				 (RETURN))))
		       (SETQ OTHERS T))
		     ((EQ SNX SEPRCHAR.RC)
		       (RETURN))
		     (OTHERS (RETURN))
		     (T (\BACKBIN STREAM)
			(RETURN)))))))))

(EMACS.BACK.SKIPSEPRS
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Backwards SKIPSEPRS. *)
    (PROG (SA CH SNX)
          (SETQ SA (fetch (READTABLEP READSA) of EMACS.READTABLE))
          (COND
	    ((EMACS.BOFP STREAM)
	      (RETURN)))
          (SETQ CH (\BACKPEEKBIN STREAM))
          (SETQ SNX (\GETBASEBYTE SA CH))
          (COND
	    ((NOT (EQ SNX SEPRCHAR.RC))
	      (RETURN)))
          (\BACKBIN STREAM)
          (do (COND
		((EMACS.BOFP STREAM)
		  (RETURN)))
	      (SETQ CH (\BACKPEEKBIN STREAM))
	      (SETQ SNX (\GETBASEBYTE SA CH))
	      (COND
		((EQ SNX SEPRCHAR.RC)
		  (\BACKBIN STREAM))
		((EQ SNX ESCAPE.RC)
		  (\BIN STREAM)
		  (COND
		    ((NOT (EMACS.BACK.ESCAPEDP STREAM))
		      (\BACKBIN STREAM)))
		  (RETURN))
		(T (RETURN)))))))

(EMACS.BACK.ESCAPEDP
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Is the previous byte escaped? *)
    (PROG (PTR SA CH SNX ANSWER)                             (* T if previous byte preceded by odd number of %%'s.
							     *)
          (SETQ PTR (GETFILEPTR STREAM))
          (COND
	    ((ILEQ PTR 1)
	      (RETURN NIL)))
          (SETQ SA (fetch (READTABLEP READSA) of EMACS.READTABLE))
          (\BACKBIN STREAM)
          (do (SETQ CH (\BACKBIN STREAM))
	      (SETQ SNX (\GETBASEBYTE SA CH))
	      (COND
		((EQ SNX ESCAPE.RC)
		  (SETQ ANSWER (NOT ANSWER)))
		(T (RETURN)))
	      (COND
		((EMACS.BOFP STREAM)
		  (RETURN))))
          (SETFILEPTR STREAM PTR)
          (RETURN ANSWER))))

(EMACS.TAB
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Lisp indent. *)
    (PROG (PTR BOL EOL CODE INDENT OFFSET TABFLG)

          (* INDENT = how much we want to indent. OFFSET = how many chars to nonws. TABFLG = any tabs present at beginning of 
	  line. *)


          (SETQ PTR (GETFILEPTR STREAM))
          (SETQ INDENT (EMACS.TAB.INDENT STREAM))
          (SETQ BOL (EMACS.BOL STREAM PTR))                  (* Calc OFFSET. *)
          (SETQ EOL (EMACS.EOL STREAM PTR))
          (EMACS.SETFILEPTR STREAM BOL)
          (SETQ OFFSET 0)
          (for I from BOL to (SUB1 EOL)
	     do (SETQ CODE (\BIN STREAM))
		(COND
		  ((EQUAL CODE (CHARCODE TAB))
		    (SETQ TABFLG T)))
		(COND
		  ((NOT (BITTEST (ELT EMACS.SYNTAX (OR (NUMBERP CODE)
						       256))
				 EMACS.WS))
		    (RETURN)))
		(SETQ OFFSET (ADD1 OFFSET)))                 (* Insert and/or delete whitespace.
							     *)
          (COND
	    (TABFLG (EMACS.DELETE.BYTES STREAM BOL (IPLUS BOL OFFSET -1))
		    (COND
		      ((NOT (ZEROP INDENT))
			(TEDIT.INSERT STREAM (ALLOCSTRING INDENT " ")
				      (ADD1 BOL)))))
	    ((IEQP OFFSET INDENT)                            (* Do nothing. *)
	      )
	    ((IGREATERP OFFSET INDENT)
	      (EMACS.DELETE.BYTES STREAM BOL (IPLUS BOL (IDIFFERENCE OFFSET INDENT)
						    -1)))
	    ((ILESSP OFFSET INDENT)
	      (TEDIT.INSERT STREAM (ALLOCSTRING (IDIFFERENCE INDENT OFFSET)
						" ")
			    (ADD1 BOL)))
	    (T (SHOULDNT)))                                  (* Reposition fileptr. *)
          (COND
	    ((ILEQ PTR (IPLUS BOL OFFSET))
	      (EMACS.SETFILEPTR STREAM (IPLUS BOL INDENT)))
	    (T (EMACS.SETFILEPTR STREAM (IPLUS PTR (IDIFFERENCE INDENT OFFSET))))))))

(EMACS.TAB.INDENT
  (LAMBDA (STREAM)                                           (* kbr: "19-Feb-85 15:14")
                                                             (* Amount to indent for Lisp indent.
							     *)
    (PROG (PTR BOD SISTER1PTR SISTER2PTR LDELIMFLG SISTER1 SISTERPTR OFFSET BOL ANSWER)
          (SETQ PTR (GETFILEPTR STREAM))                     (* SETQ BOD (EMACS.BOD STREAM PTR))
          (SETQ BOD 0)
          (EMACS.SETFILEPTR STREAM (EMACS.BOL STREAM PTR))
          (EMACS.BSKIP STREAM EMACS.WS BOD)                  (* Get SISTER1PTR, SISTER2PTR, & LDELIMFLG *)
          (do (EMACS.BSKIP STREAM EMACS.SPACE)
	      (COND
		((ILEQ (GETFILEPTR STREAM)
		       BOD)
		  (RETURN)))
	      (COND
		((AND (FMEMB (\BACKPEEKBIN STREAM)
			     EMACS.LDELIMS)
		      (NOT (EMACS.BACK.ESCAPEDP STREAM)))
		  (SETQ LDELIMFLG T)
		  (RETURN)))
	      (EMACS.SAFE.BACK.SEXPR STREAM)
	      (SETQ SISTER2PTR SISTER1PTR)
	      (SETQ SISTER1PTR (GETFILEPTR STREAM)))         (* Get SISTER1. *)
          (COND
	    (SISTER1PTR (SETFILEPTR STREAM SISTER1PTR)
			(SETQ SISTER1 (RATOM STREAM))))      (* Get SISTERPTR & OFFSET. *)
          (SETQ SISTERPTR (OR SISTER1PTR (GETFILEPTR STREAM)))
          (COND
	    ((AND SISTER1 (LITATOM SISTER1))
	      (SETQ OFFSET (GETPROP SISTER1 (QUOTE EMACS.TAB)))))
          (COND
	    (OFFSET (SETQ OFFSET (SUB1 OFFSET)))
	    ((NULL SISTER1)
	      (SETQ OFFSET 1))
	    ((NULL LDELIMFLG)
	      (SETQ OFFSET 0))
	    ((NULL SISTER2PTR)
	      (SETQ OFFSET 0))
	    (T (SETQ SISTERPTR SISTER2PTR)
	       (SETQ OFFSET 0)))                             (* Get ANSWER. *)
          (SETQ BOL (EMACS.BOL STREAM SISTERPTR))
          (EMACS.SETFILEPTR STREAM BOL)
          (SETQ ANSWER OFFSET)
          (for I from BOL to (SUB1 SISTERPTR) do (COND
						   ((IEQP (\BIN STREAM)
							  (CHARCODE TAB))
						     (SETQ ANSWER (IPLUS ANSWER 8)))
						   (T (SETQ ANSWER (ADD1 ANSWER)))))
      EXIT(EMACS.SETFILEPTR STREAM PTR)
          (RETURN ANSWER))))

(EMACS.INIT.SYNTAX
  (LAMBDA NIL                                                (* kbr: "19-Feb-85 15:14")
    (PROG NIL                                                (* "Character" 256 is used to handle IMAGEOBJs.
							     *)
          (SETQ EMACS.SYNTAX (ARRAY 257 (QUOTE WORD)
				    0 0))
          (FOR I FROM 0 TO 256 DO (SETA EMACS.SYNTAX I (LOGOR EMACS.NONCR EMACS.NONWS EMACS.NONSD 
							      EMACS.ALPHA)))
          (FOR I IN (CHARCODE (TAB LF SP)) DO (SETA EMACS.SYNTAX I (LOGOR EMACS.WS EMACS.NONCR 
									  EMACS.NONSD EMACS.SPACE)))
          (SETA EMACS.SYNTAX (CHARCODE CR)
		(LOGOR EMACS.WS EMACS.CR EMACS.NONSD))
          (FOR I IN (QUOTE (39 44 64 96)) DO (SETA EMACS.SYNTAX I (LOGOR EMACS.NONWS EMACS.NONCR 
									 EMACS.NONSD EMACS.BQ 
									 EMACS.ALPHA)))
          (SETQ EMACS.DELIMS NIL)
          (SETQ EMACS.SDELIMS NIL)
          (SETQ EMACS.LDELIMS NIL)
          (SETQ EMACS.RDELIMS NIL)
          (EMACS.DELIMS (CHARCODE "(")
			(CHARCODE ")"))
          (EMACS.DELIMS (CHARCODE "[")
			(CHARCODE "]"))
          (EMACS.DELIMS (CHARCODE "{")
			(CHARCODE "}"))
          (EMACS.DELIMS 34 34))))
)
(DECLARE: DONTEVAL@LOAD DOCOPY 
(EMACS.INIT)
(MOVD? (QUOTE TEDIT.SELECT.LINE.SCANNER)
       (QUOTE OLD.TEDIT.SELECT.LINE.SCANNER))
(MOVD (QUOTE NEW.TEDIT.SELECT.LINE.SCANNER)
      (QUOTE TEDIT.SELECT.LINE.SCANNER))
(MOVD (QUOTE EMACS)
      (QUOTE TEDIT))
)
(PUTPROPS EMACS COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (6329 45464 (EMACS.INIT 6339 . 7420) (EMACS.INIT.BACKGROUND 7422 . 8141) (DEDITEmacs 
8143 . 8656) (EMACS.INIT.COMMANDS 8658 . 9933) (EMACS.COMMAND 9935 . 10138) (EMACS.OPERATE 10140 . 
11905) (EMACS.GETKEY 11907 . 12170) (EMACS 12172 . 13213) (EMACS.PROCESS 13215 . 13491) (EMACS.TEDIT1 
13493 . 13949) (EMACS.WINDOW 13951 . 14378) (EMACS.SETFILEPTR 14380 . 14781) (EMACS.GETCARETPTR 14783
 . 15289) (EMACS.SETCARETPTR 15291 . 15772) (EMACS.SHOWCARET 15774 . 16132) (EMACS.BOL 16134 . 16658) 
(EMACS.EOL 16660 . 17178) (EMACS.DELETE.BYTES 17180 . 17976) (EMACS.BOFP 17978 . 18127) (EMACS.EOFP 
18129 . 18303) (EMACS.CCHAR 18305 . 18678) (EMACS.PEEKBIN 18680 . 18989) (EMACS.FBYTE 18991 . 19264) (
EMACS.FWORD 19266 . 19509) (EMACS.FSKIP 19511 . 20054) (EMACS.FSKIPTO 20056 . 20554) (EMACS.BBYTE 
20556 . 20834) (EMACS.BCHAR 20836 . 21349) (EMACS.BPEEKCHAR 21351 . 21752) (EMACS.BWORD 21754 . 22062)
 (EMACS.BSKIP 22064 . 22588) (EMACS.BSKIPTO 22590 . 23092) (EMACS.SET.EOF 23094 . 23623) (
EMACS.GOTO.BOL 23625 . 23900) (EMACS.BACK.BYTE 23902 . 24157) (EMACS.FWD.DELETE.BYTE 24159 . 24483) (
EMACS.GOTO.EOL 24485 . 24754) (EMACS.FWD.BYTE 24756 . 25013) (EMACS.KILL.LINE 25015 . 25633) (
EMACS.REDISPLAY 25635 . 26032) (EMACS.NEXT.LINE 26034 . 26920) (EMACS.PREVIOUS.LINE 26922 . 27707) (
EMACS.QUOTE.BYTE 27709 . 28249) (EMACS.SEARCH 28251 . 29653) (EMACS.TRANSPOSE.BYTES 29655 . 30501) (
EMACS.NEXT.SCREENFULL 30503 . 31200) (EMACS.CXCV 31202 . 32693) (EMACS.CXCW 32695 . 33010) (EMACS.CXCZ
 33012 . 33378) (EMACS.FWD.SEXPR 33380 . 34419) (EMACS.BACK.DELETE.BYTE 34421 . 34950) (EMACS.GOTO.BOD
 34952 . 35237) (EMACS.BOD 35239 . 36125) (EMACS.GOTO.EOD 36127 . 36433) (EMACS.EOD 36435 . 37321) (
EMACS.KILL.SEXPR 37323 . 37802) (EMACS.GOTO.BOF 37804 . 38074) (EMACS.GOTO.EOF 38076 . 38361) (
EMACS.BACK.WORD 38363 . 39505) (EMACS.FWD.DELETE.WORD 39507 . 39981) (EMACS.EDIT 39983 . 40560) (
EMACS.FWD.WORD 40562 . 40816) (EMACS.GRIND 40818 . 41353) (EMACS.SNARF 41355 . 41718) (EMACS.MT 41720
 . 42458) (EMACS.PREVIOUS.SCREENFULL 42460 . 43161) (EMACS.JOIN.LINES 43163 . 44272) (
EMACS.BACK.DELETE.WORD 44274 . 44715) (NEW.TEDIT.SELECT.LINE.SCANNER 44717 . 45462)) (46452 72581 (
EMACS.DELIMS 46462 . 48051) (EMACS.CR 48053 . 48744) (EMACS.RPAREN 48746 . 49148) (EMACS.RBRACKET 
49150 . 49554) (EMACS.RBRACE 49556 . 49958) (EMACS.RANGLE 49960 . 50362) (EMACS.SDELIM.COMMAND 50364
 . 50815) (EMACS.LDELIM.COMMAND 50817 . 51268) (EMACS.RDELIM.COMMAND 51270 . 51721) (EMACS.SDELIM 
51723 . 52408) (EMACS.LDELIM 52410 . 53038) (EMACS.RDELIM 53040 . 53669) (EMACS.OPEN.STRING 53671 . 
54017) (EMACS.CLOSE.STRING 54019 . 55068) (EMACS.OPEN.BALANCE 55070 . 55575) (EMACS.CLOSE.BALANCE 
55577 . 57027) (EMACS.FLUSH.CACHE 57029 . 57542) (EMACS.SCACHE 57544 . 58838) (EMACS.BCACHE 58840 . 
60385) (EMACS.SAFE.BACK.SEXPRS 60387 . 61327) (EMACS.SAFE.BACK.SEXPR 61329 . 61864) (EMACS.BACK.SEXPR 
61866 . 63742) (EMACS.BACK.WORD 63744 . 64886) (EMACS.BACK.SKIPSEPRS 64888 . 65919) (
EMACS.BACK.ESCAPEDP 65921 . 66852) (EMACS.TAB 66854 . 68933) (EMACS.TAB.INDENT 68935 . 71257) (
EMACS.INIT.SYNTAX 71259 . 72579)))))
STOP