aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-06-28 14:26:23 +0300
committerZyX <kp-pav@yandex.ru>2017-06-28 14:26:23 +0300
commit0ed95423de714edac11ccff177b8aee6b7987bac (patch)
treed1db5ee9f34434ea0b622da7ae3d460e47ece0f6
parent493d250446e5323e64c80399f0c5a15621c4f15c (diff)
downloadrneovim-0ed95423de714edac11ccff177b8aee6b7987bac.tar.gz
rneovim-0ed95423de714edac11ccff177b8aee6b7987bac.tar.bz2
rneovim-0ed95423de714edac11ccff177b8aee6b7987bac.zip
ex_getln: Call highlight callback inside :try
-rw-r--r--src/nvim/ex_getln.c31
-rw-r--r--test/functional/ui/cmdline_highlight_spec.lua15
2 files changed, 26 insertions, 20 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index f9b2d6cda8..9c494a2640 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -63,6 +63,7 @@
#include "nvim/event/loop.h"
#include "nvim/os/time.h"
#include "nvim/lib/kvec.h"
+#include "nvim/api/private/helpers.h"
/*
* Variables shared between getcmdline(), redrawcmdline() and others.
@@ -2217,6 +2218,7 @@ static bool color_cmdline(void)
static int prev_prompt_errors = 0;
Callback color_cb = { .type = kCallbackNone };
bool can_free_cb = false;
+ Error err = ERROR_INIT;
if (ccline.input_fn) {
color_cb = getln_input_callback;
@@ -2259,16 +2261,16 @@ static bool color_cmdline(void)
// appears shifted one character to the right and cursor position is no longer
// correct, with msg_col it just misses leading `:`. Since `redraw!` in
// callback lags this is least of the user problems.
+ //
+ // Also using try_start() because error messages may overwrite typed
+ // command-line which is not expected.
+ try_start();
const int saved_msg_col = msg_col;
msg_silent++;
- if (!callback_call(&color_cb, 1, &arg, &tv)) {
- msg_silent--;
- msg_col = saved_msg_col;
- goto color_cmdline_error;
- }
+ const bool cbcall_ret = callback_call(&color_cb, 1, &arg, &tv);
msg_silent--;
msg_col = saved_msg_col;
- if (got_int || did_emsg) {
+ if (try_end(&err) || !cbcall_ret) {
goto color_cmdline_error;
}
if (tv.v_type != VAR_LIST) {
@@ -2350,6 +2352,7 @@ static bool color_cmdline(void)
}
prev_prompt_errors = 0;
color_cmdline_end:
+ assert(!ERROR_SET(&err));
if (can_free_cb) {
callback_free(&color_cb);
}
@@ -2360,18 +2363,14 @@ color_cmdline_end:
tv_clear(&tv);
return ret;
color_cmdline_error:
- prev_prompt_errors++;
- const bool do_redraw = (did_emsg || got_int);
- got_int = false;
- did_emsg = false;
- if (did_throw) {
- discard_current_exception();
- }
- if (msg_list != NULL && *msg_list != NULL) {
- free_global_msglist();
+ if (ERROR_SET(&err)) {
+ emsgf(_("E5407: Callback has thrown an exception: %s"), err.msg);
+ api_clear_error(&err);
}
+ prev_prompt_errors++;
kv_size(ccline_colors) = 0;
- if (do_redraw) {
+ if (did_emsg) {
+ did_emsg = false;
prev_prompt_errors += MAX_CB_ERRORS;
redrawcmdline();
prev_prompt_errors -= MAX_CB_ERRORS;
diff --git a/test/functional/ui/cmdline_highlight_spec.lua b/test/functional/ui/cmdline_highlight_spec.lua
index 12577a4db4..8207a903f4 100644
--- a/test/functional/ui/cmdline_highlight_spec.lua
+++ b/test/functional/ui/cmdline_highlight_spec.lua
@@ -285,16 +285,23 @@ describe('Command-line coloring', function()
]])
end)
it('does the right thing when errorring', function()
- if true then return pending('echoerr does not work well now') end
set_color_cb('Echoerring')
start_prompt('e')
- -- FIXME Does not work well with :echoerr: error message overwrites cmdline.
+ -- FIXME Does not work well with :echoerr: error message not shown.
end)
it('does the right thing when throwing', function()
- if true then return pending('Throwing does not work well now') end
set_color_cb('Throwing')
start_prompt('e')
- -- FIXME Does not work well with :throw: error message overwrites cmdline.
+ screen:expect([[
+ {EOB:~ }|
+ {EOB:~ }|
+ {EOB:~ }|
+ {EOB:~ }|
+ : |
+ {ERR:E5407: Callback has thrown an exception:}|
+ {ERR: ABC} |
+ :e^ |
+ ]])
end)
it('stops executing callback after a number of errors', function()
set_color_cb('SplittedMultibyteStart')