; Run shell in a window
; FDC, 23 Feb 1986

(setq-default shell-active 0)

(defun
    (shell-newline old-line	; feed current line to shell
	(end-of-line)
	(if (! (eobp))		; if it's not the last line of the
	(progn		; buffer, copy it to the bottom.
		(beginning-of-line)
		(set-mark)
		(end-of-line)
		(setq old-line (region-to-string))
		(end-of-file)
		(insert-string
		    (substr old-line (current-column)
			(- 1 (current-column))))
	    ))
	(newline)		; put in a newline
	(exit-emacs)		; resume shell
    )
    (shell
	(pop-to-buffer "SHELL")
	(if (= shell-active 1)
	    (progn
		(end-of-file)
		(message "Resuming shell session")
		(sit-for 5))
	    (progn
		(setq shell-active 1)
		(setq needs-checkpointing 0)
		(erase-buffer)
		(message "Loading shell .....")
		(sit-for 0)
		(local-bind-to-key "shell-newline" '^M')
		(start-program "cutils:shell" "SHELL")
		(setq shell-active 0))
	)
	(novalue)
    )
)
