patch 9.1.0864: message history is fixed to 200

Problem:  message history is fixed to 200
Solution: Add the 'msghistory' option, increase the default
          value to 500 (Shougo Matsushita)

closes: #16048

Co-authored-by: Milly <milly.ca@gmail.com>
Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/feature.h b/src/feature.h
index 5fcd727..bcfc4a4 100644
--- a/src/feature.h
+++ b/src/feature.h
@@ -138,11 +138,6 @@
  */
 
 /*
- * Message history is fixed at 200 messages.
- */
-#define MAX_MSG_HIST_LEN 200
-
-/*
  * +folding		Fold lines.
  */
 #ifdef FEAT_NORMAL
diff --git a/src/message.c b/src/message.c
index 576d922..5853e47 100644
--- a/src/message.c
+++ b/src/message.c
@@ -1013,7 +1013,7 @@
 	return;
 
     // Don't let the message history get too big
-    while (msg_hist_len > MAX_MSG_HIST_LEN)
+    while (msg_hist_len > p_mhi)
 	(void)delete_first_msg();
 
     // allocate an entry and add the message at the end of the history
diff --git a/src/option.c b/src/option.c
index dcb5752..4616d63 100644
--- a/src/option.c
+++ b/src/option.c
@@ -4914,6 +4914,16 @@
 	errmsg = e_invalid_argument;
 	p_hi = 10000;
     }
+    if (p_mhi < 0)
+    {
+	errmsg = e_argument_must_be_positive;
+	p_mhi = 0;
+    }
+    else if (p_mhi > 10000)
+    {
+	errmsg = e_invalid_argument;
+	p_mhi = 10000;
+    }
     if (p_re < 0 || p_re > 2)
     {
 	errmsg = e_invalid_argument;
diff --git a/src/option.h b/src/option.h
index d5f72a1..18a7c2a 100644
--- a/src/option.h
+++ b/src/option.h
@@ -794,6 +794,7 @@
 #endif
 EXTERN long	p_mouset;	// 'mousetime'
 EXTERN int	p_more;		// 'more'
+EXTERN long	p_mhi;		// 'msghistory'
 #ifdef FEAT_MZSCHEME
 EXTERN long	p_mzq;		// 'mzquantum
 # if defined(DYNAMIC_MZSCHEME)
diff --git a/src/optiondefs.h b/src/optiondefs.h
index 585604f..81bb1db 100644
--- a/src/optiondefs.h
+++ b/src/optiondefs.h
@@ -1778,6 +1778,9 @@
     {"mousetime",   "mouset",	P_NUM|P_VI_DEF,
 			    (char_u *)&p_mouset, PV_NONE, NULL, NULL,
 			    {(char_u *)500L, (char_u *)0L} SCTX_INIT},
+    {"msghistory","mhi",    P_NUM|P_VI_DEF,
+			    (char_u *)&p_mhi, PV_NONE, NULL, NULL,
+			    {(char_u *)500L, (char_u *)0L} SCTX_INIT},
     {"mzquantum",  "mzq",   P_NUM,
 #ifdef FEAT_MZSCHEME
 			    (char_u *)&p_mzq, PV_NONE, did_set_mzquantum, NULL,
diff --git a/src/testdir/gen_opt_test.vim b/src/testdir/gen_opt_test.vim
index afea28b..ac9401e 100644
--- a/src/testdir/gen_opt_test.vim
+++ b/src/testdir/gen_opt_test.vim
@@ -85,6 +85,7 @@
       \ 'imstyle': [[0, 1], [-1, 2, 999]],
       \ 'lines': [[2, 24, 1000], [-1, 0, 1]],
       \ 'linespace': [[-1, 0, 2, 4, 999], ['']],
+      \ 'msghistory': [[0, 1, 100, 10000], [-1, 10001]],
       \ 'numberwidth': [[1, 4, 8, 10, 11, 20], [-1, 0, 21]],
       \ 'regexpengine': [[0, 1, 2], [-1, 3, 999]],
       \ 'report': [[0, 1, 2, 9999], [-1]],
diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim
index bd9da73..09a41f7 100644
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -732,6 +732,7 @@
   call assert_fails('set backupcopy=', 'E474:')
   call assert_fails('set regexpengine=3', 'E474:')
   call assert_fails('set history=10001', 'E474:')
+  call assert_fails('set msghistory=10001', 'E474:')
   call assert_fails('set numberwidth=21', 'E474:')
   call assert_fails('set colorcolumn=-a', 'E474:')
   call assert_fails('set colorcolumn=a', 'E474:')
@@ -745,6 +746,7 @@
   endif
   call assert_fails('set helpheight=-1', 'E487:')
   call assert_fails('set history=-1', 'E487:')
+  call assert_fails('set msghistory=-1', 'E487:')
   call assert_fails('set report=-1', 'E487:')
   call assert_fails('set shiftwidth=-1', 'E487:')
   call assert_fails('set sidescroll=-1', 'E487:')
diff --git a/src/version.c b/src/version.c
index d0aa403..cbc4a8e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    864,
+/**/
     863,
 /**/
     862,