Play for Vim users

As an unconditional Vim user and a strong supporter of the Crystal language, I often test some code on play.crystal-lang.org.
So I write a few lines of code, and type ESC to exit Vim’s Insert mode. Oops, but no, I wasn’t in Vim! Arghh, I just lost all my work!
Maybe a new “Undo Edit” button next to “Compile and run code” might be of some interest!
Maybe also a confirmation request “Cancel edit” after pressing ESC could be useful.
What do you think?

Maybe add some sort of edit history in the local browser?

It doesn’t make sense. If you’re a so unconditional Vim user, you should test inside Vim directly!

This isn’t ideal, but if I need to save code when I’m on play.crystal-lang.org or carc.in, I just click the “compile and run code” button, then edit again. That way I can use the back button to return to a previous state of my code. Obviously, it would be better to test in Vim directly (which I don’t do, so I can’t direct you in how) or use a text editor or IDE that has undo/redo, but if you’re intent on using Crystal Play, that’s probably the best way to do it.

Agree with the above responses - testing locally is both fast and efficient. However, play is awesome for sending snippets and proof of concept sketches to others.

To get the best of both worlds, what about inverting your flow a little? Set up an alias in your vimrc that shoots the current file or a buffer over to play. That way you can enjoy your local editor setup and share from there.

You can post to https://play.crystal-lang.org/run_requests with the following body structure

{
    "run_request": {
        "language": "crystal",
        "version": "0.35.1",
        "code": "puts \"Hello World!\""
    }
}

And it will send you back a neat response that you can map back into what you need.

{
    "run_request": {
        "run": {
            "id": "a8xg",
            "language": "crystal",
            "version": "0.35.1",
            "code": "puts \"Hello World!\"",
            "stdout": "Hello World!\n",
            "stderr": "",
            "exit_code": 0,
            "created_at": "2021-01-11T03:39:12Z",
            "url": "https://carc.in/runs/a8xg",
            "html_url": "https://carc.in/#/r/a8xg",
            "download_url": "https://carc.in/runs/a8xg.cr"
        }
    }
}
1 Like

http://play.crystal-lang.org/ should only be used to share code snippets with others, not testing code locally. You can run the Crystal Playground with crystal play (which is another software).