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

Possible fix for issue #4642: use ModeChanged events instead of InsertLeave emulation #4738

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zlogic
Copy link

@zlogic zlogic commented Mar 10, 2024

ALE is my favourite way of using LSPs and linters, the only thing that might need improvement is #4642. Any time I press Esc and start typing or moving around the document (muscle memory :) ), Vim beeps and Tried switching to NeoVim and Helix, only to return back to Vim+ALE :)

I've done some research/testing during this weekend, and it looks like Vim 9 has some issues (a timeout reset?) if a timer is started from an InsertEnterEvent.
InsertEnter is called before switching into Insert mode, so mode() might potentially return "normal" mode if the timer is triggered too early.
I was able improve the situation by specifying a shorter timeoutlen, but that doesn't seem like an ideal solution. When Esc or\<C-[\> is pressed, Vim waits some time to see if it's an escape code for something else (like an Arrow Up key).

ModeChanged looks like a more reliable way to detect an "exit insert mode" event and is a lot simpler (doesn't need a timer). Also, it can detect some other transitions like \<C-o\> in insert mode.
The ModeChanged event is available in:

so the current tests are covering both InsertMode emulation and the new ModeChanged events.

With this PoC, the situation has improved significantly on my machine - no more beeping, and exiting Insert mode is instantaneous.

zlogic added 3 commits March 9, 2024 20:32
If the ModeChanged event is available, use it instead of InsertLeave
emulation.

ModeChanged works in any case, even when using <C-c> or other shortcuts
to exit the insert mode.

Added a delay when exiting edit mode to avoid staying in Insert mode
while the linter is running.
Seems like it's more of an internal Vim quirk.
@zlogic
Copy link
Author

zlogic commented Mar 10, 2024

Or it might make sense to just make the InsertLeave emulation optional (configurable), perhaps some developers might use Esc to run the linter and other event handlers, but use \<C-c\> to temporarily exit Insert mode without any possible side-effects/callbacks.

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic, and I love this. 😄 Let's run this this and see how this behaves over time.

I'll probably follow up with a documentation update.

Cheers! 🍻

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

Successfully merging this pull request may close these issues.

2 participants