Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Add result type :return to custom eval#11

Merged
ibdknox merged 3 commits intoLightTable:masterfrom
tapeinosyne:result.return
Mar 11, 2014
Merged

Add result type :return to custom eval#11
ibdknox merged 3 commits intoLightTable:masterfrom
tapeinosyne:result.return

Conversation

@tapeinosyne
Copy link
Copy Markdown
Contributor

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.

ndr added 2 commits February 22, 2014 03:01
Allows asynchronous programmatic access to the result of a custom eval.
A custom evaller must pass an option map containing `:result-type :return`
and a `:handler object/object` that listens for a `:return` trigger;
upon successful eval of the custom function, its returned value is sent
to the triggered behavior.
Custom evallers of `:result-type :return` can include a `:trigger` keyword
in their options map to specify the trigger to raise upon successful
completion. The default trigger is `:return`.

The data sent to the handler is now a map containing:
`:result` as the eval result, and
`:loc` as the location of the cursor at eval invoke time.
@tapeinosyne
Copy link
Copy Markdown
Contributor Author

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

@sundbp
Copy link
Copy Markdown

sundbp commented Feb 22, 2014

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
Copy link
Copy Markdown
Member

ibdknox commented Feb 24, 2014

Maybe we should just merge opts into meta.

@tapeinosyne
Copy link
Copy Markdown
Contributor Author

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?

Allows to add arbitrary options to a custom evaller.
If `result-type` of the evaller is `:return`, the full map of metadata
is returned instead of just the cursor location.

The data sent to a return handler is now a map containing:
`:result` as the eval result, and
`:meta` as the metadata used for custom evaluation.
@ibdknox
Copy link
Copy Markdown
Member

ibdknox commented Mar 11, 2014

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.

ibdknox added a commit that referenced this pull request Mar 11, 2014
Add result type :return to custom eval
@ibdknox ibdknox merged commit 57793a3 into LightTable:master Mar 11, 2014
@tapeinosyne tapeinosyne deleted the result.return branch March 11, 2014 18:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants