(FILECREATED "24-May-84 11:11:16" {DSK}TEDITCOMMAND.;2 27436  

      changes to:  (FNS \TEDIT.INTERRUPT.SETUP \TEDIT.MARKACTIVE \TEDIT.MARKINACTIVE 
			\TEDIT.COMMAND.LOOP)

      previous date: "21-Apr-84 01:33:15" {DSK}TEDITCOMMAND.;1)


(PRETTYCOMPRINT TEDITCOMMANDCOMS)

(RPAQQ TEDITCOMMANDCOMS [(FILES TEXTOFD)
			 (FNS \TEDIT.INSERT.TTY.BUFFER \TEDIT.INTERRUPT.SETUP \TEDIT.MARKACTIVE 
			      \TEDIT.MARKINACTIVE \PNC \TEDIT.COMMAND.LOOP)
			 [INITVARS (TEDIT.INTERRUPTS (QUOTE ((2 BREAK)
							     (3 RAID)
							     (5 ERROR)
							     (7 HELP)
							     (20 CONTROL-T]
			 (VARS (TEDIT.COPY.PENDING NIL)
			       (TEDIT.MOVE.PENDING NIL)
			       (TEDIT.DEL.PENDING NIL)
			       (TEDIT.BLUEPENDINGDELETE NIL))
			 (GLOBALVARS TEDIT.COPY.PENDING TEDIT.MOVE.PENDING TEDIT.DEL.PENDING 
				     TEDIT.BLUEPENDINGDELETE TEDIT.INTERRUPTS)
			 (DECLARE: EVAL@COMPILE DONTCOPY (MACROS \INSERT\TTY\BUFFER \TEDIT.MOUSESTATE 
								 \TEDIT.CHECK))
			 (COMS (* Read-table Utilities)
			       (FNS \TEDIT.READTABLE \TEDIT.WORDBOUND.READTABLE TEDIT.GETSYNTAX 
				    TEDIT.SETSYNTAX TEDIT.GETFUNCTION TEDIT.SETFUNCTION TEDIT.WORDGET 
				    TEDIT.WORDSET)
			       [DECLARE: DONTEVAL@LOAD DOCOPY (VARS (TEDIT.READTABLE (\TEDIT.READTABLE
										       ))
								    (TEDIT.WORDBOUND.READTABLE
								      (\TEDIT.WORDBOUND.READTABLE]
			       (GLOBALVARS TEDIT.READTABLE TEDIT.WORDBOUND.READTABLE)
			       (DECLARE: EVAL@COMPILE DONTCOPY (RECORDS TEDITTERMCODE))
			       (DECLARE: EVAL@COMPILE DONTCOPY (CONSTANTS (NONE.TTC 0)
									  (CHARDELETE.TTC 1)
									  (WORDDELETE.TTC 2)
									  (DELETE.TTC 3)
									  (FUNCTIONCALL.TTC 4)
									  (REDO.TTC 5)
									  (UNDO.TTC 6)
									  (CMD.TTC 7)
									  (NEXT.TTC 8)
									  (PUNCT.TTC 20)
									  (TEXT.TTC 21)
									  (WHITESPACE.TTC 22)))
			       (DECLARE: EVAL@COMPILE DONTCOPY (CONSTANTS (MSPACE 153)
									  (NSPACE 152)
									  (THINSPACE 159)
									  (FIGSPACE 154])
(FILESLOAD TEXTOFD)
(DEFINEQ

(\TEDIT.INSERT.TTY.BUFFER
  [LAMBDA (SCRATCH PASS TEXTOBJ SEL)                         (* jds " 3-OCT-83 16:42")
    (PROG ((TLEN (fetch (STRINGP OFFST) of SCRATCH)))
          (COND
	    ((NOT (ZEROP TLEN))                              (* If there are typed-ahead characters cached, insert 
							     them in the text object and clear the cache.)
	      (replace (STRINGP OFFST) of SCRATCH with 0)
	      (replace (STRINGP LENGTH) of SCRATCH with \SCRATCHLEN)
	      (replace (STRINGP LENGTH) of PASS with TLEN)
	      (TEDIT.\INSERT PASS SEL TEXTOBJ BLANKSEEN CRSEEN])

(\TEDIT.INTERRUPT.SETUP
  [LAMBDA (PROC FORCEOFF)                                    (* jds " 5-Apr-84 10:37")
                                                             (* Disarm any inconvenient interrupts, and save 
							     re-arming info on the window.)
    [PROG [(TEXTOBJ (AND (PROCESSPROP PROC (QUOTE WINDOW))
			 (WINDOWPROP (PROCESSPROP PROC (QUOTE WINDOW))
				     (QUOTE TEXTOBJ))
			 (TEXTOBJ (PROCESSPROP PROC (QUOTE WINDOW]
          (UNINTERRUPTABLY
              [COND
		((AND FORCEOFF (PROCESSPROP PROC (QUOTE TEDIT.INTERRUPTS)))
                                                             (* There are disarmed interrupts;
							     re-arm them.)
		  (RESET.INTERRUPTS (PROCESSPROP PROC (QUOTE TEDIT.INTERRUPTS)))
		  (PROCESSPROP PROC (QUOTE TEDIT.INTERRUPTS)
			       NIL))
		([AND (NOT FORCEOFF)
		      (NOT (PROCESSPROP PROC (QUOTE TEDIT.INTERRUPTS]
                                                             (* There aren't any interrupts disarmed;
							     go do it.)
		  (PROCESSPROP PROC (QUOTE TEDIT.INTERRUPTS)
			       (RESET.INTERRUPTS (OR (AND TEXTOBJ (LISTGET (fetch EDITPROPS
									      of TEXTOBJ)
									   (QUOTE INTERRUPTS)))
						     TEDIT.INTERRUPTS)
						 T])]
    PROC])

(\TEDIT.MARKACTIVE
  [LAMBDA (TEXTOBJ)                                          (* jds "17-NOV-83 14:31")
    (replace EDITOPACTIVE of TEXTOBJ with T)
    TEXTOBJ])

(\TEDIT.MARKINACTIVE
  [LAMBDA (TEXTOBJ)                                          (* jds "17-NOV-83 14:32")
    (replace EDITOPACTIVE of TEXTOBJ with NIL)
    TEXTOBJ])

(\PNC
  [LAMBDA (CH STR)                                           (* jds " 7-JUN-82 14:03")
    (PROG ((LEN (fetch (STRINGP LENGTH) of STR))
	   (OFFST (fetch (STRINGP OFFST) of STR)))
          (COND
	    ((ZEROP LEN)
	      (ERROR "NO ROOM LEFT IN STRING TO PUT CHARACTER"))
	    (T (UNINTERRUPTABLY
                   (\PUTBASEBYTE (fetch (STRINGP BASE) of STR)
				 OFFST CH)
		   (replace (STRINGP OFFST) of STR with (ADD1 OFFST))
		   (replace (STRINGP LENGTH) of STR with (SUB1 LEN)))])

(\TEDIT.COMMAND.LOOP
  [LAMBDA (STREAM RTBL)                                      (* gbn "18-Apr-84 15:07")
                                                             (* Main command loop for the TEDIT editor.
							     Includes keyboard polling and command dispatch)
    (PROG ((TEXTOBJ (COND
		      ((type? STREAM STREAM)
			(fetch (TEXTSTREAM TEXTOBJ) of STREAM))
		      (T STREAM)))
	   (ISCRSTRING (ALLOCSTRING \SCRATCHLEN " "))
	   SEL WINDOW LINES IPASSSTRING)
          (SETQ SEL (fetch SEL of TEXTOBJ))
          (SETQ WINDOW (fetch \WINDOW of TEXTOBJ))
          (SETQ LINES (fetch LINES of TEXTOBJ))
          (SETQ IPASSSTRING (SUBSTRING ISCRSTRING 1))        (* Used inside \INSERT\TTY\BUFFER)
          (SETQ RTBL (OR RTBL (fetch TXTRTBL of TEXTOBJ)
			 TEDIT.READTABLE))                   (* Used to derive command characters from type-in)
          (WINDOWPROP WINDOW (QUOTE PROCESS)
		      (THIS.PROCESS))                        (* And the window to this process)
          (while (NOT (TTY.PROCESSP))
	     do                                              (* Wait until we really have the TTY before proceeding.)
		(DISMISS 250))
          (RESETLST
	    [RESETSAVE (PROGN (PROCESSPROP (THIS.PROCESS)
					   (QUOTE WINDOW)
					   WINDOW))
		       (LIST (QUOTE PROGN)
			     (LIST (QUOTE PROCESSPROP)
				   (THIS.PROCESS)
				   (KWOTE (QUOTE WINDOW))
				   (QUOTE OLDVALUE]          (* Attach the process to this window.)
	    (RESETSAVE NIL (LIST (QUOTE PROGN)
				 (LIST (QUOTE WINDOWPROP)
				       WINDOW
				       (KWOTE (QUOTE PROCESS))
				       NIL)))
	    (RESETSAVE (PROGN (\TEDIT.INTERRUPT.SETUP (THIS.PROCESS)))
		       (LIST (QUOTE \TEDIT.INTERRUPT.SETUP)
			     (THIS.PROCESS)
			     T))                             (* Disarm all interrupt chars, re-arm them when we leave
							     the edit)
	    [RESETSAVE (PROGN TEXTOBJ)
		       (QUOTE (AND (TXTFILE OLDVALUE)
				   (CLOSEF? (TXTFILE OLDVALUE]
                                                             (* Remember to close files on the way out.)
	    [RESETSAVE (PROGN (PROCESSPROP (THIS.PROCESS)
					   (QUOTE TTYEXITFN)
					   (QUOTE \TEDIT.PROCEXITFN)))
		       (LIST (QUOTE AND)
			     (LIST (QUOTE PROCESSPROP)
				   (THIS.PROCESS)
				   (KWOTE (QUOTE TTYEXITFN))
				   (QUOTE OLDVALUE]          (* Set up functions for getting in and out of the edit 
							     process)
	    [RESETSAVE (PROGN (PROCESSPROP (THIS.PROCESS)
					   (QUOTE TTYENTRYFN)
					   (QUOTE \TEDIT.PROCENTRYFN)))
		       (LIST (QUOTE AND)
			     (LIST (QUOTE PROCESSPROP)
				   (THIS.PROCESS)
				   (KWOTE (QUOTE TTYENTRYFN))
				   (QUOTE OLDVALUE]
	    (PROG (CH FN TCH (DIRTY NIL)
		      (BLANKSEEN NIL)
		      INSCH#
		      (CRSEEN NIL)
		      TLEN CHNO (READSA (fetch READSA of #CURRENTRDTBL#))
		      (TERMSA (OR (fetch TXTTERMSA of TEXTOBJ)
				  \PRIMTERMSA))
		      (TEDITSA (fetch READSA of RTBL))
		      (TEDITFNHASH (fetch READMACRODEFS of RTBL))
		      (LOOPFN (WINDOWPROP WINDOW (QUOTE TEDIT.CMD.LOOPFN)))
		      (CHARFN (WINDOWPROP WINDOW (QUOTE TEDIT.CMD.CHARFN)))
		      COMMANDFN)
	          (while (NOT (fetch EDITFINISHEDFLG of TEXTOBJ))
		     do
		      (ERSETQ
			(PROGN (\WAITFORSYSBUFP 25)
			       (while (OR TEDIT.SELPENDING (fetch EDITOPACTIVE of TEXTOBJ))
				  do                         (* Don't do anything while he's selecting or one of the 
							     lock-out ops is active.)
				     (AND (OR (EQ TEDIT.SELPENDING TEXTOBJ)
					      (fetch TCUP of (fetch CARET of TEXTOBJ)))
					  (TEDIT.FLASHCARET (fetch CARET of TEXTOBJ)))
				     (BLOCK))                (* Await type-in or mouse action)
			       (TEDIT.FLASHCARET (fetch CARET of TEXTOBJ))
			       (replace EDITOPACTIVE of TEXTOBJ with T)
			       (AND LOOPFN (ERSETQ (APPLY* LOOPFN STREAM)))
                                                             (* If the guy wants control during the loop, give it to 
							     him.)
                                                             (* Process any pending selections)
			       [ERSETQ (COND
					 (TEDIT.COPY.PENDING 
                                                             (* Have to copy the shifted SEL to caret.)
							     (SETQ TEDIT.COPY.PENDING NIL)
							     (\COPYSEL TEDIT.SHIFTEDSELECTION
								       (fetch SHIFTEDSEL
									  of TEXTOBJ))
							     (TEDIT.COPY (fetch SHIFTEDSEL
									    of TEXTOBJ)
									 (fetch SEL of TEXTOBJ))
							     (replace SET of TEDIT.SHIFTEDSELECTION
								with NIL)
							     (replace L1 of TEDIT.SHIFTEDSELECTION
								with NIL)
							     (replace LN of TEDIT.SHIFTEDSELECTION
								with NIL)
							     (\COPYSEL TEDIT.SHIFTEDSELECTION
								       (fetch SHIFTEDSEL
									  of TEXTOBJ)))
					 (TEDIT.MOVE.PENDING 
                                                             (* Have to move the ctrl-shift SEL to caret.)
							     (SETQ TEDIT.MOVE.PENDING NIL)
							     (\COPYSEL TEDIT.MOVESELECTION
								       (fetch MOVESEL of TEXTOBJ))
							     (TEDIT.DO.BLUEPENDINGDELETE SEL TEXTOBJ)
							     (TEDIT.MOVE (fetch MOVESEL of TEXTOBJ)
									 (fetch SEL of TEXTOBJ))
							     (replace SET of TEDIT.MOVESELECTION
								with NIL)
							     (replace L1 of TEDIT.MOVESELECTION
								with NIL)
							     (replace LN of TEDIT.MOVESELECTION
								with NIL)
							     (\COPYSEL TEDIT.MOVESELECTION
								       (fetch MOVESEL of TEXTOBJ)))
					 (TEDIT.DEL.PENDING 
                                                             (* Delete the current selection.)
							    (SETQ TEDIT.DEL.PENDING NIL)
                                                             (* Above all, reset the demand flag first)
							    (COND
							      ((fetch SET of TEDIT.DELETESELECTION)
                                                             (* Only try the deletion if he really set the 
							     selection.)
								(\SHOWSEL (fetch DELETESEL
									     of TEXTOBJ)
									  NIL NIL)
                                                             (* Turn off the selection highlights)
								(\SHOWSEL (fetch SEL of TEXTOBJ)
									  NIL NIL)
								(replace SET
								   of (fetch DELETESEL of TEXTOBJ)
								   with NIL)
								(\COPYSEL TEDIT.DELETESELECTION
									  (fetch SEL of TEXTOBJ))
								(TEDIT.SET.SEL.LOOKS (fetch SEL
											of TEXTOBJ)
										     (QUOTE NORMAL))
                                                             (* Grab the selection we're to use)
								(\TEDIT.DELETE (fetch SEL
										  of TEXTOBJ)
									       (fetch \TEXTOBJ
										  of (fetch SEL
											of TEXTOBJ))
									       NIL)
								(replace L1 of TEDIT.DELETESELECTION
								   with NIL)
								(replace LN of TEDIT.DELETESELECTION
								   with NIL]
			       (UNINTERRUPTABLY
                                   (replace (STRINGP OFFST) of ISCRSTRING with 0)
				   (replace (STRINGP LENGTH) of ISCRSTRING with \SCRATCHLEN))
			       [ERSETQ (while (\SYSBUFP)
					  do                 (* Handle user type-in)
					     (SETQ CH (\GETKEY))
					     (COND
					       (CHARFN       (* Give the OEM user control for each character typed.)
						       (SETQ TCH (APPLY* CHARFN STREAM CH))
						       (OR (EQ TCH T)
							   (SETQ CH TCH))
                                                             (* And let him return one of NIL for "ignore this char",
							     T for "leave it be" or a new charcode.)
						       ))
					     (SELECTC (\SYNCODE TEDITSA CH)
						      (CHARDELETE.TTC 
                                                             (* Backspace handler: Remove the character just before 
							     SEL:CH#.)
								      (\TEDIT.CHARDELETE TEXTOBJ 
										       ISCRSTRING SEL)
								      (
TEDIT.RESET.EXTEND.PENDING.DELETE SEL))
						      (WORDDELETE.TTC (\INSERT\TTY\BUFFER)
                                                             (* Insert any cached characters before doing the 
							     delete.)
								      (\TEDIT.WORDDELETE TEXTOBJ)
								      (
TEDIT.RESET.EXTEND.PENDING.DELETE SEL))
						      (DELETE.TTC 
                                                             (* DEL Key handler: Delete the selected characters)
								  (\INSERT\TTY\BUFFER)
								  (\TEDIT.DELETE SEL TEXTOBJ)
								  (TEDIT.RESET.EXTEND.PENDING.DELETE
								    SEL))
						      (UNDO.TTC 
                                                             (* He hit the CANCEL key, so go UNDO something)
								(\INSERT\TTY\BUFFER)
								(TEDIT.UNDO TEXTOBJ)
								(TEDIT.RESET.EXTEND.PENDING.DELETE
								  SEL))
						      (REDO.TTC 
                                                             (* He hit the REDO key, so go REDO something)
								(\INSERT\TTY\BUFFER)
								(TEDIT.REDO TEXTOBJ)
								(TEDIT.RESET.EXTEND.PENDING.DELETE
								  SEL))
						      [CMD.TTC 
                                                             (* The 'command' key was hit;
							     call the user's function.)
							       (\INSERT\TTY\BUFFER)
							       (COND
								 ((SETQ COMMANDFN
								     (WINDOWPROP WINDOW (QUOTE 
										  TEDIT.COMMANDFN)))
                                                             (* There IS a command function to be called.)
								   (APPLY* COMMANDFN
									   (fetch STREAMHINT
									      of TEXTOBJ)
									   TEXTOBJ SEL)
                                                             (* do it)
								   (\SHOWSEL SEL NIL NIL)
								   (TEDIT.RESET.EXTEND.PENDING.DELETE
								     SEL)
								   (\SHOWSEL SEL NIL T)
                                                             (* And forget any pending deletion.)
								   ]
						      [FUNCTIONCALL.TTC 
                                                             (* This is a special character -- it calls a function)
									(\INSERT\TTY\BUFFER)
									(COND
									  ((SETQ FN (GETHASH CH 
										      TEDITFNHASH))
                                                             (* There IS a command function to be called.)
									    (APPLY* FN
										    (fetch STREAMHINT
										       of TEXTOBJ)
										    TEXTOBJ SEL)
                                                             (* do it)
									    (\SHOWSEL SEL NIL NIL)
									    (
TEDIT.RESET.EXTEND.PENDING.DELETE SEL)                       (* After a user function, no more blue-pending-delete)
									    (\SHOWSEL SEL NIL T)
                                                             (* And forget any pending deletion.)
									    ]
						      (NEXT.TTC 
                                                             (* Move to the next blank to fill in.
							     For now, blanks are delimited by >>...<<)
								(\INSERT\TTY\BUFFER)
								(TEDIT.NEXT TEXTOBJ))
						      (SELECTC
							(AND TERMSA (fetch TERMCLASS
								       of (\SYNCODE TERMSA CH)))
							(CHARDELETE.TC 
                                                             (* Backspace handler: Remove the character just before 
							     SEL:CH#.)
								       (\TEDIT.CHARDELETE TEXTOBJ 
										       ISCRSTRING SEL)
								       (
TEDIT.RESET.EXTEND.PENDING.DELETE SEL))
							(WORDDELETE.TC (\INSERT\TTY\BUFFER)
                                                             (* Insert any cached characters before doing the 
							     delete.)
								       (\TEDIT.WORDDELETE TEXTOBJ)
								       (
TEDIT.RESET.EXTEND.PENDING.DELETE SEL))
							(LINEDELETE.TC 
                                                             (* DEL Key handler: Delete the selected characters)
								       (\INSERT\TTY\BUFFER)
								       (\TEDIT.DELETE SEL TEXTOBJ)
								       (
TEDIT.RESET.EXTEND.PENDING.DELETE SEL))
							(COND
							  (CH 
                                                             (* Any other key was hit: Just insert the character.)
							      (TEDIT.DO.BLUEPENDINGDELETE SEL TEXTOBJ)
                                                             (* Handle blue pending delete, if there is one.)
							      (COND
								((ZEROP (fetch (STRINGP LENGTH)
									   of ISCRSTRING))
								  (replace (STRINGP OFFST)
								     of ISCRSTRING with 0)
								  (replace (STRINGP LENGTH)
								     of ISCRSTRING with \SCRATCHLEN)
								  (TEDIT.\INSERT ISCRSTRING SEL 
										 TEXTOBJ BLANKSEEN 
										 CRSEEN)
								  (SETQ BLANKSEEN NIL)
								  (SETQ CRSEEN NIL)))
							      (SELCHARQ CH
									(SPACE (\INSERT\TTY\BUFFER)
									       (TEDIT.\INSERT CH SEL 
											  TEXTOBJ T 
											      NIL))
									(CR (\INSERT\TTY\BUFFER)
									    (TEDIT.\INSERT CH SEL 
											  TEXTOBJ NIL 
											   T))
									(\PNC CH ISCRSTRING]
			       (ERSETQ (\INSERT\TTY\BUFFER))
			       (replace EDITOPACTIVE of TEXTOBJ with NIL)))
		      (replace EDITOPACTIVE of TEXTOBJ with NIL])
)

(RPAQ? TEDIT.INTERRUPTS (QUOTE ((2 BREAK)
				(3 RAID)
				(5 ERROR)
				(7 HELP)
				(20 CONTROL-T))))

(RPAQQ TEDIT.COPY.PENDING NIL)

(RPAQQ TEDIT.MOVE.PENDING NIL)

(RPAQQ TEDIT.DEL.PENDING NIL)

(RPAQQ TEDIT.BLUEPENDINGDELETE NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(ADDTOVAR GLOBALVARS TEDIT.COPY.PENDING TEDIT.MOVE.PENDING TEDIT.DEL.PENDING TEDIT.BLUEPENDINGDELETE 
	  TEDIT.INTERRUPTS)
)
(DECLARE: EVAL@COMPILE DONTCOPY 
(DECLARE: EVAL@COMPILE 

(PUTPROPS \INSERT\TTY\BUFFER MACRO (NIL (\TEDIT.INSERT.TTY.BUFFER ISCRSTRING IPASSSTRING TEXTOBJ SEL)
					(SETQ BLANKSEEN NIL)
					(SETQ CRSEEN NIL)))

(PUTPROPS \TEDIT.MOUSESTATE MACRO (BUTTON 

          (* Test to see if only the specified mouse button is down. DOES NOT call GETMOUSESTATE, so the mouse-button info 
	  is the same as the last time it WAS called.)


					  (SELECTQ (CAR BUTTON)
						   (LEFT (QUOTE (IEQP LASTMOUSEBUTTONS 4)))
						   (MIDDLE (QUOTE (IEQP LASTMOUSEBUTTONS 1)))
						   (RIGHT (QUOTE (IEQP LASTMOUSEBUTTONS 2)))
						   (SHOULDNT))))

(PUTPROPS \TEDIT.CHECK MACRO [ARGS (COND
				     [(AND (BOUNDP (QUOTE CHECK))
					   CHECK)
				       (CONS (QUOTE PROGN)
					     (for I in ARGS as J on ARGS when (NOT (STRINGP I))
						collect (LIST (QUOTE OR)
							      I
							      (LIST (QUOTE HELP)
								    
					"TEdit consistency-check failure [RETURN to continue]:  "
								    (COND
								      ((STRINGP (CADR J)))
								      (T (KWOTE I]
				     (T (CONS COMMENTFLG ARGS])
)
)



(* Read-table Utilities)

(DEFINEQ

(\TEDIT.READTABLE
  [LAMBDA NIL                                                (* jds "10-Apr-84 15:28")
                                                             (* Create a TEdit read-table, to control which 
							     characters have what functions and call which commands.)
    (PROG [(RTBL (create READTABLEP
			 READMACRODEFS ←(CONS (HARRAY 50]
          (for CH in (CHARCODE (BS ↑A ↑W DEL #A #B #C ESC)) as CL
	     in (LIST CHARDELETE.TTC CHARDELETE.TTC WORDDELETE.TTC DELETE.TTC UNDO.TTC NEXT.TTC 
		      CMD.TTC REDO.TTC)
	     do                                              (* Set up the default syntax classes for command 
							     characters)
		(\SETSYNCODE (fetch READSA of RTBL)
			     CH CL))
          (for CH in (CHARCODE (↑X)) as FN in (QUOTE (\TEDIT.ABBREV.EXPAND))
	     do                                              (* Set up the default function-calling characters 
							     (↑X to expand abbrevs for now))
		(\SETSYNCODE (fetch READSA of RTBL)
			     CH FUNCTIONCALL.TTC)
		(PUTHASH CH FN (fetch READMACRODEFS of RTBL)))
          (RETURN RTBL])

(\TEDIT.WORDBOUND.READTABLE
  [LAMBDA NIL                                                (* jds "28-APR-83 17:28")

          (* Create a readtable which will let TEdit find word boundaries. A word boundary is any point where the SYNCODE of
	  the adjacent characters is different)


    (PROG [(RTBL (create READTABLEP
			 READMACRODEFS ←(HARRAY 50]
          (for CH from 0 to 255 do (\SETSYNCODE (fetch READSA of RTBL)
						CH PUNCT.TTC))
                                                             (* By default, every character except those noted below 
							     is a punctuation character)
          (for CH from (CHARCODE A) to (CHARCODE Z) do (\SETSYNCODE (fetch READSA of RTBL)
								    CH TEXT.TTC))
                                                             (* Upper case alpha)
          (for CH from (CHARCODE a) to (CHARCODE z) do (\SETSYNCODE (fetch READSA of RTBL)
								    CH TEXT.TTC))
                                                             (* Lower case alpha)
          (for CH from (CHARCODE 0) to (CHARCODE 9) do (\SETSYNCODE (fetch READSA of RTBL)
								    CH TEXT.TTC))
                                                             (* And digits are text characters)
          (for CH in (CHARCODE (CR SPACE TAB ↑L)) do (\SETSYNCODE (fetch READSA of RTBL)
								  CH WHITESPACE.TTC))
                                                             (* And these are white space)
          (for CH in (LIST MSPACE NSPACE THINSPACE FIGSPACE) do (\SETSYNCODE (fetch READSA
										of RTBL)
									     CH TEXT.TTC))
          (RETURN RTBL])

(TEDIT.GETSYNTAX
  [LAMBDA (CH TABLE)                                         (* jds "27-SEP-83 16:24")
    (SELECTC (\SYNCODE (fetch READSA of (OR TABLE TEDIT.READTABLE))
		       CH)
	     (WORDDELETE.TTC (QUOTE WORDDELETE))
	     (CHARDELETE.TTC (QUOTE CHARDELETE))
	     (DELETE.TTC (QUOTE DELETE))
	     (UNDO.TTC (QUOTE UNDO))
	     (REDO.TTC (QUOTE REDO))
	     (FUNCTIONCALL.TTC (QUOTE FN))
	     (CMD.TTC (QUOTE CMD))
	     (NEXT.TTC (QUOTE NEXT))
	     NIL])

(TEDIT.SETSYNTAX
  [LAMBDA (CHAR CLASS TABLE)                                 (* jds "27-SEP-83 16:27")
                                                             (* SETS TEDIT-STYLE SYNTAX BITS IN A TERMTABLE)
    (PROG1 (TEDIT.GETSYNTAX CHAR TABLE)
	   (\SETSYNCODE (fetch READSA of (OR TABLE TEDIT.READTABLE))
			CHAR
			(SELECTQ CLASS
				 (CHARDELETE CHARDELETE.TTC)
				 (WORDDELETE WORDDELETE.TTC)
				 ((DELETE LINEDELETE)
				   DELETE.TTC)
				 (UNDO UNDO.TTC)
				 (REDO REDO.TTC)
				 (CMD CMD.TTC)
				 (FN FUNCTIONCALL.TTC)
				 (NEXT NEXT.TTC)
				 NONE.TTC])

(TEDIT.GETFUNCTION
  [LAMBDA (CHARCODE TABLE)                                   (* jds "20-Mar-84 13:03")
                                                             (* Gets the FN that is called when CH is hit inside 
							     TEDIT.)
    (SETQ TABLE (OR TABLE TEDIT.READTABLE))
    (AND TABLE (type? READTABLEP TABLE)
	 (IEQP FUNCTIONCALL.TTC (\SYNCODE (fetch READSA of TABLE)
					  CHARCODE))
	 (fetch READMACRODEFS of TABLE)
	 (GETHASH CHARCODE (fetch READMACRODEFS of TABLE])

(TEDIT.SETFUNCTION
  [LAMBDA (CHARCODE FN RTBL)                                 (* jds "20-Mar-84 13:02")
                                                             (* Set TEDITs (read) table so that FN is called whenever
							     CHARCODE is typed.)
    (SETQ RTBL (OR RTBL TEDIT.READTABLE))
    (\SETSYNCODE (fetch READSA of RTBL)
		 CHARCODE FUNCTIONCALL.TTC)                  (* Mark the character as invoking a function)
    (OR (fetch READMACRODEFS of RTBL)
	(replace READMACRODEFS of RTBL with (HARRAY 50)))    (* Make sure there's a hash table to store the function 
							     in.)
    (PUTHASH CHARCODE FN (fetch READMACRODEFS of RTBL])

(TEDIT.WORDGET
  [LAMBDA (CH TABLE)                                         (* jds "27-MAY-83 13:24")
    (\SYNCODE (fetch READSA of (OR TABLE TEDIT.WORDBOUND.READTABLE))
	      (COND
		((SMALLP CH))
		(T (CHCON1 CH])

(TEDIT.WORDSET
  [LAMBDA (CHARCODE CLASS TABLE)                             (* jds " 1-JUN-83 12:23")
                                                             (* SETS TEDIT-STYLE SYNTAX BITS IN A TERMTABLE)
    (\SETSYNCODE (fetch READSA of (OR TABLE TEDIT.WORDBOUND.READTABLE))
		 (COND
		   ((SMALLP CHARCODE))
		   (T (CHCON1 CHARCODE)))
		 (COND
		   ((FIXP CLASS))
		   (T (SELECTQ CLASS
			       (PUNCTUATION PUNCT.TTC)
			       (WHITESPACE WHITESPACE.TTC)
			       (TEXT TEXT.TTC)
			       TEXT.TTC])
)
(DECLARE: DONTEVAL@LOAD DOCOPY 

(RPAQ TEDIT.READTABLE (\TEDIT.READTABLE))

(RPAQ TEDIT.WORDBOUND.READTABLE (\TEDIT.WORDBOUND.READTABLE))
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(ADDTOVAR GLOBALVARS TEDIT.READTABLE TEDIT.WORDBOUND.READTABLE)
)
(DECLARE: EVAL@COMPILE DONTCOPY 
[DECLARE: EVAL@COMPILE 

(ACCESSFNS TEDITTERMCODE ((TTCLASS (LOGAND DATUM 224))
			  (TTDECODE (LOGAND DATUM 31))))
]
)
(DECLARE: EVAL@COMPILE DONTCOPY 
(DECLARE: EVAL@COMPILE 

(RPAQQ NONE.TTC 0)

(RPAQQ CHARDELETE.TTC 1)

(RPAQQ WORDDELETE.TTC 2)

(RPAQQ DELETE.TTC 3)

(RPAQQ FUNCTIONCALL.TTC 4)

(RPAQQ REDO.TTC 5)

(RPAQQ UNDO.TTC 6)

(RPAQQ CMD.TTC 7)

(RPAQQ NEXT.TTC 8)

(RPAQQ PUNCT.TTC 20)

(RPAQQ TEXT.TTC 21)

(RPAQQ WHITESPACE.TTC 22)

(CONSTANTS (NONE.TTC 0)
	   (CHARDELETE.TTC 1)
	   (WORDDELETE.TTC 2)
	   (DELETE.TTC 3)
	   (FUNCTIONCALL.TTC 4)
	   (REDO.TTC 5)
	   (UNDO.TTC 6)
	   (CMD.TTC 7)
	   (NEXT.TTC 8)
	   (PUNCT.TTC 20)
	   (TEXT.TTC 21)
	   (WHITESPACE.TTC 22))
)
)
(DECLARE: EVAL@COMPILE DONTCOPY 
(DECLARE: EVAL@COMPILE 

(RPAQQ MSPACE 153)

(RPAQQ NSPACE 152)

(RPAQQ THINSPACE 159)

(RPAQQ FIGSPACE 154)

(CONSTANTS (MSPACE 153)
	   (NSPACE 152)
	   (THINSPACE 159)
	   (FIGSPACE 154))
)
)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2024 18476 (\TEDIT.INSERT.TTY.BUFFER 2034 . 2666) (\TEDIT.INTERRUPT.SETUP 2668 . 3946) 
(\TEDIT.MARKACTIVE 3948 . 4132) (\TEDIT.MARKINACTIVE 4134 . 4322) (\PNC 4324 . 4874) (
\TEDIT.COMMAND.LOOP 4876 . 18474)) (20067 26140 (\TEDIT.READTABLE 20077 . 21263) (
\TEDIT.WORDBOUND.READTABLE 21265 . 23029) (TEDIT.GETSYNTAX 23031 . 23515) (TEDIT.SETSYNTAX 23517 . 
24117) (TEDIT.GETFUNCTION 24119 . 24648) (TEDIT.SETFUNCTION 24650 . 25366) (TEDIT.WORDGET 25368 . 
25601) (TEDIT.WORDSET 25603 . 26138)))))
STOP