413 lines
12 KiB
Diff
413 lines
12 KiB
Diff
From 53989554a44caca0964376d60297f08ec257c53c Mon Sep 17 00:00:00 2001
|
|
From: Bram Moolenaar <Bram@vim.org>
|
|
Date: Mon, 23 Dec 2019 22:59:18 +0100
|
|
Subject: [PATCH] patch 8.2.0035: saving and restoring called_emsg is clumsy
|
|
|
|
Problem: Saving and restoring called_emsg is clumsy.
|
|
Solution: Count the number of error messages.
|
|
---
|
|
src/buffer.c | 12 ++++--------
|
|
src/channel.c | 6 ++----
|
|
src/drawscreen.c | 6 ++----
|
|
src/ex_cmds2.c | 2 +-
|
|
src/globals.h | 2 +-
|
|
src/gui.c | 7 ++-----
|
|
src/highlight.c | 8 ++------
|
|
src/main.c | 2 +-
|
|
src/message.c | 4 ++--
|
|
src/regexp.c | 9 ++++-----
|
|
src/search.c | 18 +++++++-----------
|
|
src/testing.c | 5 ++---
|
|
12 files changed, 30 insertions(+), 51 deletions(-)
|
|
|
|
diff --git a/src/buffer.c b/src/buffer.c
|
|
index f66c234..fd15424 100644
|
|
--- a/src/buffer.c
|
|
+++ b/src/buffer.c
|
|
@@ -3761,19 +3761,17 @@ maketitle(void)
|
|
if (stl_syntax & STL_IN_TITLE)
|
|
{
|
|
int use_sandbox = FALSE;
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
|
|
# ifdef FEAT_EVAL
|
|
use_sandbox = was_set_insecurely((char_u *)"titlestring", 0);
|
|
# endif
|
|
- called_emsg = FALSE;
|
|
build_stl_str_hl(curwin, title_str, sizeof(buf),
|
|
p_titlestring, use_sandbox,
|
|
0, maxlen, NULL, NULL);
|
|
- if (called_emsg)
|
|
+ if (called_emsg > called_emsg_before)
|
|
set_string_option_direct((char_u *)"titlestring", -1,
|
|
(char_u *)"", OPT_FREE, SID_ERROR);
|
|
- called_emsg |= save_called_emsg;
|
|
}
|
|
else
|
|
#endif
|
|
@@ -3894,19 +3892,17 @@ maketitle(void)
|
|
if (stl_syntax & STL_IN_ICON)
|
|
{
|
|
int use_sandbox = FALSE;
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
|
|
# ifdef FEAT_EVAL
|
|
use_sandbox = was_set_insecurely((char_u *)"iconstring", 0);
|
|
# endif
|
|
- called_emsg = FALSE;
|
|
build_stl_str_hl(curwin, icon_str, sizeof(buf),
|
|
p_iconstring, use_sandbox,
|
|
0, 0, NULL, NULL);
|
|
- if (called_emsg)
|
|
+ if (called_emsg > called_emsg_before)
|
|
set_string_option_direct((char_u *)"iconstring", -1,
|
|
(char_u *)"", OPT_FREE, SID_ERROR);
|
|
- called_emsg |= save_called_emsg;
|
|
}
|
|
else
|
|
#endif
|
|
diff --git a/src/channel.c b/src/channel.c
|
|
index 7edca1a..264c9f3 100644
|
|
--- a/src/channel.c
|
|
+++ b/src/channel.c
|
|
@@ -2370,17 +2370,15 @@ channel_exe_cmd(channel_T *channel, ch_part_T part, typval_T *argv)
|
|
|
|
if (STRCMP(cmd, "ex") == 0)
|
|
{
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
|
|
- called_emsg = FALSE;
|
|
ch_log(channel, "Executing ex command '%s'", (char *)arg);
|
|
++emsg_silent;
|
|
do_cmdline_cmd(arg);
|
|
--emsg_silent;
|
|
- if (called_emsg)
|
|
+ if (called_emsg > called_emsg_before)
|
|
ch_log(channel, "Ex command error: '%s'",
|
|
(char *)get_vim_var_str(VV_ERRMSG));
|
|
- called_emsg = save_called_emsg;
|
|
}
|
|
else if (STRCMP(cmd, "normal") == 0)
|
|
{
|
|
diff --git a/src/drawscreen.c b/src/drawscreen.c
|
|
index 7425ad4..05cd5aa 100644
|
|
--- a/src/drawscreen.c
|
|
+++ b/src/drawscreen.c
|
|
@@ -651,14 +651,12 @@ win_redr_ruler(win_T *wp, int always, int ignore_pum)
|
|
#ifdef FEAT_STL_OPT
|
|
if (*p_ruf)
|
|
{
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
|
|
- called_emsg = FALSE;
|
|
win_redr_custom(wp, TRUE);
|
|
- if (called_emsg)
|
|
+ if (called_emsg > called_emsg_before)
|
|
set_string_option_direct((char_u *)"rulerformat", -1,
|
|
(char_u *)"", OPT_FREE, SID_ERROR);
|
|
- called_emsg |= save_called_emsg;
|
|
return;
|
|
}
|
|
#endif
|
|
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
|
|
index 9a31887..4f8f7fb 100644
|
|
--- a/src/ex_cmds2.c
|
|
+++ b/src/ex_cmds2.c
|
|
@@ -167,7 +167,7 @@ check_due_timer(void)
|
|
// the current scope, such as being inside a try/catch.
|
|
timer_busy = timer_busy > 0 || vgetc_busy > 0;
|
|
vgetc_busy = 0;
|
|
- called_emsg = FALSE;
|
|
+ called_emsg = 0;
|
|
did_emsg = FALSE;
|
|
did_uncaught_emsg = FALSE;
|
|
must_redraw = 0;
|
|
diff --git a/src/globals.h b/src/globals.h
|
|
index 01ebbb8..5a040fc 100644
|
|
--- a/src/globals.h
|
|
+++ b/src/globals.h
|
|
@@ -226,7 +226,7 @@ EXTERN int did_uncaught_emsg; // emsg() was called and did not
|
|
#endif
|
|
EXTERN int did_emsg_syntax; // did_emsg set because of a
|
|
// syntax error
|
|
-EXTERN int called_emsg; // always set by emsg()
|
|
+EXTERN int called_emsg; // always incremented by emsg()
|
|
EXTERN int ex_exitval INIT(= 0); // exit value for ex mode
|
|
EXTERN int emsg_on_display INIT(= FALSE); // there is an error message
|
|
EXTERN int rc_did_emsg INIT(= FALSE); // vim_regcomp() called emsg()
|
|
diff --git a/src/gui.c b/src/gui.c
|
|
index 0a7f346..0d49670 100644
|
|
--- a/src/gui.c
|
|
+++ b/src/gui.c
|
|
@@ -3700,14 +3700,12 @@ get_tabline_label(
|
|
if (**opt != NUL)
|
|
{
|
|
int use_sandbox = FALSE;
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
char_u res[MAXPATHL];
|
|
tabpage_T *save_curtab;
|
|
char_u *opt_name = (char_u *)(tooltip ? "guitabtooltip"
|
|
: "guitablabel");
|
|
|
|
- called_emsg = FALSE;
|
|
-
|
|
printer_page_num = tabpage_index(tp);
|
|
# ifdef FEAT_EVAL
|
|
set_vim_var_nr(VV_LNUM, printer_page_num);
|
|
@@ -3738,10 +3736,9 @@ get_tabline_label(
|
|
curwin = curtab->tp_curwin;
|
|
curbuf = curwin->w_buffer;
|
|
|
|
- if (called_emsg)
|
|
+ if (called_emsg > called_emsg_before)
|
|
set_string_option_direct(opt_name, -1,
|
|
(char_u *)"", OPT_FREE, SID_ERROR);
|
|
- called_emsg |= save_called_emsg;
|
|
}
|
|
|
|
// If 'guitablabel'/'guitabtooltip' is not set or the result is empty then
|
|
diff --git a/src/highlight.c b/src/highlight.c
|
|
index 83d3e21..2ae3160 100644
|
|
--- a/src/highlight.c
|
|
+++ b/src/highlight.c
|
|
@@ -4055,7 +4055,7 @@ next_search_hl(
|
|
linenr_T l;
|
|
colnr_T matchcol;
|
|
long nmatched;
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
|
|
// for :{range}s/pat only highlight inside the range
|
|
if (lnum < search_first_line || lnum > search_last_line)
|
|
@@ -4081,7 +4081,6 @@ next_search_hl(
|
|
* Repeat searching for a match until one is found that includes "mincol"
|
|
* or none is found in this line.
|
|
*/
|
|
- called_emsg = FALSE;
|
|
for (;;)
|
|
{
|
|
# ifdef FEAT_RELTIME
|
|
@@ -4143,7 +4142,7 @@ next_search_hl(
|
|
if (regprog_is_copy)
|
|
cur->match.regprog = cur->hl.rm.regprog;
|
|
|
|
- if (called_emsg || got_int || timed_out)
|
|
+ if (called_emsg > called_emsg_before || got_int || timed_out)
|
|
{
|
|
// Error while handling regexp: stop using this regexp.
|
|
if (shl == search_hl)
|
|
@@ -4176,9 +4175,6 @@ next_search_hl(
|
|
break; // useful match found
|
|
}
|
|
}
|
|
-
|
|
- // Restore called_emsg for assert_fails().
|
|
- called_emsg = save_called_emsg;
|
|
}
|
|
|
|
/*
|
|
diff --git a/src/main.c b/src/main.c
|
|
index 72e51a3..eec02ea 100644
|
|
--- a/src/main.c
|
|
+++ b/src/main.c
|
|
@@ -4140,7 +4140,7 @@ cmdsrv_main(
|
|
if (xterm_dpy != NULL)
|
|
res = serverGetVimNames(xterm_dpy);
|
|
# endif
|
|
- if (called_emsg)
|
|
+ if (did_emsg)
|
|
mch_errmsg("\n");
|
|
}
|
|
else if (STRICMP(argv[i], "--servername") == 0)
|
|
diff --git a/src/message.c b/src/message.c
|
|
index 679a992..35a88df 100644
|
|
--- a/src/message.c
|
|
+++ b/src/message.c
|
|
@@ -581,7 +581,7 @@ ignore_error(char_u *msg)
|
|
#if !defined(HAVE_STRERROR) || defined(PROTO)
|
|
/*
|
|
* Replacement for perror() that behaves more or less like emsg() was called.
|
|
- * v:errmsg will be set and called_emsg will be set.
|
|
+ * v:errmsg will be set and called_emsg will be incremented.
|
|
*/
|
|
void
|
|
do_perror(char *msg)
|
|
@@ -620,7 +620,7 @@ emsg_core(char_u *s)
|
|
return msg_use_printf() ? FALSE : msg((char *)s);
|
|
#endif
|
|
|
|
- called_emsg = TRUE;
|
|
+ ++called_emsg;
|
|
|
|
#ifdef FEAT_EVAL
|
|
/* If "emsg_severe" is TRUE: When an error exception is to be thrown,
|
|
diff --git a/src/regexp.c b/src/regexp.c
|
|
index c2f29c8..37e00b8 100644
|
|
--- a/src/regexp.c
|
|
+++ b/src/regexp.c
|
|
@@ -2561,7 +2561,7 @@ vim_regcomp(char_u *expr_arg, int re_flags)
|
|
{
|
|
regprog_T *prog = NULL;
|
|
char_u *expr = expr_arg;
|
|
- int save_called_emsg;
|
|
+ int called_emsg_before;
|
|
|
|
regexp_engine = p_re;
|
|
|
|
@@ -2597,8 +2597,7 @@ vim_regcomp(char_u *expr_arg, int re_flags)
|
|
/*
|
|
* First try the NFA engine, unless backtracking was requested.
|
|
*/
|
|
- save_called_emsg = called_emsg;
|
|
- called_emsg = FALSE;
|
|
+ called_emsg_before = called_emsg;
|
|
if (regexp_engine != BACKTRACKING_ENGINE)
|
|
prog = nfa_regengine.regcomp(expr,
|
|
re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0));
|
|
@@ -2629,13 +2628,13 @@ vim_regcomp(char_u *expr_arg, int re_flags)
|
|
* but are still valid patterns, thus a retry should work.
|
|
* But don't try if an error message was given.
|
|
*/
|
|
- if (regexp_engine == AUTOMATIC_ENGINE && !called_emsg)
|
|
+ if (regexp_engine == AUTOMATIC_ENGINE
|
|
+ && called_emsg == called_emsg_before)
|
|
{
|
|
regexp_engine = BACKTRACKING_ENGINE;
|
|
prog = bt_regengine.regcomp(expr, re_flags);
|
|
}
|
|
}
|
|
- called_emsg |= save_called_emsg;
|
|
|
|
if (prog != NULL)
|
|
{
|
|
diff --git a/src/search.c b/src/search.c
|
|
index 43b2e98..c3c975e 100644
|
|
--- a/src/search.c
|
|
+++ b/src/search.c
|
|
@@ -624,7 +624,7 @@ searchit(
|
|
long nmatched;
|
|
int submatch = 0;
|
|
int first_match = TRUE;
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
#ifdef FEAT_SEARCH_EXTRA
|
|
int break_loop = FALSE;
|
|
#endif
|
|
@@ -654,7 +654,6 @@ searchit(
|
|
/*
|
|
* find the string
|
|
*/
|
|
- called_emsg = FALSE;
|
|
do // loop for count
|
|
{
|
|
// When not accepting a match at the start position set "extra_col" to
|
|
@@ -745,7 +744,7 @@ searchit(
|
|
#endif
|
|
);
|
|
// Abort searching on an error (e.g., out of stack).
|
|
- if (called_emsg
|
|
+ if (called_emsg > called_emsg_before
|
|
#ifdef FEAT_RELTIME
|
|
|| (timed_out != NULL && *timed_out)
|
|
#endif
|
|
@@ -1055,7 +1054,8 @@ searchit(
|
|
* specified, after an interrupt, after a match and after looping
|
|
* twice.
|
|
*/
|
|
- if (!p_ws || stop_lnum != 0 || got_int || called_emsg
|
|
+ if (!p_ws || stop_lnum != 0 || got_int
|
|
+ || called_emsg > called_emsg_before
|
|
#ifdef FEAT_RELTIME
|
|
|| (timed_out != NULL && *timed_out)
|
|
#endif
|
|
@@ -1082,7 +1082,7 @@ searchit(
|
|
if (extra_arg != NULL)
|
|
extra_arg->sa_wrapped = TRUE;
|
|
}
|
|
- if (got_int || called_emsg
|
|
+ if (got_int || called_emsg > called_emsg_before
|
|
#ifdef FEAT_RELTIME
|
|
|| (timed_out != NULL && *timed_out)
|
|
#endif
|
|
@@ -1096,8 +1096,6 @@ searchit(
|
|
|
|
vim_regfree(regmatch.regprog);
|
|
|
|
- called_emsg |= save_called_emsg;
|
|
-
|
|
if (!found) // did not find it
|
|
{
|
|
if (got_int)
|
|
@@ -4809,7 +4807,7 @@ is_zero_width(char_u *pattern, int move, pos_T *cur, int direction)
|
|
int nmatched = 0;
|
|
int result = -1;
|
|
pos_T pos;
|
|
- int save_called_emsg = called_emsg;
|
|
+ int called_emsg_before = called_emsg;
|
|
int flag = 0;
|
|
|
|
if (pattern == NULL)
|
|
@@ -4838,7 +4836,6 @@ is_zero_width(char_u *pattern, int move, pos_T *cur, int direction)
|
|
{
|
|
// Zero-width pattern should match somewhere, then we can check if
|
|
// start and end are in the same position.
|
|
- called_emsg = FALSE;
|
|
do
|
|
{
|
|
regmatch.startpos[0].col++;
|
|
@@ -4849,7 +4846,7 @@ is_zero_width(char_u *pattern, int move, pos_T *cur, int direction)
|
|
} while (direction == FORWARD ? regmatch.startpos[0].col < pos.col
|
|
: regmatch.startpos[0].col > pos.col);
|
|
|
|
- if (!called_emsg)
|
|
+ if (called_emsg == called_emsg_before)
|
|
{
|
|
result = (nmatched != 0
|
|
&& regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
|
|
@@ -4857,7 +4854,6 @@ is_zero_width(char_u *pattern, int move, pos_T *cur, int direction)
|
|
}
|
|
}
|
|
|
|
- called_emsg |= save_called_emsg;
|
|
vim_regfree(regmatch.regprog);
|
|
return result;
|
|
}
|
|
diff --git a/src/testing.c b/src/testing.c
|
|
index f19481f..c0360e5 100644
|
|
--- a/src/testing.c
|
|
+++ b/src/testing.c
|
|
@@ -424,15 +424,15 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
|
|
char_u *cmd = tv_get_string_chk(&argvars[0]);
|
|
garray_T ga;
|
|
int save_trylevel = trylevel;
|
|
+ int called_emsg_before = called_emsg;
|
|
|
|
// trylevel must be zero for a ":throw" command to be considered failed
|
|
trylevel = 0;
|
|
- called_emsg = FALSE;
|
|
suppress_errthrow = TRUE;
|
|
emsg_silent = TRUE;
|
|
|
|
do_cmdline_cmd(cmd);
|
|
- if (!called_emsg)
|
|
+ if (called_emsg == called_emsg_before)
|
|
{
|
|
prepare_assert_error(&ga);
|
|
ga_concat(&ga, (char_u *)"command did not fail: ");
|
|
@@ -461,7 +461,6 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
|
|
}
|
|
|
|
trylevel = save_trylevel;
|
|
- called_emsg = FALSE;
|
|
suppress_errthrow = FALSE;
|
|
emsg_silent = FALSE;
|
|
emsg_on_display = FALSE;
|
|
--
|
|
2.33.0
|
|
|