Skip to main content
Module

x/denops_std/function/mod.ts>prompt_setcallback

📚 Standard module for denops.vim
Go to Latest
function prompt_setcallback
import { prompt_setcallback } from "https://deno.land/x/denops_std@v4.3.0/function/mod.ts";

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

Parameters

denops: Denops
buf: unknown
expr: unknown

Returns

Promise<void>