Fork me on GitHub
#conjure
<
2023-02-02
>
Sigve12:02:25

Does anyone have a clever way to re-evaluate the lastly evealuated form, even if the cursor has moved? Use-case: I evaluate a function and see that its results is not what i want. I move the cursor to make and change, and want to re-evaluate the same function again. I know it is possible to set marks, but this requires planning ahead 🙃

grav13:02:06

I usually extract stuff I want to fiddle with like that into a comment-block. Then I can move freely around in the comment block and use "Send top-form to repl". Cursive is smart enough to discard the outer (comment expression, so

(comment
  (* 4 (+ 2 2)))
evaluates to 16 no matter where inside the comment block my cursor is located.

💡 2
grav13:02:17

I think the default keyshortcut is alt+shift+p

grav13:02:03

Another hack I saw from the Conjure author is this:

(do
  (defn my-fn [...])

  (my-fn 'some-value))
Evaluating the whole block re-evaluates the function, and tests is in the same breath

Sigve13:02:11

Yeah, if you know ahead what you want to work with, there are lots of alternatives. Conjure also lets you set a mark and evaluate the form at that line, which is great. But often i only know afterwards that i want to evaluate the form again. Then i have to spend time to navigate back to it. This is not a huge issue, but just a micro optimisation i am looking for 🙂

👍 6
grav13:02:34

One thing that is in Cursive, which might also exist in Conjure is the "re-run last test-action". So I have some deftest that I run once, and then I can go to whatever part of the implementation and change it, and just re-run last test action.

grav13:02:02

Sorry for referring to Cursive all the time, but I'm switching back and forth between it and Conjure all the time 😄

Sigve13:02:14

No worries. It is interesting to see how different editors work. Conjure does not have anything like this as i know of. My impression is that most people using conjure run tests outside the editor via kaocha and the like (although i like running them via conjure)

dharrigan14:02:00

Conjure does have a way to re-eval a mark

dharrigan14:02:09

so if you mark a form you can then re-eval it at any time

dharrigan14:02:15

no matter where your cursor is

dharrigan14:02:04

Perhaps useful?

dharrigan14:02:45

I also run all my tests (when I'm in a namespace) within conjure

grav14:02:15

@U11EL3P9U Are you familar with a functionality similar to Cursive's "Re-run last test-action"?

dharrigan14:02:25

Sorry no, I don't use Cursive.

dharrigan14:02:36

you can pry my (neo)vim from my dead hands 🙂

grav14:02:45

That's not the point 🙂

grav14:02:16

I have a workflow in Cursive, which I wonder if also exists in Conjure

grav14:02:48

The workflow is to re-evaluate eg "all tests in a namespace" or a specific test, when I'm somewhere else in the code base

dharrigan14:02:25

Would it work if you put a mark on the test form then go to another namespace, does eval at last mark not work?

dharrigan14:02:55

Apart from that, I guess Oli would be open to suggestions to improve conjure.

👍 2
grav14:02:03

Yeah, it might do 👍 But in some cases I might want to evaluate multiple tests, eg all tests in a ns

dharrigan14:02:19

agreed, that is missing indeed. See if there is an issue for that

dharrigan14:02:33

I wonder 'tho

dharrigan14:02:38

given that a namespace is just a form

dharrigan14:02:45

naw, that' won't work

dharrigan14:02:23

suggest in github to add run all tests in a different namespace (not simply the alternative one, which is leader tN)

👍 2
Carl03:02:34

Just to throw some ideas out there that I haven’t actually tried myself, you could possibly make a command/key binding that calls EvalForm and always puts a mark (eg mark “r”) in the current cursor position and then create a second command/key binding that calls “EvalMark r”. Perhaps there’s an auto command you could use to set the mark on eval instead

👍 4
Carl03:02:17

You’d probably want to use a global mark e.g “R” if you’re likely to be in a different file when you make a change.

Sigve07:02:02

Great idea Carl, exactly what i was looking for. I just wrapped ConjureEval to also set a global mark, but i noticed now that Conjure has an autocommand trigger by the same name

👍 2
Sigve08:02:01

Any tips on how to automate calling a specific mark? It seems that ConjureEvalMarkedForm and its keybinding prompts for a mark, rather than take it as an argument.

Carl09:02:06

Ohhh yeah I guess that makes sense. Maybe nvim_feedkeys() could be used to send the key for the register.

Sigve10:02:42

It seems to just pass the keys to the editor itself, so for example nvim_feedkeys('x', ...) deletes a character rather than passing it to the prompt :thinking_face:

Carl11:02:15

Hmm what if you feed the keys “,emr” assuming your eval mark keybinding is “,em” and the register you’re using is “r”

Sigve12:02:38

Unfortunately this seems to trigger the form keybinding and do the normal-mode action for the last letter, not pass it to the prompt

Carl23:02:49

Oh 🥲 what if you try feed keys “,em” and then use vim.schedule with a callback that does feed keys “r”? Perhaps feeding the whole sequence all at once prevents conjure taking “r” as an input. if I get time today I’ll take a look at the conjure code to see if that inspires any new ideas.

Sigve08:02:40

I cant get that working either, but i think i am doing something wrong with vim.schedule as i am not really familiar with it

Carl10:02:38

Seems like it's easier to just look at conjure's code and do this: (local eval (require "conjure.eval")) (vim.schedule (fn [] (eval.marked-form "a"))) (vim.schedule (fn [] (eval.marked-form "A")))

Sigve12:02:34

ah, thanks - that works great!

Sigve12:02:15

ended up looking like this in lua

function ConjureEvalLastFn()
    eval=require("conjure.eval")
    marked_form=eval['marked-form']
    vim.schedule(function() marked_form("R") end)
end

👏 2
🚀 2
Carl12:02:35

I’m glad it works 😄 I think I’ll try add this to my config too when I have time.