Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Limit infinite recursion in macros

Open maxponte opened this issue 9 years ago • 8 comments

What did you do?

Accidentally wrote a macro with an infinite loop

Put the exact keys you pressed.

qqiexampletextEscq@q

What did you expect to happen?

Expected the macro definition to fail and @q to remain undefined

What happened instead?

Macro got into an infinite loop and required a vscode restart

Technical details:

  • VSCode Version: 1.9.1
  • VsCodeVim Version: 0.5.2
  • OS: 10.12.3

maxponte avatar Feb 16 '17 09:02 maxponte

This doesn't seem to be how vim behaves.

It is admittedly kind of bad behavior, but at least for me on neovim, it seems to hang neovim for a long amount of time.

Also, at least for me, it doesn't seem to crash vscode. You can get things working fine again if you switch to another file and then switch back.

Chillee avatar May 02 '17 21:05 Chillee

I think we could limit macro recursion to a certain depth. That wouldn't hurt anyone. Who writes recursive macros anyways?

johnfn avatar May 03 '17 02:05 johnfn

Who does indeed? I'm sure somebody will complain though...

Do you think we bother making it a setting? And what's a good value? 10k?

Luckily, we've basically doing tail recursive optimization already :^)

Chillee avatar May 03 '17 02:05 Chillee

@Chillee can you just use your first commit and limit it to 10k

xconverge avatar Oct 05 '17 03:10 xconverge

@xconverge I'll fix it up this weekend.

Chillee avatar Oct 06 '17 01:10 Chillee

Ran into this also. Or a shortcut for interrupting ongoing commands. kapture 2018-11-22 at 9 12 27

st-schneider avatar Nov 22 '18 08:11 st-schneider

I write recursive macros! insert favourite movie-villain-esque evil laughter

I like to be able to go:

  1. Search for specific string
  2. Operate on string and it's context in a way that means it's no-longer found in the search
  3. Goto #1

That way I don't have to deal with the accursed demon that is mathematics, or holding down the @ key until my PC sprays a rapid-fire series of dings at me or any of that nonsense. Just "Computer, do this for me till you can't anymore, then stop".

But I do occasionally flub the exit condition, and would love to be able to explicitly STOP a macro (ie: #3273) regardless of it's depth of recursion because I KNOW from how I'm seeing it behave that I've done wrong.

I've seen somewhere that switching to a new tab will do it, and that seems to work okay in the short amount of time I've been testing it, but it would be really nice if Ctrl+C worked the same way as it does in VIM, because that's my exact reflexive response and it took me a significant amount of googling to find the tab-switch trick.

That said, if recursion limit is definitely going to be a thing, please make it configurable or opt-out or something! Don't take my lazy away please!

roberestarkk avatar Feb 17 '21 05:02 roberestarkk

In particular I've noticed that if the macro contains a 'search' in Vim that fails to find a result, the macro will terminate, while in VSCode it seems to not. Not sure if that's already an issue somewhere though, but that could help with unexpected recursion quite a bit.

roberestarkk avatar Feb 17 '21 05:02 roberestarkk