diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-09-27 22:21:17 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-09-27 22:50:49 +0200 |
commit | b85f1dafc7c0a19704135617454f1c66f41202c1 (patch) | |
tree | ce478ebdce2efaac4ff9f16e86bce556e2ef1e7d /src/nvim/api/vim.c | |
parent | f91cd31d7d9d70006e0000592637d5d997eab52c (diff) | |
download | rneovim-b85f1dafc7c0a19704135617454f1c66f41202c1.tar.gz rneovim-b85f1dafc7c0a19704135617454f1c66f41202c1.tar.bz2 rneovim-b85f1dafc7c0a19704135617454f1c66f41202c1.zip |
refactor(messages): fold msg_attr into msg
problem: there are too many different functions in message.c
solution: fold some of the functions into themselves
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 00641c633d..c55f9592bf 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1699,21 +1699,26 @@ static void write_msg(String message, bool to_err, bool writeln) { static StringBuilder out_line_buf = KV_INITIAL_VALUE; static StringBuilder err_line_buf = KV_INITIAL_VALUE; + StringBuilder *line_buf = to_err ? &err_line_buf : &out_line_buf; -#define PUSH_CHAR(c, line_buf, msg) \ - if (kv_max(line_buf) == 0) { \ - kv_resize(line_buf, LINE_BUFFER_MIN_SIZE); \ +#define PUSH_CHAR(c) \ + if (kv_max(*line_buf) == 0) { \ + kv_resize(*line_buf, LINE_BUFFER_MIN_SIZE); \ } \ if (c == NL) { \ - kv_push(line_buf, NUL); \ - msg(line_buf.items); \ + kv_push(*line_buf, NUL); \ + if (to_err) { \ + emsg(line_buf->items); \ + } else { \ + msg(line_buf->items, 0); \ + } \ msg_didout = true; \ - kv_drop(line_buf, kv_size(line_buf)); \ - kv_resize(line_buf, LINE_BUFFER_MIN_SIZE); \ + kv_drop(*line_buf, kv_size(*line_buf)); \ + kv_resize(*line_buf, LINE_BUFFER_MIN_SIZE); \ } else if (c == NUL) { \ - kv_push(line_buf, NL); \ + kv_push(*line_buf, NL); \ } else { \ - kv_push(line_buf, c); \ + kv_push(*line_buf, c); \ } no_wait_return++; @@ -1721,18 +1726,10 @@ static void write_msg(String message, bool to_err, bool writeln) if (got_int) { break; } - if (to_err) { - PUSH_CHAR(message.data[i], err_line_buf, emsg); - } else { - PUSH_CHAR(message.data[i], out_line_buf, msg); - } + PUSH_CHAR(message.data[i]); } if (writeln) { - if (to_err) { - PUSH_CHAR(NL, err_line_buf, emsg); - } else { - PUSH_CHAR(NL, out_line_buf, msg); - } + PUSH_CHAR(NL); } no_wait_return--; msg_end(); |