cider

A channel dedicated to the Clojure Interactive Development Environment that Rocks (aka CIDER). :cider:
Ben Sless 2020-09-23T14:44:11.001200Z

Hi all, I'm trying to do some hacking on cider. How do I ensure the code I send to the REPL will get evaluated on the namespace of the file I'm in?

dpsutton 2020-09-23T14:48:05.002400Z

when you eval in-line that happens automatically. the ns is sent along with the code form. the repl has a namespace and this is the ns that is used. i can't think of a good way to do this that also allows for input from a user.

dpsutton 2020-09-23T14:49:04.003400Z

one suggestion would be to make a read only buffer that could contain the inputs and outputs to things that are evaluated in-line. so it would appear like a repl but only contain the inputs and outputs to cider's evaluating inline

dpsutton 2020-09-23T14:50:00.004600Z

i suppose you could put stuff in the cider-send-to-repl to attempt to set the current ns to the file's ns

Ben Sless 2020-09-23T14:50:50.005200Z

I'll describe what I'm trying to do, maybe it'll help clarify things: I thought it would be nice to add a cider-decompile interactive command, sort of like cider-macroexpand-1. For that I started my hacking around the cider-macroexpand.el file

Ben Sless 2020-09-23T14:51:13.005600Z

The idea was to take the output and display it in a temporary buffer in java mode

2
Ben Sless 2020-09-23T14:51:51.005800Z

cider-macroexpand uses cider-nrepl-send-sync-request

dpsutton 2020-09-23T14:52:33.006Z

that sounds great.

Ben Sless 2020-09-23T14:53:55.006700Z

It does, but cider-nrepl-send-sync-request doesn't eval in the current ns unlike cider-interactive-eval (?)

dpsutton 2020-09-23T14:54:37.006900Z

send along the ns then

Ben Sless 2020-09-23T14:54:49.007100Z

no harm in trying

dpsutton 2020-09-23T14:56:28.008100Z

you can see how it sends that along. it sends the ns into cider-nrepl-request:eval. which just builds up a list like (("ns" whatever) ("code" "code to be evaluated") ....)

dpsutton 2020-09-23T14:56:53.008400Z

there's a helper function nrepl--eval-request which builds all that up and the ns is threaded through

Ben Sless 2020-09-23T14:58:38.008600Z

HA

Ben Sless 2020-09-23T14:58:42.008800Z

it works!

dpsutton 2020-09-23T14:58:58.009Z

awesome!

dpsutton 2020-09-23T14:59:12.009400Z

would love to see a screenshot.

Ben Sless 2020-09-23T14:59:52.009600Z

4
dpsutton 2020-09-23T15:01:32.010Z

that is super awesome!

🙃 1
Ben Sless 2020-09-23T15:01:37.010200Z

I'll prepare a PR?

dpsutton 2020-09-23T15:02:25.010600Z

what dependencies does this require?

Ben Sless 2020-09-23T15:02:55.010900Z

That's the next thing I was going to ask about 🙂

Ben Sless 2020-09-23T15:03:00.011100Z

it requires [com.clojure-goes-fast/clj-java-decompiler "0.3.0"]

Ben Sless 2020-09-23T15:03:31.011800Z

so perhaps it should be an extra module, not part of core cider

dpsutton 2020-09-23T15:03:35.012Z

yeah this may just be a cool thing people can add. not sure if CIDER should depend on that

dpsutton 2020-09-23T15:04:08.012800Z

perhaps the documentation could take this? A section on expanding and customizing CIDER and show how easy it can be to add new features like this

Ben Sless 2020-09-23T15:04:11.013Z

(transitively depends on [org.bitbucket.mstrobel/procyon-compilertools "0.5.34"])

Ben Sless 2020-09-23T15:06:01.014Z

Theoretically, there's a bigger feature here. The ability to take some arbitrary piece of code at point, wrap it in an expression, potentially parametrized over some variables, and evaluate that, instead

Ben Sless 2020-09-23T15:06:33.014600Z

off the top of my head, it could be useful for profiling, benchmarking, decompiling, they all behave the same

Ben Sless 2020-09-23T15:07:39.015200Z

That requires no extra dependencies, and introduces an easy extension point

dpsutton 2020-09-23T15:11:09.016700Z

can you give an example? or the proposed change to CIDER? i'm not following as it seems you kinda used the building blocks already present. i'm assuming you constructed a handler using one of the handler functions and that took the response, opened a new buffer and made it java mode. and the eval you reused one of the existing functions or made a new one using a template more or less?

Ben Sless 2020-09-23T15:11:30.016900Z

Yes

Ben Sless 2020-09-23T15:16:00.020200Z

This isn't a big feature, more of a convenience where you'll need to plug in a few parameters: • pre command • wrap command • output buffer name • output buffer mode • cider-jack-in extra dependencies • command name • command keys This can be exposed as a single function which will allow users to make small extensions to cider without modifying the core, even with extra dependencies

Ben Sless 2020-09-23T15:17:16.020600Z

Just eval it as a hook after loading cider

Ben Sless 2020-09-23T16:24:56.021700Z

In the meanwhile I threw my work https://github.com/bsless/clj-decompiler.el/blob/master/clj-decompiler.el, I'll add some README instructions, credits, etc. Hope you find it useful 🙂

👍 1
Ben Sless 2020-09-23T16:30:41.022800Z

Do I need to list any/all of the authors of cider-macroexpand.el in the copyright or authorship section? The file is loosely inspired by it.