@@ -10106,20 +10106,62 @@ update_topline_cursor(void)
1010610106 update_curswant ();
1010710107}
1010810108
10109+ /*
10110+ * Save the current State and go to Normal mode.
10111+ * Return TRUE if the typeahead could be saved.
10112+ */
10113+ int
10114+ save_current_state (save_state_T * sst )
10115+ {
10116+ sst -> save_msg_scroll = msg_scroll ;
10117+ sst -> save_restart_edit = restart_edit ;
10118+ sst -> save_msg_didout = msg_didout ;
10119+ sst -> save_State = State ;
10120+ sst -> save_insertmode = p_im ;
10121+ sst -> save_finish_op = finish_op ;
10122+ sst -> save_opcount = opcount ;
10123+
10124+ msg_scroll = FALSE; /* no msg scrolling in Normal mode */
10125+ restart_edit = 0 ; /* don't go to Insert mode */
10126+ p_im = FALSE; /* don't use 'insertmode' */
10127+
10128+ /*
10129+ * Save the current typeahead. This is required to allow using ":normal"
10130+ * from an event handler and makes sure we don't hang when the argument
10131+ * ends with half a command.
10132+ */
10133+ save_typeahead (& sst -> tabuf );
10134+ return sst -> tabuf .typebuf_valid ;
10135+ }
10136+
10137+ void
10138+ restore_current_state (save_state_T * sst )
10139+ {
10140+ /* Restore the previous typeahead. */
10141+ restore_typeahead (& sst -> tabuf );
10142+
10143+ msg_scroll = sst -> save_msg_scroll ;
10144+ restart_edit = sst -> save_restart_edit ;
10145+ p_im = sst -> save_insertmode ;
10146+ finish_op = sst -> save_finish_op ;
10147+ opcount = sst -> save_opcount ;
10148+ msg_didout |= sst -> save_msg_didout ; /* don't reset msg_didout now */
10149+
10150+ /* Restore the state (needed when called from a function executed for
10151+ * 'indentexpr'). Update the mouse and cursor, they may have changed. */
10152+ State = sst -> save_State ;
10153+ #ifdef CURSOR_SHAPE
10154+ ui_cursor_shape (); /* may show different cursor shape */
10155+ #endif
10156+ }
10157+
1010910158/*
1011010159 * ":normal[!] {commands}": Execute normal mode commands.
1011110160 */
1011210161 void
1011310162ex_normal (exarg_T * eap )
1011410163{
10115- int save_msg_scroll = msg_scroll ;
10116- int save_restart_edit = restart_edit ;
10117- int save_msg_didout = msg_didout ;
10118- int save_State = State ;
10119- tasave_T tabuf ;
10120- int save_insertmode = p_im ;
10121- int save_finish_op = finish_op ;
10122- int save_opcount = opcount ;
10164+ save_state_T save_state ;
1012310165#ifdef FEAT_MBYTE
1012410166 char_u * arg = NULL ;
1012510167 int l ;
@@ -10136,11 +10178,6 @@ ex_normal(exarg_T *eap)
1013610178 EMSG (_ ("E192: Recursive use of :normal too deep" ));
1013710179 return ;
1013810180 }
10139- ++ ex_normal_busy ;
10140-
10141- msg_scroll = FALSE; /* no msg scrolling in Normal mode */
10142- restart_edit = 0 ; /* don't go to Insert mode */
10143- p_im = FALSE; /* don't use 'insertmode' */
1014410181
1014510182#ifdef FEAT_MBYTE
1014610183 /*
@@ -10206,13 +10243,8 @@ ex_normal(exarg_T *eap)
1020610243 }
1020710244#endif
1020810245
10209- /*
10210- * Save the current typeahead. This is required to allow using ":normal"
10211- * from an event handler and makes sure we don't hang when the argument
10212- * ends with half a command.
10213- */
10214- save_typeahead (& tabuf );
10215- if (tabuf .typebuf_valid )
10246+ ++ ex_normal_busy ;
10247+ if (save_current_state (& save_state ))
1021610248 {
1021710249 /*
1021810250 * Repeat the :normal command for each line in the range. When no
@@ -10240,20 +10272,8 @@ ex_normal(exarg_T *eap)
1024010272 /* Might not return to the main loop when in an event handler. */
1024110273 update_topline_cursor ();
1024210274
10243- /* Restore the previous typeahead. */
10244- restore_typeahead (& tabuf );
10245-
10275+ restore_current_state (& save_state );
1024610276 -- ex_normal_busy ;
10247- msg_scroll = save_msg_scroll ;
10248- restart_edit = save_restart_edit ;
10249- p_im = save_insertmode ;
10250- finish_op = save_finish_op ;
10251- opcount = save_opcount ;
10252- msg_didout |= save_msg_didout ; /* don't reset msg_didout now */
10253-
10254- /* Restore the state (needed when called from a function executed for
10255- * 'indentexpr'). Update the mouse and cursor, they may have changed. */
10256- State = save_State ;
1025710277#ifdef FEAT_MOUSE
1025810278 setmouse ();
1025910279#endif
0 commit comments