patch 8.1.2341: not so easy to interrupt a script programatically

Problem:    Not so easy to interrupt a script programatically.
Solution:   Add the interrupt() function. (Yasuhiro Matsumoto, closes #2834)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 6a9f9d6..075ef1b 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -114,6 +114,7 @@
 static void f_inputrestore(typval_T *argvars, typval_T *rettv);
 static void f_inputsave(typval_T *argvars, typval_T *rettv);
 static void f_inputsecret(typval_T *argvars, typval_T *rettv);
+static void f_interrupt(typval_T *argvars, typval_T *rettv);
 static void f_invert(typval_T *argvars, typval_T *rettv);
 static void f_islocked(typval_T *argvars, typval_T *rettv);
 #if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
@@ -509,6 +510,7 @@
     {"inputsave",	0, 0, 0,	  f_inputsave},
     {"inputsecret",	1, 2, FEARG_1,	  f_inputsecret},
     {"insert",		2, 3, FEARG_1,	  f_insert},
+    {"interrupt",	0, 0, 0,	  f_interrupt},
     {"invert",		1, 1, FEARG_1,	  f_invert},
     {"isdirectory",	1, 1, FEARG_1,	  f_isdirectory},
 #if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
@@ -4152,6 +4154,15 @@
 }
 
 /*
+ * "interrupt()" function
+ */
+    static void
+f_interrupt(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+{
+    got_int = TRUE;
+}
+
+/*
  * "invert(expr)" function
  */
     static void
diff --git a/src/ex_eval.c b/src/ex_eval.c
index f1a8b97..097280a 100644
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -85,6 +85,7 @@
  * until the throw point for error messages has been reached.  That is, during
  * cancellation of an expression evaluation after an aborting function call or
  * due to a parsing error, aborting() always returns the same value.
+ * "got_int" is also set by calling interrupt().
  */
     int
 aborting(void)
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 6b86b37..ac25420 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -154,6 +154,7 @@
 	test_increment \
 	test_increment_dbcs \
 	test_ins_complete \
+	test_interrupt \
 	test_job_fails \
 	test_join \
 	test_json \
@@ -361,6 +362,7 @@
 	test_increment.res \
 	test_increment_dbcs.res \
 	test_ins_complete.res \
+	test_interrupt.res \
 	test_job_fails.res \
 	test_json.res \
 	test_jumplist.res \
diff --git a/src/testdir/test_interrupt.vim b/src/testdir/test_interrupt.vim
new file mode 100644
index 0000000..111752d
--- /dev/null
+++ b/src/testdir/test_interrupt.vim
@@ -0,0 +1,27 @@
+" Test behavior of interrupt()
+
+let s:bufwritepre_called = 0
+let s:bufwritepost_called = 0
+
+func s:bufwritepre()
+  let s:bufwritepre_called = 1
+  call interrupt()
+endfunction
+
+func s:bufwritepost()
+  let s:bufwritepost_called = 1
+endfunction
+
+func Test_interrupt()
+  new Xfile
+  let n = 0
+  try
+    au BufWritePre Xfile call s:bufwritepre()
+    au BufWritePost Xfile call s:bufwritepost()
+    w!
+  catch /^Vim:Interrupt$/
+  endtry
+  call assert_equal(1, s:bufwritepre_called)
+  call assert_equal(0, s:bufwritepost_called)
+  call assert_equal(0, filereadable('Xfile'))
+endfunc
diff --git a/src/version.c b/src/version.c
index bebf220..bbc71be 100644
--- a/src/version.c
+++ b/src/version.c
@@ -738,6 +738,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2341,
+/**/
     2340,
 /**/
     2339,