geiser-eval-buffer in Guile doesn't use custom readers when first run
Hi!
When running geiser-eval-buffer in a Guile script that imports or creates a custom reader, the custom reader is not defined while geiser-eval-buffer is running.
We can reproduce this with a Guile script containing the following code:
(use-modules (ice-9 rdelim))
;; https://github.com/lloda/guile-raw-strings/blob/main/mod/raw-strings.scm
(eval-when (expand load eval)
(define openc "([\"")
(define closec ")]\"")
(define extension-char #\R))
(define (reader-extension-raw-string chr port)
(define (char-please port)
(let ((c (read-char port)))
(if (eof-object? c)
(throw 'end-of-file-reading-raw-string)
c)))
(let* ((fix-open (read-delimited openc port 'split))
(fix (car fix-open))
(open (cdr fix-open))
(close
(let-syntax ((pick-close
(lambda (stx)
(syntax-case stx ()
((_ o)
#`(case o
#,@(map (lambda (a b) `((,a) ,b))
(string->list openc) (string->list closec))
(else (throw 'raw-string-delimiter-not-found fix))))))))
(pick-close open))))
(when (string-index fix char-whitespace?)
(throw 'raw-string-delimiter-has-whitespace fix))
(let search-delim ((c (char-please port)) (s '()))
(if (eqv? close c)
(let search-close ((ss (list close)) (i 0))
(if (= i (string-length fix))
(list->string (reverse! s))
(let ((c (char-please port)))
(if (eqv? (string-ref fix i) c)
(search-close (cons c ss) (+ 1 i))
(search-delim c (append ss s))))))
(search-delim (char-please port) (cons c s))))))
(read-hash-extend extension-char reader-extension-raw-string)
(define foo
#R-(Hello there!)-)
(format #t "~a~%" foo)
Running $ guile geiser-demo.scm prints Hello there!, as expected.
Starting a Geiser REPL and running geiser-eval-buffer prints
Throw to key `read-error' while reading argument `form' of command `geiser-eval':
#<unknown port>:106:5: Unknown # object: "#R"
;;; <stdin>:106:6: warning: possibly unbound variable `Hello'
;;; <stdin>:106:12: warning: possibly unbound variable `there!'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: Hello
While reading expression:
#<unknown port>:106:22: unexpected ")"
[Debugging level: 2]
Expression evaluated was:
<SNIP, contents of geiser-demo.scm>
Given that the error message being printed is from Guile, it's possible this is a Guile issue, not a Geiser one. I figured I'd report it here because I'm not sure how Geiser handles passing the script to Guile. And Guile handles the file just fine when called from the CLI.
If we evaluate the code in stages using geiser-eval-last-sexp, the code evaluates as expected.
After running the code in stages, geiser-eval-buffer works as expected.
Confirmed with $ emacs -Q and running (progn (require 'geiser) (require 'geiser-guile))
Emacs 29.3, geiser-guile 0.28.1, and geiser 0.30.