`prompt-yes-no`

I find the prompt command quite awkward to work with. This command will prompt a ‘y/n’ (though it still needs to confirm). Posting it just cause. Improvements?

Usage: prompt-yes-no 'question to user: ' your-command-on-action – none of the prompt switches will work w/ this implementation (-init y is hard coded).

define-command -override -params 2 prompt-yes-no %{
  evaluate-commands %sh{
    args="${@:1:$#-1}"
    cmd="${@: -1}"
    # No clue on how ot make prompt here accept the flag arguments properly.
    printf 'prompt -init y "%s" %%{evaluate-commands %%sh{
      case "$kak_text" in
        [yY])
          echo %s
          ;;
        ?)
          ;;
      esac
    }}\n' "$args" "$cmd"
  }
}

Just write explicit prompt commands. Kakoune is not good for running arbitrary commands from generic prompts.

def delete_buffer_on_next_key %{
  echo 'delete buffer? [y/n]'
  on-key %{
    evaluate-commands %sh{
      case "$kak_key" in
        y)
          echo 'delete-buffer'
          ;;
        n)
          ;;
        *)
          ;;
      esac
    }
  }
}

Either use on-key or prompt to suit your liking.

You can arguably do the following—but it is not safe.

def evaluate_commands_on_next_key -params 2 %{
  echo %arg{1}
  on-key %exp{
    evaluate-commands %%sh{
      case "$kak_key" in
        y)
          echo %arg{2}
          ;;
        n)
          ;;
        *)
          ;;
      esac
    }
  }
}

evaluate_commands_on_next_key 'delete buffer? [y/n]' delete-buffer

Yeah that makes sense alright