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
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
The idea was to take the output and display it in a temporary buffer in java mode
cider-macroexpand
uses cider-nrepl-send-sync-request
that sounds great.
It does, but cider-nrepl-send-sync-request
doesn't eval in the current ns unlike cider-interactive-eval
(?)
send along the ns then
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
HA
it works!
awesome!
would love to see a screenshot.
that is super awesome!
I'll prepare a PR?
what dependencies does this require?
That's the next thing I was going to ask about 🙂
it requires [com.clojure-goes-fast/clj-java-decompiler "0.3.0"]
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
(transitively depends on [org.bitbucket.mstrobel/procyon-compilertools "0.5.34"]
)
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
off the top of my head, it could be useful for profiling, benchmarking, decompiling, they all behave the same
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?
Yes
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
Just eval it as a hook after loading cider
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 🙂
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.