; Run CProlog in a window
; FDC, 27 Jan 1986

(setq-default prolog-active 0)

(defun
    (prolog-newline old-line	; feed current line to prolog
	(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 prolog
    )
    (prolog
	(if (error-occured (getenv "prolog"))
	    (progn
		(message "Sorry, you should have said 'setup cplog' %before entering emacs")
		(novalue))
	    (progn
		(pop-to-buffer "PROLOG")
		(if (= prolog-active 1)
		    (progn
			(end-of-file)
			(message "Resuming prolog session")
			(sit-for 5))
		    (progn
			(setq prolog-active 1)
			(setq needs-checkpointing 0)
			(erase-buffer)
			(message "Loading prolog .....")
			(sit-for 0)
			(local-bind-to-key "prolog-newline" '^M')
			(start-program "prolog" "PROLOG")
			(setq prolog-active 0))
		))
	)
	(novalue)
    )
)
