unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] emacs: Fix converting scheme into elisp expression.
@ 2016-03-21  8:47 Alex Kost
  2016-03-21  9:38 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Kost @ 2016-03-21  8:47 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]

There is a bug in "scheme → elisp" conversion in the emacs interface.
It can be seen with the following recipe:

1. M-x guix-licenses

2. Move to "FreeBSD" license and press "i" to describe it.

3. In the *Guix License Info* buffer you can see:

  https://www.gnu.org/licenses/license-listnilreeBSD

while it should be:

  https://www.gnu.org/licenses/license-list#FreeBSD

As you can see, "#F" is replaced with "nil".  The problem is: we receive
a string with scheme expression from geiser, and it should be converted
into elisp expression.  I don't see how to do it other than just to
replace scheme specific things (#t, #f, #<unspecified>) with elisp
analogs in this raw string.

The attached patch improves this conversion process, but it is still
ugly.  Are there better ideas how to perform this conversion?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-emacs-Fix-converting-scheme-into-elisp-expression.patch --]
[-- Type: text/x-patch, Size: 1706 bytes --]

From f127fc2ac741334340b650736b98ed15879a3be1 Mon Sep 17 00:00:00 2001
From: Alex Kost <alezost@gmail.com>
Date: Sun, 24 Jan 2016 11:16:44 +0300
Subject: [PATCH] emacs: Fix converting scheme into elisp expression.

* emacs/guix-geiser.el (guix-geiser-eval-read): Replace #f/#t with nil/t
  only when they follow "(" or " ".
---
 emacs/guix-geiser.el | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/emacs/guix-geiser.el b/emacs/guix-geiser.el
index 0e6cc03..833f5bb 100644
--- a/emacs/guix-geiser.el
+++ b/emacs/guix-geiser.el
@@ -46,11 +46,23 @@ Return a list of strings with result values of evaluation."
 (defun guix-geiser-eval-read (str &optional repl)
   "Evaluate STR with guile expression using Geiser REPL.
 Return elisp expression of the first result value of evaluation."
-  ;; Parsing scheme code with elisp `read' is probably not the best idea.
-  (read (replace-regexp-in-string
-         "#f\\|#<unspecified>" "nil"
-         (replace-regexp-in-string
-          "#t" "t" (car (guix-geiser-eval str repl))))))
+  ;; The goal is to convert a string with scheme expression into elisp
+  ;; expression.
+  (let ((result (car (guix-geiser-eval str repl))))
+    (cond
+     ((or (string= result "#f")
+          (string= result "#<unspecified>"))
+      nil)
+     ((string= result "#t")
+      t)
+     (t
+      (read (replace-regexp-in-string
+             "[ (]\\(#f\\)" "nil"
+             (replace-regexp-in-string
+              "[ (]\\(#t\\)" "t"
+              result
+              nil nil 1)
+             nil nil 1))))))
 
 (defun guix-repl-send (cmd &optional save-history)
   "Send CMD input string to the current REPL buffer.
-- 
2.6.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs: Fix converting scheme into elisp expression.
  2016-03-21  8:47 [PATCH] emacs: Fix converting scheme into elisp expression Alex Kost
@ 2016-03-21  9:38 ` Ludovic Courtès
  2016-03-23  8:28   ` Alex Kost
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2016-03-21  9:38 UTC (permalink / raw)
  To: Alex Kost; +Cc: guix-devel

Alex Kost <alezost@gmail.com> skribis:

> As you can see, "#F" is replaced with "nil".  The problem is: we receive
> a string with scheme expression from geiser, and it should be converted
> into elisp expression.  I don't see how to do it other than just to
> replace scheme specific things (#t, #f, #<unspecified>) with elisp
> analogs in this raw string.
>
> The attached patch improves this conversion process, but it is still
> ugly.  Are there better ideas how to perform this conversion?

The ideal solution would be to have a full-blown Scheme reader in elisp
(trivial in Guile-Emacs…).  Otherwise I’m not sure what can be done.

> From f127fc2ac741334340b650736b98ed15879a3be1 Mon Sep 17 00:00:00 2001
> From: Alex Kost <alezost@gmail.com>
> Date: Sun, 24 Jan 2016 11:16:44 +0300
> Subject: [PATCH] emacs: Fix converting scheme into elisp expression.
>
> * emacs/guix-geiser.el (guix-geiser-eval-read): Replace #f/#t with nil/t
>   only when they follow "(" or " ".

Looks good, thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs: Fix converting scheme into elisp expression.
  2016-03-21  9:38 ` Ludovic Courtès
@ 2016-03-23  8:28   ` Alex Kost
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Kost @ 2016-03-23  8:28 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

Ludovic Courtès (2016-03-21 12:38 +0300) wrote:

> Alex Kost <alezost@gmail.com> skribis:
>
>> As you can see, "#F" is replaced with "nil".  The problem is: we receive
>> a string with scheme expression from geiser, and it should be converted
>> into elisp expression.  I don't see how to do it other than just to
>> replace scheme specific things (#t, #f, #<unspecified>) with elisp
>> analogs in this raw string.
>>
>> The attached patch improves this conversion process, but it is still
>> ugly.  Are there better ideas how to perform this conversion?
>
> The ideal solution would be to have a full-blown Scheme reader in elisp
> (trivial in Guile-Emacs…).  Otherwise I’m not sure what can be done.

I also thought about Guile Emacs.  Maybe some day it will become simply
"Emacs" that we use all the time...  Until then this hacky way will
probably be kept, thanks for replying!

>> From f127fc2ac741334340b650736b98ed15879a3be1 Mon Sep 17 00:00:00 2001
>> From: Alex Kost <alezost@gmail.com>
>> Date: Sun, 24 Jan 2016 11:16:44 +0300
>> Subject: [PATCH] emacs: Fix converting scheme into elisp expression.
>>
>> * emacs/guix-geiser.el (guix-geiser-eval-read): Replace #f/#t with nil/t
>>   only when they follow "(" or " ".
>
> Looks good, thanks!

Committed.

-- 
Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-23  8:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-21  8:47 [PATCH] emacs: Fix converting scheme into elisp expression Alex Kost
2016-03-21  9:38 ` Ludovic Courtès
2016-03-23  8:28   ` Alex Kost

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).