]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1571: RedrawingDisabled not used consistently v9.0.1571
authorBram Moolenaar <Bram@vim.org>
Sat, 20 May 2023 13:07:00 +0000 (14:07 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 20 May 2023 13:07:00 +0000 (14:07 +0100)
Problem:    RedrawingDisabled not used consistently.
Solution:   Avoid RedrawingDisabled going negative.  Set RedrawingDisabled in
            win_split_ins(). (closes #11961)

16 files changed:
src/autocmd.c
src/buffer.c
src/cmdexpand.c
src/debugger.c
src/edit.c
src/ex_cmds.c
src/ex_docmd.c
src/ex_getln.c
src/insexpand.c
src/os_unix.c
src/popupmenu.c
src/screen.c
src/tag.c
src/userfunc.c
src/version.c
src/window.c

index 4fa8de76351ff032116b8daf66f9be691c37e92d..c93d4bd754d5f2f6994e7bc9b4a4e4bc3caf002d 100644 (file)
@@ -1602,10 +1602,7 @@ aucmd_prepbuf(
        p_acd = FALSE;
 #endif
 
-       // no redrawing and don't set the window title
-       ++RedrawingDisabled;
        (void)win_split_ins(0, WSP_TOP, auc_win, 0);
-       --RedrawingDisabled;
        (void)win_comp_pos();   // recompute window positions
        p_ea = save_ea;
 #ifdef FEAT_AUTOCHDIR
@@ -2334,7 +2331,8 @@ apply_autocmds_group(
            active_apc_list = patcmd.next;
     }
 
-    --RedrawingDisabled;
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
     autocmd_busy = save_autocmd_busy;
     filechangeshell_busy = FALSE;
     autocmd_nested = save_autocmd_nested;
index dc279ffb196e5025f59d79caa00d5b4babe28aff..ff7c50fae10c5e277d200c111f83e9d9ae6d642a 100644 (file)
@@ -2506,11 +2506,10 @@ buflist_getfile(
     }
 
     ++RedrawingDisabled;
+    int retval = FAIL;
     if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL,
                                     (options & GETF_SETMARK), lnum, forceit)))
     {
-       --RedrawingDisabled;
-
        // cursor is at to BOL and w_cursor.lnum is checked due to getfile()
        if (!p_sol && col != 0)
        {
@@ -2519,10 +2518,12 @@ buflist_getfile(
            curwin->w_cursor.coladd = 0;
            curwin->w_set_curswant = TRUE;
        }
-       return OK;
+       retval = OK;
     }
-    --RedrawingDisabled;
-    return FAIL;
+
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
+    return retval;
 }
 
 /*
index 4ef9c31121fe4f1f9e62f0a02dc99a07d24a6d18..46615383c03f470d61af3fd7c7ad55a4e5e1b3a0 100644 (file)
@@ -3937,14 +3937,12 @@ wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp)
 wildmenu_cleanup(cmdline_info_T *cclp UNUSED)
 {
     int skt = KeyTyped;
-#ifdef FEAT_EVAL
-    int old_RedrawingDisabled = RedrawingDisabled;
-#endif
 
     if (!p_wmnu || wild_menu_showing == 0)
        return;
 
 #ifdef FEAT_EVAL
+    int save_RedrawingDisabled = RedrawingDisabled;
     if (cclp->input_fn)
        RedrawingDisabled = 0;
 #endif
@@ -3974,7 +3972,7 @@ wildmenu_cleanup(cmdline_info_T *cclp UNUSED)
     wild_menu_showing = 0;
 #ifdef FEAT_EVAL
     if (cclp->input_fn)
-       RedrawingDisabled = old_RedrawingDisabled;
+       RedrawingDisabled = save_RedrawingDisabled;
 #endif
 }
 
index a04a07836121a08c87f4e01959288bd530297e2e..393e11e414fb4106c7c127136e0fd7ecc86feb77 100644 (file)
@@ -287,7 +287,8 @@ do_debug(char_u *cmd)
     }
     vim_free(cmdline);
 
-    --RedrawingDisabled;
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
     --no_wait_return;
     redraw_all_later(UPD_NOT_VALID);
     need_wait_return = FALSE;
index 64edddce8dd8f876b462034e74c1a4e5580ec409..a882d67feb679f881a3ed8016ec475da6c9fe5e0 100644 (file)
@@ -3613,7 +3613,8 @@ ins_esc(
     temp = curwin->w_cursor.col;
     if (disabled_redraw)
     {
-       --RedrawingDisabled;
+       if (RedrawingDisabled > 0)
+           --RedrawingDisabled;
        disabled_redraw = FALSE;
     }
     if (!arrow_used)
index 0fd6d10f71d6000356b55a46b4869dd3a00ef1ef..20d4d9a2eaad0061fbf7a10a9416dd40d1fadb40 100644 (file)
@@ -3219,7 +3219,8 @@ do_ecmd(
        (void)keymap_init();
 #endif
 
-    --RedrawingDisabled;
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
     did_inc_redrawing_disabled = FALSE;
     if (!skip_redraw)
     {
@@ -3263,7 +3264,7 @@ do_ecmd(
 #endif
 
 theend:
-    if (did_inc_redrawing_disabled)
+    if (did_inc_redrawing_disabled && RedrawingDisabled > 0)
        --RedrawingDisabled;
 #if defined(FEAT_EVAL)
     if (did_set_swapcommand)
@@ -3735,7 +3736,6 @@ ex_substitute(exarg_T *eap)
     int                sublen;
     int                got_quit = FALSE;
     int                got_match = FALSE;
-    int                temp;
     int                which_pat;
     char_u     *cmd;
     int                save_State;
@@ -4316,7 +4316,7 @@ ex_substitute(exarg_T *eap)
 #endif
                            // Invert the matched string.
                            // Remove the inversion afterwards.
-                           temp = RedrawingDisabled;
+                           int save_RedrawingDisabled = RedrawingDisabled;
                            RedrawingDisabled = 0;
 
                            // avoid calling update_screen() in vgetorpeek()
@@ -4386,7 +4386,7 @@ ex_substitute(exarg_T *eap)
                            msg_scroll = i;
                            showruler(TRUE);
                            windgoto(msg_row, msg_col);
-                           RedrawingDisabled = temp;
+                           RedrawingDisabled = save_RedrawingDisabled;
 
 #ifdef USE_ON_FLY_SCROLL
                            dont_scroll = FALSE; // allow scrolling here
index 430ca2ccb45550d6cd5871d46357b05d6e1ca9b7..69af1ca1d074bf0db54b49a1e32f09c6989d8677 100644 (file)
@@ -550,7 +550,8 @@ do_exmode(
 #ifdef FEAT_GUI
     --hold_gui_events;
 #endif
-    --RedrawingDisabled;
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
     --no_wait_return;
     update_screen(UPD_CLEAR);
     need_wait_return = FALSE;
@@ -631,7 +632,7 @@ do_cmdline(
     static int recursive = 0;          // recursive depth
     int                msg_didout_before_start = 0;
     int                count = 0;              // line number count
-    int                did_inc = FALSE;        // incremented RedrawingDisabled
+    int                did_inc_RedrawingDisabled = FALSE;
     int                retval = OK;
 #ifdef FEAT_EVAL
     cstack_T   cstack;                 // conditional stack
@@ -977,7 +978,7 @@ do_cmdline(
                msg_scroll = TRUE;  // put messages below each other
                ++no_wait_return;   // don't wait for return until finished
                ++RedrawingDisabled;
-               did_inc = TRUE;
+               did_inc_RedrawingDisabled = TRUE;
            }
        }
 
@@ -1336,9 +1337,10 @@ do_cmdline(
      * hit return before redrawing the screen. With the ":global" command we do
      * this only once after the command is finished.
      */
-    if (did_inc)
+    if (did_inc_RedrawingDisabled)
     {
-       --RedrawingDisabled;
+       if (RedrawingDisabled > 0)
+           --RedrawingDisabled;
        --no_wait_return;
        msg_scroll = FALSE;
 
@@ -7170,7 +7172,7 @@ do_exedit(
 
                if (exmode_was != EXMODE_VIM)
                    settmode(TMODE_RAW);
-               int save_rd = RedrawingDisabled;
+               int save_RedrawingDisabled = RedrawingDisabled;
                RedrawingDisabled = 0;
                int save_nwr = no_wait_return;
                no_wait_return = 0;
@@ -7187,7 +7189,7 @@ do_exedit(
                main_loop(FALSE, TRUE);
 
                pending_exmode_active = FALSE;
-               RedrawingDisabled = save_rd;
+               RedrawingDisabled = save_RedrawingDisabled;
                no_wait_return = save_nwr;
                msg_scroll = save_ms;
 #ifdef FEAT_GUI
@@ -8438,11 +8440,12 @@ ex_redraw(exarg_T *eap)
     void
 redraw_cmd(int clear)
 {
-    int                r = RedrawingDisabled;
-    int                p = p_lz;
-
+    int save_RedrawingDisabled = RedrawingDisabled;
     RedrawingDisabled = 0;
+
+    int save_p_lz = p_lz;
     p_lz = FALSE;
+
     validate_cursor();
     update_topline();
     update_screen(clear ? UPD_CLEAR : VIsual_active ? UPD_INVERTED : 0);
@@ -8454,8 +8457,8 @@ redraw_cmd(int clear)
 # endif
        resize_console_buf();
 #endif
-    RedrawingDisabled = r;
-    p_lz = p;
+    RedrawingDisabled = save_RedrawingDisabled;
+    p_lz = save_p_lz;
 
     // After drawing the statusline screen_attr may still be set.
     screen_stop_highlight();
@@ -8480,9 +8483,6 @@ redraw_cmd(int clear)
     static void
 ex_redrawstatus(exarg_T *eap UNUSED)
 {
-    int                r = RedrawingDisabled;
-    int                p = p_lz;
-
     if (eap->forceit)
        status_redraw_all();
     else
@@ -8490,14 +8490,18 @@ ex_redrawstatus(exarg_T *eap UNUSED)
     if (msg_scrolled && (State & MODE_CMDLINE))
        return;  // redraw later
 
+    int save_RedrawingDisabled = RedrawingDisabled;
     RedrawingDisabled = 0;
+
+    int save_p_lz = p_lz;
     p_lz = FALSE;
+
     if (State & MODE_CMDLINE)
        redraw_statuslines();
     else
        update_screen(VIsual_active ? UPD_INVERTED : 0);
-    RedrawingDisabled = r;
-    p_lz = p;
+    RedrawingDisabled = save_RedrawingDisabled;
+    p_lz = save_p_lz;
     out_flush();
 }
 
@@ -8507,16 +8511,16 @@ ex_redrawstatus(exarg_T *eap UNUSED)
     static void
 ex_redrawtabline(exarg_T *eap UNUSED)
 {
-    int                r = RedrawingDisabled;
-    int                p = p_lz;
-
+    int save_RedrawingDisabled = RedrawingDisabled;
     RedrawingDisabled = 0;
+
+    int save_p_lz = p_lz;
     p_lz = FALSE;
 
     draw_tabline();
 
-    RedrawingDisabled = r;
-    p_lz = p;
+    RedrawingDisabled = save_RedrawingDisabled;
+    p_lz = save_p_lz;
     out_flush();
 }
 
index 595286aa34a2529b8d6e21ad66cd5b433329e898..fbda2cc00db728dcabc9d21e9ce06998438593e7 100644 (file)
@@ -4545,7 +4545,7 @@ open_cmdwin(void)
     if (restart_edit != 0)     // autocmd with ":startinsert"
        stuffcharReadbuff(K_NOP);
 
-    i = RedrawingDisabled;
+    int save_RedrawingDisabled = RedrawingDisabled;
     RedrawingDisabled = 0;
 
     /*
@@ -4553,7 +4553,7 @@ open_cmdwin(void)
      */
     main_loop(TRUE, FALSE);
 
-    RedrawingDisabled = i;
+    RedrawingDisabled = save_RedrawingDisabled;
 
 # ifdef FEAT_FOLDING
     save_KeyTyped = KeyTyped;
index c20cb4f258b264cd9872a1b5a23fb683262bf7a2..3cfdface4413370334eda0031607fab42ab30976 100644 (file)
@@ -2969,12 +2969,13 @@ f_complete_add(typval_T *argvars, typval_T *rettv)
     void
 f_complete_check(typval_T *argvars UNUSED, typval_T *rettv)
 {
-    int                saved = RedrawingDisabled;
-
+    int save_RedrawingDisabled = RedrawingDisabled;
     RedrawingDisabled = 0;
+
     ins_compl_check_keys(0, TRUE);
     rettv->vval.v_number = ins_compl_interrupted();
-    RedrawingDisabled = saved;
+
+    RedrawingDisabled = save_RedrawingDisabled;
 }
 
 /*
@@ -5079,8 +5080,7 @@ ins_complete(int c, int enable_pum)
 show_pum(int prev_w_wrow, int prev_w_leftcol)
 {
     // RedrawingDisabled may be set when invoked through complete().
-    int n = RedrawingDisabled;
-
+    int save_RedrawingDisabled = RedrawingDisabled;
     RedrawingDisabled = 0;
 
     // If the cursor moved or the display scrolled we need to remove the pum
@@ -5091,7 +5091,8 @@ show_pum(int prev_w_wrow, int prev_w_leftcol)
 
     ins_compl_show_pum();
     setcursor();
-    RedrawingDisabled = n;
+
+    RedrawingDisabled = save_RedrawingDisabled;
 }
 
 /*
index 5bcac8560950d311039a72edbe3665667e8daa8a..194e4d31342fd75e3c596ad216bec6c62f041a9a 100644 (file)
@@ -4594,7 +4594,7 @@ mch_call_shell_terminal(
 
     // Only require pressing Enter when redrawing, to avoid that system() gets
     // the hit-enter prompt even though it didn't output anything.
-    if (!RedrawingDisabled)
+    if (RedrawingDisabled == 0)
        wait_return(TRUE);
     do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
 
index 7210420e1a0b61a740f7aef66d0385d7d566c953..651f51069399318645cf5c4e79868ebd32ea1d53 100644 (file)
@@ -865,7 +865,8 @@ pum_set_selected(int n, int repeat UNUSED)
            ++no_u_sync;
            resized = prepare_tagpreview(FALSE, FALSE, use_popup);
            --no_u_sync;
-           --RedrawingDisabled;
+           if (RedrawingDisabled > 0)
+               --RedrawingDisabled;
            g_do_tagpreview = 0;
 
            if (curwin->w_p_pvw
index 08e147d108e9fc69b9d6cf5e1e302e4c61e16efc..e9bc79267bdb2d156c5ab15374c4407d732a7cbf 100644 (file)
@@ -2696,7 +2696,8 @@ give_up:
 #endif
 
     entered = FALSE;
-    --RedrawingDisabled;
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
 
     /*
      * Do not apply autocommands more than 3 times to avoid an endless loop
@@ -4496,7 +4497,7 @@ redrawing(void)
        return 0;
     else
 #endif
-       return ((!RedrawingDisabled
+       return ((RedrawingDisabled == 0
 #ifdef FEAT_EVAL
                    || ignore_redraw_flag_for_testing
 #endif
index 1ee67b44dd277bde63028ca9010ba0fae82e7400..8003156f0f957b89c5a05c5f1663b5efb8824ea1 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -3829,7 +3829,8 @@ jumpto_tag(
        if (win_split(postponed_split > 0 ? postponed_split : 0,
                                                postponed_split_flags) == FAIL)
        {
-           --RedrawingDisabled;
+           if (RedrawingDisabled > 0)
+               --RedrawingDisabled;
            goto erret;
        }
        RESET_BINDING(curwin);
@@ -4032,11 +4033,13 @@ jumpto_tag(
        }
 #endif
 
-       --RedrawingDisabled;
+       if (RedrawingDisabled > 0)
+           --RedrawingDisabled;
     }
     else
     {
-       --RedrawingDisabled;
+       if (RedrawingDisabled > 0)
+           --RedrawingDisabled;
        got_int = FALSE;  // don't want entering window to fail
 
        if (postponed_split)            // close the window
index 6f0d59dfd36febd2baa408d9c144f56bae102770..5b2c876e3b53de42214a2bb99ddabe8b67204ad0 100644 (file)
@@ -3048,7 +3048,8 @@ call_user_func(
     // Invoke functions added with ":defer".
     handle_defer_one(current_funccal);
 
-    --RedrawingDisabled;
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
 
     // when the function was aborted because of an error, return -1
     if ((did_emsg && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN)
index 07fec75dcdefde366fb737b2a512511cf4b90c47..8d0d519e4d1961c1abf77b9a11e950a754d79a2f 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1571,
 /**/
     1570,
 /**/
index 18f07b17a4cba34fdc6ecb1d0bc7d5f0090f3d37..926a3f348fbf818a444a5f39812f96f8884dc0c4 100644 (file)
@@ -950,6 +950,10 @@ win_split_ins(
     int                minheight;
     int                wmh1;
     int                did_set_fraction = FALSE;
+    int                retval = FAIL;
+
+    // Do not redraw here, curwin->w_buffer may be invalid.
+    ++RedrawingDisabled;
 
     if (flags & WSP_TOP)
        oldwin = firstwin;
@@ -964,7 +968,7 @@ win_split_ins(
        if (VISIBLE_HEIGHT(oldwin) <= p_wmh && new_wp == NULL)
        {
            emsg(_(e_not_enough_room));
-           return FAIL;
+           goto theend;
        }
        need_status = STATUS_HEIGHT;
     }
@@ -1022,7 +1026,7 @@ win_split_ins(
        if (available < needed && new_wp == NULL)
        {
            emsg(_(e_not_enough_room));
-           return FAIL;
+           goto theend;
        }
        if (new_size == 0)
            new_size = oldwin->w_width / 2;
@@ -1105,7 +1109,7 @@ win_split_ins(
        if (available < needed && new_wp == NULL)
        {
            emsg(_(e_not_enough_room));
-           return FAIL;
+           goto theend;
        }
        oldwin_height = oldwin->w_height;
        if (need_status)
@@ -1188,13 +1192,13 @@ win_split_ins(
     if (new_wp == NULL)
     {
        if (wp == NULL)
-           return FAIL;
+           goto theend;
 
        new_frame(wp);
        if (wp->w_frame == NULL)
        {
            win_free(wp, NULL);
-           return FAIL;
+           goto theend;
        }
 
        // make the contents of the new window the same as the current one
@@ -1435,8 +1439,12 @@ win_split_ins(
        p_wiw = i;
     else
        p_wh = i;
+    retval = OK;
 
-    return OK;
+theend:
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
+    return retval;
 }
 
 
@@ -2460,7 +2468,8 @@ close_windows(
                }
     }
 
-    --RedrawingDisabled;
+    if (RedrawingDisabled > 0)
+       --RedrawingDisabled;
 
     if (count != tabpage_index(NULL))
        apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf);