Fork me on GitHub
#cider
<
2017-07-26
>
dominicm10:07:09

Found a bug in cider regarding pprint & load-file. I'm wondering if it's possible to view tools.nrepl's middleware ordering somehow? Quite important for diagnosing a full fix.

eggsyntax14:07:45

Does anyone know whether there are any affordances in CIDER for calling an emacs function (ie emacs lisp)? I'm playing with some ideas about automatically converting material from repl sessions to unit tests, and it would be awfully handy to be able to call some existing emacs functions. I have no reason to expect that there would be such affordances, but thought I'd ask ๐Ÿ™‚. Mostly I just want to access CIDER repl history from the current repl session.

richiardiandrea14:07:50

@eggsyntax well you can call any required cider function from your own functions

richiardiandrea14:07:52

what do you mean by affordances? maybe I don't understand this word in this context (not an English native speaker ๐Ÿ˜‰ )

eggsyntax14:07:50

Oh, sorry, I skipped a critical part โ€” Iโ€™m hoping I can somehow call emacs functions from Clojure. By affordances, I just meant some tools built into CIDER that make it possible/easier to do that. Basically Iโ€™m hoping for a foreign function interface to emacs lisp ๐Ÿ˜‰

dpsutton14:07:32

can you give an example?

richiardiandrea14:07:01

oh no problem ๐Ÿ˜„ I have never tried it but there is this https://github.com/clojure-emacs/clomacs

dpsutton14:07:52

something like

(defn clojure-function [] (let [thing (eval-emacs-lisp (goto (point-min))...
etc?

richiardiandrea14:07:59

but of course you have resort to passing chars around if you want to send stuff from/to the two worlds

eggsyntax14:07:17

@richiardiandrea hmm, Iโ€™m not quite sure how I would do it even passing chars around.

eggsyntax14:07:07

I mean, I could, say, write a watcher fn in emacs lisp that runs in the background and watches for input on some channel, but Iโ€™m hoping thereโ€™ll be at least a slightly better way ๐Ÿ™‚

dpsutton14:07:22

ha. that's a doozy

dpsutton14:07:49

emacs evals clojure in nrepl which evals emacs-lisp in emacs whic sends back to finish clojure which sends back to emacs

richiardiandrea14:07:03

yeah โ˜๏ธ

richiardiandrea14:07:10

that is passing chars around ๐Ÿ˜„

eggsyntax14:07:36

Thatโ€™s why I hoped CIDER might have something built in to make that process a bit less painful ๐Ÿ˜‰ . It didnโ€™t seem terribly likely, but worth asking ๐Ÿ™‚

eggsyntax14:07:06

The simplest thing might be to figure out how to get CIDER to constantly auto-save repl history, and then just slurp the file ๐Ÿ˜œ

eggsyntax14:07:16

Or else look how *1 (most recent output) is implemented, and build something similar for input instead of output.

eggsyntax14:07:36

(or just build the whole thing in emacs lisp, but that gets painful too, because ideally it should look back through history but filter out everything except valid clj expressions)

dpsutton15:07:24

the tough thing is that this would have to interrupt the eval order of the clojure code. It seems like it would have to do that

dpsutton15:07:29

unless you wanted to get a little janky

dpsutton15:07:42

something like (emacs-read which would prompt emacs for input

dpsutton15:07:48

ahh, there is a notion of needs input

dpsutton15:07:04

and cider could be aware that it's a programmatic input rather than user typing input

eggsyntax15:07:08

Why would it have to interrupt the eval order of clj code? I'm not immediately seeing that.

eggsyntax15:07:10

emacs-read is a builtin emacs fn? Or a clj fn in CIDER? Not finding a clear answer with a google search.

dpsutton15:07:18

because if it doesn't then clojure would try to run the emacs lisp forms, right?

dpsutton15:07:47

oh no, @eggsyntax that's not a real function. i was kinda thinking outloud

dpsutton15:07:52

about what a solution could look like

eggsyntax15:07:47

I was imagining you might send the emacs lisp forms as data, & receive data back.

dpsutton15:07:09

sure. but you probably don't want to write them as strings. so emacs-read would be a macro that would string it's whole argument and send it back to emacs

dpsutton15:07:38

with the same or similar mechanism to just read from std-input but modified to return the executed code rather than the users input

dpsutton15:07:12

(let [x (read-from-emacs (+ 1 1)) ... would let you write data for (+ 1 1), the macro turns it into a string and sends it back to emacs

eggsyntax15:07:06

Ah, yeah, good thought. Seems like you could overcome clj trying to evaluate the forms by just quoting. '(+ 1 1)

dpsutton15:07:16

yeah for sure

eggsyntax15:07:03

I should probably say what I'm imagining, as long as you're being kind enough to help brainstorm ๐Ÿ™‚ I'm just thinking of something that'll start with the last expression you entered in the repl, say (f a 1). It'll recognize that it hasn't seen a definition for f or a, and scan back through the previous expressions, looking for the most recent (def or (defn followed by f or a. Those may themselves contain undefined terms, so it recurses into searching for definitions for those. It'd definitely be easier to do it robustly in clj/s (which eg recognizes built-in keywords & knows it doesn't need to find defs for those), but I suspect you could probably hack it together in emacs lisp if necessary. Then it just strings those expressions together in the order they were seen, so you've got a self-contained sequence of expressions ending in (f a 1). Those can then get wrapped up into a deftest pretty easily, one which expects whatever the most recent return value was. The idea is that it would just save you the hassle of putting those together into a unit test manually.

eggsyntax15:07:44

Nothing huge, but I would certainly create more unit tests if I could just do that -- I tend to test stuff in the repl as I'm writing it, and try to test in it smart ways (corner cases etc), but I often don't bother to put those together into an automated test.

dpsutton15:07:18

yeah i've long wished i could take my repl exploration and make a unit test stating (is (= (last input) (last output))

dpsutton15:07:23

just with a single keystroke

dpsutton15:07:25

i'm with you

dpsutton15:07:46

finally get to a point on the repl that it's working and you've got the syntax that you like

eggsyntax15:07:43

Exactly. & then if you do try to create a unit test, you sometimes have to dig back through the repl history yourself to find that one variable you defined half an hour ago...

eggsyntax15:07:27

It seems possible, anyway. If it's not possible without a huge ugly hack, I may or may not go there ๐Ÿ˜œ

dpsutton15:07:53

well this sounds different than executing emacs lisp in clojure code

dpsutton15:07:59

since cider knows the input and output

dpsutton15:07:45

so there needs to be a get-create-test-buffer function and then just insert the testing form of (is (= repl-input repl-output

eggsyntax15:07:09

Yeah, but since cider itself is emacs lisp, that's why I was expecting I'd have to make a couple of emacs lisp calls.

dpsutton15:07:26

but you can make all of those calls from emacs lisp as far as i'm aware

eggsyntax15:07:38

Oh, so you mean a lisp function get-create-test-buffer. The only issue with doing it entirely in lisp is that it's harder to fully parse what's a valid definition, what needs to still be defined, what's a keyword or core fn, etc.

dpsutton15:07:57

yeah for sure

eggsyntax15:07:01

But it's doable ๐Ÿ™‚

dpsutton15:07:03

that would be terribly complicated

eggsyntax15:07:38

Yeah, so some way to evaluate some expressions in both lisp & clj would be ideal.

jfntn18:07:13

When navigating to source in a project that uses boot I always end up in the boot cache folder instead of the src folder, anyone knows why?

sound2gd23:07:33

how to use cider-connect to connect to a figwheel based cljs repl? I have connected to that and type (cljs) to enter cljs repl.but when evaluating code using cider-eval-defun-at-the-point it told me cider need a clojurescript repl, help