-
-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to tap> current value from inside cider inspector #3311
Comments
Just to add to the "viewer selection": At least in Clerk , viewers can be added and removed at runtime, I have experimented with the viewer selection (with fixed list), and it is very comfortable. |
Clerk supports this out-of-the box, using it's So my proposal should allow to use Clerk and Portal "as-are". It might work as well with Kindly/Clay: |
The fact that Portal can, and that there's a well-known datafy/nav set of protocols, leave me hesitant. Ideally we would not let a specific tool's idiosyncracy permeate into the default UX. I think this might be a middle ground solution: (defcustom cider-inspector-tap-transformer
"A ns-qualified, 1-arg function that will be invoked to transform an arbitrary transformation to all values
tapped via `cider-inspector-tap-current-value'.
You can use this to make tapped values easily viewable with certain tooling.
Or for any other arbitrary purpose"
"clojure.core/identity") My idea is that the UX would be invoking But then if you need a little transformation, you can write: (defn foo [x]
;; do whatever is needed to make `x` viewable.
;; for example:
(with-meta x {:viewer :my-viewer})) cider-nrepl would be responsible to require and invoke this defn. Does it sound reasonable? Please do feel free to propose a refinement. |
I think that a big added value would come if Emacs can be configured (maybe outcide Cider) with "advising" or an other form of "hook" to show in Emacs a Dropdown immidiately before "rendering" for "viewer selection". To have this in Clojure code seems to be too static to me. Even things like Portal and Clerk solve this "in code", by allowing to specify the "map viewer" while calling the |
I see! I think I like a lot having in cider something that maps very closely to
You could build commands on top of this basic For instance, would could write this Elisp code as part of your user-specific config: (defun tap-with-map-viewer
(let* ((cider-inspector-tap-transformer "my.ns/specify-map-viewer"))
(cider-inspector-tap-current-value)))
(defun tap-with-vega-lite
(let* ((cider-inspector-tap-transformer "my.ns/specify-vega-lite"))
(cider-inspector-tap-current-value)))
;; ...and so on - one defun per viewer ...and then you could ...you could also build a tiny UI (e.g. with Let me know if this would be feasible. Again, I'm open to variations. But I think the general pattern would be "offer one or two low-level building blocks, let users build added value on top". |
I put here are function which does this for
This is of course Clerk specific, so should not be in Cider, but it shows what I mean. |
Your last proposal looks good to me. In principle I agree on the "minimal code around tap>" principle Thanks for your support ! |
Yes, I think that my approach and the code you expressed in #3311 (comment) are compatible. Specifically, you could write clojure code like this: (defn make-viewer-fn [viewer]
(fn [value]
(nextjournal.clerk/with-viewer viewer
value)))
(def html-viewer (make-viewer-fn nextjournal.clerk.viewer/html-viewer))
(def table-viewer (make-viewer-fn :table))
;; and so on ...then, on the Elisp side, you'd As a refresher, a
Cheers 🍻 looking forward to your PR! |
I never wrote any EmacsLisp code... I think as well this would need a change in the cider middleware as we would need a new operation, if I understood it well. Looking here: Line 344 in 9e882ce
My "hack" uses an existing middleware op and defines a var with a random name, but I am sure we don't want this in cider. Should not be complicated, though |
it would just need a new function |
Most likely yes I'd be happy to review your PRs or support them with any advice or research. Cheers - V |
Feel free to pick up the conversation here clojure-emacs/cider-nrepl#770 (comment) |
Is your feature request related to a problem? Please describe.
I would like to visualize (graphically) parts of a complex data structure using the current value
of the
cider-inspector
, so combining the simple drilling into the data with a way to renderon key-press the data in a rich, graphical way
Describe the solution you'd like
As "visualizing of Clojure data" has a multitude of different solutions, I think the best
is a generic solution, which allows to easily
tap>
the current value in cider-inspector.Then the data renderer could be plugged in as a tap handler
So maybe adding a function such as
cider-inspector-tap-current-value
to cider inspector could be useful.Describe alternatives you've considered
Using
cider-def-current-value
can be used but requires "2 steps", namely define a var and then tap the var.I could as well write ad-hoc code which drills down and taps, but using the cider-inspector for drill down is more comfortable.
Additional context
There was an initial discussion and some proof of concept code on Slack:
https://app.slack.com/client/T03RZGPFR/C0617A8PQ/thread/C0617A8PQ-1674486881.210099
To fully solve the problem, we would need something additionally.
The "data renderer" available for Clojure (example Clerk) cannot know "how to render arbitrary data".
They expect, that a human user provide them with some "help", how to render. In Clerk this is called "viewer selection" and calling a function giving a it a "viewer"
So ideally we would have a interactive function in Cider which "request" this information from the user and sends it together with the current value to "tap>" , as part of the
cider-inspector-tap-current-value
This information could be probably a simple "string", a kind of "viewer id", which options could come from a list, which the user of cider can configure in a variable.
Without this feature, Clojure code would need to "guess" the viewer from the data, which is very likeley not working well.
The code linked above contains as well a proof of concept of such function:
clerk-tap-last-sexp-with-viewer
This does the tapping of the "last sexp", but the same could be applied for the proposed
cider-inspector-tap-current-value
The text was updated successfully, but these errors were encountered: