Subject: bug#21536: Texi, Unicode and Emacs interface

From: Alex Kost <[email-masked]>
Date: Wed, 23 Sep 2015 13:51:36 +0300

There is an interesting "bug" that leads to a problem with Emacs
interface for Guix packages.

Try "M-x guix-search-by-name RET mpfrcx".  You will get an
'encoding-error'.  This happens because:

1. Description of the 'mpfrcx' package contains a unicode symbol "–".

2. For some reason unicode symbols are not handled properly in REPLs
   connected to a guile server.

To illustrate this problem, here is the recipe:

1. Run guile server:

  guile --listen

Evaluate there:

  ((@@ (guix ui) texi->plain-text) "foo \u2015 bar.")

So far so good.

2. Now connect to it, either with:

   - netcat: "netcat localhost 37146"

   - or Geiser: "M-x connect-to-guile"

and evaluate the same expression.  This time you will get the error.

(This should probably be counted as a Guile bug, I'm not sure)

To make the connected REPL handle such unicode strings you have to
manually evaluate (setlocale LC_ALL "") there (even (setlocale LC_ALL)
works!).  So I used this as a workaround for the emacs interface in the
attached patch (I don't know if there is a better workaround).

BTW, since we now use texi for the package descriptions, does it mean
that our intention is to get rid of using unicode symbols directly?

…Hm, I've just tried ((@@ (guix ui) texi->plain-text) "@U{2012}") and
got:

  Throw to key `parser-error' with args `(#f "Unknown command" U)

>From 5226abeac27e5b6f79cc6e2b933f146040e2c2bd Mon Sep 17 00:00:00 2001
From: Alex Kost <[email-masked]>
Date: Wed, 23 Sep 2015 13:42:44 +0300
Subject: [PATCH] emacs: Handle unicode symbols in texi descriptions.

Fixes <http://bugs.gnu.org/XXXXX> (FIXME).

* emacs/guix-backend.el (guix-start-repl-maybe): Call 'setlocale' for
  the internal REPL.
---
 emacs/guix-backend.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/emacs/guix-backend.el b/emacs/guix-backend.el
index 412d648..32d449a 100644
--- a/emacs/guix-backend.el
+++ b/emacs/guix-backend.el
@@ -190,7 +190,11 @@ display messages."
                   guix-default-port (buffer-name repl))))
         (set repl-var repl)
         (and end-msg (message end-msg))
-        (unless internal
+        (if internal
+            ;; Without this, the REPL will error when package
+            ;; descriptions contain unicode symbols.  See
+            ;; <http://bugs.gnu.org/XXXXX> (FIXME) for details.
+            (guix-geiser-eval "(setlocale LC_ALL)" repl)
           (run-hooks 'guix-after-start-repl-hook))))))
 
 (defun guix-start-repl (buffer &optional address)
-- 
2.5.0