Hello,

I have posted this to /r/Racket a few days ago and someone suggested I 
should also post here.

I have been playing with racket lately. I think DrRacket is a fantastic 
editor but unfortunately as a long time vim user I feel quite uncomfortable 
when I use something else. I had some mappings to execute code while 
editing scripting languages (e.g. python, ruby) which I turned into a 
plugin a few days ago:

https://github.com/gokcehan/vim-opex

It also works for racket if your vim is compiled with `+mzscheme`. There 
are some issues (language is always `racket/base` and I think gui and 
threading do not work) but in general I'm quite happy about it. I have a 
screencast here with a racket example here if anyone is interested:

https://media.giphy.com/media/3o6fJ5GNRKb7kLtbNK/giphy.gif

This plugin simply defines two custom operator functions and the real work 
is done with mzscheme interface (`:mz` command). By default, `gx` is mapped 
to an execution operator which displays the output in `:messages` and `gz` 
is mapped to an appending operator which appends the output as comment 
below the expression. These operators either take a text object or work 
with visual selection just like builtin operators. So for example, in the 
demo, following examples are shown:

gxab -> evaluate current s-expression (or block in vim's terms)
gx2ab -> evaluate the current 2-level s-expression
v2abgx -> evaluate the current 2-level s-expression (with visual selection)
gxip -> evaluate current paragraph
gzip -> evaluate and append the output of current paragraph

More information can be found in the github page.

There are already many plugins which launches a repl from your editor and 
send text to that repl from within your editor and I think most people are 
already familiar with slime. This plugin is a different approach to the 
same problem with following differences:

- Embedded mzscheme interface is used for evaluation instead of launching 
an external process
- Operator functions are defined for mappings to work with existing text 
objects instead of custom mappings specific to an object
- Output is displayed as a vim message and history can be accessed with 
`:messages` or `:mes` for short
- Arbitrary expressions can be evaluated using `:mzscheme` command or `:mz` 
for short
- These expressions can then be accessed again from the command history 
(i.e. `q:`) which would act similarly to a repl history
- In theory, whole file can be evaluated using `:mzfile %` but this does 
not currently work when a file has a `#lang` statement

Compared to other such plugins I find this more natural and easier to work 
with. It is meant to work out of the box without any configuration. The 
only headache would be to have a vim version compiled with `+mzscheme` 
feature which may require manually compiling vim from source.

Feel free to leave comments, bugs or ideas.

*P.S.* Thank you all who worked on integrating `if_mzsch` to vim.

Gokcehan

-- 
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