;;
;; util. functions & settings for Surmulot
;;

(import '(java.io File)
	'(javax.swing UIManager))

(use '[clojure.contrib.str-utils :only (str-join)])

(UIManager/setLookAndFeel (UIManager/getSystemLookAndFeelClassName))

(defn surmulot-file [vpath]
  "Contructs an absolute file name from the elements of vpath,
a vector of nested directories below SURMULOTDIR"
  (str-join 
;   (first File/separator) 
   (first "/")
   (cons (System/getenv "SURMULOTDIR") vpath)))



;; Surmulot manager for Clojure

(import '(java.net Socket) 
	'(java.io DataOutputStream DataInputStream))

;(add-classpath (str "file:" (surmulot-file ["clojure" "javabase64.jar"])))
;(import '(it.sauronsoftware.base64 Base64))

;; (defn manager-test []
;;   (let [sock (Socket. "localhost" 20226)
;; 	in (DataInputStream. (.getInputStream sock))
;; 	out (DataOutputStream. (.getOutputStream sock))]
;;     (defn manager-do [string id]
;;       (doto out
;; 	(.writeBytes  
;; 	 (str string (char 11)
;; 	      "emacs_manager" (char 11) 
;; 	      "Q" (char 11) id 
;; 	      (char 11) (char 11)))
;; 	(.flush)))))


;(manager-test)
;(manager-do "(new-frame)" "1")


(defn emacs-do [string]
  (let [sock (Socket. "localhost" 20226)]
    (doto (DataOutputStream. (.getOutputStream sock))
      (.writeBytes  
       (str string (char 11)
	    "emacs_manager" (char 11) 
	    "Q" (char 11) "1" 
	    (char 11) (char 11)))
      (.flush))
    (.close sock)))

(defn emacs-edit-file [filename]
  (emacs-do (str "(find-file-other-frame \"" filename "\")")))

;(emacs-do "(new-frame)")

(load-file (surmulot-file ["clojure" "SliderDemo.clj"]))

