Patch 8.2.0035
Problem:    Saving and restoring called_emsg is clumsy.
Solution:   Count the number of error messages.
Files:      src/message.c, src/buffer.c, src/channel.c, src/drawscreen.c,
            src/ex_cmds2.c, src/gui.c, src/highlight.c, src/main.c,
            src/regexp.c, src/search.c, src/testing.c, src/globals.h


*** ../vim-8.2.0034/src/message.c       2019-12-21 18:25:50.453560468 +0100
--- src/message.c       2019-12-23 22:42:09.551865028 +0100
***************
*** 581,587 ****
  #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.
   */
      void
  do_perror(char *msg)
--- 581,587 ----
  #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 incremented.
   */
      void
  do_perror(char *msg)
***************
*** 620,626 ****
        return msg_use_printf() ? FALSE : msg((char *)s);
  #endif
  
!     called_emsg = TRUE;
  
  #ifdef FEAT_EVAL
      // If "emsg_severe" is TRUE: When an error exception is to be thrown,
--- 620,626 ----
        return msg_use_printf() ? FALSE : msg((char *)s);
  #endif
  
!     ++called_emsg;
  
  #ifdef FEAT_EVAL
      // If "emsg_severe" is TRUE: When an error exception is to be thrown,
*** ../vim-8.2.0034/src/buffer.c        2019-12-14 16:18:11.574458417 +0100
--- src/buffer.c        2019-12-23 22:43:20.603634830 +0100
***************
*** 3746,3764 ****
            if (stl_syntax & STL_IN_TITLE)
            {
                int     use_sandbox = FALSE;
!               int     save_called_emsg = 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)
                    set_string_option_direct((char_u *)"titlestring", -1,
                                           (char_u *)"", OPT_FREE, SID_ERROR);
-               called_emsg |= save_called_emsg;
            }
            else
  #endif
--- 3746,3762 ----
            if (stl_syntax & STL_IN_TITLE)
            {
                int     use_sandbox = FALSE;
!               int     called_emsg_before = called_emsg;
  
  # ifdef FEAT_EVAL
                use_sandbox = was_set_insecurely((char_u *)"titlestring", 0);
  # endif
                build_stl_str_hl(curwin, title_str, sizeof(buf),
                                              p_titlestring, use_sandbox,
                                              0, maxlen, NULL, NULL);
!               if (called_emsg > called_emsg_before)
                    set_string_option_direct((char_u *)"titlestring", -1,
                                           (char_u *)"", OPT_FREE, SID_ERROR);
            }
            else
  #endif
***************
*** 3879,3897 ****
            if (stl_syntax & STL_IN_ICON)
            {
                int     use_sandbox = FALSE;
!               int     save_called_emsg = 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)
                    set_string_option_direct((char_u *)"iconstring", -1,
                                           (char_u *)"", OPT_FREE, SID_ERROR);
-               called_emsg |= save_called_emsg;
            }
            else
  #endif
--- 3877,3893 ----
            if (stl_syntax & STL_IN_ICON)
            {
                int     use_sandbox = FALSE;
!               int     called_emsg_before = called_emsg;
  
  # ifdef FEAT_EVAL
                use_sandbox = was_set_insecurely((char_u *)"iconstring", 0);
  # endif
                build_stl_str_hl(curwin, icon_str, sizeof(buf),
                                                    p_iconstring, use_sandbox,
                                                    0, 0, NULL, NULL);
!               if (called_emsg > called_emsg_before)
                    set_string_option_direct((char_u *)"iconstring", -1,
                                           (char_u *)"", OPT_FREE, SID_ERROR);
            }
            else
  #endif
*** ../vim-8.2.0034/src/channel.c       2019-12-22 18:28:48.252481062 +0100
--- src/channel.c       2019-12-23 22:43:42.931562222 +0100
***************
*** 2370,2386 ****
  
      if (STRCMP(cmd, "ex") == 0)
      {
!       int save_called_emsg = 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)
            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)
      {
--- 2370,2384 ----
  
      if (STRCMP(cmd, "ex") == 0)
      {
!       int called_emsg_before = called_emsg;
  
        ch_log(channel, "Executing ex command '%s'", (char *)arg);
        ++emsg_silent;
        do_cmdline_cmd(arg);
        --emsg_silent;
!       if (called_emsg > called_emsg_before)
            ch_log(channel, "Ex command error: '%s'",
                                          (char *)get_vim_var_str(VV_ERRMSG));
      }
      else if (STRCMP(cmd, "normal") == 0)
      {
*** ../vim-8.2.0034/src/drawscreen.c    2019-11-30 22:40:44.000000000 +0100
--- src/drawscreen.c    2019-12-23 22:44:14.631458953 +0100
***************
*** 650,663 ****
  #ifdef FEAT_STL_OPT
      if (*p_ruf)
      {
!       int     save_called_emsg = called_emsg;
  
-       called_emsg = FALSE;
        win_redr_custom(wp, TRUE);
!       if (called_emsg)
            set_string_option_direct((char_u *)"rulerformat", -1,
                                           (char_u *)"", OPT_FREE, SID_ERROR);
-       called_emsg |= save_called_emsg;
        return;
      }
  #endif
--- 650,661 ----
  #ifdef FEAT_STL_OPT
      if (*p_ruf)
      {
!       int     called_emsg_before = called_emsg;
  
        win_redr_custom(wp, TRUE);
!       if (called_emsg > called_emsg_before)
            set_string_option_direct((char_u *)"rulerformat", -1,
                                           (char_u *)"", OPT_FREE, SID_ERROR);
        return;
      }
  #endif
*** ../vim-8.2.0034/src/ex_cmds2.c      2019-12-01 21:24:22.000000000 +0100
--- src/ex_cmds2.c      2019-12-23 22:45:35.319195204 +0100
***************
*** 167,173 ****
            // the current scope, such as being inside a try/catch.
            timer_busy = timer_busy > 0 || vgetc_busy > 0;
            vgetc_busy = 0;
!           called_emsg = FALSE;
            did_emsg = FALSE;
            did_uncaught_emsg = FALSE;
            must_redraw = 0;
--- 167,173 ----
            // the current scope, such as being inside a try/catch.
            timer_busy = timer_busy > 0 || vgetc_busy > 0;
            vgetc_busy = 0;
!           called_emsg = 0;
            did_emsg = FALSE;
            did_uncaught_emsg = FALSE;
            must_redraw = 0;
*** ../vim-8.2.0034/src/gui.c   2019-12-18 21:33:19.276859673 +0100
--- src/gui.c   2019-12-23 22:46:10.947078337 +0100
***************
*** 3704,3717 ****
      if (**opt != NUL)
      {
        int     use_sandbox = FALSE;
!       int     save_called_emsg = 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);
--- 3704,3715 ----
      if (**opt != NUL)
      {
        int     use_sandbox = FALSE;
!       int     called_emsg_before = called_emsg;
        char_u  res[MAXPATHL];
        tabpage_T *save_curtab;
        char_u  *opt_name = (char_u *)(tooltip ? "guitabtooltip"
                                                             : "guitablabel");
  
        printer_page_num = tabpage_index(tp);
  # ifdef FEAT_EVAL
        set_vim_var_nr(VV_LNUM, printer_page_num);
***************
*** 3742,3751 ****
        curwin = curtab->tp_curwin;
        curbuf = curwin->w_buffer;
  
!       if (called_emsg)
            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
--- 3740,3748 ----
        curwin = curtab->tp_curwin;
        curbuf = curwin->w_buffer;
  
!       if (called_emsg > called_emsg_before)
            set_string_option_direct(opt_name, -1,
                                           (char_u *)"", OPT_FREE, SID_ERROR);
      }
  
      // If 'guitablabel'/'guitabtooltip' is not set or the result is empty then
*** ../vim-8.2.0034/src/highlight.c     2019-12-05 18:33:11.000000000 +0100
--- src/highlight.c     2019-12-23 22:47:03.090906901 +0100
***************
*** 4055,4061 ****
      linenr_T  l;
      colnr_T   matchcol;
      long      nmatched;
!     int               save_called_emsg = called_emsg;
  
      // for :{range}s/pat only highlight inside the range
      if (lnum < search_first_line || lnum > search_last_line)
--- 4055,4061 ----
      linenr_T  l;
      colnr_T   matchcol;
      long      nmatched;
!     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,4087 ****
       * 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
--- 4081,4086 ----
***************
*** 4143,4149 ****
            if (regprog_is_copy)
                cur->match.regprog = cur->hl.rm.regprog;
  
!           if (called_emsg || got_int || timed_out)
            {
                // Error while handling regexp: stop using this regexp.
                if (shl == search_hl)
--- 4142,4148 ----
            if (regprog_is_copy)
                cur->match.regprog = cur->hl.rm.regprog;
  
!           if (called_emsg > called_emsg_before || got_int || timed_out)
            {
                // Error while handling regexp: stop using this regexp.
                if (shl == search_hl)
***************
*** 4176,4184 ****
            break;                      // useful match found
        }
      }
- 
-     // Restore called_emsg for assert_fails().
-     called_emsg = save_called_emsg;
  }
  
  /*
--- 4175,4180 ----
*** ../vim-8.2.0034/src/main.c  2019-12-09 23:00:49.000000000 +0100
--- src/main.c  2019-12-23 22:47:40.362784102 +0100
***************
*** 4140,4146 ****
            if (xterm_dpy != NULL)
                res = serverGetVimNames(xterm_dpy);
  # endif
!           if (called_emsg)
                mch_errmsg("\n");
        }
        else if (STRICMP(argv[i], "--servername") == 0)
--- 4140,4146 ----
            if (xterm_dpy != NULL)
                res = serverGetVimNames(xterm_dpy);
  # endif
!           if (did_emsg)
                mch_errmsg("\n");
        }
        else if (STRICMP(argv[i], "--servername") == 0)
*** ../vim-8.2.0034/src/regexp.c        2019-12-05 21:09:56.000000000 +0100
--- src/regexp.c        2019-12-23 22:48:53.138543793 +0100
***************
*** 2556,2562 ****
  {
      regprog_T   *prog = NULL;
      char_u    *expr = expr_arg;
!     int               save_called_emsg;
  
      regexp_engine = p_re;
  
--- 2556,2562 ----
  {
      regprog_T   *prog = NULL;
      char_u    *expr = expr_arg;
!     int               called_emsg_before;
  
      regexp_engine = p_re;
  
***************
*** 2592,2599 ****
      /*
       * First try the NFA engine, unless backtracking was requested.
       */
!     save_called_emsg = called_emsg;
!     called_emsg = FALSE;
      if (regexp_engine != BACKTRACKING_ENGINE)
        prog = nfa_regengine.regcomp(expr,
                re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0));
--- 2592,2598 ----
      /*
       * First try the NFA engine, unless backtracking was requested.
       */
!     called_emsg_before = called_emsg;
      if (regexp_engine != BACKTRACKING_ENGINE)
        prog = nfa_regengine.regcomp(expr,
                re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0));
***************
*** 2624,2636 ****
         * 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)
        {
            regexp_engine = BACKTRACKING_ENGINE;
            prog = bt_regengine.regcomp(expr, re_flags);
        }
      }
-     called_emsg |= save_called_emsg;
  
      if (prog != NULL)
      {
--- 2623,2635 ----
         * 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 == called_emsg_before)
        {
            regexp_engine = BACKTRACKING_ENGINE;
            prog = bt_regengine.regcomp(expr, re_flags);
        }
      }
  
      if (prog != NULL)
      {
*** ../vim-8.2.0034/src/search.c        2019-12-05 21:07:47.000000000 +0100
--- src/search.c        2019-12-23 22:50:32.378215085 +0100
***************
*** 624,630 ****
      long      nmatched;
      int               submatch = 0;
      int               first_match = TRUE;
!     int               save_called_emsg = called_emsg;
  #ifdef FEAT_SEARCH_EXTRA
      int               break_loop = FALSE;
  #endif
--- 624,630 ----
      long      nmatched;
      int               submatch = 0;
      int               first_match = TRUE;
!     int               called_emsg_before = called_emsg;
  #ifdef FEAT_SEARCH_EXTRA
      int               break_loop = FALSE;
  #endif
***************
*** 654,660 ****
      /*
       * find the string
       */
-     called_emsg = FALSE;
      do        // loop for count
      {
        // When not accepting a match at the start position set "extra_col" to
--- 654,659 ----
***************
*** 745,751 ****
  #endif
                                                      );
                // Abort searching on an error (e.g., out of stack).
!               if (called_emsg
  #ifdef FEAT_RELTIME
                        || (timed_out != NULL && *timed_out)
  #endif
--- 744,750 ----
  #endif
                                                      );
                // Abort searching on an error (e.g., out of stack).
!               if (called_emsg > called_emsg_before
  #ifdef FEAT_RELTIME
                        || (timed_out != NULL && *timed_out)
  #endif
***************
*** 1055,1061 ****
             * specified, after an interrupt, after a match and after looping
             * twice.
             */
!           if (!p_ws || stop_lnum != 0 || got_int || called_emsg
  #ifdef FEAT_RELTIME
                                || (timed_out != NULL && *timed_out)
  #endif
--- 1054,1061 ----
             * specified, after an interrupt, after a match and after looping
             * twice.
             */
!           if (!p_ws || stop_lnum != 0 || got_int
!                                           || called_emsg > called_emsg_before
  #ifdef FEAT_RELTIME
                                || (timed_out != NULL && *timed_out)
  #endif
***************
*** 1082,1088 ****
            if (extra_arg != NULL)
                extra_arg->sa_wrapped = TRUE;
        }
!       if (got_int || called_emsg
  #ifdef FEAT_RELTIME
                || (timed_out != NULL && *timed_out)
  #endif
--- 1082,1088 ----
            if (extra_arg != NULL)
                extra_arg->sa_wrapped = TRUE;
        }
!       if (got_int || called_emsg > called_emsg_before
  #ifdef FEAT_RELTIME
                || (timed_out != NULL && *timed_out)
  #endif
***************
*** 1096,1103 ****
  
      vim_regfree(regmatch.regprog);
  
-     called_emsg |= save_called_emsg;
- 
      if (!found)                   // did not find it
      {
        if (got_int)
--- 1096,1101 ----
***************
*** 4799,4805 ****
      int               nmatched = 0;
      int               result = -1;
      pos_T     pos;
!     int               save_called_emsg = called_emsg;
      int               flag = 0;
  
      if (pattern == NULL)
--- 4797,4803 ----
      int               nmatched = 0;
      int               result = -1;
      pos_T     pos;
!     int               called_emsg_before = called_emsg;
      int               flag = 0;
  
      if (pattern == NULL)
***************
*** 4828,4834 ****
      {
        // 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++;
--- 4826,4831 ----
***************
*** 4839,4845 ****
        } while (direction == FORWARD ? regmatch.startpos[0].col < pos.col
                                      : regmatch.startpos[0].col > pos.col);
  
!       if (!called_emsg)
        {
            result = (nmatched != 0
                && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
--- 4836,4842 ----
        } while (direction == FORWARD ? regmatch.startpos[0].col < pos.col
                                      : regmatch.startpos[0].col > pos.col);
  
!       if (called_emsg == called_emsg_before)
        {
            result = (nmatched != 0
                && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
***************
*** 4847,4853 ****
        }
      }
  
-     called_emsg |= save_called_emsg;
      vim_regfree(regmatch.regprog);
      return result;
  }
--- 4844,4849 ----
*** ../vim-8.2.0034/src/testing.c       2019-12-05 21:32:23.000000000 +0100
--- src/testing.c       2019-12-23 22:51:30.262022789 +0100
***************
*** 424,438 ****
      char_u    *cmd = tv_get_string_chk(&argvars[0]);
      garray_T  ga;
      int               save_trylevel = trylevel;
  
      // 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)
      {
        prepare_assert_error(&ga);
        ga_concat(&ga, (char_u *)"command did not fail: ");
--- 424,438 ----
      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;
      suppress_errthrow = TRUE;
      emsg_silent = TRUE;
  
      do_cmdline_cmd(cmd);
!     if (called_emsg == called_emsg_before)
      {
        prepare_assert_error(&ga);
        ga_concat(&ga, (char_u *)"command did not fail: ");
***************
*** 461,467 ****
      }
  
      trylevel = save_trylevel;
-     called_emsg = FALSE;
      suppress_errthrow = FALSE;
      emsg_silent = FALSE;
      emsg_on_display = FALSE;
--- 461,466 ----
*** ../vim-8.2.0034/src/globals.h       2019-12-22 15:38:02.346438575 +0100
--- src/globals.h       2019-12-23 22:51:49.829957716 +0100
***************
*** 226,232 ****
  #endif
  EXTERN int    did_emsg_syntax;            // did_emsg set because of a
                                            // syntax error
! EXTERN int    called_emsg;                // always set 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()
--- 226,232 ----
  #endif
  EXTERN int    did_emsg_syntax;            // did_emsg set because of a
                                            // syntax error
! 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()
*** ../vim-8.2.0034/src/version.c       2019-12-23 18:18:36.616536002 +0100
--- src/version.c       2019-12-23 22:41:35.219975748 +0100
***************
*** 744,745 ****
--- 744,747 ----
  {   /* Add new patch number below this line */
+ /**/
+     35,
  /**/

-- 
    [clop clop]
GUARD #1:  Halt!  Who goes there?
ARTHUR:    It is I, Arthur, son of Uther Pendragon, from the castle of
           Camelot.  King of the Britons, defeator of the Saxons, sovereign of
           all England!
GUARD #1:  Pull the other one!
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201912232159.xBNLxmMQ011800%40masaka.moolenaar.net.

Raspunde prin e-mail lui