patch 9.1.0231: Filetype may be undetected when SwapExists sets ft in other buf

Problem:  Filetype may be undetected when a SwapExists autocommand sets
          filetype in another buffer.
Solution: Make filetype detection state buffer-specific.  Also fix a
          similar problem for 'modified' (zeertzjq).

closes: #14344

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/fileio.c b/src/fileio.c
index 53bfbea..07e05fc 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -225,7 +225,7 @@
     int		may_need_lseek = FALSE;
 #endif
 
-    au_did_filetype = FALSE; // reset before triggering any autocommands
+    curbuf->b_au_did_filetype = FALSE; // reset before triggering any autocommands
 
     curbuf->b_no_eol_lnum = 0;	// in case it was set by the previous read
 
@@ -2696,7 +2696,7 @@
 	{
 	    apply_autocmds_exarg(EVENT_BUFREADPOST, NULL, sfname,
 							  FALSE, curbuf, eap);
-	    if (!au_did_filetype && *curbuf->b_p_ft != NUL)
+	    if (!curbuf->b_au_did_filetype && *curbuf->b_p_ft != NUL)
 		/*
 		 * EVENT_FILETYPE was not triggered but the buffer already has a
 		 * filetype. Trigger EVENT_FILETYPE using the existing filetype.
@@ -4492,7 +4492,7 @@
 	    int old_msg_silent = msg_silent;
 
 	    curbuf->b_flags |= BF_CHECK_RO;	// check for RO again
-	    keep_filetype = TRUE;		// don't detect 'filetype'
+	    curbuf->b_keep_filetype = TRUE;	// don't detect 'filetype'
 
 	    if (shortmess(SHM_FILEINFO))
 		msg_silent = 1;
@@ -4549,7 +4549,7 @@
 	curwin->w_cursor = old_cursor;
 	check_cursor();
 	update_topline();
-	keep_filetype = FALSE;
+	curbuf->b_keep_filetype = FALSE;
 #ifdef FEAT_FOLDING
 	{
 	    win_T	*wp;