import { fn } from "https://deno.land/x/ddu_vim@v4.0.0/deps.ts";
const { prompt_setcallback } = fn;
Set prompt callback for buffer {buf} to {expr}. When {expr} is an empty string the callback is removed. This has only effect if {buf} has 'buftype' set to "prompt".
The callback is invoked when pressing Enter. The current buffer will always be the prompt buffer. A new line for a prompt is added before invoking the callback, thus the prompt for which the callback was invoked will be in the last but one line. If the callback wants to add text to the buffer, it must insert it above the last line, since that is where the current prompt is. This can also be done asynchronously. The callback is invoked with one argument, which is the text that was entered at the prompt. This can be an empty string if the user only typed Enter. Example:
func s:TextEntered(text)
if a:text == 'exit' || a:text == 'quit'
stopinsert
" Reset 'modified' to allow the buffer to be closed.
" We assume there is nothing useful to be saved.
set nomodified
close
else
" Do something useful with "a:text". In this example
" we just repeat it.
call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
endif
endfunc
call prompt_setcallback(bufnr(), function('s:TextEntered'))
Can also be used as a method
:
GetBuffer()->prompt_setcallback(callback)
only available when compiled with the +channel
feature