diff options
author | notomo <notomo.motono@gmail.com> | 2021-01-11 15:18:51 +0900 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-01-20 16:41:39 +0100 |
commit | 8e86f5e460398962dd58ddf727a0586710ce6f95 (patch) | |
tree | e8a571174fc56f7ec5203558b6275bb5ce8b5298 /src/nvim/api/vim.c | |
parent | 1785ac3e3787e84846d753ceb73a239f5575a691 (diff) | |
download | rneovim-8e86f5e460398962dd58ddf727a0586710ce6f95.tar.gz rneovim-8e86f5e460398962dd58ddf727a0586710ce6f95.tar.bz2 rneovim-8e86f5e460398962dd58ddf727a0586710ce6f95.zip |
api: nvim_echo
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 1e972e01be..9e2fb6da6f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -990,6 +990,47 @@ void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err) set_option_to(channel_id, NULL, SREQ_GLOBAL, name, value, err); } +/// Echo a message. +/// +/// @param chunks A list of [text, hl_group] arrays, each representing a +/// text chunk with specified highlight. `hl_group` element +/// can be omitted for no highlight. +/// @param history if true, add to |message-history|. +/// @param opts Optional parameters. Reserved for future use. +void nvim_echo(Array chunks, Boolean history, Dictionary opts, Error *err) + FUNC_API_SINCE(7) +{ + HlMessage hl_msg = parse_hl_msg(chunks, err); + if (ERROR_SET(err)) { + goto error; + } + + if (opts.size > 0) { + api_set_error(err, kErrorTypeValidation, "opts dict isn't empty"); + goto error; + } + + no_wait_return++; + bool need_clear = true; + msg_start(); + for (uint32_t i = 0; i < kv_size(hl_msg); i++) { + HlMessageChunk chunk = kv_A(hl_msg, i); + msg_multiline_attr((const char *)chunk.text.data, chunk.attr, + false, &need_clear); + } + if (history) { + msg_ext_set_kind("echomsg"); + add_hl_msg_hist(hl_msg); + } else { + msg_ext_set_kind("echo"); + } + no_wait_return--; + msg_end(); + +error: + clear_hl_msg(&hl_msg); +} + /// Writes a message to the Vim output buffer. Does not append "\n", the /// message is buffered (won't display) until a linefeed is written. /// |