Geiser and org-babel hang when evaluating a source block ending in a comment with no newline
Attached is a short test file. The Scheme code block inside it ends with a comment line. There is no newline at the end of the comment.
Opening this file with a typical org-babel and geiser configuration and executing the block with C-c C-c
results in a hang. Eventually it aborts with no result.
I think the issue is in this function:
(defsubst geiser-debug--wrap-region (str)
(format "(begin %s)" str))
When str
ends in a comment with no newline, the trailing parenthesis is commented out. You can verify this from this trace (collected via dtruss on macOS):
read(0x0, ",\0", 0x1) = 1 0
read(0x0, "g\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "i\0", 0x1) = 1 0
read(0x0, "s\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "r\0", 0x1) = 1 0
read(0x0, "-\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "v\0", 0x1) = 1 0
read(0x0, "a\0", 0x1) = 1 0
read(0x0, "l\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "#\0", 0x1) = 1 0
read(0x0, "f\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "(\0", 0x1) = 1 0
read(0x0, "b\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "g\0", 0x1) = 1 0
read(0x0, "i\0", 0x1) = 1 0
read(0x0, "n\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, ";\0", 0x1) = 1 0
read(0x0, ";\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "-\0", 0x1) = 1 0
read(0x0, "*\0", 0x1) = 1 0
read(0x0, "-\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "g\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "i\0", 0x1) = 1 0
read(0x0, "s\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "r\0", 0x1) = 1 0
read(0x0, "-\0", 0x1) = 1 0
read(0x0, "s\0", 0x1) = 1 0
read(0x0, "c\0", 0x1) = 1 0
read(0x0, "h\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "m\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "-\0", 0x1) = 1 0
read(0x0, "i\0", 0x1) = 1 0
read(0x0, "m\0", 0x1) = 1 0
read(0x0, "p\0", 0x1) = 1 0
read(0x0, "l\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "m\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "n\0", 0x1) = 1 0
read(0x0, "t\0", 0x1) = 1 0
read(0x0, "a\0", 0x1) = 1 0
read(0x0, "t\0", 0x1) = 1 0
read(0x0, "i\0", 0x1) = 1 0
read(0x0, "o\0", 0x1) = 1 0
read(0x0, "n\0", 0x1) = 1 0
read(0x0, ":\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "g\0", 0x1) = 1 0
read(0x0, "u\0", 0x1) = 1 0
read(0x0, "i\0", 0x1) = 1 0
read(0x0, "l\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "-\0", 0x1) = 1 0
read(0x0, "*\0", 0x1) = 1 0
read(0x0, "-\0", 0x1) = 1 0
read(0x0, "\n\0", 0x1) = 1 0
read(0x0, "(\0", 0x1) = 1 0
read(0x0, "+\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "1\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "2\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "3\0", 0x1) = 1 0
read(0x0, ")\0", 0x1) = 1 0
read(0x0, "\n\0", 0x1) = 1 0
read(0x0, ";\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "t\0", 0x1) = 1 0
read(0x0, "e\0", 0x1) = 1 0
read(0x0, "s\0", 0x1) = 1 0
read(0x0, "t\0", 0x1) = 1 0
read(0x0, ")\0", 0x1) = 1 0
read(0x0, " \0", 0x1) = 1 0
read(0x0, "(\0", 0x1) = 1 0
read(0x0, ")\0", 0x1) = 1 0
read(0x0, "\n\0", 0x1) = 1 0
The important lines are near the bottom. Observe that there is no newline after the ; test
.
I think it should be possible to fix this simply by changing the wrapping function to something like:
(defsubst geiser-debug--wrap-region (str)
(format "(begin\n%s\n)" str))
Here's my geiser version:
(geiser . [(20200204 1826) nil "GNU Emacs and Scheme talk to each other" tar ((:commit . "b134d0620d4f38e544c76e8f756f3f0428c5143e") (:url . "http://www.nongnu.org/geiser/"))])
Please let me know if more information is needed to reproduce and fix this. Thanks!