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.

Reply via email to