LightTable / Clojure

Light Table Clojure language plugin
MIT License
99 stars 51 forks source link

Add result type :return to custom eval #11

Closed tapeinosyne closed 10 years ago

tapeinosyne commented 10 years ago

A new :result-type for custom evallers that allows to pass the evaluation's result to an arbitrary object instead of displaying it. (For those familiar with Clojure development on Emacs, this would be analogous to CIDER's eval-and-get-value, with the additional benefit of being async.)

Such a facility would be rather useful for plugin development. It grants the caller easy programmatic access to the result of a custom eval, allowing them to behave accordingly. For example, a factoring command could listen for the result of an analysis, then use its value to produce a snippet and move the cursor to the most convenient position in the editor.

This first implementation enforces a one-to-one correspondence between handlers and behaviors, because a custom evaller of type :return always raises the same trigger. An immediate improvement that I think rather desirable would be to allow the caller to also specify which trigger to raise upon successful eval, so that a single object may manage multiple events. (Edit: this improvement is now in to the branch.)

Here is a simple test case for this PR. If you are interested, I will extend the patch with the addition mentioned above and a few other things (such as returning the location, which is currently unused) before merging.

tapeinosyne commented 10 years ago

I have added custom triggers, and results are now passed as a map also including cursor data. The new test case is here.

sundbp commented 10 years ago

This looks quite useful to me. I've been thinking of using LT in a fashion similar to this project for a while, and without digging into it too much it'd strike me as this feature would be helpful in implementing it: https://groups.google.com/forum/#!topic/clojure/Olc9kznvnTw

ibdknox commented 10 years ago

Maybe we should just merge opts into meta.

tapeinosyne commented 10 years ago

Good point. Doing so also allows the caller to specify custom metadata; accordingly, the full :meta map is now sent to the return handler upon successful eval.

By the way, @ibdknox, I noticed that you bumped the Clojure plugin to 0.10 in the repo without adding new releases. Oversight?

ibdknox commented 10 years ago

Yeah, oversight. I was trying to push up a fix for Sean Corfield but didn't really want to release it until he could verify.