patch 9.0.1130: unexpected output when autoloading a script

Problem:    Unexpected output when autoloading a script for an interactive
            operation.
Solution:   Reset "KeyTyped" while loading a script and when handling a nested
            function. (closes #11773)
diff --git a/src/scriptfile.c b/src/scriptfile.c
index d348631..4b1fa6b 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -1334,10 +1334,10 @@
  * When "ret_sid" is not NULL and we loaded the script before, don't load it
  * again.
  *
- * The 'eap' argument is used when sourcing lines from a buffer instead of a
+ * The "eap" argument is used when sourcing lines from a buffer instead of a
  * file.
  *
- * If 'clearvars' is TRUE, then for scripts which are loaded more than
+ * If "clearvars" is TRUE, then for scripts which are loaded more than
  * once, clear all the functions and variables previously defined in that
  * script.
  *
@@ -1538,6 +1538,7 @@
 	current_sctx.sc_version = SCRIPT_VERSION_VIM9;
     else
 	current_sctx.sc_version = 1;  // default script version
+    current_sctx.sc_lnum = 0;
 
 #ifdef FEAT_EVAL
 # ifdef FEAT_PROFILE
@@ -1549,7 +1550,10 @@
     // Also starts profiling timer for nested script.
     save_funccal(&funccalp_entry);
 
-    current_sctx.sc_lnum = 0;
+    // Reset "KeyTyped" to avoid some commands thinking they are invoked
+    // interactively.  E.g. defining a function would output indent.
+    int save_KeyTyped = KeyTyped;
+    KeyTyped = FALSE;
 
     // Check if this script was sourced before to find its SID.
     // Always use a new sequence number.
@@ -1765,6 +1769,7 @@
 # endif
 #endif
     current_sctx = save_current_sctx;
+    KeyTyped = save_KeyTyped;
 
     if (cookie.fp != NULL)
 	fclose(cookie.fp);
diff --git a/src/testdir/dumps/Test_keytyped_in_nested_func.dump b/src/testdir/dumps/Test_keytyped_in_nested_func.dump
new file mode 100644
index 0000000..46bebea
--- /dev/null
+++ b/src/testdir/dumps/Test_keytyped_in_nested_func.dump
@@ -0,0 +1,6 @@
+| +0&#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|:+0#0000000&|"> @72
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 3840d11..be07aec 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
Binary files differ
diff --git a/src/version.c b/src/version.c
index cb4889d..212d08d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1130,
+/**/
     1129,
 /**/
     1128,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 0e6c32c..c5b41da 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -987,7 +987,14 @@
 	goto theend;
     }
 
+    // Make sure "KeyTyped" is not set, it may cause indent to be written.
+    int save_KeyTyped = KeyTyped;
+    KeyTyped = FALSE;
+
     ufunc = define_function(eap, lambda_name, lines_to_free, FALSE);
+
+    KeyTyped = save_KeyTyped;
+
     if (ufunc == NULL)
     {
 	r = eap->skip ? OK : FAIL;