]> granicus.if.org Git - vim/commitdiff
patch 8.2.2581: Vim9: sourcing Vim9 script triggers a redraw v8.2.2581
authorBram Moolenaar <Bram@vim.org>
Wed, 10 Mar 2021 12:40:08 +0000 (13:40 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 10 Mar 2021 12:40:08 +0000 (13:40 +0100)
Problem:    Vim9: sourcing Vim9 script triggers a redraw.
Solution:   Do not let setting/restoring 'cpoptions' cause a redraw.
            (closes #7920)

src/option.c
src/optionstr.c
src/scriptfile.c
src/testdir/dumps/Test_vim9_no_redraw.dump [new file with mode: 0644]
src/testdir/test_vim9_script.vim
src/version.c
src/vim.h
src/vim9script.c

index 9db9c2633f15db9a9128fb166805fc4937647518..b9d7edbbb05122a951ec6960e50c22a1fd8a6d77 100644 (file)
@@ -3176,7 +3176,9 @@ set_bool_option(
     if (curwin->w_curswant != MAXCOL
                     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
        curwin->w_set_curswant = TRUE;
-    check_redraw(options[opt_idx].flags);
+
+    if ((opt_flags & OPT_NO_REDRAW) == 0)
+       check_redraw(options[opt_idx].flags);
 
     return NULL;
 }
@@ -3192,8 +3194,8 @@ set_num_option(
     long       value,                  // new value
     char       *errbuf,                // buffer for error messages
     size_t     errbuflen,              // length of "errbuf"
-    int                opt_flags)              // OPT_LOCAL, OPT_GLOBAL and
-                                       // OPT_MODELINE
+    int                opt_flags)              // OPT_LOCAL, OPT_GLOBAL,
+                                       // OPT_MODELINE, etc.
 {
     char       *errmsg = NULL;
     long       old_value = *(long *)varp;
@@ -3734,7 +3736,8 @@ set_num_option(
     if (curwin->w_curswant != MAXCOL
                     && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
        curwin->w_set_curswant = TRUE;
-    check_redraw(options[opt_idx].flags);
+    if ((opt_flags & OPT_NO_REDRAW) == 0)
+       check_redraw(options[opt_idx].flags);
 
     return errmsg;
 }
index a1cbe262f4b9047cb5020e7d970d8db2a602a41a..521242dbcbcebac4526f654cd3c8e3e8f9933d73 100644 (file)
@@ -2461,11 +2461,14 @@ ambw_end:
                   && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0)
        curwin->w_set_curswant = TRUE;
 
+    if ((opt_flags & OPT_NO_REDRAW) == 0)
+    {
 #ifdef FEAT_GUI
-    // check redraw when it's not a GUI option or the GUI is active.
-    if (!redraw_gui_only || gui.in_use)
+       // check redraw when it's not a GUI option or the GUI is active.
+       if (!redraw_gui_only || gui.in_use)
 #endif
-       check_redraw(get_option_flags(opt_idx));
+           check_redraw(get_option_flags(opt_idx));
+    }
 
 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
     if (did_swaptcap)
index 82ae42a1a63c4ba0c43fb95dac7f19f843a5dd80..1e4b5ccf7efa5af4b6b9628880f012d358e227f4 100644 (file)
@@ -1459,7 +1459,7 @@ almosttheend:
     si = SCRIPT_ITEM(current_sctx.sc_sid);
     if (si->sn_save_cpo != NULL)
     {
-       set_option_value((char_u *)"cpo", 0L, si->sn_save_cpo, 0);
+       set_option_value((char_u *)"cpo", 0L, si->sn_save_cpo, OPT_NO_REDRAW);
        VIM_CLEAR(si->sn_save_cpo);
     }
 
diff --git a/src/testdir/dumps/Test_vim9_no_redraw.dump b/src/testdir/dumps/Test_vim9_no_redraw.dump
new file mode 100644 (file)
index 0000000..1d77a08
--- /dev/null
@@ -0,0 +1,6 @@
+|s+0&#ffffff0|o+0&#e0e0e08|m|e| |t|e|x|t| | +0&#ffffff0@64
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|:+0#0000000&|'|<|,|'|>> @68
index 32312b0a2ac4aee71667e6250022ca3a71bcd306..58a72efbb50c5ae5f4ed6881774b856c65aff3eb 100644 (file)
@@ -5,6 +5,7 @@ source term_util.vim
 source view_util.vim
 source vim9.vim
 source shared.vim
+source screendump.vim
 
 def Test_range_only()
   new
@@ -3338,6 +3339,36 @@ def Test_restoring_cpo()
   set cpo&vim
 enddef
 
+def Test_no_redraw_when_restoring_cpo()
+  CheckScreendump
+
+  var lines =<< trim END
+    vim9script
+    def script#func()
+    enddef
+  END
+  mkdir('Xdir/autoload', 'p')
+  writefile(lines, 'Xdir/autoload/script.vim')
+
+  lines =<< trim END
+      vim9script
+      set cpo+=M
+      exe 'set rtp^=' .. getcwd() .. '/Xdir'
+      au CmdlineEnter : ++once timer_start(0, () => script#func())
+      setline(1, 'some text')
+  END
+  writefile(lines, 'XTest_redraw_cpo')
+  var buf = RunVimInTerminal('-S XTest_redraw_cpo', {'rows': 6})
+  term_sendkeys(buf, "V:")
+  VerifyScreenDump(buf, 'Test_vim9_no_redraw', {})
+
+  # clean up
+  term_sendkeys(buf, "\<Esc>u")
+  StopVimInTerminal(buf)
+  delete('XTest_redraw_cpo')
+  delete('Xdir', 'rf')
+enddef
+
 
 def Test_unset_any_variable()
   var lines =<< trim END
index f3c79c82f34d29248dbec5f89aba6fb6ffa42ad4..5ae184e4ec64b618bdc96d7a702debd443d732bc 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2581,
 /**/
     2580,
 /**/
index e27bf8bb7406d934c47f30807c4ad0157a659e98..5dd69f6ee7a084871e2a9222c635313f023f068e 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1200,6 +1200,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define OPT_WINONLY    0x10    // only set window-local options
 #define OPT_NOWIN      0x20    // don't set window-local options
 #define OPT_ONECOLUMN  0x40    // list options one per line
+#define OPT_NO_REDRAW  0x80    // ignore redraw flags on option
 
 // Magic chars used in confirm dialog strings
 #define DLG_BUTTON_SEP '\n'
index 5ce7c3bdb7724e56e846c470067908f89cc3c98c..cd60b250f94cb5871e413993453e9e49e466165e 100644 (file)
@@ -75,7 +75,7 @@ ex_vim9script(exarg_T *eap UNUSED)
     if (STRCMP(p_cpo, CPO_VIM) != 0)
     {
        si->sn_save_cpo = vim_strsave(p_cpo);
-       set_option_value((char_u *)"cpo", 0L, (char_u *)CPO_VIM, 0);
+       set_option_value((char_u *)"cpo", 0L, (char_u *)CPO_VIM, OPT_NO_REDRAW);
     }
 #else
     // No check for this being the first command, it doesn't matter.