Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval and replaced evaluated form with result #110

Open
poga opened this issue Mar 7, 2021 · 2 comments
Open

Eval and replaced evaluated form with result #110

poga opened this issue Mar 7, 2021 · 2 comments

Comments

@poga
Copy link

poga commented Mar 7, 2021

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

  1. It has a delay between evaluation complete and replacing the form
  2. If I do anything while waiting for the replacement, it usually breaks.
  3. 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 😄

@kovisoft
Copy link
Owner

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.

@poga
Copy link
Author

poga commented Mar 14, 2021

Don't worry. Thanks for the great software! I can't imagine working with lisp in vim without this amazing plugin. :D

  1. 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.

  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants