;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for System version 123.228
;;; Reason:
;;;  For ZWEI:EDITOR-STREAM-MIXIN:
;;;    - better enable/disable of ibeam blinker
;;;    - typing End while in Editor will activate, rather than throwing you back
;;;      into Lisp listener in the middle of the buffer.
;;; Written 8-Apr-88 16:53:48 by pld at site Gigamos Cambridge
;;; while running on Jack Flanders from band 1
;;; with Experimental System 123.226, Experimental Local-File 73.4, Experimental FILE-Server 22.2, Experimental Unix-Interface 11.0, Experimental KERMIT 34.3, Experimental ZMail 71.0, Experimental Lambda-Diag 15.0, Experimental Tape 22.0, microcode 1755, SDU Boot Tape 3.14, SDU ROM 8.



; From modified file DJ: L.ZWEI; STREAM.LISP#179 at 8-Apr-88 16:54:11
#8R ZWEI#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "ZWEI")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: ZWEI; STREAM  "


(defmethod (editor-stream-mixin :enable-ibeam) ()
  (SETQ *STREAM-IBEAM-SHOULD-BLINK* T)
  (LET ((IBEAM-BLINKER
	  (CDR (ASSQ 'STREAM-BLINK-IBEAM
		     (WINDOW-SPECIAL-BLINKER-LIST *STREAM-SHEET*)))))
    (WHEN IBEAM-BLINKER
      (STREAM-BLINK-IBEAM IBEAM-BLINKER *STREAM-SHEET* *STREAM-BP* NIL))))

))

; From modified file DJ: L.ZWEI; STREAM.LISP#179 at 8-Apr-88 16:54:12
#8R ZWEI#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "ZWEI")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: ZWEI; STREAM  "


(defmethod (editor-stream-mixin :disable-ibeam) ()
  (SETQ *STREAM-IBEAM-SHOULD-BLINK* nil)
  (LET ((IBEAM-BLINKER
	  (CDR (ASSQ 'STREAM-BLINK-IBEAM (WINDOW-SPECIAL-BLINKER-LIST *WINDOW*)))))
    (TV:BLINKER-SET-VISIBILITY IBEAM-BLINKER NIL)))


;;;The actual editor top level, a lisp listener in an editor window

))

; From modified file DJ: L.ZWEI; STREAM.LISP#179 at 11-Apr-88 11:08:33
#8R ZWEI#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "ZWEI")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: ZWEI; STREAM  "

(DEFUN STREAM-PRE-COMMAND-HOOK-1 (CHAR)
  (let ((editing-command (cdr (assq ':editing-command rubout-handler-options)))
	(command-handler (cdr (assq ':command rubout-handler-options)))
	(activation-handler (cdr (assq ':activation rubout-handler-options)))
	(do-not-echo (cdr (assq ':do-not-echo rubout-handler-options)))
	(CHAR (CHAR-INT CHAR)))
    (COND ((OR (MEMQ CHAR editing-command)
	       (SI:ASSQ-CAREFUL CHAR editing-command))
	   (SETQ *SRE-INPUT-END-BP* (COPY-BP (INTERVAL-LAST-BP *INTERVAL*)))
	   (SETQ *SRE-INPUT-POINT* (COPY-BP *SRE-STREAM-BP*))
	   (MOVE-BP *SRE-STREAM-BP* (INTERVAL-LAST-BP *INTERVAL*))
	   (THROW 'RETURN-FROM-ANY-TYI CHAR))
	  ((AND command-handler
		(APPLY (car command-handler) CHAR (cdr command-handler)))
	   (SEND *SRE-WINDOW* ':SET-*STREAM-COMMAND-POINT*
		 (COPY-BP *SRE-STREAM-BP* ':NORMAL))
	   (MOVE-BP *SRE-STREAM-BP* *SRE-STREAM-START-BP*)
	   (THROW 'TV:RETURN-FROM-RUBOUT-HANDLER
		   (VALUES
		     `(:COMMAND ,CHAR ,(OR *NUMERIC-ARG* 1))
		     ':COMMAND)))
	  ((eq char #/End)
	   ;;Subsume rubout-handler caller's desire for End to be an Activation character --
	   ;;we are inside the editor and will interpret End as activation-with-cleanup.
	   )
	  ((OR (MEMQ CHAR do-not-echo)
	       (AND activation-handler
		    (APPLY (car activation-handler)
			   CHAR (cdr activation-handler))))
	   (SETQ *SRE-ACTIVATION-CHARACTER*
		 (IF (MEMQ CHAR do-not-echo) CHAR
		   `(:ACTIVATION ,CHAR ,(OR *NUMERIC-ARG* 1))))
	   (THROW 'RUBOUT-HANDLER T)))
  ;; Tell label to change at redisplay after this command finishes,
  ;; so that if this command activates, there will be no change.
  (send *WINDOW* ':ENTER-EDITOR)
  ;; Tell the ibeam blinker to start blinking at next redisplay, also.
  (SETQ *STREAM-IBEAM-SHOULD-BLINK* T)))

))

; From modified file DJ: L.ZWEI; STREAM.LISP#179 at 11-Apr-88 11:09:48
#8R ZWEI#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "ZWEI")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: ZWEI; STREAM  "

(DEFMETHOD (EDITOR-STREAM-MIXIN :STREAM-RUBOUT-HANDLER)
	   (&AUX (RUBOUT-HANDLER NIL) CHAR)
  ;; If there is a saved-up activation character, return it from :ANY-TYI now.
  ;; This happens at the end of a rescan of the input.
  (IF *SRE-ACTIVATION-CHARACTER*
      (PROG1 *SRE-ACTIVATION-CHARACTER*
	     (SETQ *SRE-ACTIVATION-CHARACTER* NIL))
    ;; We could just call the editor, but we must pass certain characters (editing-commands)
    ;; that the program doing the read is handling, and we also want to
    ;; save some time for alphabetic characters.
    (IF *SRE-INPUT-POINT*
	(MUST-REDISPLAY *STREAM-SHEET* DIS-BPS)
      (SETQ CHAR (FUNCALL-SELF ':ANY-TYI)))
    ;; Just type out and insert self-inserting printing characters
    ;; but not if they are the caller's editing-commands or activations or commands,
    ;; or if they have been redefined in the editor itself.
    (let ((editing-command (cdr (assq ':editing-command rubout-handler-options)))
	  (command-handler (cdr (assq ':command rubout-handler-options)))
	  (activation-handler (cdr (assq ':activation rubout-handler-options)))
	  (do-not-echo (cdr (assq ':do-not-echo rubout-handler-options)))
	  (pass-through (cdr (assq ':pass-though rubout-handler-options))))
      (IF (AND (NUMBERP CHAR)
	       (NOT (OR (MEMQ CHAR editing-command)
			(SI:ASSQ-CAREFUL CHAR editing-command)))
	       (NOT (AND command-handler
			 (APPLY (car command-handler)
				CHAR (cdr command-handler))))
	       (NOT (AND activation-handler
			 (APPLY (car activation-handler)
				CHAR (cdr activation-handler))))
	       (NOT (MEMQ CHAR DO-NOT-ECHO))
	       (OR (AND (graphic-char-p CHAR)
			(EQ 'COM-ORDINARILY-SELF-INSERT
			    (COMMAND-LOOKUP CHAR *STREAM-COMTAB*)))
		   (AND (< CHAR 400)
			(MEMQ CHAR pass-through))))
	  (LET ((*WINDOW* *STREAM-SHEET*))
	    (STREAM-IMMEDIATE-OUTPUT
	      (TV:SHEET-TYO *STREAM-SHEET* CHAR))
	    (INSERT-MOVING *STREAM-BP* CHAR)
	    CHAR)
	;; Otherwise, run the editor till COM-ACTIVATE throws to us,
	;; then throw to RUBOUT-HANDLER to restart the read using the buffer contents.
	;; Move editor point to where we are reading.
	(MOVE-BP *STREAM-BP*
		 (OR *SRE-INPUT-POINT* (INTERVAL-LAST-BP (WINDOW-INTERVAL *STREAM-SHEET*))))
	(SETQ *SRE-INPUT-POINT* NIL)
	;; Update buffer display and window data so editor gets consistent data.
	(STREAM-REDISPLAY T)
	;; Unread this character so editor will execute it.
	(WHEN CHAR (TV:IO-BUFFER-UNGET (SEND *STREAM-SHEET* ':IO-BUFFER) CHAR))
	;; Edit.
	(SET-IN-CLOSURE EDITOR-CLOSURE '*EDITOR-STREAM-ACTIVATION-NEEDED* NIL)
	;; PASS-ON characters throw here
	;; to return from the :ANY-TYI method.
	(CATCH 'RETURN-FROM-ANY-TYI
	  (LET ((*STREAM-IBEAM-SHOULD-BLINK* NIL)
		(*INSIDE-EDITOR-STREAM* NIL))
	    (SI:%BIND (LOCF (TV:SHEET-MORE-VPOS *STREAM-SHEET*)) NIL)
	    (UNLESS (BP-= *STREAM-BP* (INTERVAL-LAST-BP (WINDOW-INTERVAL *STREAM-SHEET*)))
	      (SEND SELF ':ENTER-EDITOR)
	      (send self :enable-ibeam))
	    (UNWIND-PROTECT
		(FUNCALL *STREAM-SHEET* ':EDIT EDITOR-CLOSURE)
	      (FUNCALL *STREAM-SHEET* ':EXIT-EDITOR)
	      (send self :disable-ibeam)
	      ;; Put blinker into ordinary stream mode instead of editor mode.
	      (MULTIPLE-VALUE-BIND (X Y) (TV:BLINKER-READ-CURSORPOS *STREAM-BLINKER*)
		(TV:SHEET-SET-CURSORPOS *STREAM-SHEET* X Y))
	      (FUNCALL *STREAM-BLINKER* ':SET-FOLLOW-P T)	;Make the blinker follow again
	      (TV:BLINKER-SET-VISIBILITY *STREAM-BLINKER*
					 (IF (EQ *STREAM-SHEET* TV:SELECTED-WINDOW)
					     ':BLINK ':ON)))
	    ;; Tell the :RUBOUT-HANDLER method to restart the read.
	    (THROW 'RUBOUT-HANDLER T)))))))

))
