Fork me on GitHub
Ben Sless14:09:11

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?


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.


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


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 Sless14:09:50

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 Sless14:09:13

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

Ben Sless14:09:51

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


that sounds great.

Ben Sless14:09:55

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


send along the ns then

Ben Sless14:09:49

no harm in trying


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") ....)


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


would love to see a screenshot.


that is super awesome!

šŸ™ƒ 3
Ben Sless15:09:37

I'll prepare a PR?


what dependencies does this require?

Ben Sless15:09:55

That's the next thing I was going to ask about šŸ™‚

Ben Sless15:09:00

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

Ben Sless15:09:31

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


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


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 Sless15:09:11

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

Ben Sless15:09:01

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 Sless15:09:33

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

Ben Sless15:09:39

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


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 Sless15:09:00

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 Sless15:09:16

Just eval it as a hook after loading cider

Ben Sless16:09:56

In the meanwhile I threw my work, I'll add some README instructions, credits, etc. Hope you find it useful šŸ™‚

šŸ‘ 3
Ben Sless16:09:41

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.