nmashton
nmashton

Reputation: 51

Printing UTF-8 text in slime REPL

I'm a beginning user of both Emacs and Clojure, testing my working environment with some simple text processing. I'm having problems getting the Slime REPL to properly print UTF-8 text stored in a vector.

I start by reading the contents of a file (a dictionary of Tocharian B) into a vector:

user> (def toch
        (with-open [rdr (java.io.BufferedReader.
                         (java.io.FileReader. "/directory/toch.txt"))]
          (vec (line-seq rdr))))
=> #'user/toch

I then try to get a line from the vector, and I get garbage:

user> (toch 44)
=> " Examples :   /// kektseñe akappi ste ‘the body is an impurity’ (121b5), akappī = BHS aśuciṃ (529a3). "

I can enter the string into the Slime REPL and get it back as it should be:

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). "

And I can print to disk without any problem:

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). "]

And getting lines from the vector from other REPLs (e.g. clj, lein repl) also works fine. It's only when I try to look at the contents of the vector within the Slime REPL that there's any problem.

What's going on here? Is there some miscommunication between Emacs and Swank? How can I fix this?

Upvotes: 5

Views: 545

Answers (1)

Matthias Benkard
Matthias Benkard

Reputation: 15769

Try putting

(setq slime-net-coding-system 'utf-8-unix)

into your .emacs file (or setting and saving the variable via M-x customize-variable).

In addition, make sure that you are running Clojure from within a UTF-8-enabled locale (if you're on Un*x and using Leiningen, try something like env LC_ALL=en_US.UTF-8 lein swank).

Upvotes: 3

Related Questions