[racket-dev] , en and enter! sometimes do nothing, and it's changing over releases?

From: Greg Hendershott (greghendershott at gmail.com)
Date: Mon Feb 11 18:09:23 EST 2013

>> and probably using a sandbox is the way to get it. You'd want to not use the
>> default settings for the sandbox, tho, but give more permissions for file
>> access (and probably a few other things).

Following that hint (thanks Robby!), I _seem_ to be on the right track:

#lang racket/base

(require racket/sandbox)

(struct exn:restart exn ())

(define (run path-str)
  (define path (string->path path-str))
  (display (banner))
  (let loop ()
    (when (do-run path)
      (displayln "Restarting REPL...")
      (loop))))

(define (do-run path)  ;returns #t if REPL should be restarted else #f
  ;; Parameters to set _before_ creating the sandboxed evaluator:
  (parameterize ([current-namespace (make-empty-namespace)]
                 [sandbox-input (current-input-port)]
                 [sandbox-output (current-output-port)]
                 [sandbox-error-output (current-error-port)]
                 [sandbox-security-guard (current-security-guard)] ;permissive
                 [sandbox-propagate-exceptions #f]
                 [compile-enforce-module-constants #f]
                 [compile-context-preservation-enabled #f]
                 [current-read-interaction read-interaction]
                 [current-prompt-read (make-prompt-read path)])
    (parameterize ([current-eval (make-module-evaluator path)])
      (with-handlers ([exn:fail:sandbox-terminated?
                       (lambda (exn) (eprintf "~a\n" (exn-message exn)) #f)]
                      [exn:restart? (lambda (_) #t)])
        (call-with-trusted-sandbox-configuration
         (lambda () (read-eval-print-loop)))))))

(define (make-prompt-read path)
  (let-values ([(base name dir?) (split-path path)])
    (lambda ()
      (display name) (display "> ")
      (let ([in ((current-get-interaction-input-port))])
        ((current-read-interaction) (object-name in) in)))))

(define (read-interaction src in)
  (parameterize ([read-accept-reader #t]
                 [read-accept-lang #f])
    (define stx (read-syntax src in))
    (syntax-case stx (restart)
      [(restart) (raise (exn:restart "" (current-continuation-marks)))]
      [_ stx])))

;; Example use:
(run "/Users/greg/src/scheme/misc/hello.rkt")

On Mon, Feb 11, 2013 at 11:35 AM, Greg Hendershott
<greghendershott at gmail.com> wrote:
> That would be great! It would make for such a smoother experience
> switching between DrRacket and Emacs. (DrRacket is awesome for Racket.
> Emacs is awesome for multi-language projects.)
>
> I remember staring at the Emacs Scheme mode menu the first time and
> thinking, "Huh?? Where's the 'Run' command?'" It took me awhile to
> figure out some rough equivalent. Even today I find myself wanting a
> closer equivalent.
>
> At some point soon I probably ought to pop the stack (resume working
> on my main project instead of on my tool chain). I'll set a timer and
> see how much progress I can make on this myself before I'd need to set
> it aside.
>
> On Mon, Feb 11, 2013 at 7:37 AM, Robby Findler
> <robby at eecs.northwestern.edu> wrote:
>> IMO, DrRacket-like functionality would be nice to have in an Emacs setting
>> and probably using a sandbox is the way to get it. You'd want to not use the
>> default settings for the sandbox, tho, but give more permissions for file
>> access (and probably a few other things).
>>
>> Robby
>>
>>
>> On Mon, Feb 11, 2013 at 1:07 AM, Eli Barzilay <eli at barzilay.org> wrote:
>>>
>>> 9 hours ago, Greg Hendershott wrote:
>>> > I'm inclined to add a new command to XREPL that takes that approach,
>>> > to experiment. I was spelunking in DrRacket source but I'm slow to
>>> > isolate that from what else is going on. It sounds like you
>>> > understand it; is there a code sample you could share?
>>>
>>> I'm not sure what exactly you're after, but you can get most of that
>>> using a ,switch command to create a new namespace, then using it with
>>> a "!" flag to reset it.
>>>
>>> --
>>>           ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>>>                     http://barzilay.org/                   Maze is Life!
>>> _________________________
>>>   Racket Developers list:
>>>   http://lists.racket-lang.org/dev
>>
>>

Posted on the dev mailing list.