alexherbo2 / auto-pairs.kak

Auto-pairing of characters for Kakoune
https://kakoune.org
77 stars 18 forks source link

Error: cannot unmap key that is currently executing #60

Closed greenfork closed 1 year ago

greenfork commented 1 year ago

On the latest kakoune master this key sequence from the new line (<enter>s throws these errors

error running hook WinSetOption(inserted_pairs=0)/auto-pairs: 3:7: 'unmap': cannot unmap key that is currently executing
error running hook InsertChar(s)/auto-pairs: 2:7: 'unmap': cannot unmap key that is currently executing

I checked it with clear kak -n only sourcing this plugin.

Any workaround that comes to mind?

greenfork commented 1 year ago

Looks like this commit https://github.com/mawww/kakoune/commit/e49c0fb04095a2a1c546fd033ce2a1a6df3eb8d0 is responsible for this error. The version just before this commit works fine.

krobelus commented 1 year ago

typing the opening ( adds this mapping

map -docstring 'insert a new indented line in pair' window insert <ret> '<a-;>: insert-new-line-in-pair<ret>'

which unmaps itself. (insert-new-line-in-pair triggers a hook that unmaps <ret>). We could allow the unmap to proceed. I don't see anything obviously wrong with the script.

greenfork commented 1 year ago

I suppose it will be fixed in the kakoune then. Just in case, still the same error on the latest master.

krobelus commented 1 year ago

if it's easy to rewrite the script to not rely on this behavior, we might want to keep the error.

This patch fixes your reproducer although there is a remaining issue when typing ())

diff --git a/rc/auto-pairs.kak b/rc/auto-pairs.kak
index 8583a56..fa932ac 100644
--- a/rc/auto-pairs.kak
+++ b/rc/auto-pairs.kak
@@ -103,20 +103,16 @@ define-command -override -hidden handle-inserted-opening-pair -params 2 %{
     map -docstring 'insert a new indented line in pair' window insert <ret> '<a-;>: insert-new-line-in-pair<ret>'
     map -docstring 'prompt a count for new indented lines in pair' window insert <c-ret> '<a-;>: prompt-insert-new-line-in-pair<ret>'

+    hook -group auto-pairs -once window InsertChar %exp{\Q%arg{2}} %exp{
+      unmap window insert %arg{2} # TODO quote
+    }
+
     # Enter is only available on next key.
     hook -group auto-pairs -once window InsertChar '.*' %{
       unmap window insert <ret>
       unmap window insert <c-ret>
     }

-    # Clean insert mappings and remove hooks
-    hook -group auto-pairs -once window WinSetOption 'inserted_pairs=0' "
-      unmap window insert %%🐈%arg{2}🐈
-      unmap window insert <ret>
-      unmap window insert <c-ret>
-      remove-hooks window auto-pairs
-    "
-
     # Clean state when moving or leaving insert mode
     hook -group auto-pairs -once window InsertMove '.*' %{
       reset-inserted-pairs-count
krobelus commented 1 year ago

this is fixed latest Kakoune master

greenfork commented 1 year ago

I can confirm, thanks!