Eval and replaced evaluated form with result
poga opened this issue · comments
For example, I have a form
(+ 1 2)
After evaluation, I want it to become:
3
How do I achieve it with slimv?
I have a working prototype at https://github.com/poga/slimv. It exposes two new function SlimvEvalDefunAndReplace
and SlimvEvalDefunAndReplace
.
It kinda worked. However there's some limit to it (mostly because I'm completely new to vimscript):
- It has a delay between evaluation complete and replacing the form
- If I do anything while waiting for the replacement, it usually breaks.
- It pollutes register
r
. I'm not using the register anyway but it's definitely not ideal.
My question is: Is there a better way to do this? I'm willing to contribute if you're fine with this feature. Any guidance is appreciated 😄
I've been thinking about it for a while, but I couldn't come up with a much better solution. You say there's a delay between the evaluation complete and the replace. Does it mean that the result is printed in the status line much before the text is replaced? That's strange because as I see you execute the paste right after the result is echoed.
Could you please tell me more about the rationale behind this eval_and_replace function? To be honest I don't really like the idea of combining the 'yank' and 'paste' together (or I just simply don't see the use case here). I can understand that it would be nice to have a feature that yanks the evaluation result into the register of choice, and the use may do whatever he/she wants to do with it later or (e.g. also pasting it over the original form). So I could more imagine and eval_and_yank feature instead of eval_and_replace. What do you think?
Oh, and sorry for the late answer, I was quite busy this week.
Don't worry. Thanks for the great software! I can't imagine working with lisp in vim without this amazing plugin. :D
- It's a delay between calling
SlimvEvalDefunAndReplace
and the text is actually being replaced.
After some digging, I found that the delay is mostly due to slimv
polls results from swank. The delay is gone after adding let g:slimv_updatetime = 10
to my vimrc
.
- My use-case is kinda weird: I'm using slimv as an interactive notebook. I have the following function defined:
(defun · (title)
`(✓ ,title)
)
(defun ✓ (title)
`(· ,title)
)
So, if I type
(· "buy milk")
and call SlimvEvalDefunAndReplace
, It will becomes
(✓ "buy milk")
Therefore, I can quickly track todos in my lisp session and keeps a list of current state in the source code.
eval_and_yank
is definitely great! I agree it's much better to keep yank
and paste
apart.