patch 9.0.0285: it is not easy to change the command line from a plugin

Problem:    It is not easy to change the command line from a plugin.
Solution:   Add setcmdline(). (Shougo Matsushita, closes #10869)
diff --git a/src/ex_getln.c b/src/ex_getln.c
index 2ef66ab..587a9ff 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -4211,6 +4211,35 @@
     rettv->vval.v_number = get_cmdline_screen_pos() + 1;
 }
 
+// Set the command line str to "str".
+// Returns 1 when failed, 0 when OK.
+    int
+set_cmdline_str(char_u *str, int pos)
+{
+    cmdline_info_T  *p = get_ccline_ptr();
+    int		    cmdline_type;
+    int		    len;
+
+    if (p == NULL)
+	return 1;
+
+    len = (int)STRLEN(str);
+    realloc_cmdbuff(len + 1);
+    p->cmdlen = len;
+    STRCPY(p->cmdbuff, str);
+
+    p->cmdpos = pos < 0 || pos > p->cmdlen ? p->cmdlen : pos;
+    new_cmdpos = p->cmdpos;
+
+    redrawcmd();
+
+    // Trigger CmdlineChanged autocommands.
+    cmdline_type = ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc;
+    trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED);
+
+    return 0;
+}
+
 /*
  * Set the command line byte position to "pos".  Zero is the first position.
  * Only works when the command line is being edited.
@@ -4234,6 +4263,35 @@
     return 0;
 }
 
+// "setcmdline()" function
+    void
+f_setcmdline(typval_T *argvars, typval_T *rettv)
+{
+    int pos = -1;
+
+    if (argvars[0].v_type != VAR_STRING || argvars[0].vval.v_string == NULL)
+    {
+	emsg(_(e_string_required));
+	return;
+    }
+
+    if (argvars[1].v_type != VAR_UNKNOWN)
+    {
+	int error = FALSE;
+
+	pos = (int)tv_get_number_chk(&argvars[1], &error) - 1;
+	if (error)
+	    return;
+	if (pos < 0)
+	{
+	    emsg(_(e_argument_must_be_positive));
+	    return;
+	}
+    }
+
+    rettv->vval.v_number = set_cmdline_str(argvars[0].vval.v_string, pos);
+}
+
 /*
  * "setcmdpos()" function
  */