Is it possible to use "word=all" completion for a prompt?

I see in the documentation for the prompt command that there are completions for buffers, clients, commands, and then the “call out to shell” option. Is it somehow possible to do “word=all” completion for a prompt?

Here’s what I’m looking to use it for, maybe I’m looking in the wrong place, or trying to fit a square peg in a round hole…

I have a command that either runs grep with whatever text is currently selected in the buffer, or prompts for input if there is nothing selected (selection length === 1). This allows me to use the same command for either “I want to grep something…” or “I want to grep the thing I currently have selected”. I find this reduces mental friction for me:

def grep-or-prompt \
	-docstring 'Grep current selection if greater than 1 character, or prompt for input' \
	%{ evaluate-commands %sh{

	if test "${#kak_selection}" -gt 1 ; then
		escaped=$(echo $kak_selection | sed "s/'/''/")
		printf "
			grep '$escaped'
		"
	else
		echo "prompt grep: %{ grep %val{text} }"
	fi
}}

Ideally, I’d like that prompt call to utilize the “word=all” completion, but it looks like prompt doesn’t support that for some reason…can anyone think of how I might be able to work around that? Am I just going about this in the wrong way?

How do you intend this to play with multiple cursors?

You know, I hadn’t even considered it!

I’d be fine with a solution that only works for a single cursor - I’ve never used multiple cursors with grep.

There does not seem to be something built in to directly do this. You can get completions for the words in the buffer in a prompt by pressing <c-x>w, and you can make your script do this for you:

def grep-or-prompt \
    -docstring 'Grep current selection if greater than 1 character, or prompt for input' \
    %{ evaluate-commands %sh{

    if test "${#kak_selection}" -gt 1 ; then
        escaped=$(echo $kak_selection | sed "s/'/''/")
        printf "
            grep '$escaped'
        "
    else
        echo "prompt grep: %{ grep %val{text} }"
        echo "exec <c-x>w" # start with buffer word completions
    fi
}}

If you want the words from all buffers you could extend your script to get them and print them (separated by newlines) in the -shell-script-candiates flag to the prompt command.

Isn’t anything in a client in a buffer? So buffers would cover that… and you wouldn’t really want to search for commands, as your grep across files would not find what it is in commands?

Wouldn’t buffers be the right scope?