patch 8.2.3528: 'thesaurus' and 'thesaurusfunc' do not have the same scope

Problem:    'thesaurus' and 'thesaurusfunc' do not have the same scope.
Solution:   Make 'thesaurusfunc' global-local.
diff --git a/src/insexpand.c b/src/insexpand.c
index bcaa3fd..6d5e556 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -301,7 +301,7 @@
 							)
 		 : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL
 #ifdef FEAT_COMPL_FUNC
-		     && *curbuf->b_p_tsrfu == NUL
+		     && *curbuf->b_p_tsrfu == NUL && *p_tsrfu == NUL
 #endif
 		   ))
     {
@@ -2246,7 +2246,7 @@
 	case CTRL_X_OMNI:
 	    return curbuf->b_p_ofu;
 	case CTRL_X_THESAURUS:
-	    return curbuf->b_p_tsrfu;
+	    return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : curbuf->b_p_tsrfu;
 	default:
 	    return (char_u *)"";
     }
@@ -2750,9 +2750,8 @@
 thesaurus_func_complete(int type UNUSED)
 {
 #ifdef FEAT_COMPL_FUNC
-    return (type == CTRL_X_THESAURUS
-		&& curbuf->b_p_tsrfu != NULL
-		&& *curbuf->b_p_tsrfu != NUL);
+    return type == CTRL_X_THESAURUS
+		&& (*curbuf->b_p_tsrfu != NUL || *p_tsrfu != NUL);
 #else
     return FALSE;
 #endif
diff --git a/src/option.c b/src/option.c
index 7d86ccf..e8afa7c 100644
--- a/src/option.c
+++ b/src/option.c
@@ -5131,6 +5131,11 @@
 	case PV_TSR:
 	    clear_string_option(&buf->b_p_tsr);
 	    break;
+#ifdef FEAT_COMPL_FUNC
+	case PV_TSRFU:
+	    clear_string_option(&buf->b_p_tsrfu);
+	    break;
+#endif
 	case PV_FP:
 	    clear_string_option(&buf->b_p_fp);
 	    break;
@@ -5225,6 +5230,9 @@
 #endif
 	    case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
 	    case PV_TSR:  return (char_u *)&(curbuf->b_p_tsr);
+#ifdef FEAT_COMPL_FUNC
+	    case PV_TSRFU: return (char_u *)&(curbuf->b_p_tsrfu);
+#endif
 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
 	    case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
 #endif
@@ -5305,6 +5313,10 @@
 				    ? (char_u *)&(curbuf->b_p_dict) : p->var;
 	case PV_TSR:	return *curbuf->b_p_tsr != NUL
 				    ? (char_u *)&(curbuf->b_p_tsr) : p->var;
+#ifdef FEAT_COMPL_FUNC
+	case PV_TSRFU:	return *curbuf->b_p_tsrfu != NUL
+				    ? (char_u *)&(curbuf->b_p_tsrfu) : p->var;
+#endif
 	case PV_FP:	return *curbuf->b_p_fp != NUL
 				    ? (char_u *)&(curbuf->b_p_fp) : p->var;
 #ifdef FEAT_QUICKFIX
@@ -5433,7 +5445,6 @@
 #ifdef FEAT_COMPL_FUNC
 	case PV_CFU:	return (char_u *)&(curbuf->b_p_cfu);
 	case PV_OFU:	return (char_u *)&(curbuf->b_p_ofu);
-	case PV_THSFU:	return (char_u *)&(curbuf->b_p_tsrfu);
 #endif
 #ifdef FEAT_EVAL
 	case PV_TFU:	return (char_u *)&(curbuf->b_p_tfu);
@@ -5936,8 +5947,6 @@
 	    COPY_OPT_SCTX(buf, BV_CFU);
 	    buf->b_p_ofu = vim_strsave(p_ofu);
 	    COPY_OPT_SCTX(buf, BV_OFU);
-	    buf->b_p_tsrfu = vim_strsave(p_thsfu);
-	    COPY_OPT_SCTX(buf, BV_THSFU);
 #endif
 #ifdef FEAT_EVAL
 	    buf->b_p_tfu = vim_strsave(p_tfu);
@@ -6080,6 +6089,9 @@
 #endif
 	    buf->b_p_dict = empty_option;
 	    buf->b_p_tsr = empty_option;
+#ifdef FEAT_COMPL_FUNC
+	    buf->b_p_tsrfu = empty_option;
+#endif
 #ifdef FEAT_TEXTOBJ
 	    buf->b_p_qe = vim_strsave(p_qe);
 	    COPY_OPT_SCTX(buf, BV_QE);
diff --git a/src/option.h b/src/option.h
index 89cec94..21ee569 100644
--- a/src/option.h
+++ b/src/option.h
@@ -404,7 +404,7 @@
 #ifdef FEAT_COMPL_FUNC
 EXTERN char_u	*p_cfu;		// 'completefunc'
 EXTERN char_u	*p_ofu;		// 'omnifunc'
-EXTERN char_u	*p_thsfu;	// 'thesaurusfunc'
+EXTERN char_u	*p_tsrfu;	// 'thesaurusfunc'
 #endif
 EXTERN int	p_ci;		// 'copyindent'
 #if defined(FEAT_GUI) && defined(MACOS_X)
@@ -1222,7 +1222,7 @@
     , BV_TAGS
     , BV_TC
 #ifdef FEAT_COMPL_FUNC
-    , BV_THSFU
+    , BV_TSRFU
 #endif
     , BV_TS
     , BV_TW
diff --git a/src/optiondefs.h b/src/optiondefs.h
index 042f055..d85c233 100644
--- a/src/optiondefs.h
+++ b/src/optiondefs.h
@@ -141,7 +141,7 @@
 # define PV_TFU		OPT_BUF(BV_TFU)
 #endif
 #ifdef FEAT_COMPL_FUNC
-# define PV_THSFU		OPT_BUF(BV_THSFU)
+# define PV_TSRFU	OPT_BOTH(OPT_BUF(BV_TSRFU))
 #endif
 #define PV_TAGS		OPT_BOTH(OPT_BUF(BV_TAGS))
 #define PV_TC		OPT_BOTH(OPT_BUF(BV_TC))
@@ -2634,7 +2634,7 @@
 			    {(char_u *)"", (char_u *)0L} SCTX_INIT},
     {"thesaurusfunc", "tsrfu",  P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
 #ifdef FEAT_COMPL_FUNC
-			    (char_u *)&p_thsfu, PV_THSFU,
+			    (char_u *)&p_tsrfu, PV_TSRFU,
 			    {(char_u *)"", (char_u *)0L}
 #else
 			    (char_u *)NULL, PV_NONE,
diff --git a/src/structs.h b/src/structs.h
index bd468a9..114135a 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -2864,7 +2864,6 @@
 #ifdef FEAT_COMPL_FUNC
     char_u	*b_p_cfu;	// 'completefunc'
     char_u	*b_p_ofu;	// 'omnifunc'
-    char_u	*b_p_tsrfu;	// 'thesaurusfunc'
 #endif
 #ifdef FEAT_EVAL
     char_u	*b_p_tfu;	// 'tagfunc'
@@ -2967,6 +2966,9 @@
     unsigned	b_tc_flags;     // flags for 'tagcase'
     char_u	*b_p_dict;	// 'dictionary' local value
     char_u	*b_p_tsr;	// 'thesaurus' local value
+#ifdef FEAT_COMPL_FUNC
+    char_u	*b_p_tsrfu;	// 'thesaurusfunc' local value
+#endif
     long	b_p_ul;		// 'undolevels' local value
 #ifdef FEAT_PERSISTENT_UNDO
     int		b_p_udf;	// 'undofile'
diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim
index 2cce85c..8e4254b 100644
--- a/src/testdir/test_edit.vim
+++ b/src/testdir/test_edit.vim
@@ -920,16 +920,24 @@
 
 func Test_thesaurus_func()
   new
-  set thesaurus=
-  set thesaurusfunc=MyThesaurus
+  set thesaurus=notused
+  set thesaurusfunc=NotUsed
+  setlocal thesaurusfunc=MyThesaurus
   call setline(1, "an ki")
   call cursor(1, 1)
   call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix')
   call assert_equal(['an amiable', ''], getline(1, '$'))
+
+  setlocal thesaurusfunc=NonExistingFunc
+  call assert_fails("normal $a\<C-X>\<C-T>", 'E117:')
+
+  setlocal thesaurusfunc=
   set thesaurusfunc=NonExistingFunc
   call assert_fails("normal $a\<C-X>\<C-T>", 'E117:')
-  set thesaurusfunc&
   %bw!
+
+  set thesaurusfunc=
+  set thesaurus=
 endfunc
 
 func Test_edit_CTRL_U()
diff --git a/src/version.c b/src/version.c
index 3013dfc..b1fc4dc 100644
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3528,
+/**/
     3527,
 /**/
     3526,