Fork me on GitHub

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.


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.


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


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


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 ๐Ÿ˜‰


can you give an example?


oh no problem ๐Ÿ˜„ I have never tried it but there is this


something like

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


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


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


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 ๐Ÿ™‚


ha. that's a doozy


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


yeah โ˜๏ธ


that is passing chars around ๐Ÿ˜„


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 ๐Ÿ™‚


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


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


(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)


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


unless you wanted to get a little janky


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


ahh, there is a notion of needs input


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


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


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


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


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


about what a solution could look like


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


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


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


(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


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


yeah for sure


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.


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.


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


just with a single keystroke


i'm with you


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


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


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


well this sounds different than executing emacs lisp in clojure code


since cider knows the input and output


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


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.


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


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.


yeah for sure


But it's doable ๐Ÿ™‚


that would be terribly complicated


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


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?


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