kovisoft / slimv

Official mirror of Slimv versions released on vim.org
454 stars 60 forks source link

Eval and replaced evaluated form with result #110

Open poga opened 3 years ago

poga commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.