@@ -124,7 +124,7 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T
124124static void fill_foldcolumn (char_u * p , win_T * wp , int closed , linenr_T lnum );
125125static void copy_text_attr (int off , char_u * buf , int len , int attr );
126126#endif
127- static int win_line (win_T * , linenr_T , int , int , int nochange );
127+ static int win_line (win_T * , linenr_T , int , int , int nochange , proftime_T * syntax_tm );
128128static int char_needs_redraw (int off_from , int off_to , int cols );
129129#ifdef FEAT_RIGHTLEFT
130130static void screen_line (int row , int coloff , int endcol , int clear_width , int rlflag );
@@ -185,6 +185,11 @@ static void win_redr_ruler(win_T *wp, int always);
185185static int screen_char_attr = 0 ;
186186#endif
187187
188+ #if defined(FEAT_SYN_HL ) && defined(FEAT_RELTIME )
189+ /* Can limit syntax highlight time to 'redrawtime'. */
190+ # define SYN_TIME_LIMIT 1
191+ #endif
192+
188193/*
189194 * Redraw the current window later, with update_screen(type).
190195 * Set must_redraw only if not already set to a higher value.
@@ -923,6 +928,9 @@ update_single_line(win_T *wp, linenr_T lnum)
923928{
924929 int row ;
925930 int j ;
931+ #ifdef SYN_TIME_LIMIT
932+ proftime_T syntax_tm ;
933+ #endif
926934
927935 /* Don't do anything if the screen structures are (not yet) valid. */
928936 if (!screen_valid (TRUE) || updating_screen )
@@ -931,6 +939,10 @@ update_single_line(win_T *wp, linenr_T lnum)
931939 if (lnum >= wp -> w_topline && lnum < wp -> w_botline
932940 && foldedCount (wp , lnum , & win_foldinfo ) == 0 )
933941 {
942+ #ifdef SYN_TIME_LIMIT
943+ /* Set the time limit to 'redrawtime'. */
944+ profile_setlimit (p_rdt , & syntax_tm );
945+ #endif
934946 update_prepare ();
935947
936948 row = 0 ;
@@ -944,7 +956,13 @@ update_single_line(win_T *wp, linenr_T lnum)
944956 start_search_hl ();
945957 prepare_search_hl (wp , lnum );
946958# endif
947- win_line (wp , lnum , row , row + wp -> w_lines [j ].wl_size , FALSE);
959+ win_line (wp , lnum , row , row + wp -> w_lines [j ].wl_size , FALSE,
960+ #ifdef SYN_TIME_LIMIT
961+ & syntax_tm
962+ #else
963+ NULL
964+ #endif
965+ );
948966# if defined(FEAT_SEARCH_EXTRA )
949967 end_search_hl ();
950968# endif
@@ -1140,6 +1158,9 @@ win_update(win_T *wp)
11401158#if defined(FEAT_SYN_HL ) || defined(FEAT_SEARCH_EXTRA )
11411159 int save_got_int ;
11421160#endif
1161+ #ifdef SYN_TIME_LIMIT
1162+ proftime_T syntax_tm ;
1163+ #endif
11431164
11441165 type = wp -> w_redr_type ;
11451166
@@ -1792,6 +1813,10 @@ win_update(win_T *wp)
17921813 save_got_int = got_int ;
17931814 got_int = 0 ;
17941815#endif
1816+ #ifdef SYN_TIME_LIMIT
1817+ /* Set the time limit to 'redrawtime'. */
1818+ profile_setlimit (p_rdt , & syntax_tm );
1819+ #endif
17951820#ifdef FEAT_FOLDING
17961821 win_foldinfo .fi_level = 0 ;
17971822#endif
@@ -2086,7 +2111,13 @@ win_update(win_T *wp)
20862111 /*
20872112 * Display one line.
20882113 */
2089- row = win_line (wp , lnum , srow , wp -> w_height , mod_top == 0 );
2114+ row = win_line (wp , lnum , srow , wp -> w_height , mod_top == 0 ,
2115+ #ifdef SYN_TIME_LIMIT
2116+ & syntax_tm
2117+ #else
2118+ NULL
2119+ #endif
2120+ );
20902121
20912122#ifdef FEAT_FOLDING
20922123 wp -> w_lines [idx ].wl_folded = FALSE;
@@ -2957,7 +2988,8 @@ win_line(
29572988 linenr_T lnum ,
29582989 int startrow ,
29592990 int endrow ,
2960- int nochange UNUSED ) /* not updating for changed text */
2991+ int nochange UNUSED , /* not updating for changed text */
2992+ proftime_T * syntax_tm )
29612993{
29622994 int col = 0 ; /* visual column on screen */
29632995 unsigned off ; /* offset in ScreenLines/ScreenAttrs */
@@ -3158,20 +3190,29 @@ win_line(
31583190 extra_check = 0 ;
31593191#endif
31603192#ifdef FEAT_SYN_HL
3161- if (syntax_present (wp ) && !wp -> w_s -> b_syn_error )
3193+ if (syntax_present (wp ) && !wp -> w_s -> b_syn_error
3194+ # ifdef SYN_TIME_LIMIT
3195+ && !wp -> w_s -> b_syn_slow
3196+ # endif
3197+ )
31623198 {
31633199 /* Prepare for syntax highlighting in this line. When there is an
31643200 * error, stop syntax highlighting. */
31653201 save_did_emsg = did_emsg ;
31663202 did_emsg = FALSE;
3167- syntax_start (wp , lnum );
3203+ syntax_start (wp , lnum , syntax_tm );
31683204 if (did_emsg )
31693205 wp -> w_s -> b_syn_error = TRUE;
31703206 else
31713207 {
31723208 did_emsg = save_did_emsg ;
3173- has_syntax = TRUE;
3174- extra_check = TRUE;
3209+ #ifdef SYN_TIME_LIMIT
3210+ if (!wp -> w_s -> b_syn_slow )
3211+ #endif
3212+ {
3213+ has_syntax = TRUE;
3214+ extra_check = TRUE;
3215+ }
31753216 }
31763217 }
31773218
@@ -3548,7 +3589,7 @@ win_line(
35483589# ifdef FEAT_SYN_HL
35493590 /* Need to restart syntax highlighting for this line. */
35503591 if (has_syntax )
3551- syntax_start (wp , lnum );
3592+ syntax_start (wp , lnum , syntax_tm );
35523593# endif
35533594 }
35543595#endif
@@ -4491,6 +4532,10 @@ win_line(
44914532 }
44924533 else
44934534 did_emsg = save_did_emsg ;
4535+ #ifdef SYN_TIME_LIMIT
4536+ if (wp -> w_s -> b_syn_slow )
4537+ has_syntax = FALSE;
4538+ #endif
44944539
44954540 /* Need to get the line again, a multi-line regexp may
44964541 * have made it invalid. */
0 commit comments