(require (quote scheme))

(defvar scheme-program-name "scheme" "\
*Program invoked by the `run-scheme' command.")

(defvar scheme-band-name nil "\
*Band loaded by the `run-scheme' command.")

(defvar scheme-program-arguments nil "\
*Arguments passed to the Scheme program by the `run-scheme' command.")

(defvar xscheme-allow-pipelined-evaluation t "\
If non-nil, an expression may be transmitted while another is evaluating.
Otherwise, attempting to evaluate an expression before the previous expression
has finished evaluating will signal an error.")

(defvar xscheme-startup-message "This is the Scheme process buffer.
Type \\[advertised-xscheme-send-previous-expression] to evaluate the expression before point.
Type \\[xscheme-send-control-g-interrupt] to abort evaluation.
Type \\[describe-mode] for more information.

" "String to insert into Scheme process buffer first time it is started.
Is processed with `substitute-command-keys' first.")

(defvar xscheme-signal-death-message nil "\
If non-nil, causes a message to be generated when the Scheme process dies.")

(defun xscheme-evaluation-commands (keymap) (byte-code "######" [keymap define-key "" xscheme-send-definition "" advertised-xscheme-send-previous-expression "o" xscheme-send-buffer "z" "
" xscheme-send-previous-expression "" xscheme-send-region] 9))

(defun xscheme-interrupt-commands (keymap) (byte-code "#####" [keymap define-key "" xscheme-select-process-buffer "" xscheme-send-breakpoint-interrupt "" xscheme-send-control-g-interrupt "" xscheme-send-control-u-interrupt "" xscheme-send-control-x-interrupt] 8))

(xscheme-evaluation-commands scheme-mode-map)

(xscheme-interrupt-commands scheme-mode-map)

(defun run-scheme (command-line) "\
Run an inferior Scheme process.
Output goes to the buffer `*scheme*'.
With argument, asks for a command line." (interactive (byte-code "	 
\")C" [default xscheme-process-command-line current-prefix-arg xscheme-default-command-line read-string "Run Scheme: "] 4)) (byte-code "Ĉ!!" [default xscheme-process-command-line current-prefix-arg command-line nil switch-to-buffer xscheme-start-process] 3))

(defun reset-scheme nil "\
Reset the Scheme process." (interactive) (byte-code "È!?!=?!.!&\"
!!)" [process t xscheme-process-command-line nil get-process "scheme" process-status run yes-or-no-p "The Scheme process is running, are you SURE you want to reset it? " message "Resetting Scheme process..." kill-process xscheme-start-process "Resetting Scheme process...done"] 8))

(defun xscheme-default-command-line nil (byte-code "		P

PR" [scheme-program-name scheme-program-arguments scheme-band-name " -emacs" " " "" " -band "] 5))

(defun scheme-interaction-mode nil "\
Major mode for interacting with the inferior Scheme process.
Like  scheme-mode  except that:

\\[advertised-xscheme-send-previous-expression] sends the expression before point to the Scheme process as input
\\[xscheme-yank-previous-send] yanks the expression most recently sent to Scheme

All output from the Scheme process is written in the Scheme process
buffer, which is initially named \"*scheme*\".  The result of
evaluating a Scheme expression is also printed in the process buffer,
preceded by the string \";Value: \" to highlight it.  If the process
buffer is not visible at that time, the value will also be displayed
in the minibuffer.  If an error occurs, the process buffer will
automatically pop up to show you the error message.

While the Scheme process is running, the modelines of all buffers in
scheme-mode are modified to show the state of the process.  The
possible states and their meanings are:

input		waiting for input
run		evaluating
gc		garbage collecting

The process buffer's modeline contains additional information where
the buffer's name is normally displayed: the command interpreter level
and type.

Scheme maintains a stack of command interpreters.  Every time an error
or breakpoint occurs, the current command interpreter is pushed on the
command interpreter stack, and a new command interpreter is started.
One example of why this is done is so that an error that occurs while
you are debugging another error will not destroy the state of the
initial error, allowing you to return to it after the second error has
been fixed.

The command interpreter level indicates how many interpreters are in
the command interpreter stack.  It is initially set to one, and it is
incremented every time that stack is pushed, and decremented every
time it is popped.  The following commands are useful for manipulating
the command interpreter stack:

\\[xscheme-send-breakpoint-interrupt]	pushes the stack once
\\[xscheme-send-control-u-interrupt]	pops the stack once
\\[xscheme-send-control-g-interrupt]	pops everything off
\\[xscheme-send-control-x-interrupt]	aborts evaluation, doesn't affect stack

Some possible command interpreter types and their meanings are:

[Evaluator]	read-eval-print loop for evaluating expressions
[Debugger]	single character commands for debugging errors
[Where]		single character commands for examining environments

Starting with release 6.2 of Scheme, the latter two types of command
interpreters will change the major mode of the Scheme process buffer
to scheme-debugger-mode , in which the evaluation commands are
disabled, and the keys which normally self insert instead send
themselves to the Scheme process.  The command character ? will list
the available commands.

For older releases of Scheme, the major mode will be be
scheme-interaction-mode , and the command characters must be sent as
if they were expressions.

Delete converts tabs to spaces as it moves back.
Blank lines separate paragraphs.  Semicolons start comments.

Entry to this mode calls the value of scheme-interaction-mode-hook
with no args, if that value is non-nil." (interactive) (byte-code "   !!" [nil kill-all-local-variables scheme-interaction-mode-initialize scheme-mode-variables make-local-variable xscheme-previous-send run-hooks scheme-interaction-mode-hook] 6))

(defun scheme-interaction-mode-initialize nil (byte-code "!ĉʼn" [scheme-interaction-mode-map major-mode mode-name use-local-map scheme-interaction-mode "Scheme Interaction"] 3))

(defun scheme-interaction-mode-commands (keymap) (byte-code "###" [keymap define-key "
" xscheme-send-current-line "" xscheme-send-proceed "" xscheme-yank-previous-send] 6))

(defvar scheme-interaction-mode-map nil)

(if (not scheme-interaction-mode-map) (progn (setq scheme-interaction-mode-map (make-keymap)) (scheme-mode-commands scheme-interaction-mode-map) (xscheme-interrupt-commands scheme-interaction-mode-map) (xscheme-evaluation-commands scheme-interaction-mode-map) (scheme-interaction-mode-commands scheme-interaction-mode-map)))

(defun xscheme-enter-interaction-mode nil (byte-code " q=?=  )" [major-mode xscheme-process-buffer scheme-interaction-mode scheme-debugger-mode scheme-interaction-mode-initialize] 4))

(fset (quote advertised-xscheme-send-previous-expression) (quote xscheme-send-previous-expression))

(defun scheme-debugger-mode nil "\
Major mode for executing the Scheme debugger.
Like  scheme-mode  except that the evaluation commands
are disabled, and characters that would normally be self inserting are
sent to the Scheme process instead.  Typing ?  will show you which
characters perform useful functions.

\\{scheme-debugger-mode-map}" (byte-code "!" [error "Illegal entry to scheme-debugger-mode"] 2))

(defun scheme-debugger-mode-initialize nil (byte-code "!ĉʼn" [scheme-debugger-mode-map major-mode mode-name use-local-map scheme-debugger-mode "Scheme Debugger"] 3))

(defun scheme-debugger-mode-commands (keymap) (byte-code "W	!#T)" [char keymap 32 127 define-key char-to-string scheme-debugger-self-insert] 6))

(defvar scheme-debugger-mode-map nil)

(if (not scheme-debugger-mode-map) (progn (setq scheme-debugger-mode-map (make-keymap)) (scheme-mode-commands scheme-debugger-mode-map) (xscheme-interrupt-commands scheme-debugger-mode-map) (scheme-debugger-mode-commands scheme-debugger-mode-map)))

(defun scheme-debugger-self-insert nil "\
Transmit this character to the Scheme process." (interactive) (byte-code "!" [last-command-char nil xscheme-send-char] 2))

(defun xscheme-enter-debugger-mode (prompt-string) (byte-code " q=?=?  )" [major-mode xscheme-process-buffer scheme-debugger-mode scheme-interaction-mode scheme-debugger-mode-initialize] 4))

(defun xscheme-debugger-mode-p nil (byte-code " q	=))" [buffer major-mode xscheme-process-buffer scheme-debugger-mode] 3))

(defun xscheme-send-string (&rest strings) "\
Send the string arguments to the Scheme process.
The strings are concatenated and terminated by a newline." (byte-code " ? !  db\"!= +!=	?1
:!=!" [strings xscheme-allow-pipelined-evaluation xscheme-running-p t xscheme-process-running-p yes-or-no-p "The Scheme process has died.  Reset it? " reset-scheme xscheme-wait-for-process apply insert-before-markers xscheme-send-string-1 xscheme-debugger-mode-p error "No sends allowed in debugger mode" "No sends allowed while Scheme running"] 11))

(defun xscheme-send-string-1 (strings) (byte-code "	\"!
=)" [string strings major-mode xscheme-previous-send apply concat xscheme-send-string-2 scheme-interaction-mode] 4))

(defun xscheme-send-string-2 (string) (byte-code "!	P\" !`\")" [process string get-process "scheme" send-string "
" xscheme-process-buffer-current-p set-marker process-mark] 7))

(defun xscheme-yank-previous-send nil "\
Insert the most recent expression at point." (interactive) (byte-code " c" [xscheme-previous-send nil push-mark] 2))

(defun xscheme-select-process-buffer nil "\
Select the Scheme process buffer and move to its output point." (interactive) (byte-code "È!!!!	!
!'	!!b)))" [process buffer window nil get-process "scheme" error "No scheme process" process-buffer "No process buffer" get-buffer-window select-window switch-to-buffer process-mark] 9))

(defun xscheme-send-region (start end) "\
Send the current region to the Scheme process.
The region is sent terminated by a newline." (interactive "r") (byte-code "ˆ b!!\"	\"!" [end start nil xscheme-process-buffer-current-p set-marker process-mark get-process "scheme" xscheme-send-string buffer-substring] 8))

(defun xscheme-send-definition nil "\
Send the current definition to the Scheme process.
If the current line begins with a non-whitespace character,
parse an expression from the beginning of the line and send that instead." (interactive) (byte-code " `#`!)
\"*" [start nil end t end-of-defun re-search-backward "^\\s(" error "Can't find definition" xscheme-send-region] 6))

(defun xscheme-send-next-expression nil "\
Send the expression to the right of `point' to the Scheme process." (interactive) (byte-code "` `)\")" [start nil xscheme-send-region forward-sexp] 4))

(defun xscheme-send-previous-expression nil "\
Send the expression to the left of `point' to the Scheme process." (interactive) (byte-code "`Š `)\")" [end nil xscheme-send-region backward-sexp] 4))

(defun xscheme-send-current-line nil "\
Send the current line to the Scheme process.
Useful for working with debugging Scheme under adb." (interactive) (byte-code "ˆ ` 	`\")) c!)" [line start nil beginning-of-line end-of-line buffer-substring 10 xscheme-send-string-2] 6))

(defun xscheme-send-buffer nil "\
Send the current buffer to the Scheme process." (interactive) (byte-code " 
!ed\"" [nil xscheme-process-buffer-current-p error "Not allowed to send this buffer's contents to Scheme" xscheme-send-region] 5))

(defun xscheme-send-char (char) "\
Prompt for a character and send it to the Scheme process." (interactive "cCharacter to send: ") (byte-code "!\"" [char nil send-string "scheme" char-to-string] 4))

(defun xscheme-send-breakpoint-interrupt nil "\
Cause the Scheme process to enter a breakpoint." (interactive) (byte-code "\"" [nil xscheme-send-interrupt 98] 3))

(defun xscheme-send-proceed nil "\
Cause the Scheme process to proceed from a breakpoint." (interactive) (byte-code "\"" [nil send-string "scheme" "(proceed)
"] 3))

(defun xscheme-send-control-g-interrupt nil "\
Cause the Scheme processor to halt and flush input.
Control returns to the top level rep loop." (interactive) (byte-code "Ĉ
?!+!+!!!\")" [inhibit-quit t xscheme-control-g-synchronization-p xscheme-control-g-disabled-p nil interrupt-process "scheme" message "Relax..." "Sending C-G interrupt to Scheme..." send-string char-to-string 0] 8))

(defun xscheme-send-control-u-interrupt nil "\
Cause the Scheme process to halt, returning to previous rep loop." (interactive) (byte-code "\"" [t nil xscheme-send-interrupt 117] 3))

(defun xscheme-send-control-x-interrupt nil "\
Cause the Scheme process to halt, returning to current rep loop." (interactive) (byte-code "\"" [t nil xscheme-send-interrupt 120] 3))

(defun xscheme-send-interrupt (char mark-p) "\
Send a ^A type interrupt to the Scheme process." (interactive "cInterrupt character to send: ") (byte-code "È!!\"	
!\"" [char mark-p xscheme-control-g-synchronization-p nil quit-process "scheme" send-string char-to-string 0] 7))

(defvar xscheme-process-command-line nil "\
Command used to start the most recent Scheme process.")

(defvar xscheme-previous-send "" "\
Most recent expression transmitted to the Scheme process.")

(defvar xscheme-process-filter-state (quote idle) "\
State of scheme process escape reader state machine:
idle                   waiting for an escape sequence
reading-type           received an altmode but nothing else
reading-string         reading prompt string")

(defvar xscheme-running-p nil "\
This variable, if nil, indicates that the scheme process is
waiting for input.  Otherwise, it is busy evaluating something.")

(defconst xscheme-control-g-synchronization-p t "\
If non-nil, insert markers in the scheme input stream to indicate when
control-g interrupts were signalled.  Do not allow more control-g's to be
signalled until the scheme process acknowledges receipt.")

(defvar xscheme-control-g-disabled-p nil "\
This variable, if non-nil, indicates that a control-g is being processed
by the scheme process, so additional control-g's are to be ignored.")

(defvar xscheme-allow-output-p t "\
This variable, if nil, prevents output from the scheme process
from being inserted into the process-buffer.")

(defvar xscheme-prompt "" "\
The current scheme prompt string.")

(defvar xscheme-string-accumulator "" "\
Accumulator for the string being received from the scheme process.")

(defvar xscheme-string-receiver nil "\
Procedure to send the string argument from the scheme process.")

(defvar xscheme-start-hook nil "\
If non-nil, a procedure to call when the Scheme process is started.
When called, the current buffer will be the Scheme process-buffer.")

(defvar xscheme-runlight-string nil)

(defvar xscheme-mode-string nil)

(defvar xscheme-filter-input nil)

(defun xscheme-start-process (command-line) (byte-code "!!q		!>!	!d\"d	(	!db o8
!BB\")	!d\"! 	\"	\"!)))" [buffer process xscheme-startup-message process-connection-type nil command-line t get-buffer-create "*scheme*" get-buffer-process process-status (run stop) set-marker process-mark delete-process scheme-interaction-mode insert-before-markers substitute-command-keys apply start-process "scheme" xscheme-parse-command-line xscheme-process-filter-initialize xscheme-modeline-initialize set-process-sentinel xscheme-process-sentinel set-process-filter xscheme-process-filter run-hooks xscheme-start-hook] 19))

(defun xscheme-parse-command-line (string) (byte-code "!	F	#?&	O
BĂ?	U4	#?	O

!*" [string start result index nil t substitute-in-file-name 0 string-match "[ 	]" "[^ 	]" nreverse] 7))

(defun xscheme-wait-for-process nil (byte-code "!!" [xscheme-running-p sleep-for 2 1] 4))

(defun xscheme-process-running-p nil "\
True iff there is a Scheme process whose status is `run'." (byte-code "!
!=)" [process get-process "scheme" process-status run] 4))

(defun xscheme-process-buffer nil (byte-code "!!)" [process get-process "scheme" process-buffer] 3))

(defun xscheme-process-buffer-window nil (byte-code " 
!)" [buffer xscheme-process-buffer get-buffer-window] 3))

(defun xscheme-process-buffer-current-p nil "\
True iff the current buffer is the Scheme process buffer." (byte-code " p=" [xscheme-process-buffer] 3))

(defun xscheme-process-sentinel (proc reason) (byte-code "=!= ljȉ>?!* !" [reason scheme-mode-line-process xscheme-mode-string xscheme-signal-death-message xscheme-process-filter-initialize run xscheme-modeline-initialize "" "no process" (run stop) beep message "The Scheme process has died!  Do M-x reset-scheme to restart it"] 5))

(defun xscheme-process-filter-initialize (running-p) (byte-code "ɉ
ĉƉʉˉ" [xscheme-process-filter-state xscheme-running-p running-p xscheme-control-g-disabled-p nil xscheme-allow-output-p t xscheme-prompt scheme-mode-line-process idle "" (": " xscheme-runlight-string)] 2))

(defun xscheme-process-filter (proc string) (byte-code "	
=8\"*O!TOЉ4ĉ	!))
=\"OPTOˉ		\")Pĉ)!)" [xscheme-filter-input string xscheme-process-filter-state start nil char entry xscheme-process-filter-alist xscheme-string-accumulator xscheme-string-receiver t idle string-match "" xscheme-process-filter-output 0 reading-type zerop 1 assoc funcall 2 27 reading-string error "Scheme process filter -- bad state"] 13))

(defun xscheme-process-filter-output (&rest args) (byte-code "O
\" 	\"I!!	O!	HU:n?3!!< 	TO*
	!))" [xscheme-allow-output-p string args start end apply concat xscheme-goto-output-point string-match "\\(\\|\\)" match-beginning 0 match-end insert-before-markers 12 10 beep nil] 13))

(defun xscheme-guarantee-newlines (n) (byte-code "@ 	?n(So\"ĉ$ 
) V?!S-)" [xscheme-allow-output-p stop nil n t xscheme-goto-output-point backward-char 0 insert-before-markers 10] 7))

(defun xscheme-goto-output-point nil (byte-code "!!q!b)" [process get-process "scheme" process-buffer process-mark] 4))

(defun xscheme-modeline-initialize nil (byte-code "ÉÉĉ" [xscheme-runlight-string xscheme-mode-string mode-line-buffer-identification "" ("Scheme: " xscheme-mode-string)] 2))

(defun xscheme-set-runlight (runlight) (byte-code "	 " [xscheme-runlight-string runlight xscheme-modeline-redisplay] 2))

(defun xscheme-modeline-redisplay nil (byte-code " q) !!" [other-buffer set-buffer-modified-p buffer-modified-p sit-for 0] 5))

(defvar xscheme-process-filter-alist (quote ((68 xscheme-enter-debugger-mode xscheme-process-filter:string-action) (80 xscheme-set-prompt-variable xscheme-process-filter:string-action) (82 xscheme-enter-interaction-mode xscheme-process-filter:simple-action) (98 xscheme-start-gc xscheme-process-filter:simple-action) (101 xscheme-finish-gc xscheme-process-filter:simple-action) (102 xscheme-exit-input-wait xscheme-process-filter:simple-action) (103 xscheme-enable-control-g xscheme-process-filter:simple-action) (105 xscheme-prompt-for-expression xscheme-process-filter:string-action) (109 xscheme-message xscheme-process-filter:string-action) (110 xscheme-prompt-for-confirmation xscheme-process-filter:string-action) (111 xscheme-output-goto xscheme-process-filter:simple-action) (112 xscheme-set-prompt xscheme-process-filter:string-action) (115 xscheme-enter-input-wait xscheme-process-filter:simple-action) (118 xscheme-write-value xscheme-process-filter:string-action) (119 xscheme-cd xscheme-process-filter:string-action) (122 xscheme-display-process-buffer xscheme-process-filter:simple-action) (99 xscheme-unsolicited-read-char xscheme-process-filter:simple-action))) "\
Table used to decide how to handle process filter commands.
Value is a list of entries, each entry is a list of three items.

The first item is the character that the process filter dispatches on.
The second item is the action to be taken, a function.
The third item is the handler for the entry, a function.

When the process filter sees a command whose character matches a
particular entry, it calls the handler with two arguments: the action
and the string containing the rest of the process filter's input
stream.  It is the responsibility of the handler to invoke the action
with the appropriate arguments, and to reenter the process filter with
the remaining input.")

(defun xscheme-process-filter:simple-action (action) (byte-code "‰	!" [xscheme-process-filter-state action idle funcall] 2))

(defun xscheme-process-filter:string-action (action) (byte-code "	ĉʼn" [xscheme-string-receiver action xscheme-string-accumulator xscheme-process-filter-state "" reading-string] 2))

(defconst xscheme-runlight:running "run" "\
The character displayed when the Scheme process is running.")

(defconst xscheme-runlight:input "input" "\
The character displayed when the Scheme process is waiting for input.")

(defconst xscheme-runlight:gc "gc" "\
The character displayed when the Scheme process is garbage collecting.")

(defun xscheme-start-gc nil (byte-code "!" [xscheme-runlight:gc xscheme-set-runlight] 2))

(defun xscheme-finish-gc nil (byte-code "		

!" [xscheme-running-p xscheme-runlight:running xscheme-runlight:input xscheme-set-runlight] 2))

(defun xscheme-enter-input-wait nil (byte-code "!‰" [xscheme-runlight:input xscheme-running-p nil xscheme-set-runlight] 3))

(defun xscheme-exit-input-wait nil (byte-code "!‰" [xscheme-runlight:running xscheme-running-p t xscheme-set-runlight] 3))

(defun xscheme-enable-control-g nil (byte-code "" [xscheme-control-g-disabled-p nil] 2))

(defun xscheme-display-process-buffer nil (byte-code " 	 !ċ)" [window xscheme-process-buffer-window display-buffer xscheme-process-buffer ((byte-code "!   " [window select-window xscheme-goto-output-point xscheme-debugger-mode-p xscheme-enter-interaction-mode] 5))] 4))

(defun xscheme-unsolicited-read-char nil (byte-code "" [nil] 1))

(defun xscheme-message (string) (byte-code "G!?\"\"" [string zerop xscheme-write-message-1 format ";%s"] 6))

(defun xscheme-write-value (string) (byte-code "G!\"\"\"" [string zerop xscheme-write-message-1 "(no value)" ";No value" format ";Value: %s"] 7))

(defun xscheme-write-message-1 (message-string output-string) (byte-code "!!!	?!	\"?
\"*!!" [process window message-string output-string get-process "scheme" get-buffer-window process-buffer pos-visible-in-window-p process-mark message "%s" xscheme-guarantee-newlines 1 xscheme-process-filter-output] 9))

(defun xscheme-set-prompt-variable (string) (byte-code "	" [xscheme-prompt string] 2))

(defun xscheme-set-prompt (string) (byte-code "	!	! " [xscheme-prompt string xscheme-mode-string xscheme-guarantee-newlines 2 xscheme-coerce-prompt xscheme-modeline-redisplay] 4))

(defun xscheme-output-goto nil (byte-code " !" [xscheme-goto-output-point xscheme-guarantee-newlines 2] 3))

(defun xscheme-coerce-prompt (string) (byte-code "\"*!	O	O
))P)+" [string end prompt entry xscheme-prompt-alist string-match "^[0-9]+ " match-end 0 nil assoc] 6))

(defvar xscheme-prompt-alist (quote (("[Normal REPL]" . "[Evaluator]") ("[Error REPL]" . "[Evaluator]") ("[Breakpoint REPL]" . "[Evaluator]") ("[Debugger REPL]" . "[Evaluator]") ("[Visiting environment]" . "[Evaluator]") ("[Environment Inspector]" . "[Where]"))) "\
An alist which maps the Scheme command interpreter type to a print string.")

(defun xscheme-cd (directory-string) (byte-code " q!)" [directory-string xscheme-process-buffer cd] 3))

(defun xscheme-prompt-for-confirmation (prompt-string) (byte-code "!Â!" [prompt-string xscheme-send-char y-or-n-p 121 110] 3))

(defun xscheme-prompt-for-expression (prompt-string) (byte-code "
#!" [prompt-string nil xscheme-prompt-for-expression-map xscheme-send-string-2 read-from-minibuffer] 5))

(defvar xscheme-prompt-for-expression-map nil)

(if (not xscheme-prompt-for-expression-map) (progn (setq xscheme-prompt-for-expression-map (copy-keymap minibuffer-local-map)) (substitute-key-definition (quote exit-minibuffer) (quote xscheme-prompt-for-expression-exit) xscheme-prompt-for-expression-map)))

(defun xscheme-prompt-for-expression-exit nil (interactive) (byte-code "ed\"= !" [nil xscheme-region-expression-p one exit-minibuffer error "input must be a single, complete expression"] 4))

(defun xscheme-region-expression-p (start end) (byte-code " Ǝ	!\"
8-˂.)))))" [old-syntax-table scheme-mode-syntax-table state start end syntax-table ((byte-code "!" [old-syntax-table set-syntax-table] 2)) set-syntax-table parse-partial-sexp zerop 2 many one] 8))