martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.19k stars 259 forks source link

Cyclic remapping causes 100 percent CPU load #1110

Closed MaxGyver83 closed 11 months ago

MaxGyver83 commented 11 months ago

I have tried to swap C-j and C-k (because of my custom keyboard layout). I tried:

vis:map(vis.modes.NORMAL, '<C-k>', '<C-j>')
vis:map(vis.modes.NORMAL, '<C-j>', '<C-k>')

When I then started vis again and typed <C-k>, it didn't react anymore and the CPU load went to 100%. Maybe caused by an infinite loop?

After looking through the issues, I found #750 and now I know that the correct way to swap the key bindings is:

vis:command('map! normal <C-j> <vis-selection-new-lines-above>')
vis:command('map! normal <C-k> <vis-selection-new-lines-below>')

But nevertheless, vis should print an error and stay usable in such a case.

rnpnr commented 11 months ago

Mappings are listed as being evaluated recursively in multiple places:

https://martanne.github.io/vis/man/vis.1.html#Runtime_key_mappings https://github.com/martanne/vis/wiki/FAQ#how-can-i-configure-custom-key-bindings

This is simple and easy to follow from a programming perspective. On the other hand detecting that a recursive mapping was made will make the code complex and ugly. I would be against any such change, especially since the manual specifically mentions that such mappings will cause an infinite loop and that you should use the special keys instead.

MaxGyver83 commented 11 months ago

I see. Looks like I didn't pay attention to the word "recursively" in the man page and hadn't read the FAQ.

Obviously, this information is available. On the other hand, in other minimalistic/suckless software, even hard to reach crashes, memory leaks (and probably infinite loops) get fixed. But maybe this is not true for fixes that would add too many lines of code.