This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-16
Channels
- # announcements (1)
- # aws (6)
- # babashka (17)
- # beginners (30)
- # calva (12)
- # cider (25)
- # circleci (2)
- # clojure (42)
- # clojure-australia (8)
- # clojure-czech (1)
- # clojure-europe (30)
- # clojure-france (52)
- # clojure-italy (2)
- # clojure-nl (16)
- # clojure-serbia (3)
- # clojure-uk (10)
- # clojurescript (40)
- # core-async (5)
- # cursive (24)
- # datalog (7)
- # datomic (8)
- # emacs (4)
- # events (1)
- # figwheel-main (3)
- # fulcro (2)
- # helix (5)
- # heroku (1)
- # kaocha (6)
- # leiningen (3)
- # malli (11)
- # music (5)
- # off-topic (20)
- # practicalli (1)
- # re-frame (4)
- # react (8)
- # reitit (14)
- # rewrite-clj (5)
- # rum (2)
- # schema (2)
- # shadow-cljs (23)
- # vrac (28)
- # wasm (4)
- # xtdb (12)
- # yada (5)
I don’t think we need more help with this particular issue, but there are always other issues one can tackle. 😄
I really need to do that. Let me see what I can find.
what is the cider command that lets me evaluate a function under the point in the minibuffer, supplying arguments?
or an equivalent.
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.aha, found it: cider-read-and-eval-defun-at-point
I remember now. I also remember I was getting errors and that’s why I had stopped using it and thus forgotten it.
I’ll put the error in a thread…
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
cider-eval-defun-at-point
works fine, however.
to define the function in the buffer, that is.
This is a cljs file in a Reagent project, by the way, running in a browser.
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
@U0X9N9ZK5 what about using comment
forms?
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.
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.(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)
That is really interesting… I’ll give those approaches a try.
do you use something to toss the wrap-around on and remove it quickly?
I know there are things in Emacs that do that, but I do it semi-manually with paredit.
I use lispy(ville) but paredit or any other structural-editing package should work fine once you get it into muscle memory 🙂
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
@UCPS050BV thanks!
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
I then delete it.
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.