 	(accept-process-output proc (or timeout 5))))))
 
 (defun set-socket-init-for-specware ()
-  (message "set-socket-init-for-specware")
+  ;; (message "set-socket-init-for-specware")
   (setq sw:common-lisp-image-arguments
     (list "-L" (getenv "SOCKET_INIT_FILE"))))
 

			sw:common-lisp-image-file))
      (sleep-for 2)
      (wait-for-prompt 0.5)
      (sw:eval-in-lisp-no-value
       (format "(cl:namestring (Specware::change-directory %S))" sw:common-lisp-directory))
      (let ((init-form (or (getenv "SPECWARE_INIT_FORM")

      (replace-in-string filename "/" "\\\\")
    filename))

(require 'bridge)

(defun start-specware-build-buffer (&optional name)
  (interactive)
  ;; Works with newer shell.el but not older
  ;;(setq *specware-build-buffer* (get-buffer-create *specware-build-buffer-name*))
  ;;(shell *specware-build-buffer*)
  (unless (null name)
    (setq *specware-build-buffer-name* name))

  (let ((shell-multiple-shells t)) ;; unused here, is this used by bridge code??
    (shell)
    (rename-buffer *specware-build-buffer-name*)
    (setq *specware-build-buffer* (current-buffer)))

  (set-buffer *specware-build-buffer-name*)
  (install-bridge)
  (setq bridge-handlers '(("(" . emacs-eval-handler))))

(defvar buffer-counter 0)

(defun prepare-specware-build-buffer (buffer-name dir)

  ;; on windows, a shell may die inside a live buffer (sigh).
  ;; The end of that buffer may then say "Process shell finished",
  ;; so we could look for that and make this smarter...
  ;; In the meantime, make the buffer names distinct (maybe not a bad idea anyway).

  (when *windows-system-p*
    (setq buffer-name (concat (format "[%d] " (incf buffer-counter)) buffer-name)))

  (if (and (buffer-live-p (get-buffer buffer-name))
           (not *windows-system-p*)) ;; see note above
      (rename-specware-build-buffer buffer-name)
    (start-specware-build-buffer buffer-name))

  ;; kill any prior lisp accidentally running there...
  (when (sbcl-running-in-build-buffer)
    (specware-build-command "(cl-user::quit)"))
  ;; connect to build directory
  (sit-for 5) ;; give shell time to start (sigh)
  (specware-build-cd-command dir)
  (save-excursion
    (set-buffer *specware-build-buffer-name*)
    (delete-other-windows)
    (set-frame-pixel-size (car (frames-of-buffer)) 1200 800))
  )

(defun rename-specware-build-buffer (new-name)
  (set-buffer *specware-build-buffer-name*)
  (rename-buffer new-name)
  (setq *specware-build-buffer-name* new-name))

(defun sbcl-running-in-build-buffer()
  (sit-for 0.1)
