Hello, does someone know an efficient soultion for this usecase? I often need to develop a function and try to execute it with a given set of parameters in an interactive manner. I approach this like: I edit the function, then ctrl-c-ctrl-c to reevaluate the function. A few lines below I have a function call prepared with proper parameters (generally in a comment block). So I go down to the end of the prepared function call, and evaluate it there. Do you have a nice trick to do this in a faster way? My approach takes a lot of moving around into the function definition, then to the end of the example call. I experimented with a `do` statement, that defines a function and calls it at the same time, because then ctrl-c+ctrl+c would do both, but do
messes up the indentation, and I feel there should be a better way to do it.
I wrote a simple “insert register in repl” function that I use all the time. Just save some text to a register, eval the function, then send the form to the repl
I like the pattern of having the function I'm working on in a file and the exercising code be in my repl.
1. Edit the code
2. Whack C-c C-c C-c C-z M-p RET C-z
Or
1. Edit the code
2. Eval the form (`C-c C-c`)
3. Switch to the repl (`C-c C-z`)
4. Bring up the previous form and execute it (`M-p RET`)
5. Return to the function I'm working on (`C-c C-z`)
If you're not using the current keyboard macro for anything else that can be collapsed down to
1. Edit the code
2. Whack <f4>
:)
Going the clojure.test
route though is intriguing.
I think it would be ideal to combine this with the with-test
feature of clojure.test
so that you can freely edit both the invocation and the implementation at the same time with a single C-c C-c
or C-M-x
. Unfortunately I can't seem to get CIDER to recognize with-test
as something that defines after a quick try.
Can anyone make CIDER recognize this as a test to run?
(require '[clojure.test :refer [with-test is]])
(with-test
(defn +'
"Adds two numbers"
[a b]
(+ a b))
(is (= 3 (+' 1 2))))
Note clojure.test
does this just fine:
user> (require '[clojure.test :refer [with-test is]])
(with-test
(defn +'
"Adds two numbers"
[a b]
(+ a b))
(is (= 3 (+' 1 2))))
nil#'user/+'
user> (clojure.test/run-tests 'user)
Testing user
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
{:test 1, :pass 1, :fail 0, :error 0, :type :summary}
My initial attempt was to customize the cider-test-defining-forms
to add with-test
but doing that doesn't change the behavior I'm seeing at all. ¯\(ツ)/¯
Oooooo this is super nice. Yeah after running the cider-test-run-test
function through edebug the trick is adding defn
to the cider-test-defining-forms
. With that I can whack C-c C-c C-C C-t C-t
and rerun the exercising invocation. And again if my keyboard macro slot wasn't busy with something else I could bind that to <f4>
. That's actually really nice. Great idea @pithyless! :)
OT: I'm an emacs evil-mode user and C-c C-c C-C C-t C-t
looks absolutely terrifying (compared to say , t a
), but whatever works! ;)
LOL. /me crosses self against modal editing. xD
The result's the same in either case. :)
The key sequence isn't nearly as bad as it looks if you use your 6th finger.
@timvisher are you referring to a USB foot pedal? :P
No although I've considered it! Just my palms. http://ergoemacs.org/emacs/emacs_pinky.html
So basically to type that sequence I just rest my left palm down slightly and then rapidly type c c c t t
. There's probably a better sequence but I'm not vimgolfing here. :)
Oh yeah for instance another prefix for test map is indeed ,
so it could be C-c C-c C-c , t
but then I need to lift my palm during the sequence so that's actually worse.
This is completely irrelevant to you as an evil
user but anything that makes me break the ctrl
key sequence is a big no no. It makes emacs actually feel clunky to use. It's remarkable how similar to vim it is once you're pressing ctrl
with your palm and meta
with your thumb.
(Similar to vim in terms of raw bindings vs. edit function composition which, IMO, is vim's real super power)
@pithyless exactly! Wouldn't have made the switch (from NeoVim) without EVIL. EVIL rocks.
That sounds neat. Can you share the snippet?
ha yeah. sorry. was making coffee and feeding the dog
it added it outside of the thread. But use C-x C-r C-s <register-key>
(x Resgister Save), and then you can send to the repl with the handy repl sending map at C-c C-j x
and then the register key
i do it all the time in inf-clojure
Thanks for sharing! Trying out now.
oh that's clever
great idea thanks @pithyless
Happy to help, it's something I've previously struggled with as well. Although I may just have to take @dpsutton's compliment and frame it somewhere. ;)