@@ -82,6 +82,9 @@ open_buffer(read_stdin, eap, flags)
8282#ifdef FEAT_AUTOCMD
8383 buf_T * old_curbuf ;
8484#endif
85+ #ifdef FEAT_SYN_HL
86+ long old_tw = curbuf -> b_p_tw ;
87+ #endif
8588
8689 /*
8790 * The 'readonly' flag is only set when BF_NEVERLOADED is being reset.
@@ -113,6 +116,10 @@ open_buffer(read_stdin, eap, flags)
113116 }
114117 EMSG (_ ("E83: Cannot allocate buffer, using other one..." ));
115118 enter_buffer (curbuf );
119+ #ifdef FEAT_SYN_HL
120+ if (old_tw != curbuf -> b_p_tw )
121+ check_colorcolumn (curwin );
122+ #endif
116123 return FAIL ;
117124 }
118125
@@ -786,6 +793,9 @@ handle_swap_exists(old_curbuf)
786793# if defined(FEAT_AUTOCMD ) && defined(FEAT_EVAL )
787794 cleanup_T cs ;
788795# endif
796+ #ifdef FEAT_SYN_HL
797+ long old_tw = curbuf -> b_p_tw ;
798+ #endif
789799
790800 if (swap_exists_action == SEA_QUIT )
791801 {
@@ -804,7 +814,13 @@ handle_swap_exists(old_curbuf)
804814 if (!buf_valid (old_curbuf ) || old_curbuf == curbuf )
805815 old_curbuf = buflist_new (NULL , NULL , 1L , BLN_CURBUF | BLN_LISTED );
806816 if (old_curbuf != NULL )
817+ {
807818 enter_buffer (old_curbuf );
819+ #ifdef FEAT_SYN_HL
820+ if (old_tw != curbuf -> b_p_tw )
821+ check_colorcolumn (curwin );
822+ #endif
823+ }
808824 /* If "old_curbuf" is NULL we are in big trouble here... */
809825
810826# if defined(FEAT_AUTOCMD ) && defined(FEAT_EVAL )
@@ -1364,6 +1380,9 @@ set_curbuf(buf, action)
13641380 buf_T * prevbuf ;
13651381 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
13661382 || action == DOBUF_WIPE );
1383+ #ifdef FEAT_SYN_HL
1384+ long old_tw = curbuf -> b_p_tw ;
1385+ #endif
13671386
13681387 setpcmark ();
13691388 if (!cmdmod .keepalt )
@@ -1430,21 +1449,24 @@ set_curbuf(buf, action)
14301449# endif
14311450 )
14321451#endif
1452+ {
14331453 enter_buffer (buf );
1454+ #ifdef FEAT_SYN_HL
1455+ if (old_tw != curbuf -> b_p_tw )
1456+ check_colorcolumn (curwin );
1457+ #endif
1458+ }
14341459}
14351460
14361461/*
14371462 * Enter a new current buffer.
1438- * Old curbuf must have been abandoned already!
1463+ * Old curbuf must have been abandoned already! This also means "curbuf" may
1464+ * be pointing to freed memory.
14391465 */
14401466 void
14411467enter_buffer (buf )
14421468 buf_T * buf ;
14431469{
1444- #ifdef FEAT_SYN_HL
1445- long old_tw = curbuf -> b_p_tw ;
1446- #endif
1447-
14481470 /* Copy buffer and window local option values. Not for a help buffer. */
14491471 buf_copy_options (buf , BCO_ENTER | BCO_NOHELP );
14501472 if (!buf -> b_help )
@@ -1468,8 +1490,6 @@ enter_buffer(buf)
14681490
14691491#ifdef FEAT_SYN_HL
14701492 curwin -> w_s = & (buf -> b_s );
1471- if (old_tw != buf -> b_p_tw )
1472- check_colorcolumn (curwin );
14731493#endif
14741494
14751495 /* Cursor on first line by default. */
0 commit comments