Commits

Meikel Brandmeyer committed 4f2b588

Propagate handling of character encoding through nailgun

Comments (0)

Files changed (1)

server/src/main/clojure/vimclojure/nails.clj

      (.start))))
 
 (defn- make-stream-set
-  [in out err]
-  [(-> in InputStreamReader. LineNumberingPushbackReader.)
-   (-> out OutputStreamWriter.)
-   (-> err OutputStreamWriter. PrintWriter.)])
+  [in out err encoding]
+  [(-> in (InputStreamReader. encoding) LineNumberingPushbackReader.)
+   (-> out (OutputStreamWriter. encoding))
+   (-> err (OutputStreamWriter. encoding) PrintWriter.)])
 
 (defn- set-input-stream
   [#^ThreadLocalInputStream sys local]
   [#^NGContext ctx nail]
   (let [out          (ByteArrayOutputStream.)
         err          (ByteArrayOutputStream.)
-        [clj-in clj-out clj-err] (make-stream-set (.in ctx) out err)
-        encoding     (if-let [encoding (System/getProperty "clojure.vim.encoding")]
-                       encoding
-                       "UTF-8")
+        encoding     (System/getProperty "clojure.vim.encoding" "UTF-8")
+        [clj-in clj-out clj-err] (make-stream-set (.in ctx) out err encoding)
         sys-in       (set-input-stream System/in (.in ctx))
         sys-out      (set-output-stream System/out (PrintStream. out))
         sys-err      (set-output-stream System/err (PrintStream. err))
     (set-input-stream System/in sys-in)
     (set-output-stream System/out sys-out)
     (set-output-stream System/err sys-err)
-    (.print (.out ctx)
-            (print-str
-              (util/clj->vim
-                {:value  result
-                 :stdout (.toString out encoding)
-                 :stderr (.toString err encoding)})))
+    (let [output (.getBytes
+                   (print-str
+                     (util/clj->vim
+                       {:value  result
+                        :stdout (.toString out encoding)
+                        :stderr (.toString err encoding)}))
+                   encoding)]
+      (.write (.out ctx) output 0 (alength output)))
     (.flush (.out ctx))))
 
 (defmacro defnail