emacs

Consider also joining #cider, #lsp and #inf-clojure, where most of the tool-specific discussions are happening.
furiel 2021-06-29T13:41:37.099400Z

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.

dpsutton 2021-06-29T13:43:33.101Z

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

2021-06-30T18:01:33.108700Z

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

2021-06-30T18:19:26.109100Z

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}

2021-06-30T18:21:47.109300Z

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. ¯\(ツ)

2021-06-30T18:30:20.109500Z

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! :)

pithyless 2021-06-30T18:53:37.109700Z

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! ;)

2021-06-30T19:01:46.109900Z

LOL. /me crosses self against modal editing. xD

2021-06-30T19:02:13.110100Z

The result's the same in either case. :)

🤘 1
2021-06-30T19:05:44.110400Z

The key sequence isn't nearly as bad as it looks if you use your 6th finger.

pithyless 2021-06-30T19:09:00.110600Z

@timvisher are you referring to a USB foot pedal? :P

2021-06-30T19:12:47.110800Z

No although I've considered it! Just my palms. http://ergoemacs.org/emacs/emacs_pinky.html

2021-06-30T19:14:01.111Z

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

2021-06-30T19:15:54.111200Z

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.

2021-06-30T19:16:53.111400Z

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.

2021-06-30T19:17:27.111600Z

(Similar to vim in terms of raw bindings vs. edit function composition which, IMO, is vim's real super power)

2021-07-01T01:45:24.114Z

@pithyless exactly! Wouldn't have made the switch (from NeoVim) without EVIL. EVIL rocks.

furiel 2021-06-29T13:45:03.101100Z

That sounds neat. Can you share the snippet?

dpsutton 2021-06-29T14:20:15.101300Z

ha yeah. sorry. was making coffee and feeding the dog

dpsutton 2021-06-29T14:20:55.101700Z

dpsutton 2021-06-29T14:22:54.102100Z

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

dpsutton 2021-06-29T14:23:01.102300Z

i do it all the time in inf-clojure

furiel 2021-06-29T14:24:35.102500Z

Thanks for sharing! Trying out now.

dpsutton 2021-06-29T15:59:16.103700Z

oh that's clever

furiel 2021-06-29T16:02:07.103900Z

great idea thanks @pithyless

pithyless 2021-06-29T16:04:50.104100Z

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