Search code examples
unicodeutf-8common-lispfilenamesslime

How to open a file which name contain unicode code in Lisp(sbcl+slime)?


(with-open-file (s "~/例子.txt"
                 :external-format :utf-8)
  (print s))

result:

NIL c-string encoding error:
  the character with code 20363 cannot be encoded.
  [Condition of type SB-INT:C-STRING-ENCODING-ERROR]

Example:

in Aquamacs 3.5 with newest slime & sbcl2.0.2: in Aquamacs3.5 with slime & sbcl

sbcl in iterm2 can do it:

in iterm2

Aquamacs itself can open and write filename contains utf-8 correctly, too.

I have tried to add

(setq slime-net-coding-system 'utf-8-unix)
(set-language-environment "UTF-8")

in my aquamacs config file, but it doesn't work. Please help!

Update: I have finally found the reason. When in Iterm2, the command

locale

gives this output: enter image description here

While in Aquamacs open from ui, in eshell it gives:

Result from eshell

After I added:

(setenv "LANG" "en_US.UTF-8")

to my Aquamacs config, it works! Thanks to all who reply to my question! Below is the links that helps me.

What the question exactly is

Resolutions to the question

How to set locale for Emacs open from UI


Solution

  • Add something like:

    (setenv "LANG" "en_US.UTF-8")
    

    to your emacs config. Explain is at above.