nma*_*ton 5 emacs clojure slime utf-8 swank-clojure
我是Emacs和Clojure的初级用户,通过一些简单的文本处理来测试我的工作环境.我在获取Slime REPL以正确打印存储在向量中的UTF-8文本时遇到问题.
我首先将文件(Tocharian B的字典)的内容读入一个向量:
user> (def toch
(with-open [rdr (java.io.BufferedReader.
(java.io.FileReader. "/directory/toch.txt"))]
(vec (line-seq rdr))))
=> #'user/toch
Run Code Online (Sandbox Code Playgroud)
然后我尝试从向量中获取一行,然后我得到了垃圾:
user> (toch 44)
=> " Examples : /// kektse?±e akappi ste ‚Äòthe body is an impurity‚Äô (121b5), akappƒ´ = BHS a?õuci·?É (529a3). "
Run Code Online (Sandbox Code Playgroud)
我可以将字符串输入Slime REPL并将其恢复原样:
user> " Examples : /// kektseñe akappi ste ‘the body is an impurity’ (121b5), akapp? = BHS a?uci? (529a3). "
=> " Examples : /// kektseñe akappi ste ‘the body is an impurity’ (121b5), akapp? = BHS a?uci? (529a3). "
Run Code Online (Sandbox Code Playgroud)
我可以毫无问题地打印到磁盘:
user> (binding [*out* (java.io.FileWriter. "test.txt")]
(prn (toch 44)))
=> nil
[Contents of test.txt: " Examples : /// kektseñe akappi ste ‘the body is an impurity’ (121b5), akapp? = BHS a?uci? (529a3). "]
Run Code Online (Sandbox Code Playgroud)
从其他REPL(例如clj,lein repl)的矢量中获取行也可以正常工作.只有当我试图在Slime REPL中查看向量的内容时才会出现任何问题.
这里发生了什么?Emacs和Swank之间是否存在误解?我怎样才能解决这个问题?
尝试放置
(setq slime-net-coding-system 'utf-8-unix)
Run Code Online (Sandbox Code Playgroud)
到您的.emacs文件中(或通过设置并保存变量M-x customize-variable)。
此外,请确保您在支持 UTF-8 的语言环境中运行 Clojure(如果您使用 Un*x 并使用 Leiningen,请尝试类似的操作env LC_ALL=en_US.UTF-8 lein swank)。