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

[REQUEST] Cancel completion and remove what was inserted #5278

Open
Supreeeme opened this issue Jan 22, 2025 · 4 comments
Open

[REQUEST] Cancel completion and remove what was inserted #5278

Supreeeme opened this issue Jan 22, 2025 · 4 comments

Comments

@Supreeeme
Copy link

Feature

If I choose a completion candidate but then decide I don't want to use it, I have to exit insert mode and delete whatever was inserted. It would be nice if I was able to hit some key to cancel the insertion and then delete whatever it inserted, if anything.

Usecase

No response

@Screwtapello
Copy link
Contributor

The "cycle through completion candidates" keys (<c-n> and <c-p> by default) also cycle through the "no completion selected" state. So if you show the completion menu and press <c-n> to select the first completion, you can press <c-p> to go back to "no completion selected".

Alternatively, the InsertCompletionHide hook receives the list of inserted text ranges; you could create a custom "dismiss completions" mapping that adds a one-shot hook to delete the inserted text, then executes <c-o> to hide the completion menu.

@krobelus
Copy link
Contributor

krobelus commented Jan 22, 2025 via email

@Supreeeme
Copy link
Author

That hook does not do anything for me. The main issue is I'm not sure how I would go about remove exactly what was inserted.

@krobelus
Copy link
Contributor

That hook does not do anything for me. The main issue is I'm not sure how I would go about remove exactly what was inserted.

yeah I forgot to select the inserted range.

Below is a tested implementation that removes
the inserted completion when you press .

It seems to work fine; but messing with this kind of stuff could be a rabbit
hole; other UI changes might be necessary to make the completion experience
consistent again (I guess that's obvious from the other questions you raised).
Kakoune is very flexible, you'll want to read :doc hooks and others.

# N.B. the "foo" grouping is only needed for iterating on this
remove-hooks global foo
define-command -override my-cancel-completion %{
    # .+ matches only non-empty hook parameters, which indicate that
    # some completion candidate was accepted.
    hook -group foo -once global InsertCompletionHide .+ %{
        select %val{hook_param}
        exec -draft <a-d>
    }
    execute-keys -with-hooks <esc>
}
hook -group foo global InsertCompletionShow .* %{
    map window insert <esc> <a-semicolon>:my-cancel-completion<ret>
}
hook -group foo global InsertCompletionHide .* %{
    unmap window insert <esc> <a-semicolon>:my-cancel-completion<ret>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants