import { fn } from "https://deno.land/x/ddc_vim@v4.0.5/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:
call prompt_setcallback(bufnr(), function('s:TextEntered'))
func s:TextEntered(text)
if a:text == 'exit' || a:text == 'quit'
stopinsert
close
else
call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
" Reset 'modified' to allow the buffer to be closed.
set nomodified
endif
endfunc
Can also be used as a method
:
GetBuffer()->prompt_setcallback(callback)
only available when compiled with the +channel
feature