prompt buffer supports multiline input
Problem
There is no way, not even programmatically, for a user or plugin to put multiline input into the prompt of a buftype=prompt buffer.
Also, pasting multiline input into a prompt buffer (via nvim_paste or insert-mode <c-r>+) is obviously broken.
This is not in vim's issue tracker, nor its todo list: https://github.com/vim/vim/blob/88ce0c546b54ecb0dc573b99cde6246f87b42687/runtime/doc/todo.txt#L230-L233
Expected behavior
- Phase 1
- Allow the prompt "invoke" action to be remapped, e.g. instead of Enter it could be Shift-Enter.
- By default, when the user pastes or puts text (
p,i_ctrl-r, cmd+v), Nvim replaces newlines with<space>char. - Pasting (including
<c-r>+) and "put" (p) should never invoke the prompt (by default). The prompt should invoke only when the user hits Enter.- related: https://github.com/neovim/neovim/issues/15136
- Phase 2
- Allow multiline input in a prompt (support multiline text without replacing newlines).
- The
prompt_setcallback()handler gets the full multiline input, not only the last line. - Open question: How can the user edit the full multiline input?
- The
- Allow multiline input in a prompt (support multiline text without replacing newlines).
I would like to work on this. Is there anything I should be particularly careful about?
I am thinking:
- Enter can still be invoke by default
- Shift + Enter enters a new line in the prompt
Is there anything I should be particularly careful about?
In terms of implementation, my first thought is that instead of special-casing <CR> as in the current implementation, we should:
- add a new
prompt_send()function which does what<CR>currently does. - map
<CR>toprompt_send()by default (to mimic the current behavior)
I attempted to implement a similar feature in mfussenegger/nvim-dap#773 you can look into it for details, it's important to note that Shift-Enter will not work in all terminals which could be problematic. Ctrl-C should work though for stopping multiline mode.
I suggest looking into the repl mode for IPython and Node as reference of nice features to have. For example in IPython when you start with def hello():<cr> it automatically knows that you want to enter multiline mode and it also indents your next prompt.
Node also knows to enter multiline mode automatically, if you make a syntax error while in multiline mode, it will exit on the next
For example in IPython when you start with
def hello():<cr>it automatically knows that you want to enter multiline mode and it also indents your next prompt.
That might already work for all we know, except we can't know until it becomes actually possible to... enter a linebreak in the prompt.