ale
ale copied to clipboard
Possible fix for issue #4642: use ModeChanged events instead of InsertLeave emulation
ALE is my favourite way of using LSPs and linters, the only thing that might need improvement is https://github.com/dense-analysis/ale/issues/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.
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.
This pull request has been automatically marked as stale because it has not been updated recently. Make sure to write tests and document your changes. See :help ale-dev
for information on writing tests.
If your pull request is good to merge, bother w0rp or another maintainer again, and get them to merge it.