I strongly recommend not doing this. In particular, it will break in
many situations. A few examples:
- any file that isn't written in #lang racket such as typed/racket or
scribble/manual or ...
- any file that doesn't work the same as a sequence of repl
interactions. For example, any use of mutual recursion or any
shadowing of imported ids
- any file that uses forms only allowed in modules, such as `module+`
or `provide`.

I'm not sure why `-e` doesn't evaluate in the same namespace as the
REPL, but if you put `(enter! "my-file.rkt")` in `enter.rktl` then:

$ racket -i -f enter.rktl

will do what you want.

You can generalize this to:

(dynamic-enter! (vector-ref (current-command-line-arguments) 0))

and then:

$ racket -i -f enter.rktl my-file.rkt

will do what you wanted.

Sam



On Fri, Nov 30, 2018 at 4:36 AM Habib Alamin <ha.ala...@gmail.com> wrote:
>
> I found a solution:
>
> nnoremap <leader>r :w \| !racket -e "$(grep -v '\#lang' %)" -i<cr>
>
> This little hack, instead of enter!ing a file, simply echoes the contents of 
> the file into the -e argument using a subshell. Racket treats newlines the 
> same as spaces, and ignores blank lines, but if you're a neat freak, you can 
> do:
>
> nnoremap <leader>r :w \| !racket -e "$(grep -Ev '(\#lang)\|(^$)' % \| tr '\n' 
> ' ')" -i<cr>
>
> On Friday, 30 November 2018 01:36:11 UTC, Habib Alamin wrote:
>>
>> Hi,
>>
>> I'm trying to set up a keybinding in my editor to enter the namespace of my 
>> current file in a REPL, similar to how Dr Racket's Run button works.
>>
>> I can do a racket -e '(println "Hello!") -i and it loads the REPL after 
>> printing Hello. A racket -e '(define a "a") -i also works, in that I'm able 
>> to access a in the REPL. However, I can't do racket -e '(enter! 
>> "hello.rkt")' -i. The REPL starts, but I can't access anything defined in 
>> the file.
>>
>> After asking in the IRC channel, I was asked to try
>>
>> racket -e '(let ([racketrc-path (expand-user-path "~/.racketrc")]) (and 
>> (file-exists? racketrc-path) (load racketrc-path)) (void)) (enter! 
>> "current-file.rkt") (read-eval-print-loop)
>>
>> which didn't work either. Neither did
>>
>> racket -e '(enter! "file.rkt") (read-eval-print-loop)'
>>
>> I can do a racket -if file.rkt if I get rid of the #lang racket line, but I 
>> hear using -f isn't good practice, and besides, I want to write valid Racket 
>> files; removing the #lang line breaks normal Racket operation; I can't just 
>> do a racket file.rkt.
>>
>> I'd really appreciate any help in figuring out why this is happening and a 
>> simple fix.
>>
>> Cheers,
>> Habib
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to