(FILECREATED " 8-Feb-86 18:51:58" {GOEDEL}</usr2/pds/updating/>TELLEDITOR        

      changes to:  (FNS QP.FILTER.MODE.LINE QP.UPDATE.MODELINE)

      previous date: " 2-Feb-86 23:44:17" {GOEDEL}</usr2/xerox/q/>TELLEDITOR)


(* Copyright (c) 1986 by Quintus Computer Systems, Inc. All rights reserved.)

(PRETTYCOMPRINT TELLEDITORCOMS)

(RPAQQ TELLEDITORCOMS ((SCCS)
			 (* WARNING: This material is CONFIDENTIAL and proprietary to Quintus 
			    Computer Systems Inc.)
			 (* This global variable holds a list of files that a predicate was defined 
			    in. It is used by find-definition to pass information.)
			 (GLOBALVARS QP.FIND.DEFINITION.SOURCE.FILES)
			 (VARS (QP.FIND.DEFINITION.SOURCE.FILES NIL))
			 (GLOBALVARS QP.CURRENT.TEXTSTREAM QP.BUFFERED.HIDDEN.INPUT)
			 (INITVARS QP.CURRENT.TEXTSTREAM QP.BUFFERED.HIDDEN.INPUT)
			 (MACROS QP.CLEAR.FD.BUFFER)
			 (* ----------------------------------------------------------------------)
			 (GLOBALVARS QP.CURRENT.STREAM)
			 (MACROS QP.FD.FILE)
			 (* ----------------------------------------------------------------------)
			 (FNS QP.LIBRARY)
			 (* ----------------------------------------------------------------------)
			 (FNS QP.LIBRARY.PART.TWO)
			 (* Modeline Updating)
			 (* The following functions should be replaced with prolog code in emacs.pl)
			 (FNS QP.MAKE.TAB.STRING QP.FILTER.MODE.LINE)
			 (FNS QP.UPDATE.MODELINE)
			 (* At present the global variable QP.TERM.READING.MODE is not being used.)
			 (GLOBALVARS QP.TERM.READING.MODE)
			 (VARS (QP.TERM.READING.MODE NIL))
			 (* At present the global variable QP.AT.TOP.LEVEL is not being used.)
			 (GLOBALVARS QP.AT.TOP.LEVEL)
			 (VARS (QP.AT.TOP.LEVEL NIL))
			 (FNS QP.TELL.EMACS)
			 (* See FINDDEF.LSP for the definition of QP.FIND.DEFINITION.PART.TWO)
			 (* Interprocess Communication these globals should really be in QPTEXEC.LSP 
			    with the QP.TEXEC function)
			 (GLOBALVARS QP.PROLOG.STREAM.HANDLE QP.PROLOG.WINDOW.HANDLE)
			 (FNS QP.SEND.PROLOG QP.NOT.SAFE.TO.LOAD.CODE QP.SEND.END.OF.FILE)))
(* %2/8/86  %@(#)TELLEDITOR	1.26 )



(* WARNING: This material is CONFIDENTIAL and proprietary to Quintus Computer Systems Inc.)




(* This global variable holds a list of files that a predicate was defined in. It is used by 
find-definition to pass information.)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS QP.FIND.DEFINITION.SOURCE.FILES)
)

(RPAQQ QP.FIND.DEFINITION.SOURCE.FILES NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS QP.CURRENT.TEXTSTREAM QP.BUFFERED.HIDDEN.INPUT)
)

(RPAQ? QP.CURRENT.TEXTSTREAM NIL)

(RPAQ? QP.BUFFERED.HIDDEN.INPUT NIL)
(DECLARE: EVAL@COMPILE 
(PUTPROPS QP.CLEAR.FD.BUFFER MACRO (**MACROARG** (LET NIL (BQUOTE (PROGN (SETQ 
								  QP.FIND.DEFINITION.SOURCE.FILES NIL)
									 )))))
)



(* ----------------------------------------------------------------------)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS QP.CURRENT.STREAM)
)
(DECLARE: EVAL@COMPILE 
(PUTPROPS QP.FD.FILE MACRO (**MACROARG** (LET ((DATA (CAR (NTH **MACROARG** 1))))
					      (BQUOTE (PROGN (SETQ QP.FIND.DEFINITION.SOURCE.FILES
								   (APPEND 
								  QP.FIND.DEFINITION.SOURCE.FILES
									   (LIST (\, DATA)))))))))
)



(* ----------------------------------------------------------------------)

(DEFINEQ

(QP.LIBRARY
  (LAMBDA (STREAM)
    (if (QP.NOT.SAFE.TO.LOAD.CODE)
	then (TEDIT.PROMPTPRINT STREAM (CONCAT "cannot use the library facility " 
						     "unless Prolog is at top level prompt")
				    T)
      else (SETQ QP.CURRENT.STREAM STREAM)
	     (QP.SEND.PROLOG (CONCAT "find←library←package('" (TEDIT.GETINPUT (TEXTOBJ STREAM)
										    "Library file: ")
					 "')")))))
)



(* ----------------------------------------------------------------------)

(DEFINEQ

(QP.LIBRARY.PART.TWO
  (LAMBDA (FILENAME)                                         (* pds: " 2-Feb-86 20:24")
    (if (EQUAL FILENAME (QUOTE 
			    cannot% find% library% file,% check% facts% for% library←directory/1'))
	then                                               (* the filename is really the error message above.)
	       (TEDIT.PROMPTPRINT QP.CURRENT.STREAM FILENAME T)
      else (LET ((WORKING.STREAM (QP.TEXTSTREAM (FULLNAME FILENAME (QUOTE OLD)))))
	          (if (NOT WORKING.STREAM)
		      then                                 (* no open stream, but QUINTUS.TEDIT sets 
							     QP.CURRENT.TEXTSTREAM)
			     (SETQ WORKING.STREAM (TEXTSTREAM (TEDIT FILENAME NIL NIL
									   (QUOTE (TEDIT.MODE
										      Prolog)))))
		    else (PROMPTPRINT (CONCAT "   Revisiting: " FILENAME)))
	          (TEDIT.NORMALIZECARET (TEXTOBJ WORKING.STREAM)
					  (TEDIT.SETSEL WORKING.STREAM 1 1 (QUOTE LEFT)))))))
)



(* Modeline Updating)




(* The following functions should be replaced with prolog code in emacs.pl)

(DEFINEQ

(QP.MAKE.TAB.STRING
  (LAMBDA (N)                                                (* pds: " 1-Feb-86 14:39")

          (* * Sort of a hack, granted, but saves a lot of work at runtime.)


    (if (AND (FIXP N)
		 (IGEQ N 0))
	then (SELECTQ N
			  (0 "")
			  (1 " ")
			  (2 "  ")
			  (3 "   ")
			  (4 "    ")
			  (5 "     ")
			  (6 "      ")
			  (7 "       ")
			  (8 "        ")
			  (CONCAT "        " (QP.MAKE.TAB.STRING (IDIFFERENCE N 8))))
      else (ERROR "Negative or non-integer tab" N))))

(QP.FILTER.MODE.LINE
  (LAMBDA (INPUT)                                          (* pds: " 8-Feb-86 18:47")
    (if (AND (EQ (TYPENAME INPUT)
		       (QUOTE PROLOG.TERM))
		 (EQ (fetch (PROLOG.TERM PROLOG.FUNCTOR) of INPUT)
		       (QUOTE tab)))
	then (QP.MAKE.TAB.STRING (CAR (fetch (PROLOG.TERM PROLOG.ARGS) of INPUT)))
      elseif (LISTP INPUT)
	then (CONCATLIST (for ELT in INPUT collect (QP.FILTER.MODE.LINE ELT)))
      else INPUT)))
)
(DEFINEQ

(QP.UPDATE.MODELINE
  (LAMBDA (STRING.LIST)                                      (* pds: " 8-Feb-86 18:50")
    (WINDOWPROP QP.PROLOG.WINDOW.HANDLE (QUOTE TITLE)
		  (CONCATLIST (CONS (QUOTE " Xerox Quintus Prolog")
					(for ELT in STRING.LIST collect (QP.FILTER.MODE.LINE
										ELT)))))))
)



(* At present the global variable QP.TERM.READING.MODE is not being used.)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS QP.TERM.READING.MODE)
)

(RPAQQ QP.TERM.READING.MODE NIL)



(* At present the global variable QP.AT.TOP.LEVEL is not being used.)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS QP.AT.TOP.LEVEL)
)

(RPAQQ QP.AT.TOP.LEVEL NIL)
(DEFINEQ

(QP.TELL.EMACS
  (LAMBDA (MESSAGE DATA)                                     (* pds: " 1-Feb-86 15:32")
    (SELECTQ MESSAGE
	       (top←level (SETQ QP.AT.TOP.LEVEL T))
	       (term←reading←mode (SETQ QP.TERM.READING.MODE T))
	       (done←loading (TEDIT.PROMPTPRINT QP.PROLOG.STREAM.HANDLE "done" T))
	       (update←modeline (QP.UPDATE.MODELINE DATA))
	       (clear←fd←buffer (QP.CLEAR.FD.BUFFER))
	       (fd←file (QP.FD.FILE DATA))
	       (find←definition (QP.FIND.DEFINITION.PART.TWO DATA))
	       (library (QP.LIBRARY.PART.TWO DATA))
	       (ERROR "TELL.EMACS message not defined" MESSAGE))))
)



(* See FINDDEF.LSP for the definition of QP.FIND.DEFINITION.PART.TWO)




(* Interprocess Communication these globals should really be in QPTEXEC.LSP with the QP.TEXEC 
function)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS QP.PROLOG.STREAM.HANDLE QP.PROLOG.WINDOW.HANDLE)
)
(DEFINEQ

(QP.SEND.PROLOG
  (LAMBDA (INPUT.STRING)                                     (* pds: " 1-Feb-86 14:46")
    (LET ((PROC (FIND.PROCESS QP.PROLOG.NAME)))
         (COND
	   (PROC (SETQ QP.BUFFERED.HIDDEN.INPUT (CHCON (CONCAT INPUT.STRING "."
								     (CHARACTER (CHARCODE EOL)))))
		 (PROCESS.EVAL PROC (QUOTE (RETFROM (QUOTE QP.GET.STREAM)
							  29)))
		 (TTY.PROCESS PROC))
	   (T 

          (* * Yuck!! Must fix this (CADR (PROCESSPROP (THIS.PROCESS) (QUOTE FORM))) stuff. This returns a TEXTSTREAM or 
	  TEXTOBJ.)


	      (TEDIT.PROMPTPRINT (EVAL (CADR (PROCESSPROP (THIS.PROCESS)
								  (QUOTE FORM))))
				   "Prolog is not currently running" T))))))

(QP.NOT.SAFE.TO.LOAD.CODE
  (LAMBDA NIL
    (if (AND QP.PROLOG.STREAM.HANDLE (TEXEC.EOTP (TEXTOBJ QP.PROLOG.STREAM.HANDLE)))
	then                                               (* Make sure file pointer is at cursor position)
	       (\TEXTSETFILEPTR QP.PROLOG.STREAM.HANDLE (SUB1 (TEDIT.GETPOINT 
									  QP.PROLOG.STREAM.HANDLE)))
                                                             (* check to see that there is nothing but blanks, 
							     tabs, and newlines between dot and the last prompt.)
	       (LET ((MARK (\TEXTGETFILEPTR QP.PROLOG.STREAM.HANDLE))
		     (CHAR (\BACKBIN QP.PROLOG.STREAM.HANDLE))
		     (FLAG NIL))
		    (while (OR (EQ CHAR (CHARCODE TAB))
				   (EQ CHAR (CHARCODE SP))
				   (EQ CHAR (CHARCODE EOL)))
		       do (SETQ CHAR (\BACKBIN QP.PROLOG.STREAM.HANDLE)))
		    (if (EQ CHAR (CHARCODE -))
			then (SETQ CHAR (\BACKBIN QP.PROLOG.STREAM.HANDLE))
			       (if (EQ CHAR (CHARCODE ?))
				   then (SETQ FLAG T)))
		    (\SETUPGETCH MARK (TEXTOBJ QP.PROLOG.STREAM.HANDLE))
		    (\BIN QP.PROLOG.STREAM.HANDLE)
		    (NOT FLAG))
      else T)))

(QP.SEND.END.OF.FILE
  (LAMBDA NIL
    (LET ((PROC (FIND.PROCESS QP.PROLOG.NAME)))
         (if PROC
	     then (PROCESS.EVAL PROC (QUOTE (RETFROM (QUOTE READCCODE)
							     4)))
		    (TTY.PROCESS PROC)))))
)
(PUTPROPS TELLEDITOR COPYRIGHT ("Quintus Computer Systems, Inc" 1986))
STOP