mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
ex_getln: Fix “echoerr msg not shown” problem
This also attempted to fix problem with cancelling input() on error by avoiding standard error printing facilities (assumed thrown error message is the problem), but with no luck so far.
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
|
#include "nvim/highlight_defs.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables shared between getcmdline(), redrawcmdline() and others.
|
* Variables shared between getcmdline(), redrawcmdline() and others.
|
||||||
@@ -2202,6 +2203,13 @@ enum { MAX_CB_ERRORS = 1 };
|
|||||||
/// to do.
|
/// to do.
|
||||||
static bool color_cmdline(void)
|
static bool color_cmdline(void)
|
||||||
{
|
{
|
||||||
|
bool printed_errmsg = false;
|
||||||
|
#define PRINT_ERRMSG(...) \
|
||||||
|
do { \
|
||||||
|
msg_putchar('\n'); \
|
||||||
|
msg_printf_attr(hl_attr(HLF_E)|MSG_HIST, __VA_ARGS__); \
|
||||||
|
printed_errmsg = true; \
|
||||||
|
} while (0)
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
kv_size(ccline_colors) = 0;
|
kv_size(ccline_colors) = 0;
|
||||||
|
|
||||||
@@ -2274,7 +2282,7 @@ static bool color_cmdline(void)
|
|||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
}
|
}
|
||||||
if (tv.v_type != VAR_LIST) {
|
if (tv.v_type != VAR_LIST) {
|
||||||
emsgf(_("E5400: Callback should return list"));
|
PRINT_ERRMSG(_("E5400: Callback should return list"));
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
}
|
}
|
||||||
if (tv.vval.v_list == NULL) {
|
if (tv.vval.v_list == NULL) {
|
||||||
@@ -2285,13 +2293,13 @@ static bool color_cmdline(void)
|
|||||||
for (const listitem_T *li = tv.vval.v_list->lv_first;
|
for (const listitem_T *li = tv.vval.v_list->lv_first;
|
||||||
li != NULL; li = li->li_next, i++) {
|
li != NULL; li = li->li_next, i++) {
|
||||||
if (li->li_tv.v_type != VAR_LIST) {
|
if (li->li_tv.v_type != VAR_LIST) {
|
||||||
emsgf(_("E5401: List item %i is not a List"), i);
|
PRINT_ERRMSG(_("E5401: List item %i is not a List"), i);
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
}
|
}
|
||||||
const list_T *const l = li->li_tv.vval.v_list;
|
const list_T *const l = li->li_tv.vval.v_list;
|
||||||
if (tv_list_len(l) != 3) {
|
if (tv_list_len(l) != 3) {
|
||||||
emsgf(_("E5402: List item %i has incorrect length: %li /= 3"),
|
PRINT_ERRMSG(_("E5402: List item %i has incorrect length: %li /= 3"),
|
||||||
i, tv_list_len(l));
|
i, tv_list_len(l));
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
}
|
}
|
||||||
bool error = false;
|
bool error = false;
|
||||||
@@ -2299,13 +2307,13 @@ static bool color_cmdline(void)
|
|||||||
if (error) {
|
if (error) {
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
} else if (!(prev_end <= start && start < ccline.cmdlen)) {
|
} else if (!(prev_end <= start && start < ccline.cmdlen)) {
|
||||||
emsgf(_("E5403: Chunk %i start %" PRIdVARNUMBER " not in range "
|
PRINT_ERRMSG(_("E5403: Chunk %i start %" PRIdVARNUMBER " not in range "
|
||||||
"[%" PRIdVARNUMBER ", %i)"),
|
"[%" PRIdVARNUMBER ", %i)"),
|
||||||
i, start, prev_end, ccline.cmdlen);
|
i, start, prev_end, ccline.cmdlen);
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
} else if (utf8len_tab_zero[(uint8_t)ccline.cmdbuff[start]] == 0) {
|
} else if (utf8len_tab_zero[(uint8_t)ccline.cmdbuff[start]] == 0) {
|
||||||
emsgf(_("E5405: Chunk %i start %" PRIdVARNUMBER " splits multibyte "
|
PRINT_ERRMSG(_("E5405: Chunk %i start %" PRIdVARNUMBER " splits "
|
||||||
"character"), i, start);
|
"multibyte character"), i, start);
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
}
|
}
|
||||||
if (start != prev_end) {
|
if (start != prev_end) {
|
||||||
@@ -2320,14 +2328,14 @@ static bool color_cmdline(void)
|
|||||||
if (error) {
|
if (error) {
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
} else if (!(start < end && end <= ccline.cmdlen)) {
|
} else if (!(start < end && end <= ccline.cmdlen)) {
|
||||||
emsgf(_("E5404: Chunk %i end %" PRIdVARNUMBER " not in range "
|
PRINT_ERRMSG(_("E5404: Chunk %i end %" PRIdVARNUMBER " not in range "
|
||||||
"(%" PRIdVARNUMBER ", %i]"),
|
"(%" PRIdVARNUMBER ", %i]"),
|
||||||
i, end, start, ccline.cmdlen);
|
i, end, start, ccline.cmdlen);
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
} else if (end < ccline.cmdlen
|
} else if (end < ccline.cmdlen
|
||||||
&& utf8len_tab_zero[(uint8_t)ccline.cmdbuff[end]] == 0) {
|
&& utf8len_tab_zero[(uint8_t)ccline.cmdbuff[end]] == 0) {
|
||||||
emsgf(_("E5406: Chunk %i end %" PRIdVARNUMBER " splits multibyte "
|
PRINT_ERRMSG(_("E5406: Chunk %i end %" PRIdVARNUMBER " splits multibyte "
|
||||||
"character"), i, end);
|
"character"), i, end);
|
||||||
goto color_cmdline_error;
|
goto color_cmdline_error;
|
||||||
}
|
}
|
||||||
prev_end = end;
|
prev_end = end;
|
||||||
@@ -2364,19 +2372,19 @@ color_cmdline_end:
|
|||||||
return ret;
|
return ret;
|
||||||
color_cmdline_error:
|
color_cmdline_error:
|
||||||
if (ERROR_SET(&err)) {
|
if (ERROR_SET(&err)) {
|
||||||
emsgf(_("E5407: Callback has thrown an exception: %s"), err.msg);
|
PRINT_ERRMSG(_("E5407: Callback has thrown an exception: %s"), err.msg);
|
||||||
api_clear_error(&err);
|
api_clear_error(&err);
|
||||||
}
|
}
|
||||||
|
assert(printed_errmsg);
|
||||||
|
|
||||||
prev_prompt_errors++;
|
prev_prompt_errors++;
|
||||||
kv_size(ccline_colors) = 0;
|
kv_size(ccline_colors) = 0;
|
||||||
if (did_emsg) {
|
prev_prompt_errors += MAX_CB_ERRORS;
|
||||||
did_emsg = false;
|
redrawcmdline();
|
||||||
prev_prompt_errors += MAX_CB_ERRORS;
|
prev_prompt_errors -= MAX_CB_ERRORS;
|
||||||
redrawcmdline();
|
ret = false;
|
||||||
prev_prompt_errors -= MAX_CB_ERRORS;
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
goto color_cmdline_end;
|
goto color_cmdline_end;
|
||||||
|
#undef PRINT_ERRMSG
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1611,6 +1611,27 @@ void msg_puts_attr_len(const char *const str, const ptrdiff_t len, int attr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print a formatted message
|
||||||
|
///
|
||||||
|
/// Message printed is limited by #IOSIZE. Must not be used from inside
|
||||||
|
/// msg_puts_attr().
|
||||||
|
///
|
||||||
|
/// @param[in] attr Highlight attributes.
|
||||||
|
/// @param[in] fmt Format string.
|
||||||
|
void msg_printf_attr(const int attr, const char *const fmt, ...)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
static char msgbuf[IOSIZE];
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
const size_t len = vim_vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap, NULL);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
msg_scroll = true;
|
||||||
|
msg_puts_attr_len(msgbuf, (ptrdiff_t)len, attr);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The display part of msg_puts_attr_len().
|
* The display part of msg_puts_attr_len().
|
||||||
* May be called recursively to display scroll-back text.
|
* May be called recursively to display scroll-back text.
|
||||||
|
@@ -289,7 +289,16 @@ describe('Command-line coloring', function()
|
|||||||
it('does the right thing when errorring', function()
|
it('does the right thing when errorring', function()
|
||||||
set_color_cb('Echoerring')
|
set_color_cb('Echoerring')
|
||||||
start_prompt('e')
|
start_prompt('e')
|
||||||
-- FIXME Does not work well with :echoerr: error message not shown.
|
screen:expect([[
|
||||||
|
{EOB:~ }|
|
||||||
|
{EOB:~ }|
|
||||||
|
{EOB:~ }|
|
||||||
|
{EOB:~ }|
|
||||||
|
: |
|
||||||
|
{ERR:E5407: Callback has thrown an exception:}|
|
||||||
|
{ERR: Vim(echoerr):HERE} |
|
||||||
|
:e^ |
|
||||||
|
]])
|
||||||
end)
|
end)
|
||||||
it('does the right thing when throwing', function()
|
it('does the right thing when throwing', function()
|
||||||
set_color_cb('Throwing')
|
set_color_cb('Throwing')
|
||||||
|
Reference in New Issue
Block a user