Fork me on GitHub
#cider
<
2021-04-16
>
bozhidar05:04:23

I don’t think we need more help with this particular issue, but there are always other issues one can tackle. 😄

jmckitrick14:04:09

I really need to do that. Let me see what I can find.

macrobartfast19:04:03

what is the cider command that lets me evaluate a function under the point in the minibuffer, supplying arguments?

macrobartfast19:04:14

or an equivalent.

macrobartfast19:04:42

I’m constantly typing out functions in my buffer with arguments so I can evaluate them then deleting them. So, if I made

(defn foobar [x]
  (* 2 x))
I would then write
(foobar 8)
below it and run a cider eval on it, then delete it. Alternately I suppose I could copy paste it into the repl, but that would take as much time.

macrobartfast20:04:59

aha, found it: cider-read-and-eval-defun-at-point

macrobartfast20:04:28

I remember now. I also remember I was getting errors and that’s why I had stopped using it and thus forgotten it.

macrobartfast20:04:49

I’ll put the error in a thread…

macrobartfast20:04:59

when running cider-read-and-eval-defun-at-point on

(defn foobar [x]
  (* 2 x))
I get
Show: Project-Only All
  Hide: Clojure Java REPL Tooling Duplicates  (24 frames hidden)

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling *cider-repl past/someproject:localhost:3333(clj)* at (1:1)
   #:clojure.error{:phase :compile-syntax-check,
                   :line 1,
                   :column 1,
                   :source
                   "*cider-repl past/someproject:localhost:3333(clj)*"}
1. Caused by java.lang.RuntimeException
   Unable to resolve symbol: foobar in this context

                 Util.java:  221  clojure.lang.Util/runtimeException
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
                  AFn.java:   22  clojure.lang.AFn/run
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  748  java.lang.Thread/run

macrobartfast20:04:36

cider-eval-defun-at-point works fine, however.

macrobartfast20:04:51

to define the function in the buffer, that is.

macrobartfast20:04:31

This is a cljs file in a Reagent project, by the way, running in a browser.

macrobartfast20:04:03

I am also open to better approaches… basically, I write a function that takes a few arguments that would be normally supplied by a calling function; I want to try it out with some fake arguments without having to write it out in my file with those arguments. Currently, I write it in the buffer with the mock arguments so I can call cider-eval-defun-at-point or cider-eval-last-sexp

yuhan03:04:54

@U0X9N9ZK5 what about using comment forms?

macrobartfast03:04:53

Well, I have in the past… but that just clutters my code overall and makes it less readable… and I have to type it all out. When cider-read-and-eval-defun-at-point worked, it was literally just a matter of the binding that triggered the function, tap in a couple arguments when it appeared in the minibuffer, and enter and voila.

yuhan03:04:13

Right, that's understandable - I've never used that command before but it seems useful. What I sometimes do is take advantage of the fact that (#'foo x) calls the function in the var - so I'll do a quick wrap-round and forward-sexp

((defn foobar [x]
   (* 2 x)) 10)
try out a couple of arguments without having to go back and forth with the minibuffer + history, then raise the defun when I'm done to get rid of the args.

yuhan03:04:35

(this is particularly useful when you're debugging some function definition on a fixed set of arguments - cider-eval-defun from anywhere in the form re-defs the function and calls it in one go)

macrobartfast05:04:33

That is really interesting… I’ll give those approaches a try.

macrobartfast05:04:44

do you use something to toss the wrap-around on and remove it quickly?

macrobartfast05:04:06

I know there are things in Emacs that do that, but I do it semi-manually with paredit.

yuhan05:04:56

I use lispy(ville) but paredit or any other structural-editing package should work fine once you get it into muscle memory 🙂

yuhan05:04:22

for me it's ESC (evil normal state), { (start of defun) M-9 (wrap in parens) M-a (goto end of form and enter evil insert state) then at the end, navigate to the right spot and M-r to raise

macrobartfast20:04:03

I am also open to better approaches… basically, I write a function that takes a few arguments that would be normally supplied by a calling function; I want to try it out with some fake arguments without having to write it out in my file with those arguments. Currently, I write it in the buffer with the mock arguments so I can call cider-eval-defun-at-point or cider-eval-last-sexp

macrobartfast20:04:37

I then delete it.

macrobartfast20:04:19

I do this with most functions I define, so dozens of times a day. Probably my doing this is the result of a bad approach… not sure.