mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.7k stars 705 forks source link

[BUG] Command completion stops to work when command is invoked in user-mode #5166

Closed VKondakoff closed 1 month ago

VKondakoff commented 2 months ago

Version of Kakoune

v2023.08.05

Reproducer

I created a simple command to browse the open buffers:

define-command open_buffer_picker %{
  prompt buffer: %{
    buffer %val{text}
  }
}
complete-command -menu open_buffer_picker buffer
map -docstring "open buffer picker"      global user b ": open_buffer_picker<ret>"

Outcome

If I launch the command from the command prompt the completion works:

Снимок экрана 2024-05-03 в 19 25 15

If I launch the same command from user-mode (by pressing <Space>-b) there is no completion:

Снимок экрана 2024-05-03 в 19 25 35

Expectations

I was expecting to see completion when launching command from command prompt AND user mode. It is interesting that the old completion syntax works both in prompt and in user mode:

define-command -hidden open_buffer_picker %{
  prompt buffer: -menu -buffer-completion %{
    buffer %val{text}
  }
}
map -docstring "open buffer picker"      global user b ": open_buffer_picker<ret>"
Снимок экрана 2024-05-03 в 19 35 22

Is this a bug or am I doing something wrong?

Additional information

MacOS 12.7.4, zsh.

Screwtapello commented 2 months ago

In your examples, open_buffer_picker is a command which accepts no arguments, but Kakoune is told to use buffer-completion anyway. Because of the -menu option, Kakoune will force you to choose a buffer name to add to the command-line, guaranteeing a "wrong argument count" error.

When the command is invoked without an argument (such as from a user-mode mapping), it runs the prompt command, which uses a similar user-interface, but which asks the user for a string which will be handled by a user script, rather than being executed by Kakoune as a command. As a result, it has its own, independent settings.

declare-command options like -buffer-completion have been deprecated in favour of the separate complete-command command, which modifies the completion settings for a specific user-declared command. However, prompt is a built-in command, not a user-declared command. It still requires options like -buffer-completion to control what kind of completion it provides, they have not been deprecated, and complete-command does not affect it.

Long story short, the "old" code you present under "Expectations" is still correct, and still the way to achieve the result you want with modern versions of Kakoune.

Incidentally, I assume this is a simplified test-case meant to demonstrate the problem, and not something you actually use in your kakrc. If you want a buffer picker, you could just use map global user b :b<space> since the buffer command already uses buffer-completion and already switches to the selected buffer when you hit <ret>.

VKondakoff commented 1 month ago

declare-command options like -buffer-completion have been deprecated in favour of the separate complete-command command, which modifies the completion settings for a specific user-declared command. However, prompt is a built-in command, not a user-declared command. It still requires options like -buffer-completion to control what kind of completion it provides, they have not been deprecated, and complete-command does not affect it.

Got it, thank you! Closing the issue.

If you want a buffer picker, you could just use map global user b :b since the buffer command already uses buffer-completion and already switches to the selected buffer when you hit .

This! Exactly, thank you once again.