(defvar display-subprocess-window nil "\
If non-nil, the suprocess window is displayed whenever input is received.")

(defvar command-prefix-string "$ " "\
String to insert to distinguish commands entered by user.")

(defvar subprocess-running nil)

(defvar command-mode-map nil)

(if command-mode-map nil (setq command-mode-map (make-sparse-keymap)) (define-key command-mode-map "
" (quote command-send-input)) (define-key command-mode-map "" (quote command-kill-line)))

(defun subprocess-input (name str) "\
Handles input from a subprocess.  Called by Emacs." (byte-code "	!p	qdbcc
q)" [display-subprocess-window subprocess-buf old-buffer str display-buffer 10] 2))

(defun subprocess-exit (name) "\
Called by Emacs upon subprocess exit." (byte-code "" [subprocess-running nil] 2))

(defun start-subprocess nil "\
Spawns an asynchronous subprocess with output redirected to
the buffer *COMMAND*.  Within this buffer, use C-m to send
the last line to the subprocess or to bring another line to
the end." (byte-code "!!
q!)#'\"" [subprocess-running t subprocess-buf command-mode-map return get-buffer-create "*COMMAND*" use-local-map spawn-subprocess 1 subprocess-input subprocess-exit send-command-to-subprocess "ON SEVERE_ERROR THEN CONTINUE"] 7))

(defun subprocess-command nil "\
Starts asynchronous subprocess if not running and switches to its window." (interactive) (byte-code "ˆ?	 	!db" [subprocess-running subprocess-buf nil start-subprocess pop-to-buffer] 3))

(defun command-send-input nil "\
If at last line of buffer, sends the current line to
the spawned subprocess.  Otherwise brings back current
line to the last line for resubmission." (interactive) (byte-code "È ` `\"m5	? 	2 \"
c!U  !

GOcUc)" [current-line subprocess-running command-prefix-string nil beginning-of-line buffer-substring end-of-line start-subprocess send-command-to-subprocess 1 next-line end-of-buffer backward-char string-equal 0] 16))

(defun command-kill-line nil "\
Kills the current line.  Used in command mode." (interactive) (byte-code "  " [nil beginning-of-line kill-line] 3))

(define-key esc-map "$" (quote subprocess-command))