diff options
Diffstat (limited to 'src/nvim/api/vim.c')
| -rw-r--r-- | src/nvim/api/vim.c | 31 | 
1 files changed, 16 insertions, 15 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 03b9257d79..9834633813 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -512,23 +512,24 @@ void vim_unsubscribe(uint64_t channel_id, String event)  ///        `emsg` instead of `msg` to print each line)  static void write_msg(String message, bool to_err)  { -  static int pos = 0; -  static char line_buf[LINE_BUFFER_SIZE]; +  static int out_pos = 0, err_pos = 0; +  static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE]; + +#define PUSH_CHAR(i, pos, line_buf, msg)                                      \ +  if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) {                 \ +    line_buf[pos] = NUL;                                                      \ +    msg((uint8_t *)line_buf);                                                 \ +    pos = 0;                                                                  \ +    continue;                                                                 \ +  }                                                                           \ +                                                                              \ +  line_buf[pos++] = message.data[i];    for (uint32_t i = 0; i < message.size; i++) { -    if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { -      // Flush line -      line_buf[pos] = NUL; -      if (to_err) { -        emsg((uint8_t *)line_buf); -      } else { -        msg((uint8_t *)line_buf); -      } - -      pos = 0; -      continue; +    if (to_err) { +      PUSH_CHAR(i, err_pos, err_line_buf, emsg); +    } else { +      PUSH_CHAR(i, out_pos, out_line_buf, msg);      } - -    line_buf[pos++] = message.data[i];    }  }  | 
