Patch 9.0.0844
Problem:    Handling 'statusline' errors is spread out.
Solution:   Pass the option name to the lower levels so the option can be
            reset there when an error is encountered. (Luuk van Baal,
            closes #11467)
Files:      src/buffer.c, src/proto/buffer.pro, src/drawscreen.c, src/gui.c,
            src/hardcopy.c, src/screen.c


*** ../vim-9.0.0843/src/buffer.c        2022-10-29 19:54:03.849448379 +0100
--- src/buffer.c        2022-11-07 12:14:56.053760004 +0000
***************
*** 3959,3978 ****
        {
  #ifdef FEAT_STL_OPT
            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
                title_str = p_titlestring;
--- 3959,3967 ----
        {
  #ifdef FEAT_STL_OPT
            if (stl_syntax & STL_IN_TITLE)
!               build_stl_str_hl(curwin, title_str, sizeof(buf), p_titlestring,
!                                   (char_u *)"titlestring", 0,
!                                   0, maxlen, NULL, NULL);
            else
  #endif
                title_str = p_titlestring;
***************
*** 4090,4109 ****
        {
  #ifdef FEAT_STL_OPT
            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
                icon_str = p_iconstring;
--- 4079,4086 ----
        {
  #ifdef FEAT_STL_OPT
            if (stl_syntax & STL_IN_ICON)
!               build_stl_str_hl(curwin, icon_str, sizeof(buf), p_iconstring,
!                                (char_u *)"iconstring", 0, 0, 0, NULL, NULL);
            else
  #endif
                icon_str = p_iconstring;
***************
*** 4228,4234 ****
      char_u    *out,           // buffer to write into != NameBuff
      size_t    outlen,         // length of out[]
      char_u    *fmt,
!     int               use_sandbox UNUSED, // "fmt" was set insecurely, use 
sandbox
      int               fillchar,
      int               maxwidth,
      stl_hlrec_T **hltab,      // return: HL attributes (can be NULL)
--- 4205,4212 ----
      char_u    *out,           // buffer to write into != NameBuff
      size_t    outlen,         // length of out[]
      char_u    *fmt,
!     char_u    *opt_name,      // option name corresponding to "fmt"
!     int               opt_scope,      // scope for "opt_name"
      int               fillchar,
      int               maxwidth,
      stl_hlrec_T **hltab,      // return: HL attributes (can be NULL)
***************
*** 4241,4246 ****
--- 4219,4225 ----
      char_u    *t;
      int               byteval;
  #ifdef FEAT_EVAL
+     int               use_sandbox;
      win_T     *save_curwin;
      buf_T     *save_curbuf;
      int               save_VIsual_active;
***************
*** 4276,4281 ****
--- 4255,4264 ----
      stl_hlrec_T *sp;
      int               save_redraw_not_allowed = redraw_not_allowed;
      int               save_KeyTyped = KeyTyped;
+     // TODO: find out why using called_emsg_before makes tests fail, does it
+     // matter?
+     // int    called_emsg_before = called_emsg;
+     int               did_emsg_before = did_emsg;
  
      // When inside update_screen() we do not want redrawing a statusline,
      // ruler, title, etc. to trigger another redraw, it may cause an endless
***************
*** 4295,4304 ****
      }
  
  #ifdef FEAT_EVAL
!     /*
!      * When the format starts with "%!" then evaluate it as an expression and
!      * use the result as the actual format string.
!      */
      if (fmt[0] == '%' && fmt[1] == '!')
      {
        typval_T        tv;
--- 4278,4288 ----
      }
  
  #ifdef FEAT_EVAL
!     // if "fmt" was set insecurely it needs to be evaluated in the sandbox
!     use_sandbox = was_set_insecurely(opt_name, opt_scope);
! 
!     // When the format starts with "%!" then evaluate it as an expression and
!     // use the result as the actual format string.
      if (fmt[0] == '%' && fmt[1] == '!')
      {
        typval_T        tv;
***************
*** 5181,5186 ****
--- 5165,5180 ----
      // A user function may reset KeyTyped, restore it.
      KeyTyped = save_KeyTyped;
  
+     // Check for an error.  If there is one the display will be messed up and
+     // might loop redrawing.  Avoid that by making the corresponding option
+     // empty.
+     // TODO: find out why using called_emsg_before makes tests fail, does it
+     // matter?
+     // if (called_emsg > called_emsg_before)
+     if (did_emsg > did_emsg_before)
+       set_string_option_direct(opt_name, -1, (char_u *)"",
+                                             OPT_FREE | opt_scope, SID_ERROR);
+ 
      return width;
  }
  #endif // FEAT_STL_OPT
*** ../vim-9.0.0843/src/proto/buffer.pro        2022-06-27 23:14:56.000000000 
+0100
--- src/proto/buffer.pro        2022-11-07 11:53:10.237790991 +0000
***************
*** 1,7 ****
  /* buffer.c */
  int get_highest_fnum(void);
  void buffer_ensure_loaded(buf_T *buf);
! int open_buffer(int read_stdin, exarg_T *eap, int flags);
  void set_bufref(bufref_T *bufref, buf_T *buf);
  int bufref_valid(bufref_T *bufref);
  int buf_valid(buf_T *buf);
--- 1,7 ----
  /* buffer.c */
  int get_highest_fnum(void);
  void buffer_ensure_loaded(buf_T *buf);
! int open_buffer(int read_stdin, exarg_T *eap, int flags_arg);
  void set_bufref(bufref_T *bufref, buf_T *buf);
  int bufref_valid(bufref_T *bufref);
  int buf_valid(buf_T *buf);
***************
*** 48,54 ****
  void maketitle(void);
  void resettitle(void);
  void free_titles(void);
! int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int 
use_sandbox, int fillchar, int maxwidth, stl_hlrec_T **hltab, stl_hlrec_T 
**tabtab);
  void get_rel_pos(win_T *wp, char_u *buf, int buflen);
  char_u *fix_fname(char_u *fname);
  void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname);
--- 48,54 ----
  void maketitle(void);
  void resettitle(void);
  void free_titles(void);
! int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, 
char_u *opt_name, int opt_scope, int fillchar, int maxwidth, stl_hlrec_T 
**hltab, stl_hlrec_T **tabtab);
  void get_rel_pos(win_T *wp, char_u *buf, int buflen);
  char_u *fix_fname(char_u *fname);
  void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname);
*** ../vim-9.0.0843/src/drawscreen.c    2022-10-14 17:04:05.891675444 +0100
--- src/drawscreen.c    2022-11-07 11:32:01.053839159 +0000
***************
*** 573,579 ****
  redraw_custom_statusline(win_T *wp)
  {
      static int            entered = FALSE;
-     int                   saved_did_emsg = did_emsg;
  
      // When called recursively return.  This can happen when the statusline
      // contains an expression that triggers a redraw.
--- 573,578 ----
***************
*** 581,598 ****
        return;
      entered = TRUE;
  
-     did_emsg = FALSE;
      win_redr_custom(wp, FALSE);
-     if (did_emsg)
-     {
-       // When there is an error disable the statusline, otherwise the
-       // display is messed up with errors and a redraw triggers the problem
-       // again and again.
-       set_string_option_direct((char_u *)"statusline", -1,
-               (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL
-                                       ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
-     }
-     did_emsg |= saved_did_emsg;
      entered = FALSE;
  }
  #endif
--- 580,586 ----
***************
*** 673,684 ****
  #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
--- 661,667 ----
*** ../vim-9.0.0843/src/gui.c   2022-11-06 11:27:35.890580888 +0000
--- src/gui.c   2022-11-07 11:32:01.053839159 +0000
***************
*** 3763,3770 ****
      opt = (tooltip ? &p_gtt : &p_gtl);
      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"
--- 3763,3768 ----
***************
*** 3773,3779 ****
        printer_page_num = tabpage_index(tp);
  # ifdef FEAT_EVAL
        set_vim_var_nr(VV_LNUM, printer_page_num);
-       use_sandbox = was_set_insecurely(opt_name, 0);
  # endif
        // It's almost as going to the tabpage, but without autocommands.
        curtab->tp_firstwin = firstwin;
--- 3771,3776 ----
***************
*** 3788,3794 ****
        curbuf = curwin->w_buffer;
  
        // Can't use NameBuff directly, build_stl_str_hl() uses it.
!       build_stl_str_hl(curwin, res, MAXPATHL, *opt, use_sandbox,
                                                 0, (int)Columns, NULL, NULL);
        STRCPY(NameBuff, res);
  
--- 3785,3791 ----
        curbuf = curwin->w_buffer;
  
        // Can't use NameBuff directly, build_stl_str_hl() uses it.
!       build_stl_str_hl(curwin, res, MAXPATHL, *opt, opt_name, 0,
                                                 0, (int)Columns, NULL, NULL);
        STRCPY(NameBuff, res);
  
***************
*** 3799,3808 ****
        lastwin = curtab->tp_lastwin;
        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
--- 3796,3801 ----
*** ../vim-9.0.0843/src/hardcopy.c      2022-06-29 18:39:05.015841419 +0100
--- src/hardcopy.c      2022-11-07 11:47:32.093847114 +0000
***************
*** 471,477 ****
      if (*p_header != NUL)
      {
        linenr_T        tmp_lnum, tmp_topline, tmp_botline;
-       int             use_sandbox = FALSE;
  
        /*
         * Need to (temporarily) set current line number and first/last line
--- 471,476 ----
***************
*** 487,498 ****
        curwin->w_botline = lnum + 63;
        printer_page_num = pagenum;
  
! # ifdef FEAT_EVAL
!       use_sandbox = was_set_insecurely((char_u *)"printheader", 0);
! # endif
!       build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE),
!                                                 p_header, use_sandbox,
!                                                 ' ', width, NULL, NULL);
  
        // Reset line numbers
        curwin->w_cursor.lnum = tmp_lnum;
--- 486,493 ----
        curwin->w_botline = lnum + 63;
        printer_page_num = pagenum;
  
!       build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE), p_header,
!                          (char_u *)"printheader", 0, ' ', width, NULL, NULL);
  
        // Reset line numbers
        curwin->w_cursor.lnum = tmp_lnum;
*** ../vim-9.0.0843/src/screen.c        2022-11-02 13:30:37.538314551 +0000
--- src/screen.c        2022-11-07 11:51:58.397799678 +0000
***************
*** 1284,1292 ****
      char_u    buf[MAXPATHL];
      char_u    *stl;
      char_u    *p;
      stl_hlrec_T *hltab;
      stl_hlrec_T *tabtab;
-     int               use_sandbox = FALSE;
      win_T     *ewp;
      int               p_crb_save;
  
--- 1284,1293 ----
      char_u    buf[MAXPATHL];
      char_u    *stl;
      char_u    *p;
+     char_u    *opt_name;
+     int         opt_scope = 0;
      stl_hlrec_T *hltab;
      stl_hlrec_T *tabtab;
      win_T     *ewp;
      int               p_crb_save;
  
***************
*** 1306,1314 ****
        fillchar = ' ';
        attr = HL_ATTR(HLF_TPF);
        maxwidth = Columns;
! # ifdef FEAT_EVAL
!       use_sandbox = was_set_insecurely((char_u *)"tabline", 0);
! # endif
      }
      else
      {
--- 1307,1313 ----
        fillchar = ' ';
        attr = HL_ATTR(HLF_TPF);
        maxwidth = Columns;
!       opt_name = (char_u *)"tabline";
      }
      else
      {
***************
*** 1319,1324 ****
--- 1318,1324 ----
        if (draw_ruler)
        {
            stl = p_ruf;
+           opt_name = (char_u *)"rulerformat";
            // advance past any leading group spec - implicit in ru_col
            if (*stl == '%')
            {
***************
*** 1341,1361 ****
                fillchar = ' ';
                attr = 0;
            }
- 
- # ifdef FEAT_EVAL
-           use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0);
- # endif
        }
        else
        {
            if (*wp->w_p_stl != NUL)
                stl = wp->w_p_stl;
            else
                stl = p_stl;
- # ifdef FEAT_EVAL
-           use_sandbox = was_set_insecurely((char_u *)"statusline",
-                                        *wp->w_p_stl == NUL ? 0 : OPT_LOCAL);
- # endif
        }
  
        col += wp->w_wincol;
--- 1341,1357 ----
                fillchar = ' ';
                attr = 0;
            }
        }
        else
        {
+           opt_name = (char_u *)"statusline";
            if (*wp->w_p_stl != NUL)
+           {
                stl = wp->w_p_stl;
+               opt_scope = OPT_LOCAL;
+           }
            else
                stl = p_stl;
        }
  
        col += wp->w_wincol;
***************
*** 1374,1380 ****
      // might change the option value and free the memory.
      stl = vim_strsave(stl);
      width = build_stl_str_hl(ewp, buf, sizeof(buf),
!                               stl, use_sandbox,
                                fillchar, maxwidth, &hltab, &tabtab);
      vim_free(stl);
      ewp->w_p_crb = p_crb_save;
--- 1370,1376 ----
      // might change the option value and free the memory.
      stl = vim_strsave(stl);
      width = build_stl_str_hl(ewp, buf, sizeof(buf),
!                               stl, opt_name, opt_scope,
                                fillchar, maxwidth, &hltab, &tabtab);
      vim_free(stl);
      ewp->w_p_crb = p_crb_save;
***************
*** 4547,4564 ****
  
      // Use the 'tabline' option if it's set.
      if (*p_tal != NUL)
-     {
-       int     saved_did_emsg = did_emsg;
- 
-       // Check for an error.  If there is one we would loop in redrawing the
-       // screen.  Avoid that by making 'tabline' empty.
-       did_emsg = FALSE;
        win_redr_custom(NULL, FALSE);
-       if (did_emsg)
-           set_string_option_direct((char_u *)"tabline", -1,
-                                          (char_u *)"", OPT_FREE, SID_ERROR);
-       did_emsg |= saved_did_emsg;
-     }
      else
  #endif
      {
--- 4543,4549 ----
*** ../vim-9.0.0843/src/version.c       2022-11-07 11:17:24.381584835 +0000
--- src/version.c       2022-11-07 11:36:20.577876030 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     844,
  /**/

-- 
"Space is big.  Really big.  You just won't believe how vastly hugely mind-
bogglingly big it is.  I mean, you may think it's a long way down the
road to the chemist, but that's just peanuts to space."
                -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/20221107121750.0D5A61C0739%40moolenaar.net.

Raspunde prin e-mail lui